126 lines
6.8 KiB
Java
126 lines
6.8 KiB
Java
package org.gcube.informationsystem.model.impl.properties;
|
|
|
|
import java.util.Calendar;
|
|
import java.util.UUID;
|
|
|
|
import org.gcube.informationsystem.base.reference.Element;
|
|
import org.gcube.informationsystem.model.reference.entities.Facet;
|
|
import org.gcube.informationsystem.model.reference.entities.Resource;
|
|
import org.gcube.informationsystem.model.reference.properties.PropagationConstraint;
|
|
import org.gcube.informationsystem.model.reference.properties.PropagationConstraint.AddConstraint;
|
|
import org.gcube.informationsystem.model.reference.properties.PropagationConstraint.RemoveConstraint;
|
|
import org.gcube.informationsystem.model.reference.properties.Property;
|
|
import org.gcube.informationsystem.model.reference.relations.ConsistsOf;
|
|
import org.gcube.informationsystem.utils.ElementMapper;
|
|
import org.junit.Assert;
|
|
import org.junit.Test;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
/**
|
|
* @author Luca Frosini (ISTI - CNR)
|
|
*/
|
|
public class PropagationConstraintTest {
|
|
|
|
private static Logger logger = LoggerFactory.getLogger(PropagationConstraintTest.class);
|
|
|
|
@Test
|
|
public void testPropagationConstraint() throws Exception {
|
|
PropagationConstraint propagationConstraint = new PropagationConstraintImpl();
|
|
propagationConstraint.setAddConstraint(AddConstraint.propagate);
|
|
propagationConstraint.setRemoveConstraint(RemoveConstraint.cascadeWhenOrphan);
|
|
String pg = ElementMapper.marshal(propagationConstraint);
|
|
|
|
Property property = ElementMapper.unmarshal(Property.class, pg);
|
|
Assert.assertTrue(property instanceof PropagationConstraint);
|
|
logger.debug(ElementMapper.marshal(property));
|
|
|
|
PropagationConstraint pgUnm = ElementMapper.unmarshal(PropagationConstraint.class, pg);
|
|
Assert.assertTrue(property instanceof PropagationConstraint);
|
|
logger.debug(ElementMapper.marshal(pgUnm));
|
|
}
|
|
|
|
@Test
|
|
public void testPropagationConstraintByString() throws Exception {
|
|
AddConstraint addConstraint = AddConstraint.propagate;
|
|
RemoveConstraint removeConstraint = RemoveConstraint.cascade;
|
|
PropagationConstraint pc = new PropagationConstraintImpl();
|
|
pc.setAddConstraint(addConstraint);
|
|
pc.setRemoveConstraint(removeConstraint);
|
|
|
|
String json = ElementMapper.marshal(pc);
|
|
logger.debug(json);
|
|
|
|
Property property = ElementMapper.unmarshal(Property.class, json);
|
|
Assert.assertTrue(property instanceof PropagationConstraint);
|
|
Assert.assertTrue(((PropagationConstraint) property).getAddConstraint().compareTo(addConstraint)==0);
|
|
Assert.assertTrue(((PropagationConstraint) property).getRemoveConstraint().compareTo(removeConstraint)==0);
|
|
logger.debug(ElementMapper.marshal(property));
|
|
|
|
PropagationConstraint propagationConstraint = ElementMapper.unmarshal(PropagationConstraint.class, json);
|
|
Assert.assertTrue(propagationConstraint instanceof PropagationConstraint);
|
|
Assert.assertTrue(propagationConstraint.getAddConstraint().compareTo(addConstraint)==0);
|
|
Assert.assertTrue(propagationConstraint.getRemoveConstraint().compareTo(removeConstraint)==0);
|
|
logger.debug(ElementMapper.marshal(property));
|
|
}
|
|
|
|
@Test
|
|
public void testPropagationConstraintSpecilization() throws Exception {
|
|
AddConstraint addConstraint = AddConstraint.propagate;
|
|
RemoveConstraint removeConstraint = RemoveConstraint.cascade;
|
|
String marshalled = "{\"" + Element.CLASS_PROPERTY + "\":\"MyPropagationConstraint\",\"" + Element.SUPERCLASSES_PROPERTY + "\":[\"" + PropagationConstraint.NAME + "\", \"" + Property.NAME + "\"],\"" + PropagationConstraint.ADD_PROPERTY + "\":\""+ addConstraint + "\",\""+ PropagationConstraint.REMOVE_PROPERTY + "\":\"" + removeConstraint + "\"}";
|
|
logger.debug(marshalled);
|
|
|
|
Property property = ElementMapper.unmarshal(Property.class, marshalled);
|
|
Assert.assertTrue(property instanceof PropagationConstraint);
|
|
Assert.assertTrue(((PropagationConstraint) property).getAddConstraint().compareTo(addConstraint)==0);
|
|
Assert.assertTrue(((PropagationConstraint) property).getRemoveConstraint().compareTo(removeConstraint)==0);
|
|
logger.debug(ElementMapper.marshal(property));
|
|
|
|
PropagationConstraint propagationConstraint = ElementMapper.unmarshal(PropagationConstraint.class, marshalled);
|
|
Assert.assertTrue(propagationConstraint instanceof PropagationConstraint);
|
|
Assert.assertTrue(propagationConstraint.getAddConstraint().compareTo(addConstraint)==0);
|
|
Assert.assertTrue(propagationConstraint.getRemoveConstraint().compareTo(removeConstraint)==0);
|
|
logger.debug(ElementMapper.marshal(property));
|
|
}
|
|
|
|
|
|
@Test
|
|
public void testPropagationConstraintSpecilizationInside() throws Exception {
|
|
AddConstraint addConstraint = AddConstraint.propagate;
|
|
RemoveConstraint removeConstraint = RemoveConstraint.cascade;
|
|
String pcString = "{\"" + Element.CLASS_PROPERTY + "\":\"My" + PropagationConstraint.NAME + "\",\"" + Element.SUPERCLASSES_PROPERTY + "\":[\"" + PropagationConstraint.NAME + "\", \"" + Property.NAME + "\"],\"" + PropagationConstraint.ADD_PROPERTY + "\":\""+ addConstraint + "\",\""+ PropagationConstraint.REMOVE_PROPERTY + "\":\"" + removeConstraint + "\"}";
|
|
logger.debug(pcString);
|
|
|
|
HeaderImpl header = new HeaderImpl();
|
|
header.setUUID(UUID.randomUUID());
|
|
header.creator = "luca.frosini";
|
|
header.modifiedBy = "luca.frosini";
|
|
header.creationTime = Calendar.getInstance().getTime();
|
|
header.lastUpdateTime = Calendar.getInstance().getTime();
|
|
|
|
String hString = ElementMapper.marshal(header);
|
|
|
|
|
|
// TODO This fails
|
|
String consistsOfString = "{\"" + Element.CLASS_PROPERTY + "\":\"" + ConsistsOf.NAME + "\",\"" + ConsistsOf.PROPAGATION_CONSTRAINT_PROPERTY + "\":"+ pcString + ",\"" + ConsistsOf.HEADER_PROPERTY + "\": " + hString + ",\"" + ConsistsOf.TARGET_PROPERTY + "\":{\"@superClasses\":[\"SoftwareFacet\", \"Facet\"],\"@class\":\"MySoftwareFacet\",\"header\":"+ "{\"@class\":\"Header\",\"uuid\":\"3ace4bd0-e5cd-49a3-97a8-a0a9468ce6d4\",\"creator\":null, \"creationTime\":null, \"lastUpdateTime\":null}" + ",\"name\":\"WhnManager\",\"group\":\"VREManagement\",\"version\":\"2.0.0-SNAPSHOT\",\"description\":\"Web Hosting Node Service\",\"qualifier\":null,\"optional\":false}" + "}";
|
|
logger.debug(consistsOfString);
|
|
|
|
@SuppressWarnings("unchecked")
|
|
ConsistsOf<Resource,Facet> consistsOf = ElementMapper.unmarshal(ConsistsOf.class, consistsOfString);
|
|
Assert.assertTrue(consistsOf instanceof ConsistsOf);
|
|
|
|
PropagationConstraint propagationConstraint = consistsOf.getPropagationConstraint();
|
|
Assert.assertTrue(propagationConstraint instanceof PropagationConstraint);
|
|
Assert.assertTrue(propagationConstraint.getAddConstraint().compareTo(addConstraint)==0);
|
|
Assert.assertTrue(propagationConstraint.getRemoveConstraint().compareTo(removeConstraint)==0);
|
|
logger.debug(ElementMapper.marshal(propagationConstraint));
|
|
|
|
|
|
Facet facet = consistsOf.getTarget();
|
|
logger.debug(ElementMapper.marshal(facet));
|
|
|
|
Assert.assertTrue(facet.getAdditionalProperties().containsKey("version"));
|
|
}
|
|
}
|