Updated test classes

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/data-transfer/uri-resolver@131221 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Francesco Mangiacrapa 2016-09-08 13:29:57 +00:00
parent c42dbf04a0
commit cf2e1c8e36
3 changed files with 128 additions and 78 deletions

View File

@ -9,10 +9,6 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.StringReader;
import java.io.UnsupportedEncodingException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.Enumeration;
import java.util.HashMap;
@ -501,68 +497,4 @@ public class GeonetworkResolver extends HttpServlet{
response.sendRedirect(response.encodeRedirectURL(redirectTo));
return;
}
/**
* The main method.
*
* @param args the arguments
* @throws UnsupportedEncodingException the unsupported encoding exception
*/
public static void main(String[] args) throws UnsupportedEncodingException {
/*String scopeValue ="/gcube/devsec/devVRE";
String remainValue = "/srv/en/mef.export";
String queryString = "scope=/gcube/devsec/devVRE&remainPath=/srv/en/mef.export&version=2.0.2&request=GetCapabilities&service=CSW";
ServerParameters geonetworkParams = new ServerParameters("http://geoserver-dev2.d4science-ii.research-infrastructures.eu/geonetwork", "", "");
String newQueryString = purgeScopeFromQueryString(scopeValue, queryString);
logger.info("Purged query string from "+scopeValue+" is: "+newQueryString);
String baseURL = remainValue==null ||remainValue.isEmpty()?geonetworkParams.getUrl()+"/"+CSW_SERVER:geonetworkParams.getUrl()+"/"+CSW_SERVER+remainValue;
logger.info("New base URL "+baseURL);
newQueryString = purgeRemainFromQueryString(remainValue, newQueryString);
logger.info("Purged query string from "+remainValue+" is: "+newQueryString);
String gnGetlURL = newQueryString==null || newQueryString.isEmpty()? baseURL : baseURL+"?"+newQueryString;
logger.info("Sending get request to URL: "+gnGetlURL);*/
HTTPCallsUtils httpUtils = new HTTPCallsUtils();
String data ="";
String contentType = "application/x-www-form-urlencoded";
String uuid = "fao-fsa-map-27.7.j";
String gnCSWlURL = "http://geoserver-dev2.d4science-ii.research-infrastructures.eu/geonetwork/srv/en//srv/en/mef.export";
try {
/*File file = File.createTempFile(uuid, ".xml");
InputStream response = httpUtils.post(gnCSWlURL, file, contentType);*/
//MAP
Map<String, String[]> map = new HashMap<String, String[]>();
String[] value = new String[1];
value[0]=uuid;
map.put(UUID, value);
// data = "<request><uuid>"+uuid+"</uuid></request>";
data = "uuid="+uuid;
byte[] byteArray = data.getBytes();
InputStream response = httpUtils.post(gnCSWlURL, new ByteArrayInputStream(byteArray), contentType, map);
if(response!=null){
try {
final Path destination = Paths.get("test");
Files.copy(response, destination);
}
catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}catch (Exception e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
}

View File

@ -1,9 +1,14 @@
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;
/**
@ -13,23 +18,44 @@ import org.junit.Test;
*/
public class GeonetworkQueryTest {
private String[] scopes = {"/gcube/devsec/devVRE"};
private static final int MAX = 10;
private String[] scopes = {"/gcube/devsec"};
private String[] scopesProd = {"/d4science.research-infrastructures.eu"};
@Test
private LoginLevel loginLevel = LoginLevel.CKAN;
private Type account = Type.CKAN;
// @Test
public void getCount() throws Exception{
try{
for(String scope:scopes){
ScopeProvider.instance.set(scope);
GeoNetworkReader reader=GeoNetwork.get();
final GNSearchRequest req=new GNSearchRequest();
GeoNetworkPublisher reader=GeoNetwork.get();
reader.login(loginLevel);
Configuration config = reader.getConfiguration();
Account account=config.getScopeConfiguration().getAccounts().get(account);
System.out.println("User: "+account.getUser()+", Pwd: "+account.getPassword());
// req.addParam("keyword", "Thredds");
req.addParam(GNSearchRequest.Param.any,"");
int publicCount=reader.query(req).getCount();
reader.login(LoginLevel.CKAN);
int totalCount=reader.query(req).getCount();
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();
@ -37,7 +63,12 @@ public class GeonetworkQueryTest {
}
// @Test
private boolean containsString(String txt, String value){
return txt.contains(value);
}
@Test
public void getCountProd() throws Exception{
try{
for(String scope:scopesProd){
@ -47,7 +78,7 @@ public class GeonetworkQueryTest {
// req.addParam("keyword", "Thredds");
req.addParam(GNSearchRequest.Param.any,"Thredds");
int publicCount=reader.query(req).getCount();
reader.login(LoginLevel.SCOPE);
reader.login(loginLevel);
int totalCount=reader.query(req).getCount();
System.out.println("SCOPE "+scope+" found "+totalCount+" (public : "+publicCount+", private :"+(totalCount-publicCount)+")");
}

View File

@ -0,0 +1,87 @@
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.HashMap;
import java.util.Map;
import org.gcube.datatransfer.resolver.gis.geonetwork.GeonetworkResolver;
import org.gcube.datatransfer.resolver.gis.geonetwork.HTTPCallsUtils;
/**
*
*/
/**
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* Sep 8, 2016
*/
public class GeonetworkResolverTest {
/**
* The main method.
*
* @param args the arguments
* @throws UnsupportedEncodingException the unsupported encoding exception
*/
public static void main(String[] args) throws UnsupportedEncodingException {
/*String scopeValue ="/gcube/devsec/devVRE";
String remainValue = "/srv/en/mef.export";
String queryString = "scope=/gcube/devsec/devVRE&remainPath=/srv/en/mef.export&version=2.0.2&request=GetCapabilities&service=CSW";
ServerParameters geonetworkParams = new ServerParameters("http://geoserver-dev2.d4science-ii.research-infrastructures.eu/geonetwork", "", "");
String newQueryString = purgeScopeFromQueryString(scopeValue, queryString);
logger.info("Purged query string from "+scopeValue+" is: "+newQueryString);
String baseURL = remainValue==null ||remainValue.isEmpty()?geonetworkParams.getUrl()+"/"+CSW_SERVER:geonetworkParams.getUrl()+"/"+CSW_SERVER+remainValue;
logger.info("New base URL "+baseURL);
newQueryString = purgeRemainFromQueryString(remainValue, newQueryString);
logger.info("Purged query string from "+remainValue+" is: "+newQueryString);
String gnGetlURL = newQueryString==null || newQueryString.isEmpty()? baseURL : baseURL+"?"+newQueryString;
logger.info("Sending get request to URL: "+gnGetlURL);*/
HTTPCallsUtils httpUtils = new HTTPCallsUtils();
String data ="";
String contentType = "application/x-www-form-urlencoded";
String uuid = "fao-fsa-map-27.7.j";
String gnCSWlURL = "http://geoserver-dev2.d4science-ii.research-infrastructures.eu/geonetwork/srv/en//srv/en/mef.export";
try {
/*File file = File.createTempFile(uuid, ".xml");
InputStream response = httpUtils.post(gnCSWlURL, file, contentType);*/
//MAP
Map<String, String[]> map = new HashMap<String, String[]>();
String[] value = new String[1];
value[0]=uuid;
map.put(GeonetworkResolver.UUID, value);
// data = "<request><uuid>"+uuid+"</uuid></request>";
data = "uuid="+uuid;
byte[] byteArray = data.getBytes();
InputStream response = httpUtils.post(gnCSWlURL, new ByteArrayInputStream(byteArray), contentType, map);
if(response!=null){
try {
final Path destination = Paths.get("test");
Files.copy(response, destination);
}
catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}catch (Exception e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
}