Improving tests
This commit is contained in:
parent
164bf463b9
commit
b1a00addf8
|
@ -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
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue