176 lines
9.6 KiB
Java
176 lines
9.6 KiB
Java
package org.gcube.informationsystem.types;
|
|
|
|
import org.gcube.informationsystem.base.reference.entities.EntityElement;
|
|
import org.gcube.informationsystem.base.reference.properties.PropertyElement;
|
|
import org.gcube.informationsystem.context.reference.entities.Context;
|
|
import org.gcube.informationsystem.context.reference.relations.IsParentOf;
|
|
import org.gcube.informationsystem.model.reference.entities.Entity;
|
|
import org.gcube.informationsystem.model.reference.entities.Facet;
|
|
import org.gcube.informationsystem.model.reference.entities.Resource;
|
|
import org.gcube.informationsystem.model.reference.properties.Encrypted;
|
|
import org.gcube.informationsystem.model.reference.properties.Header;
|
|
import org.gcube.informationsystem.model.reference.properties.PropagationConstraint;
|
|
import org.gcube.informationsystem.model.reference.properties.Property;
|
|
import org.gcube.informationsystem.model.reference.relations.ConsistsOf;
|
|
import org.gcube.informationsystem.model.reference.relations.IsRelatedTo;
|
|
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.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.gcube.informationsystem.utils.TypeVersion;
|
|
import org.junit.Test;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
/**
|
|
* @author Luca Frosini (ISTI - CNR)
|
|
*/
|
|
public class SerializationTest {
|
|
|
|
private static Logger logger = LoggerFactory.getLogger(SerializationTest.class);
|
|
|
|
@Test
|
|
public void serialize() throws Exception{
|
|
TypeMapper.serializeType(EntityTest.class);
|
|
}
|
|
|
|
@Test
|
|
public void makeFacetTypeDefinition() throws Exception{
|
|
EntityType facetTypeDefinitionSelf = (EntityType) TypeMapper.createTypeDefinition(FacetType.class);
|
|
logger.info(ElementMapper.marshal(facetTypeDefinitionSelf));
|
|
}
|
|
|
|
|
|
@Test
|
|
public void makeResourceTypeDefinition() throws Exception{
|
|
EntityType resourceTypeDefinitionSelf = (EntityType) TypeMapper.createTypeDefinition(ResourceType.class);
|
|
logger.info(ElementMapper.marshal(resourceTypeDefinitionSelf));
|
|
}
|
|
|
|
@Test
|
|
public void testPropertyTypeDefinition() throws Exception{
|
|
@SuppressWarnings("unchecked")
|
|
PropertyType<PropertyElement> basePropertyTypeDefinition = (PropertyType<PropertyElement>) TypeMapper.createTypeDefinition(PropertyElement.class);
|
|
logger.info(ElementMapper.marshal(basePropertyTypeDefinition));
|
|
|
|
@SuppressWarnings("unchecked")
|
|
PropertyType<Property> propertyTypeDefinition = (PropertyType<Property>) TypeMapper.createTypeDefinition(Property.class);
|
|
logger.info(ElementMapper.marshal(propertyTypeDefinition));
|
|
|
|
@SuppressWarnings("unchecked")
|
|
PropertyType<Header> headerTypeDefinition = (PropertyType<Header>) TypeMapper.createTypeDefinition(Header.class);
|
|
logger.info(ElementMapper.marshal(headerTypeDefinition));
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
PropertyType<PropagationConstraint> propagationConstraintDefinition = (PropertyType<PropagationConstraint>) TypeMapper.createTypeDefinition(PropagationConstraint.class);
|
|
logger.info(ElementMapper.marshal(propagationConstraintDefinition));
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
PropertyType<Encrypted> encryptedTypeDefinition = (PropertyType<Encrypted>) TypeMapper.createTypeDefinition(Encrypted.class);
|
|
logger.info(ElementMapper.marshal(encryptedTypeDefinition));
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
PropertyType<PropertyDefinition> propertyDefinition = (PropertyType<PropertyDefinition>) TypeMapper.createTypeDefinition(PropertyDefinition.class);
|
|
logger.info(ElementMapper.marshal(propertyDefinition));
|
|
|
|
@SuppressWarnings("unchecked")
|
|
PropertyType<LinkedEntity> resourceEntryDefinition = (PropertyType<LinkedEntity>) TypeMapper.createTypeDefinition(LinkedEntity.class);
|
|
logger.info(ElementMapper.marshal(resourceEntryDefinition));
|
|
}
|
|
|
|
@Test
|
|
public void testEntityTypeDefinition() throws Exception{
|
|
EntityType baseEntityTypeDefinition = (EntityType) TypeMapper.createTypeDefinition(EntityElement.class);
|
|
logger.info(ElementMapper.marshal(baseEntityTypeDefinition));
|
|
|
|
EntityType entityTypeDefinition = (EntityType) TypeMapper.createTypeDefinition(Entity.class);
|
|
logger.info(ElementMapper.marshal(entityTypeDefinition));
|
|
|
|
ResourceType resourceTypeDefinition = (ResourceType) TypeMapper.createTypeDefinition(Resource.class);
|
|
logger.info(ElementMapper.marshal(resourceTypeDefinition));
|
|
|
|
FacetType facetTypeDefinition = (FacetType) TypeMapper.createTypeDefinition(Facet.class);
|
|
logger.info(ElementMapper.marshal(facetTypeDefinition));
|
|
|
|
EntityType contextTypeDefinition = (EntityType) TypeMapper.createTypeDefinition(Context.class);
|
|
logger.info(ElementMapper.marshal(contextTypeDefinition));
|
|
|
|
EntityType entityTypeDefinitionSelf = (EntityType) TypeMapper.createTypeDefinition(EntityType.class);
|
|
logger.info(ElementMapper.marshal(entityTypeDefinitionSelf));
|
|
|
|
EntityType resourceTypeDefinitionSelf = (EntityType) TypeMapper.createTypeDefinition(ResourceType.class);
|
|
logger.info(ElementMapper.marshal(resourceTypeDefinitionSelf));
|
|
|
|
EntityType facetTypeDefinitionSelf = (EntityType) TypeMapper.createTypeDefinition(FacetType.class);
|
|
logger.info(ElementMapper.marshal(facetTypeDefinitionSelf));
|
|
}
|
|
|
|
@Test
|
|
public void testRelationTypeDefinition() throws Exception{
|
|
@SuppressWarnings("unchecked")
|
|
RelationType<EntityType,EntityType> relationTypeDefinition = (RelationType<EntityType,EntityType>) TypeMapper.createTypeDefinition(Relation.class);
|
|
logger.info(ElementMapper.marshal(relationTypeDefinition));
|
|
|
|
IsRelatedToType isRelatedToTypeDefinition = (IsRelatedToType) TypeMapper.createTypeDefinition(IsRelatedTo.class);
|
|
logger.info(ElementMapper.marshal(isRelatedToTypeDefinition));
|
|
|
|
ConsistsOfType consistsOfTypeDefinition = (ConsistsOfType) TypeMapper.createTypeDefinition(ConsistsOf.class);
|
|
logger.info(ElementMapper.marshal(consistsOfTypeDefinition));
|
|
|
|
@SuppressWarnings("unchecked")
|
|
RelationType<EntityType,EntityType> isParentOfTypeDefinition = (RelationType<EntityType,EntityType>) TypeMapper.createTypeDefinition(IsParentOf.class);
|
|
logger.info(ElementMapper.marshal(isParentOfTypeDefinition));
|
|
|
|
@SuppressWarnings("unchecked")
|
|
RelationType<EntityType,EntityType> rtdSelf = (RelationType<EntityType,EntityType>) TypeMapper.createTypeDefinition(RelationType.class);
|
|
logger.info(ElementMapper.marshal(rtdSelf));
|
|
|
|
@SuppressWarnings("unchecked")
|
|
RelationType<EntityType,EntityType> isRelatedToTypeDefinitionSelf = (RelationType<EntityType,EntityType>) TypeMapper.createTypeDefinition(IsRelatedToType.class);
|
|
logger.info(ElementMapper.marshal(isRelatedToTypeDefinitionSelf));
|
|
|
|
@SuppressWarnings("unchecked")
|
|
RelationType<EntityType,EntityType> consistsOfTypeDefinitionSelf = (RelationType<EntityType,EntityType>) TypeMapper.createTypeDefinition(ConsistsOfType.class);
|
|
logger.info(ElementMapper.marshal(consistsOfTypeDefinitionSelf));
|
|
}
|
|
|
|
@Test
|
|
public void testGetEnumcostants(){
|
|
Class<?> clz = PropagationConstraint.RemoveConstraint.class;
|
|
|
|
Object[] constants = clz.getEnumConstants();
|
|
for(Object constant : constants){
|
|
logger.trace("{}", constant.toString());
|
|
}
|
|
|
|
}
|
|
|
|
@Test
|
|
public void testTypeSerialization() throws Exception {
|
|
String serialized = TypeMapper.serializeType(Header.class);
|
|
logger.info(serialized);
|
|
@SuppressWarnings("unchecked")
|
|
PropertyType<Header> propertyType = (PropertyType<Header>) TypeMapper.deserializeTypeDefinition(serialized);
|
|
TypeVersion typeVersion = propertyType.getVersion();
|
|
logger.debug("Version {}", typeVersion.toString());
|
|
logger.info(ElementMapper.marshal(propertyType));
|
|
|
|
String json = "{\"@class\":\"PropertyType\",\"header\":null,\"name\":\"Header\",\"description\":\"\",\"superClasses\":[\"Property\"],\"properties\":[{\"@class\":\"PropertyDefinition\",\"name\":\"lastUpdateTime\",\"description\":\"\",\"mandatory\":true,\"readonly\":false,\"notnull\":true,\"max\":null,\"min\":null,\"regexp\":null,\"linkedType\":null,\"linkedClass\":null,\"type\":6},{\"@class\":\"PropertyDefinition\",\"name\":\"modifiedBy\",\"description\":\"\",\"mandatory\":true,\"readonly\":false,\"notnull\":true,\"max\":null,\"min\":null,\"regexp\":null,\"linkedType\":null,\"linkedClass\":null,\"type\":7},{\"@class\":\"PropertyDefinition\",\"name\":\"creator\",\"description\":\"\",\"mandatory\":true,\"readonly\":true,\"notnull\":true,\"max\":null,\"min\":null,\"regexp\":null,\"linkedType\":null,\"linkedClass\":null,\"type\":7},{\"@class\":\"PropertyDefinition\",\"name\":\"creationTime\",\"description\":\"\",\"mandatory\":true,\"readonly\":true,\"notnull\":true,\"max\":null,\"min\":null,\"regexp\":null,\"linkedType\":null,\"linkedClass\":null,\"type\":6},{\"@class\":\"PropertyDefinition\",\"name\":\"uuid\",\"description\":\"\",\"mandatory\":true,\"readonly\":true,\"notnull\":true,\"max\":null,\"min\":null,\"regexp\":\"^([a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}){1}$\",\"linkedType\":null,\"linkedClass\":null,\"type\":7}],\"abstract\":false,\"version\":\"1.0.0\"}";
|
|
logger.info(json);
|
|
@SuppressWarnings("unchecked")
|
|
PropertyType<Header> headerType = (PropertyType<Header>) TypeMapper.deserializeTypeDefinition(json);
|
|
logger.info(ElementMapper.marshal(headerType));
|
|
}
|
|
|
|
}
|