From a746eb869b3d793b29c7b92de49de2f183d8f610 Mon Sep 17 00:00:00 2001 From: Luca Frosini Date: Fri, 28 Oct 2016 10:06:54 +0000 Subject: [PATCH] git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/information-system/resource-registry-publisher@133702 82a268e6-3cf1-43bd-a215-b396298e98cf --- pom.xml | 7 +++ .../proxy/ResourceRegistryPublisherImpl.java | 45 ++++++++++++++---- .../publisher/EntityManagementTest.java | 47 +------------------ src/test/resources/logback-test.xml | 3 +- 4 files changed, 47 insertions(+), 55 deletions(-) diff --git a/pom.xml b/pom.xml index 6335ba4..7fba289 100644 --- a/pom.xml +++ b/pom.xml @@ -89,6 +89,13 @@ gcube-resources test + + org.gcube.information-system + resource-registry-client + [1.0.0-SNAPSHOT, 2.0.0-SNAPSHOT) + test + + diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/publisher/proxy/ResourceRegistryPublisherImpl.java b/src/main/java/org/gcube/informationsystem/resourceregistry/publisher/proxy/ResourceRegistryPublisherImpl.java index c1325dc..3366a52 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/publisher/proxy/ResourceRegistryPublisherImpl.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/publisher/proxy/ResourceRegistryPublisherImpl.java @@ -254,6 +254,7 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher public F createFacet(Class facetClass, F facet) { try { + logger.info("Going to create: {}", facet); StringWriter stringWriter = new StringWriter(); stringWriter.append(PATH_SEPARATOR); stringWriter.append(EntityPath.ENTITY_PATH_PART); @@ -269,7 +270,9 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher ResourceRegistryCall call = new ResourceRegistryCall<>(facetClass, httpInputs); - return delegate.make(call); + F f = delegate.make(call); + logger.info("{} successfully created", f); + return f; } catch (Exception e) { logger.error("Error Creating {}", facet, e); throw new ServiceException(e); @@ -279,6 +282,7 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher @Override public F updateFacet(Class facetClass, F facet) { try { + logger.info("Going to update: {}", facet); StringWriter stringWriter = new StringWriter(); stringWriter.append(PATH_SEPARATOR); stringWriter.append(EntityPath.ENTITY_PATH_PART); @@ -294,7 +298,9 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher ResourceRegistryCall call = new ResourceRegistryCall<>(facetClass, httpInputs); - return delegate.make(call); + F f = delegate.make(call); + logger.info("{} successfully updated", f); + return f; } catch (Exception e) { logger.error("Error Updating {}", facet, e); throw new ServiceException(e); @@ -304,6 +310,7 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher @Override public boolean deleteFacet(F facet) { try { + logger.info("Going to delete: {}", facet); StringWriter stringWriter = new StringWriter(); stringWriter.append(PATH_SEPARATOR); stringWriter.append(EntityPath.ENTITY_PATH_PART); @@ -316,7 +323,9 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher ResourceRegistryCall call = new ResourceRegistryCall<>(Boolean.class, httpInputs); - return delegate.make(call); + boolean deleted = delegate.make(call); + logger.info("{} {}", facet, deleted?" successfully deleted": "was NOT deleted"); + return deleted; } catch (Exception e) { logger.error("Error Removing {}", facet, e); throw new ServiceException(e); @@ -327,6 +336,7 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher public R createResource(Class resourceClass, R resource) { try { + logger.info("Going to create: {}", resource); StringWriter stringWriter = new StringWriter(); stringWriter.append(PATH_SEPARATOR); stringWriter.append(EntityPath.ENTITY_PATH_PART); @@ -342,7 +352,9 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher ResourceRegistryCall call = new ResourceRegistryCall<>(resourceClass, httpInputs); - return delegate.make(call); + R r = delegate.make(call); + logger.info("{} successfully created", r); + return r; } catch (Exception e) { logger.error("Error Creating Facet", e); throw new ServiceException(e); @@ -352,6 +364,7 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher @Override public boolean deleteResource(R resource) { try { + logger.info("Going to delete: {}", resource); StringWriter stringWriter = new StringWriter(); stringWriter.append(PATH_SEPARATOR); stringWriter.append(EntityPath.ENTITY_PATH_PART); @@ -364,7 +377,9 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher ResourceRegistryCall call = new ResourceRegistryCall<>(Boolean.class, httpInputs); - return delegate.make(call); + boolean deleted = delegate.make(call); + logger.info("{} {}", resource, deleted?" successfully deleted": "was NOT deleted"); + return deleted; } catch (Exception e) { logger.error("Error Removing {}", resource, e); throw new ServiceException(e); @@ -375,6 +390,7 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher public > C createConsistsOf( Class consistsOfClass, C consistsOf) { try { + logger.info("Going to create: {}", consistsOf); StringWriter stringWriter = new StringWriter(); stringWriter.append(PATH_SEPARATOR); stringWriter.append(EntityPath.ENTITY_PATH_PART); @@ -398,7 +414,9 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher ResourceRegistryCall call = new ResourceRegistryCall<>(consistsOfClass, httpInputs); - return delegate.make(call); + C c = delegate.make(call); + logger.info("{} successfully created", c); + return c; } catch (Exception e) { logger.error("Error Creating Facet", e); throw new ServiceException(e); @@ -409,6 +427,7 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher public > boolean deleteConsistsOf( C consistsOf) { try { + logger.info("Going to delete: {}", consistsOf); StringWriter stringWriter = new StringWriter(); stringWriter.append(PATH_SEPARATOR); stringWriter.append(EntityPath.ENTITY_PATH_PART); @@ -421,7 +440,9 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher ResourceRegistryCall call = new ResourceRegistryCall<>(Boolean.class, httpInputs); - return delegate.make(call); + boolean deleted = delegate.make(call); + logger.info("{} {}", consistsOf, deleted?" successfully deleted": "was NOT deleted"); + return deleted; } catch (Exception e) { logger.error("Error Removing {}", consistsOf, e); throw new ServiceException(e); @@ -433,6 +454,7 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher Class isRelatedToClass, I isRelatedTo) { try { + logger.info("Going to create: {}", isRelatedTo); StringWriter stringWriter = new StringWriter(); stringWriter.append(PATH_SEPARATOR); stringWriter.append(EntityPath.ENTITY_PATH_PART); @@ -456,7 +478,9 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher ResourceRegistryCall call = new ResourceRegistryCall<>( isRelatedToClass, httpInputs); - return delegate.make(call); + I i = delegate.make(call); + logger.info("{} successfully created", i); + return i; } catch (Exception e) { logger.error("Error Creating Facet", e); throw new ServiceException(e); @@ -466,6 +490,7 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher @Override public > boolean deleteIsRelatedTo(I isRelatedTo) { try { + logger.info("Going to delete: {}", isRelatedTo); StringWriter stringWriter = new StringWriter(); stringWriter.append(PATH_SEPARATOR); stringWriter.append(EntityPath.ENTITY_PATH_PART); @@ -478,7 +503,9 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher ResourceRegistryCall call = new ResourceRegistryCall<>(Boolean.class, httpInputs); - return delegate.make(call); + boolean deleted = delegate.make(call); + logger.info("{} {}", isRelatedTo, deleted?" successfully deleted": "was NOT deleted"); + return deleted; } catch (Exception e) { logger.error("Error Removing {}", isRelatedTo, e); throw new ServiceException(e); diff --git a/src/test/java/org/gcube/informationsystem/resourceregistry/publisher/EntityManagementTest.java b/src/test/java/org/gcube/informationsystem/resourceregistry/publisher/EntityManagementTest.java index aa76608..b44a1c5 100644 --- a/src/test/java/org/gcube/informationsystem/resourceregistry/publisher/EntityManagementTest.java +++ b/src/test/java/org/gcube/informationsystem/resourceregistry/publisher/EntityManagementTest.java @@ -14,7 +14,6 @@ import org.gcube.informationsystem.impl.entity.resource.EServiceImpl; import org.gcube.informationsystem.impl.entity.resource.HostingNodeImpl; import org.gcube.informationsystem.impl.relation.IsIdentifiedByImpl; import org.gcube.informationsystem.impl.relation.isrelatedto.HostsImpl; -import org.gcube.informationsystem.impl.utils.Entities; import org.gcube.informationsystem.model.entity.Facet; import org.gcube.informationsystem.model.entity.Resource; import org.gcube.informationsystem.model.entity.facet.CPUFacet; @@ -56,9 +55,7 @@ public class EntityManagementTest { cpuFacet.setModel("Opteron"); cpuFacet.setVendor("AMD"); - logger.debug("Going to create: {}", cpuFacet); CPUFacet createdCpuFacet = resourceRegistryPublisher.createFacet(CPUFacet.class, cpuFacet); - logger.debug("Created: {}", createdCpuFacet); Assert.assertTrue(cpuFacet.getClockSpeed().compareTo(createdCpuFacet.getClockSpeed())==0); Assert.assertTrue(cpuFacet.getModel().compareTo(createdCpuFacet.getModel())==0); @@ -75,9 +72,7 @@ public class EntityManagementTest { String additionPropertyValue = "Test"; createdCpuFacet.setAdditionalProperty(additionPropertyKey, additionPropertyValue); - logger.debug("Going to update: {}", cpuFacet); CPUFacet updatedCpuFacet = resourceRegistryPublisher.updateFacet(CPUFacet.class, createdCpuFacet); - logger.debug("Updated: {}", updatedCpuFacet); Assert.assertTrue(createdCpuFacet.getClockSpeed().compareTo(updatedCpuFacet.getClockSpeed())==0); Assert.assertTrue(createdCpuFacet.getModel().compareTo(updatedCpuFacet.getModel())==0); Assert.assertTrue(createdCpuFacet.getVendor().compareTo(updatedCpuFacet.getVendor())==0); @@ -86,7 +81,6 @@ public class EntityManagementTest { boolean deleted = resourceRegistryPublisher.deleteFacet(updatedCpuFacet); Assert.assertTrue(deleted); - } @Test @@ -102,11 +96,8 @@ public class EntityManagementTest { IsIdentifiedBy isIdentifiedByESSF = new IsIdentifiedByImpl<>(eService, softwareFacet, null); eService.addFacet(isIdentifiedByESSF); - Entities.registerSubtypes(IsIdentifiedBy.class, SoftwareFacet.class, EService.class, HostingNode.class, NetworkingFacet.class, CPUFacet.class); - - logger.debug("Going to create : {}", eService); EService createdEService = resourceRegistryPublisher.createResource(EService.class, eService); - logger.debug("Created : {}", createdEService); + List idenficationFacets = createdEService.getIdentificationFacets(); Assert.assertTrue(idenficationFacets!=null); Assert.assertTrue(idenficationFacets.size()==1); @@ -124,10 +115,7 @@ public class EntityManagementTest { networkingFacet.setMask("255.255.248.0"); networkingFacet.setBroadcastAddress("146.48.87.255"); - logger.debug("Going to create : {}", networkingFacet); NetworkingFacet createdNetworkingFacet = resourceRegistryPublisher.createFacet(NetworkingFacet.class, networkingFacet); - logger.debug("Created : {}", createdNetworkingFacet); - HostingNode hostingNode = new HostingNodeImpl(); @@ -145,10 +133,7 @@ public class EntityManagementTest { hostingNode.attachResource(hosts); - - logger.debug("Going to create : {}", hostingNode); HostingNode createdHostingNode = resourceRegistryPublisher.createResource(HostingNode.class, hostingNode); - logger.debug("Created : {}", createdHostingNode); List> consistsOfList = createdHostingNode.getConsistsOf(); CPUFacet createdCPUFacet = null; @@ -159,28 +144,23 @@ public class EntityManagementTest { } Assert.assertTrue(createdCPUFacet!=null); - logger.debug("Created : {}", createdCPUFacet); + logger.info("Created : {}", createdCPUFacet); - logger.debug("Going to delete : {}", createdHostingNode); boolean deleted = resourceRegistryPublisher.deleteResource(createdHostingNode); Assert.assertTrue(deleted); - logger.debug("Going to delete : {}", createdCPUFacet); deleted = resourceRegistryPublisher.deleteFacet(createdCPUFacet); Assert.assertTrue(deleted); - logger.debug("Going to delete : {}", createdNetworkingFacet); deleted = resourceRegistryPublisher.deleteFacet(createdNetworkingFacet); Assert.assertTrue(deleted); - logger.debug("Going to delete : {}", createdSoftwareFacet); deleted = resourceRegistryPublisher.deleteFacet(createdSoftwareFacet); Assert.assertTrue(deleted); - logger.debug("Going to delete : {}", createdEService); deleted = resourceRegistryPublisher.deleteResource(createdEService); Assert.assertTrue(deleted); @@ -198,19 +178,10 @@ public class EntityManagementTest { IsIdentifiedBy isIdentifiedBy = new IsIdentifiedByImpl(eService, softwareFacet, null); eService.addFacet(isIdentifiedBy); - Entities.registerSubtypes(IsIdentifiedBy.class, SoftwareFacet.class, EService.class); - - - logger.debug("Going to create : {}", eService); EService createdEService = resourceRegistryPublisher.createResource(EService.class, eService); - logger.debug("Created : {}", createdEService); - HostingNode hostingNode = new HostingNodeImpl(); - - logger.debug("Going to create : {}", hostingNode); HostingNode createdHostingNode = resourceRegistryPublisher.createResource(HostingNode.class, hostingNode); - logger.debug("Created : {}", createdHostingNode); CPUFacet cpuFacet = new CPUFacetImpl(); @@ -218,44 +189,30 @@ public class EntityManagementTest { cpuFacet.setModel("Opteron"); cpuFacet.setVendor("AMD"); - - Entities.registerSubtypes(HostingNode.class, CPUFacet.class); - - - logger.debug("Going to create: {}", cpuFacet); CPUFacet createdCpuFacet = resourceRegistryPublisher.createFacet(CPUFacet.class, cpuFacet); - logger.debug("Created: {}", createdCpuFacet); IsIdentifiedBy isIdentifiedByCPUFacet = new IsIdentifiedByImpl<>(createdHostingNode, createdCpuFacet, null); - logger.debug("Going to create : {}", isIdentifiedByCPUFacet); @SuppressWarnings("unchecked") IsIdentifiedBy createdIsIdentifiedByCPUFacet = resourceRegistryPublisher.createConsistsOf(IsIdentifiedBy.class, isIdentifiedByCPUFacet); - logger.debug("Created : {}", createdIsIdentifiedByCPUFacet); Hosts hosts = new HostsImpl<>(createdHostingNode, createdEService, null); - logger.debug("Going to create : {}", hosts); @SuppressWarnings("unchecked") Hosts createdHosts = resourceRegistryPublisher.createIsRelatedTo(Hosts.class, hosts); - logger.debug("Created : {}", createdHosts); - logger.debug("Going to delete : {}", createdIsIdentifiedByCPUFacet); boolean deleted = resourceRegistryPublisher.deleteConsistsOf(createdIsIdentifiedByCPUFacet); Assert.assertTrue(deleted); - logger.debug("Going to delete : {}", createdCpuFacet); deleted = resourceRegistryPublisher.deleteFacet(createdCpuFacet); Assert.assertTrue(deleted); - logger.debug("Going to delete : {}", createdHosts); deleted = resourceRegistryPublisher.deleteIsRelatedTo(createdHosts); Assert.assertTrue(deleted); - logger.debug("Going to delete : {}", createdHostingNode); deleted = resourceRegistryPublisher.deleteResource(createdHostingNode); Assert.assertTrue(deleted); } diff --git a/src/test/resources/logback-test.xml b/src/test/resources/logback-test.xml index 4f36cc8..6dd5446 100644 --- a/src/test/resources/logback-test.xml +++ b/src/test/resources/logback-test.xml @@ -7,7 +7,8 @@ - + +