uri-resolver/src/test/java/GeonetworkQueryTest.java

90 lines
2.8 KiB
Java

import it.geosolutions.geonetwork.util.GNSearchRequest;
import it.geosolutions.geonetwork.util.GNSearchResponse;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.spatial.data.geonetwork.GeoNetwork;
import org.gcube.spatial.data.geonetwork.GeoNetworkPublisher;
import org.gcube.spatial.data.geonetwork.GeoNetworkReader;
import org.gcube.spatial.data.geonetwork.LoginLevel;
import org.gcube.spatial.data.geonetwork.configuration.Configuration;
import org.gcube.spatial.data.geonetwork.model.Account;
import org.gcube.spatial.data.geonetwork.model.Account.Type;
import org.junit.Test;
/**
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* Aug 31, 2016
*/
public class GeonetworkQueryTest {
private static final int MAX = 10;
private String[] scopes = {"/gcube/devsec"};
private String[] scopesProd = {"/d4science.research-infrastructures.eu"};
private LoginLevel loginLevel = LoginLevel.CKAN;
private Type accountType = Type.CKAN;
// @Test
public void getCount() throws Exception{
try{
for(String scope:scopes){
ScopeProvider.instance.set(scope);
GeoNetworkPublisher reader=GeoNetwork.get();
reader.login(loginLevel);
Configuration config = reader.getConfiguration();
Account account=config.getScopeConfiguration().getAccounts().get(accountType);
System.out.println("User: "+account.getUser()+", Pwd: "+account.getPassword());
// req.addParam("keyword", "Thredds");
final GNSearchRequest req=new GNSearchRequest();
req.addParam(GNSearchRequest.Param.any,"Thredds");
GNSearchResponse resp = reader.query(req);
int publicCount= resp.getCount();
int totalCount=resp.getCount();
System.out.println("SCOPE "+scope+" found "+totalCount+" (public : "+publicCount+", private :"+(totalCount-publicCount)+")");
if(totalCount==0)
return;
for(int i=0; i<MAX; i++){
String xml = reader.getByIdAsRawString(resp.getMetadata(i).getUUID());
System.out.println(i+") is Thredds? "+containsString(xml, "Thredds"));
}
}
}catch(Exception e){
e.printStackTrace();
}
}
private boolean containsString(String txt, String value){
return txt.contains(value);
}
@Test
public void getCountProd() throws Exception{
try{
for(String scope:scopesProd){
ScopeProvider.instance.set(scope);
GeoNetworkReader reader=GeoNetwork.get();
final GNSearchRequest req=new GNSearchRequest();
// req.addParam("keyword", "Thredds");
req.addParam(GNSearchRequest.Param.any,"Thredds");
int publicCount=reader.query(req).getCount();
reader.login(loginLevel);
int totalCount=reader.query(req).getCount();
System.out.println("SCOPE "+scope+" found "+totalCount+" (public : "+publicCount+", private :"+(totalCount-publicCount)+")");
}
}catch (Exception e) {
e.printStackTrace();
}
}
}