added a test case

This commit is contained in:
Francesco Mangiacrapa 2021-02-12 18:38:31 +01:00
parent 31b12b587d
commit 0e9cee9612
2 changed files with 64 additions and 0 deletions

View File

@ -3,6 +3,12 @@ package org.gcube.datacatalogue.utillibrary.server;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Arrays;
@ -417,6 +423,52 @@ public class DataCatalogueImpl implements DataCatalogue {
return toReturn;
}
// /**
// * Retrieve an url for the tuple scope, entity, entity name
// * @param context
// * @param entityContext
// * @param entityName
// */
// private String getUrlForProduct(String context, EntityContext entityContext, String entityName){
//
// String toReturn = null;
//
// try {
// LOG.debug("URI-Resolver URL: "+getUriResolverUrl());
// URL url = new URL(getUriResolverUrl());
// URLConnection con = url.openConnection();
// HttpURLConnection http = (HttpURLConnection)con;
// http.setRequestMethod("POST"); // PUT is another valid option
// http.setDoOutput(true);
// http.setRequestProperty("Content-Type", ContentType.APPLICATION_JSON.toString());
//
// JSONObject requestEntity = new JSONObject();
// requestEntity.put("gcube_scope", context);
// requestEntity.put("entity_context", entityContext.toString());
// requestEntity.put("entity_name", entityName);
//
// try(OutputStream os = con.getOutputStream()) {
// byte[] input = requestEntity.toJSONString().getBytes("utf-8");
// os.write(input, 0, input.length);
// }
//
// try (BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream(), "utf-8"))) {
// StringBuilder response = new StringBuilder();
// String responseLine = null;
// while ((responseLine = br.readLine()) != null) {
// response.append(responseLine.trim());
// }
// toReturn = response.toString();
// }
//
//
// }catch (Exception e) {
// e.printStackTrace();
// }
//
// return toReturn;
// }
@Override
public LandingPages getLandingPages() throws Exception {

View File

@ -321,5 +321,17 @@ public class TestDataCatalogueLib {
customFieldsToChange.put("key-random-0", "patched");
instance.patchFieldsForDataset(productName, customFieldsToChange);
}
//@Test
public void getUrlProduct() throws Exception{
ScopeProvider.instance.set(scope);
SecurityTokenProvider.instance.set(authorizationToken);
DataCatalogueImpl instance = factory.getUtilsPerScope(scope);
String datasetName = productName;
String url = instance.getUnencryptedUrlFromDatasetIdOrName(datasetName);
LOG.debug("url is " + url);
}
}