From 5d9da9850871107ec087988791d837088a4508ef Mon Sep 17 00:00:00 2001 From: Luca Frosini Date: Fri, 24 Jan 2020 11:25:13 +0100 Subject: [PATCH] Fixed Schema management and test --- .../instances/type/SchemaManagementImpl.java | 22 ++++++---- .../instances/SmartgearResourcesTest.java | 2 +- .../type/SchemaManagementImplTest.java | 42 ++++++++++++------- 3 files changed, 42 insertions(+), 24 deletions(-) diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/instances/type/SchemaManagementImpl.java b/src/main/java/org/gcube/informationsystem/resourceregistry/instances/type/SchemaManagementImpl.java index fac5896..6965a33 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/instances/type/SchemaManagementImpl.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/instances/type/SchemaManagementImpl.java @@ -90,12 +90,14 @@ public class SchemaManagementImpl implements SchemaManagement { node.put(ISManageable.CLASS_PROPERTY, ResourceTypeDefinition.NAME); } else if(oClass.isSubClassOf(Facet.NAME)) { node.put(ISManageable.CLASS_PROPERTY, FacetTypeDefinition.NAME); - } else if(oClass.isSubClassOf(Relation.NAME)) { - node.put(ISManageable.CLASS_PROPERTY, RelationTypeDefinition.NAME); - } + } else if(oClass.isSubClassOf(IsRelatedTo.NAME)) { + node.put(ISManageable.CLASS_PROPERTY, IsRelatedToTypeDefinition.NAME); + } else if(oClass.isSubClassOf(ConsistsOf.NAME)) { + node.put(ISManageable.CLASS_PROPERTY, ConsistsOfTypeDefinition.NAME); + } if(!oClass.isSubClassOf(Resource.NAME)) { - ArrayNode arrayNode = (ArrayNode) node.get(PropertyCapableTypeDefinition.PROPERTIES_PROPERTY); + ArrayNode arrayNode = (ArrayNode) node.get(EntityTypeDefinition.PROPERTIES_PROPERTY); Iterator iterator = arrayNode.iterator(); while(iterator.hasNext()) { ObjectNode propertyNode = (ObjectNode) iterator.next(); @@ -113,6 +115,7 @@ public class SchemaManagementImpl implements SchemaManagement { } */ + private TypeDefinition getTypeDefinition(OClass oClass) throws SchemaException { try { ERManagement erManagement = null; @@ -128,12 +131,17 @@ public class SchemaManagementImpl implements SchemaManagement { ((FacetTypeDefinitionManagement) erManagement).setName(oClass.getName()); } else if(oClass.isSubClassOf(IsRelatedTo.NAME)) { erManagement = new IsRelatedToTypeDefinitionManagement(); + ((IsRelatedToTypeDefinitionManagement) erManagement).setName(oClass.getName()); } else if(oClass.isSubClassOf(ConsistsOf.NAME)) { erManagement = new ConsistsOfTypeDefinitionManagement(); - + ((ConsistsOfTypeDefinitionManagement) erManagement).setName(oClass.getName()); + } + if(erManagement!=null) { + String ret = erManagement.read(); + return TypeBinder.deserializeTypeDefinition(ret); + }else { + throw new SchemaException("You can only request schema of IS Model types and their specilization"); } - String ret = erManagement.read(); - return TypeBinder.deserializeTypeDefinition(ret); } catch(Exception e) { throw new SchemaException(e); } diff --git a/src/test/java/org/gcube/informationsystem/resourceregistry/instances/SmartgearResourcesTest.java b/src/test/java/org/gcube/informationsystem/resourceregistry/instances/SmartgearResourcesTest.java index b02b3fa..12dfba8 100644 --- a/src/test/java/org/gcube/informationsystem/resourceregistry/instances/SmartgearResourcesTest.java +++ b/src/test/java/org/gcube/informationsystem/resourceregistry/instances/SmartgearResourcesTest.java @@ -262,7 +262,7 @@ public class SmartgearResourcesTest extends ContextTest { Assert.assertTrue(sfList.size()==1); List cfList = hostingNodeToUpdate.getFacets(CPUFacet.class); - Assert.assertTrue(cfList.size()==4); + Assert.assertTrue(cfList.size()==cpuFacets.size()); List nfList = hostingNodeToUpdate.getFacets(NetworkingFacet.class); Assert.assertTrue(nfList.size()==1); diff --git a/src/test/java/org/gcube/informationsystem/resourceregistry/type/SchemaManagementImplTest.java b/src/test/java/org/gcube/informationsystem/resourceregistry/type/SchemaManagementImplTest.java index 247965e..4cd9277 100644 --- a/src/test/java/org/gcube/informationsystem/resourceregistry/type/SchemaManagementImplTest.java +++ b/src/test/java/org/gcube/informationsystem/resourceregistry/type/SchemaManagementImplTest.java @@ -20,6 +20,7 @@ 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.resourceregistry.api.exceptions.schema.SchemaAlreadyPresentException; +import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaException; import org.gcube.informationsystem.resourceregistry.instances.type.SchemaManagement; import org.gcube.informationsystem.resourceregistry.instances.type.SchemaManagementImpl; import org.gcube.informationsystem.types.TypeBinder; @@ -117,29 +118,38 @@ public class SchemaManagementImplTest { boolean includeSubTypes = true; SchemaManagement schemaManagement = new SchemaManagementImpl(); - String list = schemaManagement.read(BaseProperty.NAME, includeSubTypes); - logger.debug("{} list : {}", BaseProperty.NAME, list); - - List typeDefinitions = ISMapper.unmarshalList(TypeDefinition.class, list); - logger.debug("{}", typeDefinitions); - - list = schemaManagement.read(Entity.NAME, includeSubTypes); - logger.debug("{} list : {}", Entity.NAME, list); - - list = schemaManagement.read(Resource.NAME, includeSubTypes); - logger.debug("{} list : {}", Resource.NAME, list); + try { + schemaManagement.read(BaseProperty.NAME, includeSubTypes); + throw new Exception("Should not be allowed to get " + BaseProperty.NAME + " schema"); + } catch (SchemaException e) { + + } + + try { + schemaManagement.read(Entity.NAME, includeSubTypes); + throw new Exception("Should not be allowed to get " + Entity.NAME + " schema"); + } catch (SchemaException e) { + + } + + String list = schemaManagement.read(Resource.NAME, includeSubTypes); + logger.info("{} list : {}", Resource.NAME, list); list = schemaManagement.read(Facet.NAME, includeSubTypes); - logger.debug("{} list : {}", Facet.NAME, list); + logger.info("{} list : {}", Facet.NAME, list); - list = schemaManagement.read(Relation.NAME, includeSubTypes); - logger.debug("{} list : {}", Relation.NAME, list); + try { + schemaManagement.read(Relation.NAME, includeSubTypes); + throw new Exception("Should not be allowed to get " + Relation.NAME + " schema"); + } catch (SchemaException e) { + + } list = schemaManagement.read(ConsistsOf.NAME, includeSubTypes); - logger.debug("{} list : {}", ConsistsOf.NAME, list); + logger.info("{} list : {}", ConsistsOf.NAME, list); list = schemaManagement.read(IsRelatedTo.NAME, includeSubTypes); - logger.debug("{} list : {}", IsRelatedTo.NAME, list); + logger.info("{} list : {}", IsRelatedTo.NAME, list); }