@ -8,6 +8,7 @@ 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.DeleteConstraint ;
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 ;
@ -29,6 +30,7 @@ public class PropagationConstraintTest {
PropagationConstraint propagationConstraint = new PropagationConstraintImpl ( ) ;
propagationConstraint . setAddConstraint ( AddConstraint . propagate ) ;
propagationConstraint . setRemoveConstraint ( RemoveConstraint . cascadeWhenOrphan ) ;
propagationConstraint . setDeleteConstraint ( DeleteConstraint . cascade ) ;
String pg = ElementMapper . marshal ( propagationConstraint ) ;
Property property = ElementMapper . unmarshal ( Property . class , pg ) ;
@ -44,9 +46,12 @@ public class PropagationConstraintTest {
public void testPropagationConstraintByString ( ) throws Exception {
AddConstraint addConstraint = AddConstraint . propagate ;
RemoveConstraint removeConstraint = RemoveConstraint . cascade ;
DeleteConstraint deleteConstraint = DeleteConstraint . keep ;
PropagationConstraint pc = new PropagationConstraintImpl ( ) ;
pc . setAddConstraint ( addConstraint ) ;
pc . setRemoveConstraint ( removeConstraint ) ;
pc . setDeleteConstraint ( deleteConstraint ) ;
String json = ElementMapper . marshal ( pc ) ;
logger . debug ( json ) ;
@ -55,12 +60,14 @@ public class PropagationConstraintTest {
Assert . assertTrue ( property instanceof PropagationConstraint ) ;
Assert . assertTrue ( ( ( PropagationConstraint ) property ) . getAddConstraint ( ) . compareTo ( addConstraint ) = = 0 ) ;
Assert . assertTrue ( ( ( PropagationConstraint ) property ) . getRemoveConstraint ( ) . compareTo ( removeConstraint ) = = 0 ) ;
Assert . assertTrue ( ( ( PropagationConstraint ) property ) . getDeleteConstraint ( ) . compareTo ( deleteConstraint ) = = 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 ) ;
Assert . assertTrue ( propagationConstraint . getDeleteConstraint ( ) . compareTo ( deleteConstraint ) = = 0 ) ;
logger . debug ( ElementMapper . marshal ( property ) ) ;
}
@ -68,19 +75,29 @@ public class PropagationConstraintTest {
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 + "\"}" ;
DeleteConstraint deleteConstraint = DeleteConstraint . keep ;
String marshalled = "{\"" +
Element . CLASS_PROPERTY + "\":\"MyPropagationConstraint\",\"" +
Element . SUPERCLASSES_PROPERTY + "\":[\"" + PropagationConstraint . NAME + "\", \"" + Property . NAME + "\"],\"" +
PropagationConstraint . ADD_PROPERTY + "\":\"" + addConstraint + "\",\"" +
PropagationConstraint . REMOVE_PROPERTY + "\":\"" + removeConstraint + "\",\"" +
PropagationConstraint . DELETE_PROPERTY + "\":\"" + deleteConstraint +
"\"}" ;
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 ) ;
Assert . assertTrue ( ( ( PropagationConstraint ) property ) . getDeleteConstraint ( ) . compareTo ( deleteConstraint ) = = 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 ) ;
Assert . assertTrue ( propagationConstraint . getDeleteConstraint ( ) . compareTo ( deleteConstraint ) = = 0 ) ;
logger . debug ( ElementMapper . marshal ( property ) ) ;
}
@ -88,11 +105,14 @@ public class PropagationConstraintTest {
public void testPropagationConstraintSpecilizationInside ( ) throws Exception {
AddConstraint addConstraint = AddConstraint . propagate ;
RemoveConstraint removeConstraint = RemoveConstraint . cascade ;
DeleteConstraint deleteConstraint = DeleteConstraint . keep ;
String pcString = "{" +
"\"" + Element . CLASS_PROPERTY + "\":\"My" + PropagationConstraint . NAME + "\"," +
"\"" + Element . SUPERCLASSES_PROPERTY + "\":[\"" + PropagationConstraint . NAME + "\", \"" + Property . NAME + "\"],\"" +
PropagationConstraint . ADD_PROPERTY + "\":\"" + addConstraint + "\",\"" +
PropagationConstraint . REMOVE_PROPERTY + "\":\"" + removeConstraint + "\"" +
PropagationConstraint . REMOVE_PROPERTY + "\":\"" + removeConstraint + "\",\"" +
PropagationConstraint . DELETE_PROPERTY + "\":\"" + deleteConstraint + "\"" +
"}" ;
logger . debug ( pcString ) ;
@ -147,6 +167,7 @@ public class PropagationConstraintTest {
Assert . assertTrue ( propagationConstraint instanceof PropagationConstraint ) ;
Assert . assertTrue ( propagationConstraint . getAddConstraint ( ) . compareTo ( addConstraint ) = = 0 ) ;
Assert . assertTrue ( propagationConstraint . getRemoveConstraint ( ) . compareTo ( removeConstraint ) = = 0 ) ;
Assert . assertTrue ( propagationConstraint . getDeleteConstraint ( ) . compareTo ( deleteConstraint ) = = 0 ) ;
logger . debug ( ElementMapper . marshal ( propagationConstraint ) ) ;