Updated Tests

This commit is contained in:
Francesco Mangiacrapa 2022-11-08 10:53:02 +01:00
parent 44b87e9aff
commit 7a7b39418f
2 changed files with 73 additions and 9 deletions

View File

@ -1,20 +1,26 @@
package org.gcube.application; package org.gcube.application;
import static org.gcube.application.geoportal.client.plugins.GeoportalAbstractPlugin.projects;
import java.io.IOException; import java.io.IOException;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry;
import org.bson.Document;
import org.gcube.application.geoportal.common.model.configuration.Configuration; import org.gcube.application.geoportal.common.model.configuration.Configuration;
import org.gcube.application.geoportal.common.model.document.Project; import org.gcube.application.geoportal.common.model.document.Project;
import org.gcube.application.geoportal.common.model.document.lifecycle.LifecycleInformation; import org.gcube.application.geoportal.common.model.document.lifecycle.LifecycleInformation;
import org.gcube.application.geoportal.common.model.document.relationships.Relationship; import org.gcube.application.geoportal.common.model.document.relationships.Relationship;
import org.gcube.application.geoportal.common.model.document.relationships.RelationshipNavigationObject; import org.gcube.application.geoportal.common.model.document.relationships.RelationshipNavigationObject;
import org.gcube.application.geoportal.common.model.rest.QueryRequest;
import org.gcube.application.geoportalcommon.ConvertToDataValueObjectModel; import org.gcube.application.geoportalcommon.ConvertToDataValueObjectModel;
import org.gcube.application.geoportalcommon.ProjectDVBuilder; import org.gcube.application.geoportalcommon.ProjectDVBuilder;
import org.gcube.application.geoportalcommon.geoportal.GeoportalClientCaller; import org.gcube.application.geoportalcommon.geoportal.GeoportalClientCaller;
@ -23,6 +29,7 @@ import org.gcube.application.geoportalcommon.shared.SearchingFilter;
import org.gcube.application.geoportalcommon.shared.SearchingFilter.LOGICAL_OP; import org.gcube.application.geoportalcommon.shared.SearchingFilter.LOGICAL_OP;
import org.gcube.application.geoportalcommon.shared.WhereClause; import org.gcube.application.geoportalcommon.shared.WhereClause;
import org.gcube.application.geoportalcommon.shared.geoportal.ResultDocumentDV; import org.gcube.application.geoportalcommon.shared.geoportal.ResultDocumentDV;
import org.gcube.application.geoportalcommon.shared.geoportal.config.ItemFieldDV;
import org.gcube.application.geoportalcommon.shared.geoportal.project.LifecycleInformationDV; import org.gcube.application.geoportalcommon.shared.geoportal.project.LifecycleInformationDV;
import org.gcube.application.geoportalcommon.shared.geoportal.project.PhaseDV; import org.gcube.application.geoportalcommon.shared.geoportal.project.PhaseDV;
import org.gcube.application.geoportalcommon.shared.geoportal.project.ProjectDV; import org.gcube.application.geoportalcommon.shared.geoportal.project.ProjectDV;
@ -47,7 +54,7 @@ public class Project_Tests {
private static String CONTEXT = "/gcube/devsec/devVRE"; private static String CONTEXT = "/gcube/devsec/devVRE";
private static String TOKEN = ""; // devVRE private static String TOKEN = ""; // devVRE
private static String PROFILE_ID = "profiledConcessioni"; private static String PROFILE_ID = "profiledConcessioni";
private static String PROJECT_ID = "632c633155e2947b0278c999"; private static String PROJECT_ID = "6365485fa8d67f4c82794cc4";
@Before @Before
public void getClient() { public void getClient() {
@ -67,7 +74,7 @@ public class Project_Tests {
} }
} }
// @Test //@Test
public void getByID() throws Exception { public void getByID() throws Exception {
Project project = client.getProjectByID(PROFILE_ID, PROJECT_ID); Project project = client.getProjectByID(PROFILE_ID, PROJECT_ID);
ProjectDVBuilder projectBuilder = ProjectDVBuilder.newBuilder().fullDocumentMap(true); ProjectDVBuilder projectBuilder = ProjectDVBuilder.newBuilder().fullDocumentMap(true);
@ -79,9 +86,11 @@ public class Project_Tests {
Object theValue = theMap.get(key); Object theValue = theMap.get(key);
System.out.println("The key: " + key + " has value: " + theValue); System.out.println("The key: " + key + " has value: " + theValue);
} }
System.out.println(projectDV.getSpatialReference());
} }
// @Test //@Test
public void getListProjectsDV() throws Exception { public void getListProjectsDV() throws Exception {
List<Project> listOfProjects = client.getListForProfileID(PROFILE_ID); List<Project> listOfProjects = client.getListForProfileID(PROFILE_ID);
ProjectDVBuilder projectBuilder = ProjectDVBuilder.newBuilder().fullDocumentMap(true); ProjectDVBuilder projectBuilder = ProjectDVBuilder.newBuilder().fullDocumentMap(true);
@ -93,7 +102,7 @@ public class Project_Tests {
} }
// @Test //@Test
public void getResultDocumentForID() { public void getResultDocumentForID() {
try { try {
ProjectsCaller projects = GeoportalClientCaller.projects(); ProjectsCaller projects = GeoportalClientCaller.projects();
@ -106,10 +115,11 @@ public class Project_Tests {
} }
} }
// @Test @Test
public void getListProjectsDVFiltered() throws Exception { public void getListProjectsDVFiltered() throws Exception {
// List<Project> listOfProjects = client.getListForProfileID(PROFILE_ID); // List<Project> listOfProjects = client.getListForProfileID(PROFILE_ID);
SearchingFilter filter = new SearchingFilter(); SearchingFilter filter = new SearchingFilter();
// Where Clause // Where Clause
@ -118,9 +128,19 @@ public class Project_Tests {
// searchInto.put("_id", "61f0299baf51592c36795f52"); // searchInto.put("_id", "61f0299baf51592c36795f52");
// searchInto.put("_theDocument.nome", "Test progetto con clustering di // searchInto.put("_theDocument.nome", "Test progetto con clustering di
// fileset"); // fileset");
WhereClause whereClause = new WhereClause(LOGICAL_OP.AND, searchInto); // searchInto.put("_theDocument.paroleChiaveLibere", "scavo");
// searchInto.put("_theDocument.editore", "scavo");
// searchInto.put("_theDocument.paroleChiaveICCD", "scavo");
// searchInto.put("_theDocument.responsabile", "scavo");
WhereClause whereClause = new WhereClause(LOGICAL_OP.OR, searchInto);
conditions.add(whereClause); conditions.add(whereClause);
filter.setConditions(conditions); filter.setConditions(conditions);
List<ItemFieldDV> orderByFields = new ArrayList<ItemFieldDV>();
List<String> jsonFields = Arrays.asList("_theDocument.dataInizioProgetto");
ItemFieldDV itemField = new ItemFieldDV("dataInizioProgetto", jsonFields, "$or", false, false, false);
orderByFields.add(itemField);
filter.setOrderByFields(orderByFields);
LinkedHashMap<String, Object> projection = new LinkedHashMap<String, Object>(); LinkedHashMap<String, Object> projection = new LinkedHashMap<String, Object>();
// default // default
@ -148,8 +168,9 @@ public class Project_Tests {
List<ResultDocumentDV> results = ConvertToDataValueObjectModel.toListResultDocument(projects); List<ResultDocumentDV> results = ConvertToDataValueObjectModel.toListResultDocument(projects);
int i = 0; int i = 0;
for (ResultDocumentDV projectDV : results) { for (ResultDocumentDV projectDV : results) {
System.out.println(++i + ") " + projectDV); System.out.println(++i + ") " + projectDV.getId() + " dataInizioProgetto: "+projectDV.getDocumentAsMap().get("dataInizioProgetto"));
} }
// TEST TO PROJECT DV // TEST TO PROJECT DV
/* /*
@ -161,6 +182,46 @@ public class Project_Tests {
* for (ProjectDV projectDV : listProjects) { System.out.println(++i + ") " + * for (ProjectDV projectDV : listProjects) { System.out.println(++i + ") " +
* projectDV); } * projectDV); }
*/ */
/*int limit = 2;
LinkedHashMap<String, Object> documentAsMap = new LinkedHashMap<String, Object>(limit);
try {
// Project theProject =
// GeoportalClientCaller.projects().getProjectByID(profileID, projectID);
QueryRequest request = new QueryRequest();
request.setFilter(Document.parse("{\"" + Project.ID + "\" : " + "{\"$eq\" : \"" + PROJECT_ID + "\"}}"));
request.setProjection(Document.parse("{\"" + Project.ID + "\" : " + "1}"));
// should be one
projects(PROFILE_ID).build().f
projects(PROFILE_ID).build().query(request).forEachRemaining(p -> {
try {
System.out.println("p is: "+p);
Iterator<Entry<String, Object>> entrySetsIt = p.getTheDocument().entrySet().iterator();
int i = 0;
while (entrySetsIt.hasNext()) {
if (i > limit)
break;
Entry<String, Object> entry = entrySetsIt.next();
documentAsMap.put(entry.getKey(), entry.getValue());
i++;
}
} catch (Exception e) {
throw e;
}
});
System.out.println("getEntrySetsDocumentForProjectID returning map: "+documentAsMap);
} catch (Exception e) {
String erroMsg = "Error occurred on loading EntrySets document for profileID " + PROFILE_ID
+ " and projectID " + PROJECT_ID;
e.printStackTrace();
}*/
} }
// @Test // @Test
@ -207,7 +268,7 @@ public class Project_Tests {
for (Relationship relationship : relations) { for (Relationship relationship : relations) {
System.out.println("\n\ngetRelationshipsChain for "+relationship); System.out.println("\n\ngetRelationshipsChain for "+relationship);
Iterator<RelationshipNavigationObject> iterator = client.getRelationshipChain(PROFILE_ID, PROJECT_ID, Iterator<RelationshipNavigationObject> iterator = client.getRelationshipChain(PROFILE_ID, PROJECT_ID,
relationship.getRelationshipName()); relationship.getRelationshipName(), true);
while (iterator.hasNext()) { while (iterator.hasNext()) {
RelationshipNavigationObject nav = (RelationshipNavigationObject) iterator.next(); RelationshipNavigationObject nav = (RelationshipNavigationObject) iterator.next();

View File

@ -157,7 +157,7 @@ public class UCD_Tests {
* @return the UCD for data list handler ids * @return the UCD for data list handler ids
* @throws Exception the exception * @throws Exception the exception
*/ */
// @Test //@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);
@ -313,6 +313,9 @@ public class UCD_Tests {
System.out.println("UCD profileID:" + useCaseDescriptorDV.getProfileID()); System.out.println("UCD profileID:" + useCaseDescriptorDV.getProfileID());
List<HandlerDeclarationDV> handlers = useCaseDescriptorDV.getHandlers(); List<HandlerDeclarationDV> handlers = useCaseDescriptorDV.getHandlers();
for (HandlerDeclarationDV handler : handlers) { for (HandlerDeclarationDV handler : handlers) {
System.out.println("\n\thandler id:" + handler.getId());
System.out.println("\thandler ItemType:" + handler.getItemType());
System.out.println("\thandler Type:" + handler.getType());
ConfigurationDV<?> config = handler.getConfiguration(); ConfigurationDV<?> config = handler.getConfiguration();
System.out.println("\tConfig type:" + config.getConfigurationType()); System.out.println("\tConfig type:" + config.getConfigurationType());
// System.out.println("\tConfig:" + config.getConfiguration()); // System.out.println("\tConfig:" + config.getConfiguration());