package org.gcube.informationsystem.types; import org.gcube.informationsystem.base.reference.properties.Header; import org.gcube.informationsystem.context.reference.relations.IsParentOf; import org.gcube.informationsystem.model.impl.properties.PropagationConstraintImpl; 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.relations.IsRelatedTo; import org.gcube.informationsystem.types.reference.relations.RelationTypeDefinition; import org.gcube.informationsystem.utils.ISMapper; 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); @Test public void serialize() throws Exception{ TypeBinder.serializeType(EntityTest.class); } @Test public void getISParentOfSchema() throws Exception{ @SuppressWarnings("rawtypes") RelationTypeDefinition relationTypeDefinition = (RelationTypeDefinition) TypeBinder.createTypeDefinition(IsRelatedTo.class); logger.info(ISMapper.marshal(relationTypeDefinition)); @SuppressWarnings("rawtypes") RelationTypeDefinition rtd = (RelationTypeDefinition) TypeBinder.createTypeDefinition(IsParentOf.class); logger.info(ISMapper.marshal(rtd)); @SuppressWarnings("rawtypes") RelationTypeDefinition rtdSelf = (RelationTypeDefinition) TypeBinder.createTypeDefinition(RelationTypeDefinition.class); logger.info(ISMapper.marshal(rtdSelf)); } @Test public void testGetEnumcostants(){ Class clz = PropagationConstraint.RemoveConstraint.class; Object[] constants = clz.getEnumConstants(); for(Object constant : constants){ logger.trace("{}", constant.toString()); } } @Test public void testPropagationConstraint() throws Exception { PropagationConstraint propagationConstraint = new PropagationConstraintImpl(); propagationConstraint.setAddConstraint(AddConstraint.propagate); propagationConstraint.setRemoveConstraint(RemoveConstraint.cascadeWhenOrphan); ObjectMapper mapper = new ObjectMapper(); String pg = mapper.writeValueAsString(propagationConstraint); PropagationConstraint pgUnm = mapper.readValue(pg, PropagationConstraint.class); logger.debug("{}", pgUnm); } @Test public void testTypeSerialization() throws Exception { String serialized = TypeBinder.serializeType(Header.class); logger.info(serialized); } }