Fix tests

This commit is contained in:
Fabio Sinibaldi 2023-01-18 17:43:44 +01:00
parent 56bac71bb2
commit a86310ade5
3 changed files with 120 additions and 53 deletions

View File

@ -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());
}

View File

@ -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 <M extends Project,C extends Projects<M>> 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<M> client = (Projects<M>) 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<RelationshipNavigationObject> 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());
}
}

View File

@ -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<M extends Project,C extends Projects<M>> 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<M> client = (Projects<M>) 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<M extends Project,C extends Projects<M>> 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<M> client = (Projects<M>) 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<M extends Project,C extends Projects<M>> exte
});
}
@Test
public void testRelationships() throws Exception{
assumeTrue(GCubeTest.isTestInfrastructureEnabled());
Projects<M> client = (Projects<M>) 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<RelationshipNavigationObject> 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());
}
}