2019-03-22 15:18:23 +01:00
package org.gcube.informationsystem.types ;
2021-02-11 22:09:02 +01:00
import org.gcube.informationsystem.base.reference.AccessType ;
2020-01-30 10:26:43 +01:00
import org.gcube.informationsystem.base.reference.entities.EntityElement ;
import org.gcube.informationsystem.base.reference.properties.PropertyElement ;
2021-10-25 11:38:06 +02:00
import org.gcube.informationsystem.contexts.reference.entities.Context ;
import org.gcube.informationsystem.contexts.reference.relations.IsParentOf ;
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-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 ;
2020-01-29 16:33:51 +01:00
import org.gcube.informationsystem.model.reference.properties.Property ;
2023-02-27 15:07:41 +01:00
import org.gcube.informationsystem.model.reference.properties.Vault ;
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 ;
2021-10-25 18:12:04 +02:00
import org.gcube.informationsystem.queries.templates.reference.entities.QueryTemplate ;
2021-10-25 10:58:30 +02:00
import org.gcube.informationsystem.queries.templates.reference.properties.TemplateVariable ;
2023-02-03 14:39:25 +01:00
import org.gcube.informationsystem.serialization.ElementMapper ;
2023-02-10 17:03:50 +01:00
import org.gcube.informationsystem.types.annotations.Final ;
import org.gcube.informationsystem.types.reference.Change ;
import org.gcube.informationsystem.types.reference.TypeMetadata ;
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-05-08 17:33:40 +02:00
import org.gcube.informationsystem.types.reference.properties.LinkedEntity ;
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.relations.ConsistsOfType ;
import org.gcube.informationsystem.types.reference.relations.IsRelatedToType ;
import org.gcube.informationsystem.types.reference.relations.RelationType ;
2021-10-21 10:11:45 +02:00
import org.gcube.informationsystem.utils.Version ;
2021-02-11 22:09:02 +01:00
import org.junit.Assert ;
2019-03-22 15:18:23 +01:00
import org.junit.Test ;
import org.slf4j.Logger ;
import org.slf4j.LoggerFactory ;
2021-01-19 15:32:19 +01:00
/ * *
* @author Luca Frosini ( ISTI - CNR )
* /
2019-03-22 15:18:23 +01:00
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 " )
2021-02-11 22:09:02 +01:00
PropertyType < PropertyElement > propertyElement = ( PropertyType < PropertyElement > ) TypeMapper . createTypeDefinition ( PropertyElement . class ) ;
Assert . assertTrue ( propertyElement . getAccessType ( ) = = AccessType . PROPERTY_ELEMENT ) ;
logger . info ( ElementMapper . marshal ( propertyElement ) ) ;
2020-01-29 16:33:51 +01:00
2021-02-11 22:09:02 +01:00
@SuppressWarnings ( { " unchecked " , " rawtypes " } )
PropertyType < PropertyType > propertyType = ( PropertyType < PropertyType > ) TypeMapper . createTypeDefinition ( PropertyType . class ) ;
Assert . assertTrue ( propertyType . getAccessType ( ) = = AccessType . PROPERTY_TYPE ) ;
logger . info ( ElementMapper . marshal ( propertyType ) ) ;
2020-01-29 16:33:51 +01:00
@SuppressWarnings ( " unchecked " )
2021-02-11 22:09:02 +01:00
PropertyType < PropertyDefinition > propertyDefinition = ( PropertyType < PropertyDefinition > ) TypeMapper . createTypeDefinition ( PropertyDefinition . class ) ;
Assert . assertTrue ( propertyDefinition . getAccessType ( ) = = AccessType . PROPERTY_DEFINITION ) ;
logger . info ( ElementMapper . marshal ( propertyDefinition ) ) ;
2020-01-29 16:33:51 +01:00
@SuppressWarnings ( " unchecked " )
2021-02-11 22:09:02 +01:00
PropertyType < LinkedEntity > linkedEntity = ( PropertyType < LinkedEntity > ) TypeMapper . createTypeDefinition ( LinkedEntity . class ) ;
Assert . assertTrue ( linkedEntity . getAccessType ( ) = = AccessType . PROPERTY_ELEMENT ) ;
logger . info ( ElementMapper . marshal ( linkedEntity ) ) ;
2020-01-29 16:33:51 +01:00
@SuppressWarnings ( " unchecked " )
2021-02-11 22:09:02 +01:00
PropertyType < Property > property = ( PropertyType < Property > ) TypeMapper . createTypeDefinition ( Property . class ) ;
Assert . assertTrue ( property . getAccessType ( ) = = AccessType . PROPERTY ) ;
logger . info ( ElementMapper . marshal ( property ) ) ;
2020-01-29 16:33:51 +01:00
2021-02-11 22:09:02 +01:00
@SuppressWarnings ( " unchecked " )
PropertyType < Header > header = ( PropertyType < Header > ) TypeMapper . createTypeDefinition ( Header . class ) ;
Assert . assertTrue ( header . getAccessType ( ) = = AccessType . PROPERTY ) ;
logger . info ( ElementMapper . marshal ( header ) ) ;
2020-01-29 16:33:51 +01:00
@SuppressWarnings ( " unchecked " )
2021-02-11 22:09:02 +01:00
PropertyType < PropagationConstraint > propagationConstraint = ( PropertyType < PropagationConstraint > ) TypeMapper . createTypeDefinition ( PropagationConstraint . class ) ;
Assert . assertTrue ( propagationConstraint . getAccessType ( ) = = AccessType . PROPERTY ) ;
logger . info ( ElementMapper . marshal ( propagationConstraint ) ) ;
2020-01-29 16:33:51 +01:00
@SuppressWarnings ( " unchecked " )
2023-02-27 15:07:41 +01:00
PropertyType < Vault > vault = ( PropertyType < Vault > ) TypeMapper . createTypeDefinition ( Vault . class ) ;
Assert . assertTrue ( vault . getAccessType ( ) = = AccessType . PROPERTY ) ;
logger . info ( ElementMapper . marshal ( vault ) ) ;
2021-02-12 12:08:30 +01:00
2021-10-21 12:47:50 +02:00
@SuppressWarnings ( " unchecked " )
PropertyType < TemplateVariable > templateVariable = ( PropertyType < TemplateVariable > ) TypeMapper . createTypeDefinition ( TemplateVariable . class ) ;
Assert . assertTrue ( templateVariable . getAccessType ( ) = = AccessType . PROPERTY_ELEMENT ) ;
logger . info ( ElementMapper . marshal ( templateVariable ) ) ;
2020-01-29 16:33:51 +01:00
}
2020-01-23 17:14:44 +01:00
@Test
public void testEntityTypeDefinition ( ) throws Exception {
2021-02-11 22:09:02 +01:00
EntityType entityElement = ( EntityType ) TypeMapper . createTypeDefinition ( EntityElement . class ) ;
Assert . assertTrue ( entityElement . getAccessType ( ) = = AccessType . ENTITY_ELEMENT ) ;
logger . info ( ElementMapper . marshal ( entityElement ) ) ;
2020-01-23 17:14:44 +01:00
2021-02-11 22:09:02 +01:00
EntityType entity = ( EntityType ) TypeMapper . createTypeDefinition ( Entity . class ) ;
Assert . assertTrue ( entity . getAccessType ( ) = = AccessType . ENTITY ) ;
logger . info ( ElementMapper . marshal ( entity ) ) ;
2020-01-23 17:14:44 +01:00
2021-02-11 22:09:02 +01:00
ResourceType resource = ( ResourceType ) TypeMapper . createTypeDefinition ( Resource . class ) ;
Assert . assertTrue ( resource . getAccessType ( ) = = AccessType . RESOURCE ) ;
logger . info ( ElementMapper . marshal ( resource ) ) ;
2020-01-23 17:14:44 +01:00
2021-02-11 22:09:02 +01:00
FacetType facet = ( FacetType ) TypeMapper . createTypeDefinition ( Facet . class ) ;
Assert . assertTrue ( facet . getAccessType ( ) = = AccessType . FACET ) ;
logger . info ( ElementMapper . marshal ( facet ) ) ;
2020-01-23 17:14:44 +01:00
2021-02-11 22:09:02 +01:00
EntityType context = ( EntityType ) TypeMapper . createTypeDefinition ( Context . class ) ;
Assert . assertTrue ( context . getAccessType ( ) = = AccessType . CONTEXT ) ;
logger . info ( ElementMapper . marshal ( context ) ) ;
2020-01-23 17:14:44 +01:00
2021-02-11 22:09:02 +01:00
EntityType entityType = ( EntityType ) TypeMapper . createTypeDefinition ( EntityType . class ) ;
Assert . assertTrue ( entityType . getAccessType ( ) = = AccessType . ENTITY_TYPE ) ;
logger . info ( ElementMapper . marshal ( entityType ) ) ;
2020-01-23 17:14:44 +01:00
2021-02-11 22:09:02 +01:00
EntityType resourceType = ( EntityType ) TypeMapper . createTypeDefinition ( ResourceType . class ) ;
Assert . assertTrue ( resourceType . getAccessType ( ) = = AccessType . ENTITY_TYPE ) ;
logger . info ( ElementMapper . marshal ( resourceType ) ) ;
2020-01-23 17:14:44 +01:00
2021-02-11 22:09:02 +01:00
EntityType facetType = ( EntityType ) TypeMapper . createTypeDefinition ( FacetType . class ) ;
Assert . assertTrue ( facetType . getAccessType ( ) = = AccessType . ENTITY_TYPE ) ;
logger . info ( ElementMapper . marshal ( facetType ) ) ;
2021-10-25 18:12:04 +02:00
EntityType queryTemplateType = ( EntityType ) TypeMapper . createTypeDefinition ( QueryTemplate . class ) ;
Assert . assertTrue ( queryTemplateType . getAccessType ( ) = = AccessType . QUERY_TEMPLATE ) ;
logger . info ( ElementMapper . marshal ( queryTemplateType ) ) ;
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 " )
2021-02-11 22:09:02 +01:00
RelationType < EntityType , EntityType > relation = ( RelationType < EntityType , EntityType > ) TypeMapper . createTypeDefinition ( Relation . class ) ;
Assert . assertTrue ( relation . getAccessType ( ) = = AccessType . RELATION ) ;
logger . info ( ElementMapper . marshal ( relation ) ) ;
2019-11-04 18:06:46 +01:00
2021-02-11 22:09:02 +01:00
IsRelatedToType isRelatedTo = ( IsRelatedToType ) TypeMapper . createTypeDefinition ( IsRelatedTo . class ) ;
Assert . assertTrue ( isRelatedTo . getAccessType ( ) = = AccessType . IS_RELATED_TO ) ;
logger . info ( ElementMapper . marshal ( isRelatedTo ) ) ;
2020-01-23 17:14:44 +01:00
2021-02-11 22:09:02 +01:00
ConsistsOfType consistsOf = ( ConsistsOfType ) TypeMapper . createTypeDefinition ( ConsistsOf . class ) ;
Assert . assertTrue ( consistsOf . getAccessType ( ) = = AccessType . CONSISTS_OF ) ;
logger . info ( ElementMapper . marshal ( consistsOf ) ) ;
2019-11-04 18:06:46 +01:00
2020-01-23 17:14:44 +01:00
@SuppressWarnings ( " unchecked " )
2021-02-11 22:09:02 +01:00
RelationType < EntityType , EntityType > isParentOf = ( RelationType < EntityType , EntityType > ) TypeMapper . createTypeDefinition ( IsParentOf . class ) ;
Assert . assertTrue ( isParentOf . getAccessType ( ) = = AccessType . IS_PARENT_OF ) ;
logger . info ( ElementMapper . marshal ( isParentOf ) ) ;
2020-01-23 17:14:44 +01:00
@SuppressWarnings ( " unchecked " )
2021-02-11 22:09:02 +01:00
RelationType < EntityType , EntityType > relationType = ( RelationType < EntityType , EntityType > ) TypeMapper . createTypeDefinition ( RelationType . class ) ;
Assert . assertTrue ( relationType . getAccessType ( ) = = AccessType . RELATION_TYPE ) ;
logger . info ( ElementMapper . marshal ( relationType ) ) ;
2020-01-23 17:14:44 +01:00
@SuppressWarnings ( " unchecked " )
2021-02-11 22:09:02 +01:00
RelationType < EntityType , EntityType > isRelatedToType = ( RelationType < EntityType , EntityType > ) TypeMapper . createTypeDefinition ( IsRelatedToType . class ) ;
Assert . assertTrue ( isRelatedToType . getAccessType ( ) = = AccessType . RELATION_TYPE ) ;
logger . info ( ElementMapper . marshal ( isRelatedToType ) ) ;
2019-11-05 18:42:25 +01:00
2020-01-23 17:14:44 +01:00
@SuppressWarnings ( " unchecked " )
2021-02-11 22:09:02 +01:00
RelationType < EntityType , EntityType > consistsOfType = ( RelationType < EntityType , EntityType > ) TypeMapper . createTypeDefinition ( ConsistsOfType . class ) ;
Assert . assertTrue ( consistsOfType . getAccessType ( ) = = AccessType . RELATION_TYPE ) ;
logger . info ( ElementMapper . marshal ( consistsOfType ) ) ;
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 ( ) ) ;
}
}
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 ) ;
2020-12-11 13:09:02 +01:00
@SuppressWarnings ( " unchecked " )
PropertyType < Header > propertyType = ( PropertyType < Header > ) TypeMapper . deserializeTypeDefinition ( serialized ) ;
2021-10-21 10:11:45 +02:00
Version typeVersion = propertyType . getVersion ( ) ;
2020-12-11 13:09:02 +01:00
logger . debug ( " Version {} " , typeVersion . toString ( ) ) ;
logger . info ( ElementMapper . marshal ( propertyType ) ) ;
2020-12-14 10:10:49 +01:00
2021-06-23 10:50:12 +02:00
String json = " { \" @class \" : \" PropertyType \" , \" header \" :null, \" name \" : \" Header \" , \" description \" : \" This class provides metadata per every IdentifiableElement \" , \" superClasses \" :[ \" Property \" ], \" properties \" :[{ \" @class \" : \" PropertyDefinition \" , \" name \" : \" creationTime \" , \" description \" : \" Creation time. It represents the difference, measured in milliseconds, between the creation time and midnight, January 1, 1970, UTC. \" , \" mandatory \" :true, \" readonly \" :true, \" notnull \" :true, \" max \" :null, \" min \" :null, \" regexp \" :null, \" type \" : \" Date \" },{ \" @class \" : \" PropertyDefinition \" , \" name \" : \" lastUpdateTime \" , \" description \" : \" Last Update time. At creation time it assumes the same value of creationTime. It represents the difference, measured in milliseconds, between the creation time and midnight, January 1, 1970, UTC. \" , \" mandatory \" :true, \" readonly \" :false, \" notnull \" :true, \" max \" :null, \" min \" :null, \" regexp \" :null, \" type \" : \" Date \" },{ \" @class \" : \" PropertyDefinition \" , \" name \" : \" createdBy \" , \" description \" : \" The user that created the Entity or the Relation. It is initialized at creation time. \" , \" mandatory \" :true, \" readonly \" :true, \" notnull \" :true, \" max \" :null, \" min \" :null, \" regexp \" :null, \" type \" : \" String \" },{ \" @class \" : \" PropertyDefinition \" , \" name \" : \" uuid \" , \" description \" : \" This UUID is be used to identify the Entity or the Relation univocally. \" , \" 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}$ \" , \" type \" : \" String \" },{ \" @class \" : \" PropertyDefinition \" , \" name \" : \" lastUpdateBy \" , \" description \" : \" The user that made the last update to the Entity or the Relation. At creation time, it assumes the same value of creator. \" , \" mandatory \" :true, \" readonly \" :false, \" notnull \" :true, \" max \" :null, \" min \" :null, \" regexp \" :null, \" type \" : \" String \" }], \" accessType \" : \" PROPERTY \" , \" abstract \" :false, \" version \" : \" 1.0.0 \" , \" changelog \" :{ \" 1.0.0 \" : \" First Version \" }} " ;
2020-12-14 10:10:49 +01:00
logger . info ( json ) ;
@SuppressWarnings ( " unchecked " )
PropertyType < Header > headerType = ( PropertyType < Header > ) TypeMapper . deserializeTypeDefinition ( json ) ;
logger . info ( ElementMapper . marshal ( headerType ) ) ;
2021-06-23 10:50:12 +02:00
2019-10-24 15:03:14 +02:00
}
2019-10-24 19:50:43 +02:00
2023-02-10 17:03:50 +01:00
@TypeMetadata ( name = TestVersionNotInChangelog . NAME , description = " This type is a test to check version compliancy " , version = " 2.1.0 " )
@Change ( version = " 1.1.0 " , description = " A test of the declared version which is not in changelog " )
@Change ( version = Version . MINIMAL_VERSION_STRING , description = Version . MINIMAL_VERSION_DESCRIPTION )
@Final
interface TestVersionNotInChangelog extends Property {
public static final String NAME = " TestVersionNotInChangelog " ; // TestVersionNotInChangelog.class.getSimpleName();
}
@TypeMetadata ( name = TestVersionNotHighest . NAME , description = " This type is a test to check version compliancy " , version = " 1.0.0 " )
@Change ( version = " 1.1.0 " , description = " A test of the declared version which is not the highest in changelog " )
@Change ( version = Version . MINIMAL_VERSION_STRING , description = Version . MINIMAL_VERSION_DESCRIPTION )
@Final
interface TestVersionNotHighest extends Property {
public static final String NAME = " TestVersionNotHighest " ; // TestVersionNotHighest.class.getSimpleName();
}
@Test ( expected = RuntimeException . class )
public void testVersionNotInChangelog ( ) throws Exception {
TypeMapper . serializeType ( TestVersionNotInChangelog . class ) ;
}
@Test ( expected = RuntimeException . class )
public void testVersionNotHighest ( ) throws Exception {
TypeMapper . serializeType ( TestVersionNotHighest . class ) ;
}
2019-03-22 15:18:23 +01:00
}