Fixed JUnit Tests

This commit is contained in:
Francesco Mangiacrapa 2022-09-13 16:21:53 +02:00
parent 1b11e3fba2
commit 6901b7573d
3 changed files with 94 additions and 26 deletions

View File

@ -3,8 +3,6 @@ package org.gcube.application;
import java.io.IOException; import java.io.IOException;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
@ -21,17 +19,6 @@ import org.junit.Test;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.datatype.jsr310.JSR310Module;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
public class LoadDocumentConfiguration { public class LoadDocumentConfiguration {
private static String TOKEN = ""; private static String TOKEN = "";

View File

@ -27,7 +27,6 @@ import org.gcube.application.geoportalcommon.shared.geoportal.project.ProjectDV;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider; import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.common.scope.api.ScopeProvider; import org.gcube.common.scope.api.ScopeProvider;
import org.junit.Before; import org.junit.Before;
import org.junit.Test;
import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.core.JsonParser;
@ -43,9 +42,9 @@ public class Project_Tests {
// private static String TOKEN = ""; //preVRE // private static String TOKEN = ""; //preVRE
private static String CONTEXT = "/gcube/devsec/devVRE"; private static String CONTEXT = "/gcube/devsec/devVRE";
private static String TOKEN = "c41a00c0-7897-48d2-a67a-05190d6ce5e6-98187548"; // devVRE private static String TOKEN = ""; // devVRE
private static String PROFILE_ID = "profiledConcessioni"; private static String PROFILE_ID = "profiledConcessioni";
private static String PROJECT_ID = "62962b2502ad3d25dc21deac"; private static String PROJECT_ID = "630f905855e2947b0278c1a8";
@Before @Before
public void getClient() { public void getClient() {
@ -55,7 +54,7 @@ public class Project_Tests {
client = GeoportalClientCaller.projects(); client = GeoportalClientCaller.projects();
} }
// @Test //@Test
public void getList() throws Exception { public void getList() throws Exception {
List<Project> listOfProjects = client.getListForProfileID(PROFILE_ID); List<Project> listOfProjects = client.getListForProfileID(PROFILE_ID);
@ -71,6 +70,12 @@ public class Project_Tests {
ProjectDVBuilder projectBuilder = ProjectDVBuilder.newBuilder().fullDocumentMap(true); ProjectDVBuilder projectBuilder = ProjectDVBuilder.newBuilder().fullDocumentMap(true);
ProjectDV projectDV = ConvertToDataValueObjectModel.toProjectDV(project, projectBuilder); ProjectDV projectDV = ConvertToDataValueObjectModel.toProjectDV(project, projectBuilder);
System.out.println(projectDV); System.out.println(projectDV);
LinkedHashMap<String, Object> theMap = projectDV.getTheDocument().getDocumentAsMap();
for (String key : theMap.keySet()) {
Object theValue = theMap.get(key);
System.out.println("The key: "+key+" has value: "+theValue);
}
} }
// @Test // @Test
@ -163,20 +168,20 @@ public class Project_Tests {
System.out.println(client.getTotalDocument(PROFILE_ID)); System.out.println(client.getTotalDocument(PROFILE_ID));
} }
// @Test //@Test
public void getListPhases() throws Exception { public void getListPhases() throws Exception {
List<String> idsPhases = client.getIDsPhases(PROFILE_ID); List<String> idsPhases = client.getIDsPhases(PROFILE_ID);
System.out.println(idsPhases); System.out.println(idsPhases);
PhaseDV[] phases = client.getPhases(PROFILE_ID); PhaseDV[] phases = client.getPhasesIntoDocumentStoreCollection(PROFILE_ID);
for (PhaseDV phaseDV : phases) { for (PhaseDV phaseDV : phases) {
System.out.println(phaseDV); System.out.println(phaseDV);
} }
} }
@Test //@Test
public void deserializeISOJSONObjectAsDate() throws Exception { public void deserializeISOJSONObjectAsDate() throws Exception {
String jsonDate = "{hour=0, minute=0, " + "dayOfYear=259, " + "dayOfWeek=MONDAY, " + "dayOfMonth=16, " String jsonDate = "{hour=0, minute=0, " + "dayOfYear=259, " + "dayOfWeek=MONDAY, " + "dayOfMonth=16, "

View File

@ -5,11 +5,11 @@ import java.util.Arrays;
import java.util.List; import java.util.List;
import org.gcube.application.geoportal.common.model.useCaseDescriptor.UseCaseDescriptor; import org.gcube.application.geoportal.common.model.useCaseDescriptor.UseCaseDescriptor;
import org.gcube.application.geoportal.common.utils.FileSets;
import org.gcube.application.geoportalcommon.ConvertToDataValueObjectModel; import org.gcube.application.geoportalcommon.ConvertToDataValueObjectModel;
import org.gcube.application.geoportalcommon.geoportal.GeoportalClientCaller; import org.gcube.application.geoportalcommon.geoportal.GeoportalClientCaller;
import org.gcube.application.geoportalcommon.geoportal.UseCaseDescriptorCaller; import org.gcube.application.geoportalcommon.geoportal.UseCaseDescriptorCaller;
import org.gcube.application.geoportalcommon.shared.geoportal.ConfigurationDV; import org.gcube.application.geoportalcommon.shared.geoportal.ConfigurationDV;
import org.gcube.application.geoportalcommon.shared.geoportal.config.ActionDefinitionDV;
import org.gcube.application.geoportalcommon.shared.geoportal.config.GcubeProfileDV; import org.gcube.application.geoportalcommon.shared.geoportal.config.GcubeProfileDV;
import org.gcube.application.geoportalcommon.shared.geoportal.config.ItemFieldDV; import org.gcube.application.geoportalcommon.shared.geoportal.config.ItemFieldDV;
import org.gcube.application.geoportalcommon.shared.geoportal.ucd.GEOPORTAL_DATA_HANDLER; import org.gcube.application.geoportalcommon.shared.geoportal.ucd.GEOPORTAL_DATA_HANDLER;
@ -20,6 +20,13 @@ import org.gcube.common.scope.api.ScopeProvider;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
/**
* The Class UCD_Tests.
*
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
*
* Sep 9, 2022
*/
public class UCD_Tests { public class UCD_Tests {
private UseCaseDescriptorCaller client = null; private UseCaseDescriptorCaller client = null;
@ -28,10 +35,15 @@ public class UCD_Tests {
// private static String TOKEN = ""; //preVRE // private static String TOKEN = ""; //preVRE
private static String CONTEXT = "/gcube/devsec/devVRE"; private static String CONTEXT = "/gcube/devsec/devVRE";
private static String TOKEN = "c41a00c0-7897-48d2-a67a-05190d6ce5e6-98187548"; // devVRE private static String TOKEN = ""; // devVRE
private static String PROFILE_ID = "profiledConcessioni"; private static String PROFILE_ID = "profiledConcessioni";
/**
* Gets the client.
*
* @return the client
*/
@Before @Before
public void getClient() { public void getClient() {
// assumeTrue(GCubeTest.isTestInfrastructureEnabled()); // assumeTrue(GCubeTest.isTestInfrastructureEnabled());
@ -40,6 +52,12 @@ public class UCD_Tests {
client = GeoportalClientCaller.useCaseDescriptors(); client = GeoportalClientCaller.useCaseDescriptors();
} }
/**
* Gets the list.
*
* @return the list
* @throws Exception the exception
*/
@Test @Test
public void getList() throws Exception { public void getList() throws Exception {
ScopeProvider.instance.set(CONTEXT); ScopeProvider.instance.set(CONTEXT);
@ -52,6 +70,12 @@ public class UCD_Tests {
} }
} }
/**
* Gets the item by ID.
*
* @return the item by ID
* @throws Exception the exception
*/
// @Test // @Test
public void getItemByID() throws Exception { public void getItemByID() throws Exception {
ScopeProvider.instance.set(CONTEXT); ScopeProvider.instance.set(CONTEXT);
@ -61,6 +85,11 @@ public class UCD_Tests {
System.out.println(ucd); System.out.println(ucd);
} }
/**
* Convert to DV object.
*
* @throws Exception the exception
*/
// @Test // @Test
public void convertToDVObject() throws Exception { public void convertToDVObject() throws Exception {
ScopeProvider.instance.set(CONTEXT); ScopeProvider.instance.set(CONTEXT);
@ -74,7 +103,13 @@ public class UCD_Tests {
} }
} }
@Test /**
* Gets the UCD for data entry handler ids.
*
* @return the UCD for data entry handler ids
* @throws Exception the exception
*/
//@Test
public void getUCDFor_DataEntry_HandlerIds() throws Exception { public void getUCDFor_DataEntry_HandlerIds() throws Exception {
ScopeProvider.instance.set(CONTEXT); ScopeProvider.instance.set(CONTEXT);
SecurityTokenProvider.instance.set(TOKEN); SecurityTokenProvider.instance.set(TOKEN);
@ -111,7 +146,13 @@ public class UCD_Tests {
} }
// @Test /**
* Gets the UCD for data list handler ids.
*
* @return the UCD for data list handler ids
* @throws Exception the exception
*/
//@Test
public void getUCDFor_DataList_HandlerIds() throws Exception { public void getUCDFor_DataList_HandlerIds() throws Exception {
ScopeProvider.instance.set(CONTEXT); ScopeProvider.instance.set(CONTEXT);
SecurityTokenProvider.instance.set(TOKEN); SecurityTokenProvider.instance.set(TOKEN);
@ -146,7 +187,13 @@ public class UCD_Tests {
} }
@Test /**
* Gets the configurations for UC D data handlers.
*
* @return the configurations for UC D data handlers
* @throws Exception the exception
*/
//@Test
public void getConfigurations_ForUCD_Data_Handlers() throws Exception { public void getConfigurations_ForUCD_Data_Handlers() throws Exception {
ScopeProvider.instance.set(CONTEXT); ScopeProvider.instance.set(CONTEXT);
SecurityTokenProvider.instance.set(TOKEN); SecurityTokenProvider.instance.set(TOKEN);
@ -157,7 +204,8 @@ public class UCD_Tests {
UseCaseDescriptorCaller client = GeoportalClientCaller.useCaseDescriptors(); UseCaseDescriptorCaller client = GeoportalClientCaller.useCaseDescriptors();
if (handlersIds == null) { if (handlersIds == null) {
handlersIds = Arrays.asList(GEOPORTAL_DATA_HANDLER.geoportal_data_list.getId(), GEOPORTAL_DATA_HANDLER.geoportal_data_entry.getId()); //handlersIds = Arrays.asList(GEOPORTAL_DATA_HANDLER.geoportal_data_list.getId(), GEOPORTAL_DATA_HANDLER.geoportal_data_entry.getId());
handlersIds = Arrays.asList(GEOPORTAL_DATA_HANDLER.geoportal_workflow_action_list.getId());
System.out.println("handlersIds is null, so using default: " + handlersIds); System.out.println("handlersIds is null, so using default: " + handlersIds);
} }
listUseCaseDescriptor = client.getListForHandlerIds(handlersIds); listUseCaseDescriptor = client.getListForHandlerIds(handlersIds);
@ -195,6 +243,10 @@ public class UCD_Tests {
List<ItemFieldDV> listItems = toListItemFields(config); List<ItemFieldDV> listItems = toListItemFields(config);
System.out.println("\t\t"+listItems); System.out.println("\t\t"+listItems);
break; break;
case actions_definition:
List<ActionDefinitionDV> listActions = toListActionsDefinition(config);
System.out.println("\t\t"+listActions);
break;
default: default:
break; break;
@ -205,6 +257,11 @@ public class UCD_Tests {
} }
} }
/**
* Registrer file sets.
*
* @throws Exception the exception
*/
// @Test // @Test
public void registrerFileSets() throws Exception { public void registrerFileSets() throws Exception {
ScopeProvider.instance.set(CONTEXT); ScopeProvider.instance.set(CONTEXT);
@ -234,6 +291,25 @@ public class UCD_Tests {
return null; return null;
} }
/**
* To list actions definition.
*
* @param config the config
* @return the list
*/
private List<ActionDefinitionDV> toListActionsDefinition(ConfigurationDV<?> config) {
try {
return (List<ActionDefinitionDV>) config.getConfiguration();
} catch (Exception e) {
System.err.println("Error on casting " + ConfigurationDV.class.getName() + " to List of "
+ ActionDefinitionDV.class.getName());
}
return null;
}
/** /**
* To list item fields. * To list item fields.
* *