Relationship tests
This commit is contained in:
parent
2b40d4058a
commit
118a3474fa
|
@ -93,7 +93,7 @@ public class ProfiledDocumentsTest<M extends Project,C extends Projects<M>> exte
|
|||
Project source = client.createNew(new Document().append("field","value"));
|
||||
Project target = client.createNew(new Document().append("field2","value"));
|
||||
|
||||
String relId="associate";
|
||||
String relId="follows";
|
||||
|
||||
|
||||
Project linkedSource = client.setRelation(
|
||||
|
|
|
@ -339,7 +339,7 @@ public class ProfiledMongoManager extends MongoManager implements MongoManagerI<
|
|||
reverseRel.setTargetID(id);
|
||||
reverseRel.setTargetUCD(getUseCaseDescriptor().getId());
|
||||
log.info("Setting reverse relation {} ",reverseRel);
|
||||
otherManager.lock(other.getId(),"Setting reverse relation "+reverseRel);
|
||||
other = otherManager.lock(other.getId(),"Setting reverse relation "+reverseRel);
|
||||
other.addRelation(reverseRel);
|
||||
otherManager.unlockAndUpdate(other);
|
||||
}
|
||||
|
@ -388,7 +388,7 @@ public class ProfiledMongoManager extends MongoManager implements MongoManagerI<
|
|||
log.debug("Removing reverse of {} ",r);
|
||||
ProfiledMongoManager otherManager = (targetUCD.equals(this.useCaseDescriptor.getId()))?this:new ProfiledMongoManager(targetUCD);
|
||||
Project other = getByID(targetId);
|
||||
otherManager.lock(other.getId(),"Remove reverse relation "+toDeleteReverseRelation + " toward "+getUseCaseDescriptor().getId()+":"+id);
|
||||
other = otherManager.lock(other.getId(),"Remove reverse relation "+toDeleteReverseRelation + " toward "+getUseCaseDescriptor().getId()+":"+id);
|
||||
final String finalToDeleteReverseRelation = toDeleteReverseRelation;
|
||||
other.getRelationships().removeIf(revRel ->revRel.getRelationshipName().equals(finalToDeleteReverseRelation)&&
|
||||
revRel.getTargetID().equals(id)&&revRel.getTargetUCD().equals(getUseCaseDescriptor().getId()));
|
||||
|
|
|
@ -31,21 +31,4 @@ public class InexistentUseCaseDescriptorTests extends AbstractProfiledDocumentsT
|
|||
assertEquals(404,resp.getStatus());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Test(expected = Exception.class)
|
||||
public void getAll() {
|
||||
super.getAll();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Test(expected = Exception.class)
|
||||
public void getByID() {
|
||||
super.getByID();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Test(expected = Exception.class)
|
||||
public void getConfiguration() {
|
||||
super.getByID();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@ import org.gcube.application.geoportal.service.BasicServiceTestUnit;
|
|||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.opengis.service.Interface;
|
||||
|
||||
import javax.ws.rs.client.Entity;
|
||||
import javax.ws.rs.client.WebTarget;
|
||||
|
@ -58,13 +59,12 @@ public abstract class AbstractProfiledDocumentsTests extends BasicServiceTestUni
|
|||
}
|
||||
|
||||
@Test
|
||||
public void getByID(){
|
||||
public void scanAllById(){
|
||||
assumeTrue(GCubeTest.isTestInfrastructureEnabled());
|
||||
baseTarget().request(MediaType.APPLICATION_JSON).get(List.class).forEach(d ->{
|
||||
|
||||
try {
|
||||
check(baseTarget().path((Serialization.convert(d, Project.class)).getId())
|
||||
.request(MediaType.APPLICATION_JSON).get(), Project.class);
|
||||
getById((Serialization.convert(d, Project.class)).getId());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace(System.err);
|
||||
Assert.fail(e.getMessage());
|
||||
|
@ -104,6 +104,36 @@ public abstract class AbstractProfiledDocumentsTests extends BasicServiceTestUni
|
|||
return doc;
|
||||
}
|
||||
|
||||
protected Project getById(String id ) throws Exception {
|
||||
Project doc =check(baseTarget().path(id).request(MediaType.APPLICATION_JSON).get(), Project.class);
|
||||
BasicTests.validate(doc);
|
||||
assertTrue(doc.getLifecycleInformation().getPhase().equals(LifecycleInformation.CommonPhases.DRAFT_PHASE));
|
||||
return doc;
|
||||
}
|
||||
|
||||
protected Project setRelation(Project current, String targetId, String targetUCD, String relationId) throws Exception {
|
||||
|
||||
Project doc =check(baseTarget().path(InterfaceConstants.Methods.RELATIONSHIP).
|
||||
path(current.getId()).path(relationId).
|
||||
queryParam(InterfaceConstants.Parameters.TARGET_ID,targetId).
|
||||
queryParam(InterfaceConstants.Parameters.TARGET_UCD,targetUCD).
|
||||
request(MediaType.APPLICATION_JSON).
|
||||
put(Entity.json("")), Project.class);
|
||||
BasicTests.validate(doc);
|
||||
return doc;
|
||||
}
|
||||
|
||||
protected Project deleteRelation(Project current, String targetId, String targetUCD, String relationId) throws Exception {
|
||||
|
||||
Project doc =check(baseTarget().path(InterfaceConstants.Methods.RELATIONSHIP).
|
||||
path(current.getId()).path(relationId).
|
||||
queryParam(InterfaceConstants.Parameters.TARGET_ID,targetId).
|
||||
queryParam(InterfaceConstants.Parameters.TARGET_UCD,targetUCD).
|
||||
request(MediaType.APPLICATION_JSON).
|
||||
delete(), Project.class);
|
||||
BasicTests.validate(doc);
|
||||
return doc;
|
||||
}
|
||||
protected void delete(String id) throws Exception {
|
||||
delete(id,false);
|
||||
}
|
||||
|
|
|
@ -3,20 +3,28 @@ package org.gcube.application.geoportal.service.profiledDocuments;
|
|||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.bson.Document;
|
||||
import org.gcube.application.cms.serialization.Serialization;
|
||||
import org.gcube.application.cms.tests.model.BasicTests;
|
||||
import org.gcube.application.geoportal.common.model.document.Project;
|
||||
import org.gcube.application.geoportal.common.model.document.identification.SpatialReference;
|
||||
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.model.useCaseDescriptor.Field;
|
||||
import org.gcube.application.geoportal.common.rest.InterfaceConstants;
|
||||
import org.gcube.application.geoportal.common.utils.StorageUtils;
|
||||
import org.gcube.application.geoportal.common.utils.tests.GCubeTest;
|
||||
import org.gcube.application.geoportal.service.utils.UserUtils;
|
||||
import org.junit.Test;
|
||||
|
||||
import javax.management.relation.Relation;
|
||||
import javax.ws.rs.client.Entity;
|
||||
import javax.ws.rs.client.WebTarget;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assume.assumeTrue;
|
||||
|
||||
@Slf4j
|
||||
public class ProfiledConcessioniTests extends AbstractProfiledDocumentsTests{
|
||||
|
@ -25,12 +33,14 @@ public class ProfiledConcessioniTests extends AbstractProfiledDocumentsTests{
|
|||
|
||||
@Override
|
||||
protected WebTarget baseTarget() {
|
||||
assumeTrue(GCubeTest.isTestInfrastructureEnabled());
|
||||
String testProfileId="profiledConcessioni";
|
||||
return super.baseTarget().path(testProfileId);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSDI() throws Exception {
|
||||
assumeTrue(GCubeTest.isTestInfrastructureEnabled());
|
||||
UserUtils.DEFAULT_ROLES.add("Data-Manager");
|
||||
// Create new
|
||||
|
||||
|
@ -82,6 +92,51 @@ public class ProfiledConcessioniTests extends AbstractProfiledDocumentsTests{
|
|||
System.out.println("Project "+doc.getId()+" published with spatial reference "+doc.getIdentificationReferenceByType(SpatialReference.SPATIAL_REFERENCE_TYPE).get(0));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testRelations() throws Exception {
|
||||
assumeTrue(GCubeTest.isTestInfrastructureEnabled());
|
||||
|
||||
Document theDoc=Document.parse("{\n" +
|
||||
"\"posizionamentoScavo\" :{\n" +
|
||||
"\t\"titolo\" : \"mio titolo\"}}");
|
||||
|
||||
Project doc1 = createNew(theDoc);
|
||||
Project doc2 = createNew(theDoc);
|
||||
|
||||
String rel = "follows";
|
||||
String reverse = "precedes";
|
||||
log.info("Creating relation ");
|
||||
doc1 = setRelation(doc1,doc2.getId(),null,rel);
|
||||
|
||||
log.debug("JSON Doc 1 : {}",Serialization.write(doc1));
|
||||
// check relation
|
||||
assertTrue(doc1.getRelationships().size()==1);
|
||||
assertEquals(doc1.getRelationships().get(0).getTargetID(),doc2.getId());
|
||||
assertEquals(doc1.getRelationships().get(0).getTargetUCD(),doc2.getProfileID());
|
||||
assertEquals(doc1.getRelationships().get(0).getRelationshipName(),rel);
|
||||
|
||||
// check reverse
|
||||
doc2=getById(doc2.getId());
|
||||
log.debug("JSON Doc 2 : {}",Serialization.write(doc2));
|
||||
assertTrue(doc2.getRelationships().size()==1);
|
||||
assertEquals(doc2.getRelationships().get(0).getTargetID(),doc1.getId());
|
||||
assertEquals(doc2.getRelationships().get(0).getTargetUCD(),doc1.getProfileID());
|
||||
assertEquals(doc2.getRelationships().get(0).getRelationshipName(),reverse);
|
||||
|
||||
|
||||
// clean
|
||||
doc2 = deleteRelation(doc2, doc1.getId(), doc1.getProfileID(),reverse);
|
||||
log.debug("JSON Doc 2 : {}",Serialization.write(doc2));
|
||||
assertTrue(doc2.getRelationships()==null || doc2.getRelationships().isEmpty());
|
||||
|
||||
doc1 = getById(doc1.getId());
|
||||
log.debug("JSON Doc 1 : {}",Serialization.write(doc1));
|
||||
assertTrue(doc1.getRelationships()==null || doc1.getRelationships().isEmpty());
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void delete() throws Exception {
|
||||
Document theDoc=Document.parse("{\n" +
|
||||
|
|
Loading…
Reference in New Issue