Tests
This commit is contained in:
parent
b23305d0fc
commit
e32a540c8e
|
@ -382,7 +382,7 @@ public class ProfiledMongoManager extends MongoManager implements MongoManagerI<
|
|||
|
||||
|
||||
private StepExecutionReport step(ProfiledDocument theDocument, String step, Document callParameters) throws StepException {
|
||||
log.info("[Profile {} ] Invoking Step {} on {}" ,profile.getId(),step,getManager().getDescriptor());
|
||||
log.info("[Profile {}] Invoking Step {} on {}" ,profile.getId(),step,getManager().getDescriptor());
|
||||
StepExecutionRequest request=new StepExecutionRequest();
|
||||
request.setCallParameters(callParameters);
|
||||
request.setDocument(theDocument);
|
||||
|
@ -392,7 +392,7 @@ public class ProfiledMongoManager extends MongoManager implements MongoManagerI<
|
|||
request.setUser(user.getUser());
|
||||
request.setContext(user.getContext());
|
||||
|
||||
log.debug("Requesting Step Execution {} ",request);
|
||||
log.debug("Requesting Step Execution {}",request);
|
||||
|
||||
StepExecutionReport report= getManager().performStep(request);
|
||||
log.debug("Report is {}",report);
|
||||
|
@ -401,13 +401,13 @@ public class ProfiledMongoManager extends MongoManager implements MongoManagerI<
|
|||
}
|
||||
|
||||
private EventExecutionReport triggerEvent(ProfiledDocument theDocument, String event, Document parameters) throws EventException {
|
||||
log.info("[Profile {} ] triggering event {} on {}" ,profile.getId(),event,getManager().getDescriptor());
|
||||
log.info("[Profile {}] triggering event {} on {}" ,profile.getId(),event,getManager().getDescriptor());
|
||||
EventExecutionRequest request= new EventExecutionRequest();
|
||||
request.setEvent(event);
|
||||
request.setProfile(profile);
|
||||
request.setCallParameters(parameters);
|
||||
request.setDocument(theDocument);
|
||||
log.debug("Triggering {} ",request);
|
||||
log.debug("Triggering {}",request);
|
||||
return getManager().onEvent(request);
|
||||
}
|
||||
|
||||
|
|
|
@ -101,10 +101,10 @@ public class ProfiledDocuments {
|
|||
return new GuardedMethod<ProfiledDocument>() {
|
||||
@Override
|
||||
protected ProfiledDocument run() throws Exception, WebApplicationException {
|
||||
log.info("Registering {} file(s) for ProfiledDocument ({}, ID {}) at path {}",
|
||||
log.info("Registering {} file(s) for ProfiledDocument ({}, ID {}) with {}",
|
||||
request.getStreams().size(),
|
||||
manager.getProfile().getId(),
|
||||
id,request.getDestinationPath());
|
||||
id,request);
|
||||
request.validate();
|
||||
return manager.registerFileSet(id,request);
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package org.gcube.application.geoportal.service;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.jayway.jsonpath.JsonPath;
|
||||
import org.bson.Document;
|
||||
import org.gcube.application.cms.serialization.Serialization;
|
||||
import org.gcube.application.cms.tests.TokenSetter;
|
||||
|
@ -8,6 +9,7 @@ import org.gcube.application.cms.tests.model.concessioni.TestConcessioniModel;
|
|||
import org.gcube.application.geoportal.common.model.JSONPathWrapper;
|
||||
import org.gcube.application.geoportal.common.model.document.ProfiledDocument;
|
||||
import org.gcube.application.geoportal.common.model.document.filesets.RegisteredFileSet;
|
||||
import org.gcube.application.geoportal.common.model.document.lifecycle.LifecycleInformation;
|
||||
import org.gcube.application.geoportal.common.model.rest.Configuration;
|
||||
import org.gcube.application.geoportal.common.model.rest.QueryRequest;
|
||||
import org.gcube.application.geoportal.common.model.rest.RegisterFileSetRequest;
|
||||
|
@ -30,8 +32,7 @@ import java.util.List;
|
|||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public abstract class ProfiledDocumentsTests extends BasicServiceTestUnit{
|
||||
|
||||
public abstract class AbstractProfiledDocumentsTests extends BasicServiceTestUnit{
|
||||
|
||||
|
||||
@Before
|
||||
|
@ -78,119 +79,31 @@ public abstract class ProfiledDocumentsTests extends BasicServiceTestUnit{
|
|||
|
||||
// CREATE / edit / delete
|
||||
|
||||
@Test
|
||||
public void registerNew() throws Exception {
|
||||
createNew();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void edit() throws Exception {
|
||||
ProfiledDocument doc=createNew();
|
||||
String beforeJson=doc.getTheDocument().toJson();
|
||||
doc.getTheDocument().put("someStrangeField","someOtherRandomValue");
|
||||
String edited=doc.getTheDocument().toJson();
|
||||
Assert.assertNotEquals(beforeJson,doc.getTheDocument().toJson());
|
||||
doc=check(baseTarget().path(doc.get_id()).request(MediaType.APPLICATION_JSON).
|
||||
put(Entity.entity(doc.getTheDocument(), MediaType.APPLICATION_JSON)),ProfiledDocument.class);
|
||||
Assert.assertEquals(edited,doc.getTheDocument().toJson());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddSingleFileSet() throws Exception {
|
||||
|
||||
ProfiledDocument doc = createNew();
|
||||
// Try set releazione scavo
|
||||
String fileSetPath="relazioneScavo";
|
||||
String fieldPath="relazioneScavo";
|
||||
String filename = "relazione.pdf";
|
||||
|
||||
// INSERT ONE, MERGE INFO (NB default values already exist)
|
||||
doc = upload(
|
||||
new StorageUtils(),
|
||||
doc.get_id(),
|
||||
fileSetPath,
|
||||
fieldPath,
|
||||
Document.parse("{\"titolo\" : \"mio titolo\",\"some\" : \"something\" }"),
|
||||
RegisterFileSetRequest.ClashOptions.MERGE_EXISTING,
|
||||
filename);
|
||||
assertTrue("Relazione exists",doc.getTheDocument().containsKey(fileSetPath));
|
||||
RegisteredFileSet set = Serialization.convert(doc.getTheDocument().get(fileSetPath), RegisteredFileSet.class);
|
||||
assertTrue("Correctly merged attributes ",set.getString("titolo").equals("mio titolo"));
|
||||
assertTrue("Correctly merged attributes ",set.getString("some").equals("something"));
|
||||
|
||||
// REPLACE SAME, CHANGE TITLE
|
||||
doc = upload(
|
||||
new StorageUtils(),
|
||||
doc.get_id(),
|
||||
fileSetPath,
|
||||
fieldPath,
|
||||
Document.parse("{\"titolo\" : \"mio altro titolo\"}"),
|
||||
RegisterFileSetRequest.ClashOptions.REPLACE_EXISTING,
|
||||
filename);
|
||||
set = Serialization.convert(doc.getTheDocument().get(fileSetPath), RegisteredFileSet.class);
|
||||
assertTrue("Correctly merged attributes ",set.getString("titolo").equals("mio altro titolo"));
|
||||
assertTrue("Correctly merged attributes ",!set.containsKey("some"));
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMutlipleFileSet() throws Exception {
|
||||
|
||||
ProfiledDocument doc = createNew();
|
||||
// ADD 4 IMGS
|
||||
for (int i = 0; i < 4; i++) {
|
||||
doc = upload(
|
||||
new StorageUtils(),
|
||||
doc.get_id(),
|
||||
"immagini",
|
||||
"imgs",
|
||||
null,
|
||||
RegisterFileSetRequest.ClashOptions.APPEND,
|
||||
"relazione.pdf");
|
||||
}
|
||||
assertTrue(doc.getTheDocument().containsKey("immagini"));
|
||||
assertTrue("Expected 4 imgs registered",Serialization.convert(doc.getTheDocument().get("immagini"), List.class).size()==4);
|
||||
|
||||
|
||||
// Replace img [3]
|
||||
doc = upload(
|
||||
new StorageUtils(),
|
||||
doc.get_id(),
|
||||
"immagini[3]",
|
||||
"imgs",
|
||||
Document.parse("{\"titolo\" : \"mia immagine\"}"),
|
||||
RegisterFileSetRequest.ClashOptions.REPLACE_EXISTING,
|
||||
"relazione.pdf");
|
||||
|
||||
String title = new JSONPathWrapper(doc.getTheDocument().toJson()).
|
||||
getByPath("immagini[3].titolo",String.class).get(0);
|
||||
|
||||
assertTrue("Changed Title",title.equals("mia immagine"));
|
||||
}
|
||||
|
||||
|
||||
|
||||
// @@@@@@@@@@@@@@@ Routines
|
||||
protected ProfiledDocument createNew() throws Exception {
|
||||
Document document =new Document(Collections.singletonMap("dumbKey","dumbValue"));
|
||||
|
||||
protected ProfiledDocument createNew(Document content) throws Exception {
|
||||
return check(baseTarget().request(MediaType.APPLICATION_JSON).
|
||||
post(Entity.entity(document, MediaType.APPLICATION_JSON)),ProfiledDocument.class);
|
||||
post(Entity.entity(content, MediaType.APPLICATION_JSON)),ProfiledDocument.class);
|
||||
}
|
||||
|
||||
protected ProfiledDocument update(String id, Document newContent)throws Exception {
|
||||
return check(baseTarget().path(id).request(MediaType.APPLICATION_JSON).
|
||||
put(Entity.entity(newContent, MediaType.APPLICATION_JSON)),ProfiledDocument.class);
|
||||
}
|
||||
|
||||
protected ProfiledDocument upload(StorageUtils storage,
|
||||
String id,
|
||||
String path,
|
||||
String parentPath,
|
||||
String fieldName,
|
||||
String fieldDefinitionPath,
|
||||
Document attributes,
|
||||
RegisterFileSetRequest.ClashOptions clashPolicy,
|
||||
String ...files) throws Exception {
|
||||
FileSets.RequestBuilder builder = FileSets.build(path);
|
||||
FileSets.RequestBuilder builder = FileSets.build(parentPath,fieldName,fieldDefinitionPath);
|
||||
|
||||
builder.setFieldDescriptionPath(fieldDefinitionPath).setClashPolicy(clashPolicy).setAttributes(attributes);
|
||||
builder.setClashPolicy(clashPolicy).setAttributes(attributes);
|
||||
|
||||
for(String file:files)
|
||||
builder.add(storage.putOntoStorage(new File(TestConcessioniModel.getBaseFolder(),file),file));
|
||||
|
@ -210,4 +123,5 @@ public abstract class ProfiledDocumentsTests extends BasicServiceTestUnit{
|
|||
assertTrue(toReturn.getLifecycleInformation().getLastInvokedStep().equals(request.getStepID()));
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
}
|
|
@ -11,6 +11,7 @@ import org.gcube.application.geoportal.common.model.legacy.Concessione;
|
|||
import org.gcube.application.geoportal.common.model.legacy.Concessione.Paths;
|
||||
import org.gcube.application.geoportal.common.model.legacy.LayerConcessione;
|
||||
import org.gcube.application.geoportal.common.model.legacy.report.ValidationReport.ValidationStatus;
|
||||
import org.gcube.application.geoportal.common.model.rest.AddSectionToConcessioneRequest;
|
||||
import org.gcube.application.geoportal.common.model.rest.QueryRequest;
|
||||
import org.gcube.application.geoportal.common.rest.InterfaceConstants;
|
||||
import org.gcube.application.geoportal.common.utils.FileSets;
|
||||
|
@ -51,25 +52,30 @@ public class ConcessioniOverMongoTest extends BasicServiceTestUnit{
|
|||
|
||||
//Used for local test data
|
||||
private static Concessione upload(StorageUtils storage, WebTarget target,String id, String path, String ...files) throws Exception {
|
||||
FileSets.RequestBuilder builder = FileSets.build(path);
|
||||
AddSectionToConcessioneRequest request = new AddSectionToConcessioneRequest();
|
||||
request.setDestinationPath(path);
|
||||
request.setStreams(new ArrayList<>());
|
||||
|
||||
|
||||
for(String file:files)
|
||||
builder.add(storage.putOntoStorage(new File(TestConcessioniModel.getBaseFolder(),file),file));
|
||||
request.getStreams()
|
||||
.add(storage.putOntoStorage(new File(TestConcessioniModel.getBaseFolder(),file),file));
|
||||
|
||||
return check(target.path(FILES_PATH).path(id).request(MediaType.APPLICATION_JSON).
|
||||
post(Entity.entity(Serialization.write(builder.getTheRequest()),
|
||||
post(Entity.entity(Serialization.write(request),
|
||||
MediaType.APPLICATION_JSON)),Concessione.class);
|
||||
}
|
||||
|
||||
//generic
|
||||
private static Concessione upload(StorageUtils storage, WebTarget target,String id, String path, File ...files) throws Exception {
|
||||
FileSets.RequestBuilder builder = FileSets.build(path);
|
||||
|
||||
AddSectionToConcessioneRequest request = new AddSectionToConcessioneRequest();
|
||||
request.setDestinationPath(path);
|
||||
request.setStreams(new ArrayList<>());
|
||||
for(File file:files)
|
||||
builder.add(storage.putOntoStorage(file,file.getName()));
|
||||
request.getStreams().add(storage.putOntoStorage(file,file.getName()));
|
||||
|
||||
return check(target.path(FILES_PATH).path(id).request(MediaType.APPLICATION_JSON).
|
||||
post(Entity.entity(Serialization.write(builder.getTheRequest()),
|
||||
post(Entity.entity(Serialization.write(request),
|
||||
MediaType.APPLICATION_JSON)),Concessione.class);
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,151 @@
|
|||
package org.gcube.application.geoportal.service;
|
||||
|
||||
import org.bson.Document;
|
||||
import org.gcube.application.cms.serialization.Serialization;
|
||||
import org.gcube.application.geoportal.common.model.JSONPathWrapper;
|
||||
import org.gcube.application.geoportal.common.model.document.ProfiledDocument;
|
||||
import org.gcube.application.geoportal.common.model.document.filesets.GCubeSDILayer;
|
||||
import org.gcube.application.geoportal.common.model.document.filesets.Materialization;
|
||||
import org.gcube.application.geoportal.common.model.document.filesets.RegisteredFileSet;
|
||||
import org.gcube.application.geoportal.common.model.document.lifecycle.LifecycleInformation;
|
||||
import org.gcube.application.geoportal.common.model.rest.RegisterFileSetRequest;
|
||||
import org.gcube.application.geoportal.common.model.rest.StepExecutionRequest;
|
||||
import org.gcube.application.geoportal.common.rest.InterfaceConstants;
|
||||
import org.gcube.application.geoportal.common.utils.StorageUtils;
|
||||
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;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class DummyProfiledDocumentTest extends AbstractProfiledDocumentsTests{
|
||||
|
||||
@Override
|
||||
protected WebTarget baseTarget() {
|
||||
String testProfileId="profiledConcessioni";
|
||||
return target(InterfaceConstants.Methods.PROJECTS).path(testProfileId);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void registerNew() throws Exception {
|
||||
|
||||
ProfiledDocument doc = createNew(new Document("field","value"));
|
||||
assertTrue(doc!=null);
|
||||
assertTrue(doc.get_id()!=null);
|
||||
assertTrue(doc.getLifecycleInformation().getPhase().equals(LifecycleInformation.DRAFT_PHASE));
|
||||
assertTrue(doc.getTheDocument()!=null);
|
||||
assertTrue(doc.getTheDocument().containsKey("field"));
|
||||
assertTrue(doc.getTheDocument().getString("field").equals("value"));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void edit() throws Exception {
|
||||
ProfiledDocument doc=createNew(new Document());
|
||||
String beforeJson=doc.getTheDocument().toJson();
|
||||
doc.getTheDocument().put("someStrangeField","someOtherRandomValue");
|
||||
String edited=doc.getTheDocument().toJson();
|
||||
Assert.assertNotEquals(beforeJson,doc.getTheDocument().toJson());
|
||||
doc=check(baseTarget().path(doc.get_id()).request(MediaType.APPLICATION_JSON).
|
||||
put(Entity.entity(doc.getTheDocument(), MediaType.APPLICATION_JSON)),ProfiledDocument.class);
|
||||
Assert.assertEquals(edited,doc.getTheDocument().toJson());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUploadFileSet() throws Exception {
|
||||
|
||||
Document baseDoc=new Document();
|
||||
baseDoc.put("relazioneScavo",new Document("title","My Title"));
|
||||
|
||||
ProfiledDocument doc = createNew(baseDoc);
|
||||
assertTrue(doc.getTheDocument().containsKey("relazioneScavo"));
|
||||
|
||||
|
||||
// Try set releazione scavo
|
||||
String parentPath="relazioneScavo";
|
||||
String fieldName="fileset";
|
||||
String fieldDefinition="relazioneScavo.children[?(@.fileset)]";
|
||||
|
||||
String filename = "relazione.pdf";
|
||||
|
||||
|
||||
|
||||
// INSERT ONE, MERGE INFO (NB default values already exist)
|
||||
doc = upload(
|
||||
new StorageUtils(),
|
||||
doc.get_id(),
|
||||
parentPath,fieldName,
|
||||
fieldDefinition,
|
||||
new Document("customField","customFieldValue"),
|
||||
RegisterFileSetRequest.ClashOptions.REPLACE_EXISTING,
|
||||
filename);
|
||||
|
||||
JSONPathWrapper wrapper = new JSONPathWrapper(doc.getTheDocument().toJson());
|
||||
assertTrue("Relazione exists",wrapper.getMatchingPaths(parentPath).size()==1);
|
||||
RegisteredFileSet fs = Serialization.convert(wrapper.getByPath(parentPath+"."+fieldName).get(0),RegisteredFileSet.class);
|
||||
assertTrue(fs.getPayloads().size()==1);
|
||||
assertTrue(fs.getString("customField").equals("customFieldValue"));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSDI() throws Exception {
|
||||
// Create new
|
||||
ProfiledDocument doc = createNew(new Document("posizionamentoScavo",new Document("title","Mio pos")));
|
||||
|
||||
// register filesets
|
||||
doc = upload(
|
||||
new StorageUtils(),
|
||||
doc.get_id(),
|
||||
"posizionamentoScavo","fileset",
|
||||
"posizionamentoScavo.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.get_id(),req);
|
||||
System.out.println(doc);
|
||||
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.getPayloads().size()==2);
|
||||
assertTrue(fs.getMaterializations().size()>0);
|
||||
|
||||
|
||||
for(Object matObj : wrapper.getByPath("$..fileset."+RegisteredFileSet.MATERIALIZATIONS)){
|
||||
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
|
||||
for(Object platformObj : wrapper.getByPath("$..[?(@."+ Materialization.TYPE +" == '"+GCubeSDILayer.GCUBE_SDY_LAYER_TYPE+"' )]")){
|
||||
Document platform=Serialization.asDocument(platformObj);
|
||||
assertTrue(platform.containsKey("_type"));
|
||||
if(platform.get("_type").equals("GeoServer")){
|
||||
assertTrue(platform.containsKey("layerName"));
|
||||
assertTrue(platform.containsKey("workspace"));
|
||||
assertTrue(platform.containsKey("storeName"));
|
||||
assertTrue(platform.containsKey("persistencePath"));
|
||||
assertTrue(platform.get("files",List.class).size()==2);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -8,7 +8,8 @@ import javax.ws.rs.core.Response;
|
|||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class InexistentProfileTests extends ProfiledDocumentsTests {
|
||||
public class InexistentProfileTests extends AbstractProfiledDocumentsTests {
|
||||
|
||||
@Override
|
||||
protected WebTarget baseTarget() {
|
||||
String testProfileId="profiledConcessioni";
|
||||
|
|
|
@ -17,7 +17,7 @@ import javax.ws.rs.core.Response;
|
|||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class ProfiledConcessioniTests extends ProfiledDocumentsTests{
|
||||
public class ProfiledConcessioniTests extends AbstractProfiledDocumentsTests{
|
||||
|
||||
|
||||
@Override
|
||||
|
@ -29,12 +29,13 @@ public class ProfiledConcessioniTests extends ProfiledDocumentsTests{
|
|||
@Test
|
||||
public void testSDI() throws Exception {
|
||||
// Create new
|
||||
ProfiledDocument doc = createNew();
|
||||
ProfiledDocument doc = createNew(new Document());
|
||||
|
||||
// register filesets
|
||||
doc = upload(
|
||||
new StorageUtils(),
|
||||
doc.get_id(),
|
||||
"posizionamentoScavo.fileset",
|
||||
"posizionamentoScavo","fileset",
|
||||
"posizionamentoScavo.children[?(@.fileset)]",
|
||||
Document.parse("{\"titolo\" : \"mio titolo\",\"some\" : \"something\" }"),
|
||||
RegisterFileSetRequest.ClashOptions.MERGE_EXISTING,
|
||||
|
|
Loading…
Reference in New Issue