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;
|
2022-03-11 16:42:33 +01:00
|
|
|
import org.gcube.application.cms.tests.TokenSetter;
|
2022-02-16 17:12:54 +01:00
|
|
|
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;
|
2022-02-16 17:12:54 +01:00
|
|
|
import org.gcube.application.geoportal.common.model.document.filesets.RegisteredFileSet;
|
2022-03-04 14:23:20 +01:00
|
|
|
import org.gcube.application.geoportal.common.model.useCaseDescriptor.Field;
|
2022-02-16 17:12:54 +01:00
|
|
|
import org.gcube.application.geoportal.common.model.rest.RegisterFileSetRequest;
|
|
|
|
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;
|
2022-03-11 16:42:33 +01:00
|
|
|
import org.junit.BeforeClass;
|
2022-02-16 17:12:54 +01:00
|
|
|
import org.junit.Test;
|
|
|
|
|
|
|
|
import javax.ws.rs.client.Entity;
|
|
|
|
import javax.ws.rs.client.WebTarget;
|
|
|
|
import javax.ws.rs.core.MediaType;
|
|
|
|
|
|
|
|
import static org.junit.Assert.assertTrue;
|
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
|
|
|
|
|
|
|
@Override
|
|
|
|
protected WebTarget baseTarget() {
|
2022-04-08 13:17:52 +02:00
|
|
|
String testProfileId="basic";
|
2022-02-16 17:12:54 +01:00
|
|
|
return target(InterfaceConstants.Methods.PROJECTS).path(testProfileId);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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-03-04 14:23:20 +01:00
|
|
|
Project doc = createNew(new Document("field","value"));
|
2022-02-17 16:01:39 +01:00
|
|
|
|
2022-02-16 17:12:54 +01:00
|
|
|
assertTrue(doc.getTheDocument().containsKey("field"));
|
|
|
|
assertTrue(doc.getTheDocument().getString("field").equals("value"));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@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"));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testDelete() throws Exception {
|
|
|
|
assumeTrue(GCubeTest.isTestInfrastructureEnabled());
|
|
|
|
delete(createWithFileSet().getId());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
// Try set releazione scavo
|
2022-04-08 14:52:11 +02:00
|
|
|
String parentPath="section";
|
2022-02-16 17:12:54 +01:00
|
|
|
String fieldName="fileset";
|
2022-04-08 14:52:11 +02:00
|
|
|
String fieldDefinition="section."+Field.CHILDREN+"[?(@.fileset)]";
|
2022-02-16 17:12:54 +01:00
|
|
|
|
|
|
|
String filename = "relazione.pdf";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 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,
|
|
|
|
filename);
|
2022-05-17 11:43:50 +02:00
|
|
|
return doc;
|
2022-02-16 17:12:54 +01:00
|
|
|
}
|
|
|
|
|
2022-03-04 11:30:48 +01:00
|
|
|
// @Test
|
|
|
|
// public void testSDI() throws Exception {
|
|
|
|
// // Create new
|
2022-03-04 14:23:20 +01:00
|
|
|
// Project doc = createNew(new Document("posizionamentoScavo",new Document("title","Mio pos")));
|
2022-03-04 11:30:48 +01:00
|
|
|
//
|
|
|
|
// // register filesets
|
|
|
|
// doc = upload(
|
|
|
|
// new StorageUtils(),
|
|
|
|
// doc.getId(),
|
|
|
|
// "posizionamentoScavo","fileset",
|
|
|
|
// "posizionamentoScavo."+Field.CHILDREN+"[?(@.fileset)]",
|
|
|
|
// null,
|
|
|
|
// RegisterFileSetRequest.ClashOptions.REPLACE_EXISTING,
|
|
|
|
// "pos.shp","pos.shx");
|
|
|
|
//
|
|
|
|
// System.out.println("Registered posizionamento, result is "+ Serialization.write(doc));
|
|
|
|
//
|
|
|
|
// // invoke step SUBMIT-FOR-REVIEW
|
|
|
|
// StepExecutionRequest req=new StepExecutionRequest();
|
|
|
|
// req.setStepID("SUBMIT-FOR-REVIEW");
|
|
|
|
// doc=step(doc.getId(),req);
|
|
|
|
// System.out.println(doc);
|
|
|
|
// if(doc.getLifecycleInformation().getErrorMessages()!=null) {
|
|
|
|
// System.out.println("ERROR MESSAGES");
|
|
|
|
// doc.getLifecycleInformation().getErrorMessages().forEach(s -> System.out.println(s));
|
|
|
|
// }
|
|
|
|
// if(doc.getLifecycleInformation().getWarningMessages()!=null) {
|
|
|
|
// System.out.println("WARNING MESSAGES");
|
|
|
|
// doc.getLifecycleInformation().getWarningMessages().forEach(s -> System.out.println(s));
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// assertTrue(doc.getLifecycleInformation().getLastOperationStatus().equals(LifecycleInformation.Status.OK));
|
|
|
|
//
|
|
|
|
// JSONPathWrapper wrapper = new JSONPathWrapper(doc.getTheDocument().toJson());
|
|
|
|
// RegisteredFileSet fs = Serialization.convert(wrapper.getByPath("$..fileset").get(0),RegisteredFileSet.class);
|
|
|
|
// assertTrue(fs!=null);
|
|
|
|
// assertTrue(fs.getPayloads().size()==2);
|
|
|
|
// assertTrue(fs.getMaterializations().size()>0);
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// for(Object matObj : wrapper.getByPath("$..[?(@."+ Materialization.TYPE +" == '"+GCubeSDILayer.GCUBE_SDY_LAYER_TYPE+"' )]")){
|
|
|
|
// GCubeSDILayer layer = Serialization.convert(matObj, GCubeSDILayer.class);
|
|
|
|
// System.out.println("Checking Layer : "+layer);
|
|
|
|
// assertTrue(layer.getType().equals(GCubeSDILayer.GCUBE_SDY_LAYER_TYPE));
|
|
|
|
// assertTrue(layer.getOGCLinks().size()>0);
|
|
|
|
// assertTrue(layer.getPlatformInfo().size()>0);
|
|
|
|
// assertTrue(layer.getBBox()!=null);
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// // Checking platform info GeoServer
|
|
|
|
// for(Object platformObj : wrapper.getByPath("$..[?(@."+ Materialization.TYPE +" == 'GeoServer' )]")){
|
|
|
|
// Document platform=Serialization.asDocument(platformObj);
|
|
|
|
// assertTrue(platform.containsKey("layerName"));
|
|
|
|
// assertTrue(platform.containsKey("workspace"));
|
|
|
|
// assertTrue(platform.containsKey("storeName"));
|
|
|
|
// assertTrue(platform.containsKey("persistencePath"));
|
|
|
|
// assertTrue(platform.get("files",List.class).size()==2);
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// req.setStepID("APPROVE DRAFT");
|
|
|
|
// doc=step(doc.getId(),req);
|
|
|
|
// if(doc.getLifecycleInformation().getErrorMessages()!=null) {
|
|
|
|
// System.out.println("ERROR MESSAGES");
|
|
|
|
// doc.getLifecycleInformation().getErrorMessages().forEach(s -> System.out.println(s));
|
|
|
|
// }
|
|
|
|
// if(doc.getLifecycleInformation().getWarningMessages()!=null) {
|
|
|
|
// System.out.println("WARNING MESSAGES");
|
|
|
|
// doc.getLifecycleInformation().getWarningMessages().forEach(s -> System.out.println(s));
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// assertTrue(doc.getLifecycleInformation().getLastOperationStatus().equals(LifecycleInformation.Status.OK));
|
|
|
|
//
|
|
|
|
// }
|
2022-02-16 17:12:54 +01:00
|
|
|
|
|
|
|
}
|