From a86310ade540472c0c3aaafd2df569f726fbbe21 Mon Sep 17 00:00:00 2001 From: Fabio Sinibaldi Date: Wed, 18 Jan 2023 17:43:44 +0100 Subject: [PATCH] Fix tests --- .../geoportal/clients/BasicVreTests.java | 2 - .../clients/ProfiledConcessioniTest.java | 79 ++++++++++++++-- .../clients/ProfiledDocumentsTest.java | 92 ++++++++++--------- 3 files changed, 120 insertions(+), 53 deletions(-) diff --git a/geoportal-client/src/test/java/org/gcube/application/geoportal/clients/BasicVreTests.java b/geoportal-client/src/test/java/org/gcube/application/geoportal/clients/BasicVreTests.java index cacdbdb..bc540dd 100644 --- a/geoportal-client/src/test/java/org/gcube/application/geoportal/clients/BasicVreTests.java +++ b/geoportal-client/src/test/java/org/gcube/application/geoportal/clients/BasicVreTests.java @@ -11,8 +11,6 @@ public class BasicVreTests extends GCubeTest { @BeforeClass public static void setScope(){ assumeTrue(isTestInfrastructureEnabled()); -// TokenSetter.set("/pred4s/preprod/preVRE"); - // TokenSetter.set("/d4science.research-infrastructures.eu/D4OS/GeoNA-Prototype"); TokenSetter.set(GCubeTest.getContext()); } diff --git a/geoportal-client/src/test/java/org/gcube/application/geoportal/clients/ProfiledConcessioniTest.java b/geoportal-client/src/test/java/org/gcube/application/geoportal/clients/ProfiledConcessioniTest.java index 8af8aae..6ae0741 100644 --- a/geoportal-client/src/test/java/org/gcube/application/geoportal/clients/ProfiledConcessioniTest.java +++ b/geoportal-client/src/test/java/org/gcube/application/geoportal/clients/ProfiledConcessioniTest.java @@ -2,12 +2,20 @@ package org.gcube.application.geoportal.clients; import com.fasterxml.jackson.core.JsonProcessingException; import lombok.Data; +import lombok.extern.slf4j.Slf4j; import org.bson.Document; import org.gcube.application.cms.tests.TestDocuments; import org.gcube.application.cms.tests.Tests; import org.gcube.application.geoportal.client.utils.Serialization; import org.gcube.application.geoportal.common.faults.InvalidRequestException; +import org.gcube.application.geoportal.common.model.JSONPathWrapper; import org.gcube.application.geoportal.common.model.document.Project; +import org.gcube.application.geoportal.common.model.document.access.Access; +import org.gcube.application.geoportal.common.model.document.access.AccessPolicy; +import org.gcube.application.geoportal.common.model.document.filesets.RegisteredFileSet; +import org.gcube.application.geoportal.common.model.document.relationships.RelationshipNavigationObject; +import org.gcube.application.geoportal.common.model.rest.CreateRelationshipRequest; +import org.gcube.application.geoportal.common.model.rest.DeleteRelationshipRequest; import org.gcube.application.geoportal.common.model.rest.RegisterFileSetRequest; import org.gcube.application.geoportal.common.model.rest.StepExecutionRequest; import org.gcube.application.geoportal.common.model.useCaseDescriptor.Field; @@ -17,6 +25,7 @@ import org.gcube.application.geoportal.common.rest.Projects; import org.gcube.application.geoportal.common.utils.FileSets; import org.gcube.application.geoportal.common.utils.Files; import org.gcube.application.geoportal.common.utils.StorageUtils; +import org.gcube.application.geoportal.common.utils.tests.GCubeTest; import org.junit.Test; import java.io.File; @@ -24,8 +33,14 @@ import java.io.FileNotFoundException; import java.io.IOException; import java.nio.charset.Charset; import java.rmi.RemoteException; +import java.util.Iterator; -public class ProfiledConcessioniTest extends ProfiledDocumentsTest{ +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assume.assumeTrue; + +@Slf4j +public class ProfiledConcessioniTest > extends GenericUseCases{ @Data private static class MyClass { @@ -38,13 +53,9 @@ public class ProfiledConcessioniTest extends ProfiledDocumentsTest{ } public void test(){ - UseCaseDescriptor p=null; - HandlerDeclaration h = p.getHandlersMapByID().get("MyID").get(0); - Document doc = h.getConfiguration(); - System.out.println(Serialization.convert(doc, MyClass.class)); } @@ -78,11 +89,28 @@ public class ProfiledConcessioniTest extends ProfiledDocumentsTest{ // Set relazione - client.registerFileSet(project.getId(), FileSets. + + Access toSetAccess = new Access(); + toSetAccess.setPolicy(AccessPolicy.RESTRICTED); + toSetAccess.setLicense("CC0-1.0"); + + RegisterFileSetRequest request=FileSets. prepareRequest(new StorageUtils(), "$.relazioneScavo","fileset", "$.relazioneScavo."+Field.CHILDREN+"[?(@.fileset)]", - new File(Tests.FOLDER_CONCESSIONI,"relazione.pdf"))); + new File(Tests.FOLDER_CONCESSIONI,"relazione.pdf")); + request.setToSetAccess(toSetAccess); + + project=client.registerFileSet(project.getId(), request); + + String jsonDoc=project.getTheDocument().toJson(); + log.info("Registered fileset. Result is {}", jsonDoc); + RegisteredFileSet f= Serialization.convert(new JSONPathWrapper(jsonDoc).getByPath( + request.getParentPath()+"."+request.getFieldName()).get(0),RegisteredFileSet.class); + + assertEquals(Serialization.convert(f.getAccess(),Access.class).getPolicy(),toSetAccess.getPolicy()); + assertEquals(Serialization.convert(f.getAccess(),Access.class).getLicense(),toSetAccess.getLicense()); + // Set Abstract @@ -126,4 +154,41 @@ public class ProfiledConcessioniTest extends ProfiledDocumentsTest{ return client.getById(project.getId()); } + + @Test + public void testRelationships() throws Exception{ + assumeTrue(GCubeTest.isTestInfrastructureEnabled()); + Projects client = (Projects) getClient(); + Project source = client.createNew(new Document().append("field","value")); + Project target = client.createNew(new Document().append("field2","value")); + + String relId="follows"; + + + Project linkedSource = client.setRelation( + new CreateRelationshipRequest(source.getId(),relId, + target.getId(), null)); + + assertTrue(linkedSource.getRelationships()!=null); + assertTrue(!linkedSource.getRelationships().isEmpty()); + assertTrue(linkedSource.getRelationships().get(0).getRelationshipName().equals(relId)); + assertTrue(linkedSource.getRelationships().get(0).getTargetID().equals(target.getId())); + assertTrue(linkedSource.getRelationships().get(0).getTargetUCD().equals(target.getProfileID())); + + Iterator it = client.getRelationshipChain(source.getId(),relId,true); + System.out.println("Scanning rel .."); + it.forEachRemaining(r -> { + System.out.println(r.getTarget().getId()); + System.out.println("Children size : "+r.getChildren().size()); + }); + + + Project unLinkedSource = client.deleteRelation( + new DeleteRelationshipRequest(source.getId(),relId, + target.getId(),null)); + + + assertTrue(unLinkedSource.getRelationships()==null || unLinkedSource.getRelationships().isEmpty()); + + } } diff --git a/geoportal-client/src/test/java/org/gcube/application/geoportal/clients/ProfiledDocumentsTest.java b/geoportal-client/src/test/java/org/gcube/application/geoportal/clients/ProfiledDocumentsTest.java index 5296118..725a3f1 100644 --- a/geoportal-client/src/test/java/org/gcube/application/geoportal/clients/ProfiledDocumentsTest.java +++ b/geoportal-client/src/test/java/org/gcube/application/geoportal/clients/ProfiledDocumentsTest.java @@ -3,42 +3,49 @@ package org.gcube.application.geoportal.clients; import com.fasterxml.jackson.core.JsonProcessingException; import lombok.extern.slf4j.Slf4j; import org.bson.Document; +import org.gcube.application.cms.tests.Tests; +import org.gcube.application.geoportal.client.utils.Serialization; +import org.gcube.application.geoportal.common.faults.InvalidRequestException; +import org.gcube.application.geoportal.common.model.JSONPathWrapper; 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.access.Access; +import org.gcube.application.geoportal.common.model.document.access.AccessPolicy; +import org.gcube.application.geoportal.common.model.document.filesets.RegisteredFileSet; import org.gcube.application.geoportal.common.model.document.relationships.RelationshipNavigationObject; import org.gcube.application.geoportal.common.model.rest.CreateRelationshipRequest; import org.gcube.application.geoportal.common.model.rest.DeleteRelationshipRequest; import org.gcube.application.geoportal.common.model.rest.QueryRequest; +import org.gcube.application.geoportal.common.model.rest.RegisterFileSetRequest; import org.gcube.application.geoportal.common.rest.Projects; +import org.gcube.application.geoportal.common.utils.FileSets; +import org.gcube.application.geoportal.common.utils.StorageUtils; import org.gcube.application.geoportal.common.utils.tests.GCubeTest; import org.junit.Test; +import java.io.File; +import java.io.FileNotFoundException; import java.rmi.RemoteException; import java.time.LocalDateTime; import java.util.Iterator; import java.util.concurrent.atomic.AtomicLong; import static org.gcube.application.geoportal.client.utils.Serialization.write; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import static org.junit.Assume.assumeTrue; @Slf4j public class ProfiledDocumentsTest> extends GenericUseCases { -// protected String getProfileID(){return "basic";} - -// protected C getClient(){ -// return (C) customModel(getProfileID(), Project.class, DefaultDocumentsClient.class).build(); -// } - @Test - public void registerNew() throws RemoteException, JsonProcessingException { + public void registerNew() throws RemoteException, JsonProcessingException, FileNotFoundException, InvalidRequestException { assumeTrue(GCubeTest.isTestInfrastructureEnabled()); Projects client = (Projects) getClient(); Document theDoc= Document.parse("{\n" + - "\"posizionamentoScavo\" :{\n" + + "\"section\" :{\n" + "\t\"titolo\" : \"mio titolo\"}}"); theDoc.put("startTime", LocalDateTime.now()); @@ -46,6 +53,39 @@ public class ProfiledDocumentsTest> exte Project p =client.createNew(theDoc); log.debug("Registered project (AS JSON) : {}", write(p)); + + + } + + + @Test + public void testAccess() throws FileNotFoundException, RemoteException, InvalidRequestException, JsonProcessingException { + assumeTrue(GCubeTest.isTestInfrastructureEnabled()); + Projects client = (Projects) getClient(); + + Document theDoc= Document.parse("{\n" + + "\"section\" :{\n" + + "\t\"titolo\" : \"mio titolo\"}}"); + + theDoc.put("startTime", LocalDateTime.now()); + + Project p =client.createNew(theDoc); + + RegisterFileSetRequest fsRequest = prepareRequest(); + + Access access = new Access(); + access.setLicense("CC0-1.0"); + access.setPolicy(AccessPolicy.RESTRICTED); + fsRequest.setToSetAccess(access); + + p=client.registerFileSet(p.getId(),fsRequest); + + log.info("Registered fileset. Result is {}", Serialization.write(p)); + RegisteredFileSet f= Serialization.convert(new JSONPathWrapper(p.getTheDocument().toJson()). + getByPath(fsRequest.getParentPath()+"."+fsRequest.getFieldName()).get(0),RegisteredFileSet.class); + + assertEquals(Serialization.convert(f.getAccess(),Access.class).getPolicy(),AccessPolicy.RESTRICTED); + } @Test @@ -86,41 +126,5 @@ public class ProfiledDocumentsTest> exte }); } - @Test - public void testRelationships() throws Exception{ - assumeTrue(GCubeTest.isTestInfrastructureEnabled()); - Projects client = (Projects) getClient(); - Project source = client.createNew(new Document().append("field","value")); - Project target = client.createNew(new Document().append("field2","value")); - - String relId="follows"; - - - Project linkedSource = client.setRelation( - new CreateRelationshipRequest(source.getId(),relId, - target.getId(), null)); - - assertTrue(linkedSource.getRelationships()!=null); - assertTrue(!linkedSource.getRelationships().isEmpty()); - assertTrue(linkedSource.getRelationships().get(0).getRelationshipName().equals(relId)); - assertTrue(linkedSource.getRelationships().get(0).getTargetID().equals(target.getId())); - assertTrue(linkedSource.getRelationships().get(0).getTargetUCD().equals(target.getProfileID())); - - Iterator it = client.getRelationshipChain(source.getId(),relId,true); - System.out.println("Scanning rel .."); - it.forEachRemaining(r -> { - System.out.println(r.getTarget().getId()); - System.out.println("Children size : "+r.getChildren().size()); - }); - - - Project unLinkedSource = client.deleteRelation( - new DeleteRelationshipRequest(source.getId(),relId, - target.getId(),null)); - - - assertTrue(unLinkedSource.getRelationships()==null || unLinkedSource.getRelationships().isEmpty()); - - } }