geoportal-data-common/src/test/java/org/gcube/application/UCD_Tests.java

144 lines
4.8 KiB
Java
Raw Normal View History

2022-03-11 12:01:27 +01:00
package org.gcube.application;
2022-05-20 12:31:39 +02:00
import java.util.ArrayList;
2022-03-17 16:03:32 +01:00
import java.util.Arrays;
2022-03-11 12:01:27 +01:00
import java.util.List;
import org.gcube.application.geoportal.common.model.useCaseDescriptor.UseCaseDescriptor;
2022-03-16 18:10:17 +01:00
import org.gcube.application.geoportalcommon.ConvertToDataValueObjectModel;
2022-03-11 12:01:27 +01:00
import org.gcube.application.geoportalcommon.geoportal.GeoportalClientCaller;
import org.gcube.application.geoportalcommon.geoportal.UseCaseDescriptorCaller;
2022-03-17 16:03:32 +01:00
import org.gcube.application.geoportalcommon.shared.geoportal.GEOPORTAL_DATA_HANDLER;
2022-03-17 16:46:50 +01:00
import org.gcube.application.geoportalcommon.shared.geoportal.UseCaseDescriptorDV;
2022-03-11 12:01:27 +01:00
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.common.scope.api.ScopeProvider;
import org.junit.Before;
import org.junit.Test;
public class UCD_Tests {
private UseCaseDescriptorCaller client = null;
// private static String CONTEXT = "/pred4s/preprod/preVRE";
// private static String TOKEN = ""; //preVRE
private static String CONTEXT = "/gcube/devsec/devVRE";
2022-05-20 15:43:35 +02:00
private static String TOKEN = ""; // devVRE
2022-03-11 12:01:27 +01:00
private static String PROFILE_ID = "profiledConcessioni";
2022-05-20 15:43:35 +02:00
//@Before
2022-03-11 12:01:27 +01:00
public void getClient() {
// assumeTrue(GCubeTest.isTestInfrastructureEnabled());
ScopeProvider.instance.set(CONTEXT);
SecurityTokenProvider.instance.set(TOKEN);
client = GeoportalClientCaller.useCaseDescriptors();
}
2022-05-20 15:43:35 +02:00
//@Test
2022-03-11 12:01:27 +01:00
public void getList() throws Exception {
ScopeProvider.instance.set(CONTEXT);
SecurityTokenProvider.instance.set(TOKEN);
List<UseCaseDescriptor> listOfUCD = client.getList();
int i = 0;
for (UseCaseDescriptor useCaseDescriptor : listOfUCD) {
System.out.println(++i + ") " + useCaseDescriptor);
}
}
2022-05-20 12:31:39 +02:00
// @Test
2022-03-11 12:01:27 +01:00
public void getItemByID() throws Exception {
ScopeProvider.instance.set(CONTEXT);
SecurityTokenProvider.instance.set(TOKEN);
2022-03-16 18:10:17 +01:00
UseCaseDescriptor ucd = client.getUCDForId(PROFILE_ID);
2022-03-11 12:01:27 +01:00
System.out.println(ucd);
}
2022-05-20 12:31:39 +02:00
// @Test
2022-03-16 18:10:17 +01:00
public void convertToDVObject() throws Exception {
ScopeProvider.instance.set(CONTEXT);
SecurityTokenProvider.instance.set(TOKEN);
List<UseCaseDescriptor> listOfUCD = client.getList();
int i = 0;
for (UseCaseDescriptor useCaseDescriptor : listOfUCD) {
System.out.println(++i + ") " + useCaseDescriptor);
ConvertToDataValueObjectModel.toUseCaseDescriptorDV(useCaseDescriptor, null);
}
}
2022-05-20 12:31:39 +02:00
2022-05-20 15:43:35 +02:00
//@Test
public void getUCDForDataEntryHandlerIds() throws Exception {
2022-03-17 16:03:32 +01:00
ScopeProvider.instance.set(CONTEXT);
SecurityTokenProvider.instance.set(TOKEN);
2022-05-20 12:31:39 +02:00
2022-05-20 15:43:35 +02:00
List<String> handlersIds = null;
2022-05-20 12:31:39 +02:00
List<UseCaseDescriptor> listUseCaseDescriptor;
try {
UseCaseDescriptorCaller client = GeoportalClientCaller.useCaseDescriptors();
if (handlersIds == null) {
handlersIds = Arrays.asList(GEOPORTAL_DATA_HANDLER.geoportal_data_entry.getId());
System.out.println("handlersIds is null, so using default: " + handlersIds);
}
listUseCaseDescriptor = client.getListForHandlerIds(handlersIds);
} catch (Exception e) {
String error = "Error on contacting the Geoportal service";
System.out.println(error + " for handlers: " + handlersIds);
throw new Exception(
"Error when contacting the Geoportal service. Refresh and try again or contact the support", e);
}
if (listUseCaseDescriptor == null) {
listUseCaseDescriptor = new ArrayList<UseCaseDescriptor>();
2022-03-17 16:03:32 +01:00
}
2022-05-20 12:31:39 +02:00
List<UseCaseDescriptorDV> listUCDDV = new ArrayList<UseCaseDescriptorDV>(listUseCaseDescriptor.size());
for (UseCaseDescriptor ucd : listUseCaseDescriptor) {
listUCDDV.add(ConvertToDataValueObjectModel.toUseCaseDescriptorDV(ucd, null));
}
System.out.println(listUCDDV);
2022-03-17 16:03:32 +01:00
}
2022-05-20 15:43:35 +02:00
//@Test
public void getUCDForDatalistHandlerIds() throws Exception {
ScopeProvider.instance.set(CONTEXT);
SecurityTokenProvider.instance.set(TOKEN);
List<String> handlersIds = null;
List<UseCaseDescriptor> listUseCaseDescriptor;
try {
UseCaseDescriptorCaller client = GeoportalClientCaller.useCaseDescriptors();
if (handlersIds == null) {
handlersIds = Arrays.asList(GEOPORTAL_DATA_HANDLER.geoportal_data_list.getId());
System.out.println("handlersIds is null, so using default: " + handlersIds);
}
listUseCaseDescriptor = client.getListForHandlerIds(handlersIds);
} catch (Exception e) {
String error = "Error on contacting the Geoportal service";
System.out.println(error + " for handlers: " + handlersIds);
throw new Exception(
"Error when contacting the Geoportal service. Refresh and try again or contact the support", e);
}
if (listUseCaseDescriptor == null) {
listUseCaseDescriptor = new ArrayList<UseCaseDescriptor>();
}
List<UseCaseDescriptorDV> listUCDDV = new ArrayList<UseCaseDescriptorDV>(listUseCaseDescriptor.size());
for (UseCaseDescriptor ucd : listUseCaseDescriptor) {
listUCDDV.add(ConvertToDataValueObjectModel.toUseCaseDescriptorDV(ucd, null));
}
System.out.println(listUCDDV);
}
2022-03-16 18:10:17 +01:00
2022-03-11 12:01:27 +01:00
}