diff --git a/src/test/java/org/gcube/informationsystem/impl/properties/EncryptedTest.java b/src/test/java/org/gcube/informationsystem/impl/properties/EncryptedTest.java index 5d3f23c..943e9f2 100644 --- a/src/test/java/org/gcube/informationsystem/impl/properties/EncryptedTest.java +++ b/src/test/java/org/gcube/informationsystem/impl/properties/EncryptedTest.java @@ -60,6 +60,7 @@ public class EncryptedTest extends ContextTest { @Test public void testEncryptedClass() throws Exception { String value = "myValue"; + String encryptedValue = EncryptedImpl.encrypt(value); Encrypted encrypted = new EncryptedImpl(); encrypted.setEncryptedValue(EncryptedImpl.encrypt(value)); @@ -67,10 +68,21 @@ public class EncryptedTest extends ContextTest { String json = ElementMapper.marshal(encrypted); logger.debug(json); - Encrypted unmarshalled = ElementMapper.unmarshal(Encrypted.class, json); - String decrypted = EncryptedImpl.decrypt(unmarshalled.getEncryptedValue()); + Property property = ElementMapper.unmarshal(Property.class, json); + Assert.assertTrue(property instanceof Encrypted); + Assert.assertTrue(((Encrypted) property).getEncryptedValue().compareTo(encryptedValue)==0); + String decryptedValue = EncryptedImpl.decrypt(((Encrypted) property).getEncryptedValue()); + Assert.assertTrue(decryptedValue.compareTo(value)==0); + logger.debug(ElementMapper.marshal(property)); + + + encrypted = ElementMapper.unmarshal(Encrypted.class, json); + Assert.assertTrue(property instanceof Encrypted); + Assert.assertTrue(encrypted.getEncryptedValue().compareTo(encryptedValue)==0); + decryptedValue = EncryptedImpl.decrypt(((Encrypted) property).getEncryptedValue()); + Assert.assertTrue(decryptedValue.compareTo(value)==0); + logger.debug(ElementMapper.marshal(encrypted)); - Assert.assertTrue(decrypted.compareTo(value)==0); } @Test @@ -87,9 +99,14 @@ public class EncryptedTest extends ContextTest { String marshalled = "{\"" + Element.CLASS_PROPERTY + "\":\"MyEncrypted\",\"" + Element.SUPERCLASSES_PROPERTY + "\":[\"" + Encrypted.NAME + "\", \"" + Property.NAME + "\"],\"" + Encrypted.VALUE + "\":\""+ encryptedValue + "\"}"; Property property = ElementMapper.unmarshal(Property.class, marshalled); Assert.assertTrue(property instanceof Encrypted); - Encrypted encrypted = (Encrypted) property; - Assert.assertTrue(encrypted.getEncryptedValue().compareTo(encryptedValue)==0); + Assert.assertTrue(((Encrypted) property).getEncryptedValue().compareTo(encryptedValue)==0); logger.debug(ElementMapper.marshal(property)); + + Encrypted encrypted = ElementMapper.unmarshal(Encrypted.class, marshalled); + Assert.assertTrue(property instanceof Encrypted); + Assert.assertTrue(encrypted.getEncryptedValue().compareTo(encryptedValue)==0); + logger.debug(ElementMapper.marshal(encrypted)); + } @Test diff --git a/src/test/java/org/gcube/informationsystem/model/impl/properties/HeaderTest.java b/src/test/java/org/gcube/informationsystem/model/impl/properties/HeaderTest.java index 332bde1..51f818a 100644 --- a/src/test/java/org/gcube/informationsystem/model/impl/properties/HeaderTest.java +++ b/src/test/java/org/gcube/informationsystem/model/impl/properties/HeaderTest.java @@ -4,8 +4,8 @@ import java.util.Calendar; import java.util.Date; import java.util.UUID; -import org.gcube.informationsystem.model.impl.properties.HeaderImpl; import org.gcube.informationsystem.model.reference.properties.Header; +import org.gcube.informationsystem.model.reference.properties.Property; import org.gcube.informationsystem.utils.ElementMapper; import org.junit.Assert; import org.junit.Test; @@ -27,11 +27,18 @@ public class HeaderTest { String json = ElementMapper.marshal(header); logger.debug(json); - Header h = ElementMapper.unmarshal(Header.class, json); + Property property = ElementMapper.unmarshal(Property.class, json); + Assert.assertTrue(property instanceof Header); + Assert.assertTrue(((Header) property).getCreationTime().compareTo(date)==0); + Assert.assertTrue(((Header) property).getLastUpdateTime().compareTo(date)==0); + logger.debug(ElementMapper.marshal(property)); + + Header h = ElementMapper.unmarshal(Header.class, json); + Assert.assertTrue(property instanceof Header); Assert.assertTrue(h.getCreationTime().compareTo(date)==0); Assert.assertTrue(h.getLastUpdateTime().compareTo(date)==0); - + logger.debug(ElementMapper.marshal(h)); } } diff --git a/src/test/java/org/gcube/informationsystem/types/SerializationTest.java b/src/test/java/org/gcube/informationsystem/types/SerializationTest.java index 3ffc83e..053733a 100644 --- a/src/test/java/org/gcube/informationsystem/types/SerializationTest.java +++ b/src/test/java/org/gcube/informationsystem/types/SerializationTest.java @@ -20,19 +20,18 @@ import org.gcube.informationsystem.model.reference.relations.Relation; import org.gcube.informationsystem.types.reference.entities.EntityType; import org.gcube.informationsystem.types.reference.entities.FacetType; import org.gcube.informationsystem.types.reference.entities.ResourceType; +import org.gcube.informationsystem.types.reference.properties.LinkedEntity; import org.gcube.informationsystem.types.reference.properties.PropertyDefinition; import org.gcube.informationsystem.types.reference.properties.PropertyType; -import org.gcube.informationsystem.types.reference.properties.LinkedEntity; import org.gcube.informationsystem.types.reference.relations.ConsistsOfType; import org.gcube.informationsystem.types.reference.relations.IsRelatedToType; import org.gcube.informationsystem.types.reference.relations.RelationType; import org.gcube.informationsystem.utils.ElementMapper; +import org.junit.Assert; import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import com.fasterxml.jackson.databind.ObjectMapper; - public class SerializationTest { private static Logger logger = LoggerFactory.getLogger(SerializationTest.class); @@ -161,12 +160,15 @@ public class SerializationTest { PropagationConstraint propagationConstraint = new PropagationConstraintImpl(); propagationConstraint.setAddConstraint(AddConstraint.propagate); propagationConstraint.setRemoveConstraint(RemoveConstraint.cascadeWhenOrphan); - String pg = ElementMapper.marshal(propagationConstraint); - PropagationConstraint pgUnm = ElementMapper.unmarshal(PropagationConstraint.class, pg); + Property property = ElementMapper.unmarshal(Property.class, pg); + Assert.assertTrue(property instanceof PropagationConstraint); + logger.debug(ElementMapper.marshal(property)); - logger.debug("{}", pgUnm); + PropagationConstraint pgUnm = ElementMapper.unmarshal(PropagationConstraint.class, pg); + Assert.assertTrue(property instanceof PropagationConstraint); + logger.debug(ElementMapper.marshal(pgUnm)); } @Test