added junit test

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/data-transfer/uri-resolver@174056 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Francesco Mangiacrapa 2018-11-08 14:33:24 +00:00
parent 1964cf9788
commit d5d41a1d2a
1 changed files with 98 additions and 13 deletions

View File

@ -19,6 +19,7 @@ import org.apache.commons.io.FilenameUtils;
import org.apache.commons.io.IOUtils;
import org.apache.http.HttpStatus;
import org.gcube.datatransfer.resolver.util.HTTPCallsUtils;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -38,10 +39,11 @@ public class TestResolvers {
/**
* Storage hub test.
* @throws Exception
*
* @throws Exception the exception
*/
//@Test
public void storageHubTest() throws Exception{
public void testStorageHub() throws Exception{
String storageHubId = "2019b881-083b-444a-81be-8abee4b91020";
String url = String.format("%s/shub/%s",URI_RESOLVER_SERVICE_ENDPOINT,storageHubId);
@ -81,10 +83,11 @@ public class TestResolvers {
/**
* Storage hub test.
* @throws Exception
*
* @throws Exception the exception
*/
//@Test
public void storageIDTest() throws Exception{
public void testStorageID() throws Exception{
String storageID = "clZ2YmxTYytETzVLaHkwMjM3TmVETTFMb256YVRMS3lHbWJQNStIS0N6Yz0";
String url = String.format("%s/%s",URI_RESOLVER_SERVICE_ENDPOINT,storageID);
@ -124,10 +127,11 @@ public class TestResolvers {
/**
* Storage hub test.
* @throws Exception
*
* @throws Exception the exception
*/
//@Test
public void storageIDdoHEADTest() throws Exception{
public void testStorageIDdoHEAD() throws Exception{
String storageID = "clZ2YmxTYytETzVLaHkwMjM3TmVETTFMb256YVRMS3lHbWJQNStIS0N6Yz0";
String url = String.format("%s/%s",URI_RESOLVER_SERVICE_ENDPOINT,storageID);
@ -162,10 +166,11 @@ public class TestResolvers {
/**
* Storage hub test.
* @throws Exception
*
* @throws Exception the exception
*/
//@Test
public void catalogueResolverTest() throws Exception{
public void testCatalogueResolver() throws Exception{
String entityName = "sarda-sarda";
String entityContext = "ctlg";
@ -202,10 +207,11 @@ public class TestResolvers {
/**
* Storage hub test.
* @throws Exception
*
* @throws Exception the exception
*/
//@Test
public void catalogueResolverCreatePublicItemURLTest() throws Exception{
public void testCatalogueResolverCreatePublicItemURL() throws Exception{
String entityName = "sarda-sarda";
//String entityContext = "product";
@ -245,10 +251,11 @@ public class TestResolvers {
/**
* Storage hub test.
* @throws Exception
*
* @throws Exception the exception
*/
//@Test
public void catalogueResolverCreatePubrivatetemURLTest() throws Exception{
public void testCatalogueResolverCreatePubrivatetemURL() throws Exception{
String entityName = "dynamic_reporting";
//String entityContext = "product";
@ -285,6 +292,70 @@ public class TestResolvers {
throw e;
}
}
//@Test
/**
* Test gis resolver.
*
* @throws Exception the exception
*/
@Test
public void testGisResolver() throws Exception{
String gisUUID = "55c19a1f-214b-4f81-9220-fba09fcfa91f";
String scope = "/gcube/devsec/devVRE";
String queryString = "gis-UUID="+gisUUID +"&scope="+scope;
String url = String.format("%s/gis?%s",URI_RESOLVER_SERVICE_ENDPOINT,queryString);
logger.info("Request to URL: "+url);
URL toURL;
int status;
try {
toURL = new URL(url);
HttpURLConnection con = (HttpURLConnection) toURL.openConnection();
con.setRequestMethod("GET");
con.connect();
status = con.getResponseCode();
//printHeaders(con.getHeaderFields());
System.out.println("Response status is: "+status);
if(status==HttpStatus.SC_SEE_OTHER){
System.out.println("\nResponse to URL: "+url);
System.out.println(IOUtils.toString(con.getInputStream()));
}else{
System.err.println("\nNo file reachable at: "+url);
}
//con.setRequestProperty("Content-Type", "application/json");
//con.setConnectTimeout(5000);
//con.setReadTimeout(5000)
}
catch (Exception e) {
// TODO Auto-generated catch block
logger.error("Error: ",e);
throw e;
}
}
/**
* Gets the content reponse.
*
@ -314,6 +385,11 @@ public class TestResolvers {
return content.toString();
}
/**
* Prints the headers.
*
* @param map the map
*/
public static void printHeaders(Map<String, List<String>> map){
System.out.println("Printing Response Header...");
@ -323,10 +399,19 @@ public class TestResolvers {
}
/**
* Gets the filename.
*
* @param map the map
* @return the filename
*/
public static String getFilename(Map<String, List<String>> map){
List<String> contentDispValue = map.get("content-disposition");
String fileName = "filename";
List<String> contentDispValue = map.get("content-disposition");
if(contentDispValue==null)
return fileName;
System.out.println("Printing content-disposition from Response Header...");
for (String value : contentDispValue) {
System.out.println(value);