gcube-cms-suite/geoportal-service/src/test/java/org/gcube/application/geoportal/service/profiledDocuments/DummyProjectTest.java

162 lines
6.1 KiB
Java
Raw Normal View History

2022-02-24 18:09:30 +01:00
package org.gcube.application.geoportal.service.profiledDocuments;
2022-02-16 17:12:54 +01:00
import org.bson.Document;
import org.gcube.application.cms.serialization.Serialization;
import org.gcube.application.geoportal.common.model.JSONPathWrapper;
2022-03-04 14:23:20 +01:00
import org.gcube.application.geoportal.common.model.document.Project;
2023-01-10 11:42:09 +01:00
import org.gcube.application.geoportal.common.model.document.access.Access;
import org.gcube.application.geoportal.common.model.document.access.AccessPolicy;
2022-02-16 17:12:54 +01:00
import org.gcube.application.geoportal.common.model.document.filesets.RegisteredFileSet;
2022-09-30 14:57:28 +02:00
import org.gcube.application.geoportal.common.model.document.relationships.Relationship;
2022-02-16 17:12:54 +01:00
import org.gcube.application.geoportal.common.model.rest.RegisterFileSetRequest;
2022-09-26 16:11:20 +02:00
import org.gcube.application.geoportal.common.model.useCaseDescriptor.Field;
2022-02-16 17:12:54 +01:00
import org.gcube.application.geoportal.common.rest.InterfaceConstants;
import org.gcube.application.geoportal.common.utils.StorageUtils;
2022-03-11 16:42:33 +01:00
import org.gcube.application.geoportal.common.utils.tests.GCubeTest;
2022-02-24 18:09:30 +01:00
import org.gcube.application.geoportal.service.BasicServiceTestUnit;
2022-02-16 17:12:54 +01:00
import org.junit.Assert;
import org.junit.Test;
import javax.ws.rs.client.Entity;
import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.MediaType;
2022-08-31 18:06:19 +02:00
import java.time.LocalDateTime;
2022-09-30 14:57:28 +02:00
import static org.junit.Assert.*;
2022-03-11 16:42:33 +01:00
import static org.junit.Assume.assumeTrue;
2022-02-16 17:12:54 +01:00
2022-03-04 14:23:20 +01:00
public class DummyProjectTest extends AbstractProfiledDocumentsTests{
2022-02-16 17:12:54 +01:00
2022-08-04 17:02:47 +02:00
// Try set releazione scavo
String parentPath="section";
String fieldName="fileset";
String fieldDefinition="section."+Field.CHILDREN+"[?(@.fileset)]";
2023-01-10 15:57:40 +01:00
String filename = "concessioni/sample.tif";
2022-08-04 17:02:47 +02:00
2022-02-16 17:12:54 +01:00
@Override
protected WebTarget baseTarget() {
2022-04-08 13:17:52 +02:00
String testProfileId="basic";
2022-08-31 18:06:19 +02:00
return super.baseTarget().path(testProfileId);
2022-02-16 17:12:54 +01:00
}
2022-03-11 16:42:33 +01:00
2022-02-16 17:12:54 +01:00
@Test
public void registerNew() throws Exception {
2022-03-22 18:07:34 +01:00
assumeTrue(GCubeTest.isTestInfrastructureEnabled());
2022-08-31 18:06:19 +02:00
Document doc = new Document("field","value");
doc.put("startTime", LocalDateTime.now());
System.out.println(Serialization.write(doc));
Project project = createNew(doc);
System.out.println(Serialization.write(project));
assertTrue(project.getTheDocument().containsKey("field"));
assertTrue(project.getTheDocument().getString("field").equals("value"));
2022-02-16 17:12:54 +01:00
}
@Test
public void edit() throws Exception {
2022-03-22 18:07:34 +01:00
assumeTrue(GCubeTest.isTestInfrastructureEnabled());
2022-03-04 14:23:20 +01:00
Project doc=createNew(new Document());
2022-02-16 17:12:54 +01:00
String beforeJson=doc.getTheDocument().toJson();
doc.getTheDocument().put("someStrangeField","someOtherRandomValue");
String edited=doc.getTheDocument().toJson();
Assert.assertNotEquals(beforeJson,doc.getTheDocument().toJson());
2022-02-24 18:09:30 +01:00
doc= BasicServiceTestUnit.check(baseTarget().path(doc.getId()).request(MediaType.APPLICATION_JSON).
2022-03-04 14:23:20 +01:00
put(Entity.entity(doc.getTheDocument(), MediaType.APPLICATION_JSON)), Project.class);
2022-02-16 17:12:54 +01:00
Assert.assertEquals(edited,doc.getTheDocument().toJson());
}
@Test
public void testUploadFileSet() throws Exception {
2022-03-22 18:07:34 +01:00
assumeTrue(GCubeTest.isTestInfrastructureEnabled());
2022-05-17 11:43:50 +02:00
Project doc = createWithFileSet();
JSONPathWrapper wrapper = new JSONPathWrapper(doc.getTheDocument().toJson());
assertTrue("Relazione exists",wrapper.getMatchingPaths("section").size()==1);
RegisteredFileSet fs = Serialization.convert(wrapper.getByPath("section.fileset").get(0),RegisteredFileSet.class);
assertTrue(fs.getPayloads().size()==1);
assertTrue(fs.getString("customField").equals("customFieldValue"));
2022-08-04 17:02:47 +02:00
// test replace
doc = upload(
new StorageUtils(),
doc.getId(),
parentPath,fieldName,
fieldDefinition,
new Document("customField","customFieldValue"),
RegisterFileSetRequest.ClashOptions.REPLACE_EXISTING,
2023-01-10 11:42:09 +01:00
new Access(),filename);
2022-08-04 17:02:47 +02:00
wrapper = new JSONPathWrapper(doc.getTheDocument().toJson());
assertTrue("Relazione exists",wrapper.getMatchingPaths("section").size()==1);
fs = Serialization.convert(wrapper.getByPath("section.fileset").get(0),RegisteredFileSet.class);
assertTrue(fs.getPayloads().size()==1);
assertTrue(fs.getString("customField").equals("customFieldValue"));
2022-05-17 11:43:50 +02:00
}
@Test
2022-08-31 18:06:19 +02:00
public void testSimpleDelete() throws Exception {
assumeTrue(GCubeTest.isTestInfrastructureEnabled());
Document baseDoc=new Document();
baseDoc.put("section",new Document("title","My Title"));
Project doc = createNew(baseDoc);
}
@Test
public void testFullDelete() throws Exception {
2022-05-17 11:43:50 +02:00
assumeTrue(GCubeTest.isTestInfrastructureEnabled());
2022-05-31 16:10:41 +02:00
delete(createWithFileSet().getId(),true);
2022-05-17 11:43:50 +02:00
}
2022-08-31 18:06:19 +02:00
2022-05-17 11:43:50 +02:00
private Project createWithFileSet() throws Exception {
2022-02-16 17:12:54 +01:00
Document baseDoc=new Document();
2022-04-08 14:52:11 +02:00
baseDoc.put("section",new Document("title","My Title"));
2022-02-16 17:12:54 +01:00
2022-03-04 14:23:20 +01:00
Project doc = createNew(baseDoc);
2022-02-16 17:12:54 +01:00
2023-01-10 11:42:09 +01:00
Access access =new Access();
access.setLicense("test-license");
access.setPolicy(AccessPolicy.RESTRICTED);
2022-02-16 17:12:54 +01:00
// INSERT ONE, MERGE INFO (NB default values already exist)
doc = upload(
new StorageUtils(),
2022-02-23 17:13:22 +01:00
doc.getId(),
2022-02-16 17:12:54 +01:00
parentPath,fieldName,
fieldDefinition,
new Document("customField","customFieldValue"),
RegisterFileSetRequest.ClashOptions.REPLACE_EXISTING,
2023-01-10 11:42:09 +01:00
access,filename);
2022-08-04 17:02:47 +02:00
2022-05-17 11:43:50 +02:00
return doc;
2022-02-16 17:12:54 +01:00
}
2023-01-10 15:57:40 +01:00
// Not automatic, needs generation of locked project
2022-03-04 11:30:48 +01:00
// @Test
2023-01-10 15:57:40 +01:00
// public void testUnlock() throws Exception {
// assumeTrue(GCubeTest.isTestInfrastructureEnabled());
// assumeTrue(false);
// String id = "627e87bb02ad3d1a2e0e9e18";
// String ucd = "profiledConcessioni";
// Project p =check(target(InterfaceConstants.Methods.PROJECTS).path(ucd).path(InterfaceConstants.Methods.FORCE_UNLOCK).path(id).request(MediaType.APPLICATION_JSON).
// put(Entity.entity("", MediaType.APPLICATION_JSON)), Project.class);
// assertNull(p.getLock());
2022-03-04 11:30:48 +01:00
// }
2022-02-16 17:12:54 +01:00
}