From cf2e1c8e36e1625d8077ef5524a224d17c73e287 Mon Sep 17 00:00:00 2001 From: Francesco Mangiacrapa Date: Thu, 8 Sep 2016 13:29:57 +0000 Subject: [PATCH] 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 --- .../gis/geonetwork/GeonetworkResolver.java | 68 --------------- src/test/java/GeonetworkQueryTest.java | 51 ++++++++--- src/test/java/GeonetworkResolverTest.java | 87 +++++++++++++++++++ 3 files changed, 128 insertions(+), 78 deletions(-) create mode 100644 src/test/java/GeonetworkResolverTest.java diff --git a/src/main/java/org/gcube/datatransfer/resolver/gis/geonetwork/GeonetworkResolver.java b/src/main/java/org/gcube/datatransfer/resolver/gis/geonetwork/GeonetworkResolver.java index d5e3db3..4b24440 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/gis/geonetwork/GeonetworkResolver.java +++ b/src/main/java/org/gcube/datatransfer/resolver/gis/geonetwork/GeonetworkResolver.java @@ -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 map = new HashMap(); - String[] value = new String[1]; - value[0]=uuid; - map.put(UUID, value); -// data = ""+uuid+""; - 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(); - } - - } } diff --git a/src/test/java/GeonetworkQueryTest.java b/src/test/java/GeonetworkQueryTest.java index 72946bb..ef43df5 100644 --- a/src/test/java/GeonetworkQueryTest.java +++ b/src/test/java/GeonetworkQueryTest.java @@ -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 map = new HashMap(); + String[] value = new String[1]; + value[0]=uuid; + map.put(GeonetworkResolver.UUID, value); +// data = ""+uuid+""; + 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(); + } + + } +}