added new junit tests

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/data-transfer/uri-resolver@174039 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Francesco Mangiacrapa 2018-11-07 11:27:45 +00:00
parent b618fc0e47
commit 2a9753b095
1 changed files with 83 additions and 1 deletions

View File

@ -16,6 +16,7 @@ import java.util.List;
import java.util.Map;
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.slf4j.Logger;
@ -121,6 +122,44 @@ public class TestResolvers {
}
}
/**
* Storage hub test.
* @throws Exception
*/
//@Test
public void storageIDdoHEADTest() throws Exception{
String storageID = "clZ2YmxTYytETzVLaHkwMjM3TmVETTFMb256YVRMS3lHbWJQNStIS0N6Yz0";
String url = String.format("%s/%s",URI_RESOLVER_SERVICE_ENDPOINT,storageID);
logger.info("Request to URL: "+url);
URL toURL;
int status;
try {
toURL = new URL(url);
HttpURLConnection con = (HttpURLConnection) toURL.openConnection();
con.setRequestMethod("HEAD");
con.connect();
status = con.getResponseCode();
//printHeaders(con.getHeaderFields());
System.out.println("Response status is: "+status);
if(status==HttpStatus.SC_OK){
System.out.println("\nFile to URL: "+url +" is reachable via doHEAD");
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;
}
}
/**
* Storage hub test.
* @throws Exception
@ -166,7 +205,7 @@ public class TestResolvers {
* @throws Exception
*/
//@Test
public void catalogueResolverCreateItemURLTest() throws Exception{
public void catalogueResolverCreatePublicItemURLTest() throws Exception{
String entityName = "sarda-sarda";
//String entityContext = "product";
@ -189,6 +228,49 @@ public class TestResolvers {
// json.append("gcube_scope", scope);
// json.append("entity_context", entityContext);
// json.append("entity_name", entityName);
// System.out.println("Sending json object: "+json.toString());
InputStream response = httCaller.post(url, jsonString, "application/json");
System.out.println("Response: \n"+getContentReponse(response));
//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;
}
}
/**
* Storage hub test.
* @throws Exception
*/
//@Test
public void catalogueResolverCreatePubrivatetemURLTest() throws Exception{
String entityName = "dynamic_reporting";
//String entityContext = "product";
String entityContext = "dataset";
String scope = "/gcube/devsec/devVRE";
String url = String.format("%s/%s",URI_RESOLVER_SERVICE_ENDPOINT,"catalogue");
logger.info("POST Request to URL: "+url);
try {
HTTPCallsUtils httCaller = new HTTPCallsUtils(null, null);
String jsonString =
"{" +
"\"gcube_scope\":\""+scope+"\"," +
"\"entity_context\":\""+entityContext+"\"," +
"\"entity_name\":\""+entityName+"\"" +
"}";
System.out.println("Sending JSON: "+jsonString);
// JSONObject json = new JSONObject();
// json.append("gcube_scope", scope);
// json.append("entity_context", entityContext);
// json.append("entity_name", entityName);
// System.out.println("Sending json object: "+json.toString());
InputStream response = httCaller.post(url, jsonString, "application/json");
System.out.println("Response: \n"+getContentReponse(response));