Luca Frosini 2016-10-28 10:06:54 +00:00
parent 8fa72b179f
commit a746eb869b
4 changed files with 47 additions and 55 deletions

View File

@ -89,6 +89,13 @@
<artifactId>gcube-resources</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.gcube.information-system</groupId>
<artifactId>resource-registry-client</artifactId>
<version>[1.0.0-SNAPSHOT, 2.0.0-SNAPSHOT)</version>
<scope>test</scope>
</dependency>
</dependencies>

View File

@ -254,6 +254,7 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
public <F extends Facet> F createFacet(Class<F> 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<F> 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 extends Facet> F updateFacet(Class<F> 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<F> 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 <F extends Facet> 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<Boolean> 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 extends Resource> R createResource(Class<R> 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<R> 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 <R extends Resource> 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<Boolean> 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 extends ConsistsOf<? extends Resource, ? extends Facet>> C createConsistsOf(
Class<C> 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<C> 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 <C extends ConsistsOf<? extends Resource, ? extends Facet>> 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<Boolean> 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<I> 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<I> 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 <I extends IsRelatedTo<? extends Resource, ? extends Resource>> 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<Boolean> 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);

View File

@ -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<EService, SoftwareFacet> 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<? extends Facet> 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<ConsistsOf<? extends Resource, ? extends Facet>> 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<Resource, Facet> isIdentifiedBy = new IsIdentifiedByImpl<Resource, Facet>(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<HostingNode, CPUFacet> isIdentifiedByCPUFacet = new IsIdentifiedByImpl<>(createdHostingNode, createdCpuFacet, null);
logger.debug("Going to create : {}", isIdentifiedByCPUFacet);
@SuppressWarnings("unchecked")
IsIdentifiedBy<HostingNode, CPUFacet> createdIsIdentifiedByCPUFacet = resourceRegistryPublisher.createConsistsOf(IsIdentifiedBy.class, isIdentifiedByCPUFacet);
logger.debug("Created : {}", createdIsIdentifiedByCPUFacet);
Hosts<HostingNode, EService> hosts = new HostsImpl<>(createdHostingNode, createdEService, null);
logger.debug("Going to create : {}", hosts);
@SuppressWarnings("unchecked")
Hosts<HostingNode, EService> 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);
}

View File

@ -7,7 +7,8 @@
</appender>
<logger name="org.gcube" level="TRACE" />
<logger name="org.gcube" level="INFO" />
<logger name="org.gcube.informationsystem" level="INFO" />
<root level="WARN">
<appender-ref ref="STDOUT" />