2019-03-22 15:18:23 +01:00
|
|
|
package org.gcube.informationsystem.types;
|
|
|
|
|
2020-01-30 10:26:43 +01:00
|
|
|
import org.gcube.informationsystem.base.reference.entities.EntityElement;
|
|
|
|
import org.gcube.informationsystem.base.reference.properties.PropertyElement;
|
2020-01-23 17:14:44 +01:00
|
|
|
import org.gcube.informationsystem.context.reference.entities.Context;
|
2019-11-04 18:06:46 +01:00
|
|
|
import org.gcube.informationsystem.context.reference.relations.IsParentOf;
|
2019-03-22 15:18:23 +01:00
|
|
|
import org.gcube.informationsystem.model.impl.properties.PropagationConstraintImpl;
|
2020-01-23 17:14:44 +01:00
|
|
|
import org.gcube.informationsystem.model.reference.entities.Entity;
|
|
|
|
import org.gcube.informationsystem.model.reference.entities.Facet;
|
|
|
|
import org.gcube.informationsystem.model.reference.entities.Resource;
|
2020-01-29 16:33:51 +01:00
|
|
|
import org.gcube.informationsystem.model.reference.properties.Encrypted;
|
2020-01-20 10:24:55 +01:00
|
|
|
import org.gcube.informationsystem.model.reference.properties.Header;
|
2019-03-22 15:18:23 +01:00
|
|
|
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;
|
2020-01-29 16:33:51 +01:00
|
|
|
import org.gcube.informationsystem.model.reference.properties.Property;
|
2020-01-23 17:14:44 +01:00
|
|
|
import org.gcube.informationsystem.model.reference.relations.ConsistsOf;
|
2019-11-04 18:06:46 +01:00
|
|
|
import org.gcube.informationsystem.model.reference.relations.IsRelatedTo;
|
2020-01-23 17:14:44 +01:00
|
|
|
import org.gcube.informationsystem.model.reference.relations.Relation;
|
2020-01-30 10:26:43 +01:00
|
|
|
import org.gcube.informationsystem.types.reference.entities.EntityType;
|
|
|
|
import org.gcube.informationsystem.types.reference.entities.FacetType;
|
|
|
|
import org.gcube.informationsystem.types.reference.entities.ResourceType;
|
2020-01-29 16:33:51 +01:00
|
|
|
import org.gcube.informationsystem.types.reference.properties.PropertyDefinition;
|
2020-01-30 10:26:43 +01:00
|
|
|
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;
|
2020-02-03 10:51:29 +01:00
|
|
|
import org.gcube.informationsystem.utils.ElementMapper;
|
2019-03-22 15:18:23 +01:00
|
|
|
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{
|
2020-02-04 09:30:19 +01:00
|
|
|
TypeMapper.serializeType(EntityTest.class);
|
2019-03-22 15:18:23 +01:00
|
|
|
}
|
|
|
|
|
2020-01-23 17:14:44 +01:00
|
|
|
@Test
|
2020-02-03 10:51:29 +01:00
|
|
|
public void makeFacetTypeDefinition() throws Exception{
|
2020-02-04 09:30:19 +01:00
|
|
|
EntityType facetTypeDefinitionSelf = (EntityType) TypeMapper.createTypeDefinition(FacetType.class);
|
2020-02-03 10:51:29 +01:00
|
|
|
logger.info(ElementMapper.marshal(facetTypeDefinitionSelf));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void makeResourceTypeDefinition() throws Exception{
|
2020-02-04 09:30:19 +01:00
|
|
|
EntityType resourceTypeDefinitionSelf = (EntityType) TypeMapper.createTypeDefinition(ResourceType.class);
|
2020-02-03 10:51:29 +01:00
|
|
|
logger.info(ElementMapper.marshal(resourceTypeDefinitionSelf));
|
2020-01-23 17:14:44 +01:00
|
|
|
}
|
|
|
|
|
2020-01-29 16:33:51 +01:00
|
|
|
@Test
|
|
|
|
public void testPropertyTypeDefinition() throws Exception{
|
|
|
|
@SuppressWarnings("unchecked")
|
2020-02-04 09:30:19 +01:00
|
|
|
PropertyType<PropertyElement> basePropertyTypeDefinition = (PropertyType<PropertyElement>) TypeMapper.createTypeDefinition(PropertyElement.class);
|
2020-02-03 10:51:29 +01:00
|
|
|
logger.info(ElementMapper.marshal(basePropertyTypeDefinition));
|
2020-01-29 16:33:51 +01:00
|
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
2020-02-04 09:30:19 +01:00
|
|
|
PropertyType<Property> propertyTypeDefinition = (PropertyType<Property>) TypeMapper.createTypeDefinition(Property.class);
|
2020-02-03 10:51:29 +01:00
|
|
|
logger.info(ElementMapper.marshal(propertyTypeDefinition));
|
2020-01-29 16:33:51 +01:00
|
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
2020-02-04 09:30:19 +01:00
|
|
|
PropertyType<Header> headerTypeDefinition = (PropertyType<Header>) TypeMapper.createTypeDefinition(Header.class);
|
2020-02-03 10:51:29 +01:00
|
|
|
logger.info(ElementMapper.marshal(headerTypeDefinition));
|
2020-01-29 16:33:51 +01:00
|
|
|
|
|
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
2020-02-04 09:30:19 +01:00
|
|
|
PropertyType<PropagationConstraint> propagationConstraintDefinition = (PropertyType<PropagationConstraint>) TypeMapper.createTypeDefinition(PropagationConstraint.class);
|
2020-02-03 10:51:29 +01:00
|
|
|
logger.info(ElementMapper.marshal(propagationConstraintDefinition));
|
2020-01-29 16:33:51 +01:00
|
|
|
|
|
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
2020-02-04 09:30:19 +01:00
|
|
|
PropertyType<Encrypted> encryptedTypeDefinition = (PropertyType<Encrypted>) TypeMapper.createTypeDefinition(Encrypted.class);
|
2020-02-03 10:51:29 +01:00
|
|
|
logger.info(ElementMapper.marshal(encryptedTypeDefinition));
|
2020-01-29 16:33:51 +01:00
|
|
|
|
|
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
2020-02-04 09:30:19 +01:00
|
|
|
PropertyType<PropertyDefinition> propertyDefinition = (PropertyType<PropertyDefinition>) TypeMapper.createTypeDefinition(PropertyDefinition.class);
|
2020-02-03 10:51:29 +01:00
|
|
|
logger.info(ElementMapper.marshal(propertyDefinition));
|
2020-01-29 16:33:51 +01:00
|
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
2020-02-04 09:30:19 +01:00
|
|
|
PropertyType<LinkedEntity> resourceEntryDefinition = (PropertyType<LinkedEntity>) TypeMapper.createTypeDefinition(LinkedEntity.class);
|
2020-02-03 10:51:29 +01:00
|
|
|
logger.info(ElementMapper.marshal(resourceEntryDefinition));
|
2020-01-29 16:33:51 +01:00
|
|
|
}
|
|
|
|
|
2020-01-23 17:14:44 +01:00
|
|
|
@Test
|
|
|
|
public void testEntityTypeDefinition() throws Exception{
|
2020-02-04 09:30:19 +01:00
|
|
|
EntityType baseEntityTypeDefinition = (EntityType) TypeMapper.createTypeDefinition(EntityElement.class);
|
2020-02-03 10:51:29 +01:00
|
|
|
logger.info(ElementMapper.marshal(baseEntityTypeDefinition));
|
2020-01-23 17:14:44 +01:00
|
|
|
|
2020-02-04 09:30:19 +01:00
|
|
|
EntityType entityTypeDefinition = (EntityType) TypeMapper.createTypeDefinition(Entity.class);
|
2020-02-03 10:51:29 +01:00
|
|
|
logger.info(ElementMapper.marshal(entityTypeDefinition));
|
2020-01-23 17:14:44 +01:00
|
|
|
|
2020-02-04 09:30:19 +01:00
|
|
|
ResourceType resourceTypeDefinition = (ResourceType) TypeMapper.createTypeDefinition(Resource.class);
|
2020-02-03 10:51:29 +01:00
|
|
|
logger.info(ElementMapper.marshal(resourceTypeDefinition));
|
2020-01-23 17:14:44 +01:00
|
|
|
|
2020-02-04 09:30:19 +01:00
|
|
|
FacetType facetTypeDefinition = (FacetType) TypeMapper.createTypeDefinition(Facet.class);
|
2020-02-03 10:51:29 +01:00
|
|
|
logger.info(ElementMapper.marshal(facetTypeDefinition));
|
2020-01-23 17:14:44 +01:00
|
|
|
|
2020-02-04 09:30:19 +01:00
|
|
|
EntityType contextTypeDefinition = (EntityType) TypeMapper.createTypeDefinition(Context.class);
|
2020-02-03 10:51:29 +01:00
|
|
|
logger.info(ElementMapper.marshal(contextTypeDefinition));
|
2020-01-23 17:14:44 +01:00
|
|
|
|
2020-02-04 09:30:19 +01:00
|
|
|
EntityType entityTypeDefinitionSelf = (EntityType) TypeMapper.createTypeDefinition(EntityType.class);
|
2020-02-03 10:51:29 +01:00
|
|
|
logger.info(ElementMapper.marshal(entityTypeDefinitionSelf));
|
2020-01-23 17:14:44 +01:00
|
|
|
|
2020-02-04 09:30:19 +01:00
|
|
|
EntityType resourceTypeDefinitionSelf = (EntityType) TypeMapper.createTypeDefinition(ResourceType.class);
|
2020-02-03 10:51:29 +01:00
|
|
|
logger.info(ElementMapper.marshal(resourceTypeDefinitionSelf));
|
2020-01-23 17:14:44 +01:00
|
|
|
|
2020-02-04 09:30:19 +01:00
|
|
|
EntityType facetTypeDefinitionSelf = (EntityType) TypeMapper.createTypeDefinition(FacetType.class);
|
2020-02-03 10:51:29 +01:00
|
|
|
logger.info(ElementMapper.marshal(facetTypeDefinitionSelf));
|
2020-01-23 17:14:44 +01:00
|
|
|
}
|
2019-11-04 18:06:46 +01:00
|
|
|
|
|
|
|
@Test
|
2020-01-23 17:14:44 +01:00
|
|
|
public void testRelationTypeDefinition() throws Exception{
|
|
|
|
@SuppressWarnings("unchecked")
|
2020-02-04 09:30:19 +01:00
|
|
|
RelationType<EntityType,EntityType> relationTypeDefinition = (RelationType<EntityType,EntityType>) TypeMapper.createTypeDefinition(Relation.class);
|
2020-02-03 10:51:29 +01:00
|
|
|
logger.info(ElementMapper.marshal(relationTypeDefinition));
|
2019-11-04 18:06:46 +01:00
|
|
|
|
2020-02-04 09:30:19 +01:00
|
|
|
IsRelatedToType isRelatedToTypeDefinition = (IsRelatedToType) TypeMapper.createTypeDefinition(IsRelatedTo.class);
|
2020-02-03 10:51:29 +01:00
|
|
|
logger.info(ElementMapper.marshal(isRelatedToTypeDefinition));
|
2020-01-23 17:14:44 +01:00
|
|
|
|
2020-02-04 09:30:19 +01:00
|
|
|
ConsistsOfType consistsOfTypeDefinition = (ConsistsOfType) TypeMapper.createTypeDefinition(ConsistsOf.class);
|
2020-02-03 10:51:29 +01:00
|
|
|
logger.info(ElementMapper.marshal(consistsOfTypeDefinition));
|
2019-11-04 18:06:46 +01:00
|
|
|
|
2020-01-23 17:14:44 +01:00
|
|
|
@SuppressWarnings("unchecked")
|
2020-02-04 09:30:19 +01:00
|
|
|
RelationType<EntityType,EntityType> isParentOfTypeDefinition = (RelationType<EntityType,EntityType>) TypeMapper.createTypeDefinition(IsParentOf.class);
|
2020-02-03 10:51:29 +01:00
|
|
|
logger.info(ElementMapper.marshal(isParentOfTypeDefinition));
|
2020-01-23 17:14:44 +01:00
|
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
2020-02-04 09:30:19 +01:00
|
|
|
RelationType<EntityType,EntityType> rtdSelf = (RelationType<EntityType,EntityType>) TypeMapper.createTypeDefinition(RelationType.class);
|
2020-02-03 10:51:29 +01:00
|
|
|
logger.info(ElementMapper.marshal(rtdSelf));
|
2020-01-23 17:14:44 +01:00
|
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
2020-02-04 09:30:19 +01:00
|
|
|
RelationType<EntityType,EntityType> isRelatedToTypeDefinitionSelf = (RelationType<EntityType,EntityType>) TypeMapper.createTypeDefinition(IsRelatedToType.class);
|
2020-02-03 10:51:29 +01:00
|
|
|
logger.info(ElementMapper.marshal(isRelatedToTypeDefinitionSelf));
|
2019-11-05 18:42:25 +01:00
|
|
|
|
2020-01-23 17:14:44 +01:00
|
|
|
@SuppressWarnings("unchecked")
|
2020-02-04 09:30:19 +01:00
|
|
|
RelationType<EntityType,EntityType> consistsOfTypeDefinitionSelf = (RelationType<EntityType,EntityType>) TypeMapper.createTypeDefinition(ConsistsOfType.class);
|
2020-02-03 10:51:29 +01:00
|
|
|
logger.info(ElementMapper.marshal(consistsOfTypeDefinitionSelf));
|
2019-11-04 18:06:46 +01:00
|
|
|
}
|
|
|
|
|
2019-03-22 15:18:23 +01:00
|
|
|
@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);
|
|
|
|
|
2020-04-29 19:46:48 +02:00
|
|
|
String pg = ElementMapper.marshal(propagationConstraint);
|
2019-03-22 15:18:23 +01:00
|
|
|
|
2020-04-29 19:46:48 +02:00
|
|
|
PropagationConstraint pgUnm = ElementMapper.unmarshal(PropagationConstraint.class, pg);
|
2019-03-22 15:18:23 +01:00
|
|
|
|
|
|
|
logger.debug("{}", pgUnm);
|
|
|
|
}
|
|
|
|
|
2019-10-24 15:03:14 +02:00
|
|
|
@Test
|
|
|
|
public void testTypeSerialization() throws Exception {
|
2020-02-04 09:30:19 +01:00
|
|
|
String serialized = TypeMapper.serializeType(Header.class);
|
2019-10-24 15:03:14 +02:00
|
|
|
logger.info(serialized);
|
|
|
|
}
|
2019-10-24 19:50:43 +02:00
|
|
|
|
2019-03-22 15:18:23 +01:00
|
|
|
}
|