Fixing bug and added tests

This commit is contained in:
Luca Frosini 2021-03-03 17:18:36 +01:00
parent ec9b6665ca
commit 88baf3cb90
5 changed files with 410 additions and 358 deletions

View File

@ -128,7 +128,7 @@ public abstract class ElementManagement<El extends OElement, T extends Type> {
}
protected void setAsEntryPoint(Operation operation) {
entryPoint = true;
this.entryPoint = true;
this.operation = operation;
}
@ -202,15 +202,24 @@ public abstract class ElementManagement<El extends OElement, T extends Type> {
if(element != null) {
try {
oClass = ElementManagementUtility.getOClass(element);
if(typeName==null) {
typeName = oClass.getName();
}
getCachedType().setOClass(oClass);
}catch (ResourceRegistryException e) {
try {
oClass = getCachedType().getOClass();
if(typeName==null) {
typeName = oClass.getName();
}
}catch (Exception e1) {
throw e;
}
}
} else {
if(typeName==null) {
throw new SchemaException("Unknown type name. Please set it first.");
}
oClass = getCachedType().getOClass();
AccessType gotAccessType = cachedType.getAccessType();
if(accessType!=gotAccessType) {
@ -386,10 +395,10 @@ public abstract class ElementManagement<El extends OElement, T extends Type> {
getWorkingContext().addElement(element, oDatabaseDocument);
sanityCheck();
element.save();
sanityCheck();
return element;
} catch(ResourceRegistryException e) {
throw e;
@ -407,10 +416,10 @@ public abstract class ElementManagement<El extends OElement, T extends Type> {
HeaderUtility.updateModifiedByAndLastUpdate(element);
sanityCheck();
element.save();
sanityCheck();
return element;
} catch(ResourceRegistryException e) {
throw e;
@ -1160,7 +1169,7 @@ public abstract class ElementManagement<El extends OElement, T extends Type> {
// mandatory and notnull constraints due to technical problem
// https://www.orientdb.com/docs/last/java/Graph-Schema-Property.html#using-constraints
// Going to validate them here
cleanCachedSerialization();
JsonNode instances = createCompleteJsonNode();
Set<PropertyDefinition> definedProperties = getAllProperties();

View File

@ -393,6 +393,7 @@ public class ResourceManagement extends EntityManagement<Resource, ResourceType>
*/
@Override
public void sanityCheck() throws SchemaViolationException, ResourceRegistryException {
cleanCachedSerialization();
JsonNode resourceInstance = createCompleteJsonNode();
TypesCache typesCache = TypesCache.getInstance();

View File

@ -1,11 +1,14 @@
package org.gcube.informationsystem.resourceregistry.instances.model.relations;
import java.util.Iterator;
import org.gcube.informationsystem.base.reference.AccessType;
import org.gcube.informationsystem.model.impl.properties.PropagationConstraintImpl;
import org.gcube.informationsystem.model.reference.entities.Facet;
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;
import org.gcube.informationsystem.model.reference.relations.ConsistsOf;
import org.gcube.informationsystem.resourceregistry.api.exceptions.NotFoundException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.relation.consistsOf.ConsistsOfAlreadyPresentException;
@ -20,6 +23,7 @@ import org.gcube.informationsystem.types.reference.entities.FacetType;
import com.orientechnologies.orient.core.db.document.ODatabaseDocument;
import com.orientechnologies.orient.core.record.ODirection;
import com.orientechnologies.orient.core.record.OEdge;
import com.orientechnologies.orient.core.record.OVertex;
/**
@ -63,6 +67,27 @@ public class ConsistsOfManagement extends RelationManagement<FacetManagement, Fa
return facetManagement;
}
@Override
protected OEdge reallyCreate() throws ResourceRegistryException {
OEdge thisOEdge = super.reallyCreate();
OVertex target = (OVertex) getTargetEntityManagement().getElement();
int count = 0;
Iterable<OEdge> iterable = target.getEdges(ODirection.IN);
Iterator<OEdge> iterator = iterable.iterator();
while(iterator.hasNext()) {
iterator.next();
++count;
}
if(count > 1) {
throw new SchemaViolationException("It is not possible to create multiple " + ConsistsOf.NAME + " between the same " + Facet.NAME);
}
return thisOEdge;
}
protected void checkResource() throws SchemaViolationException, ResourceRegistryException {
if(!entryPoint) {
return;
@ -78,13 +103,13 @@ public class ConsistsOfManagement extends RelationManagement<FacetManagement, Fa
}
if(operation == Operation.UPDATE) {
// an update to the Facet only modify the Facet properties, no need to check the source resource
// an update to the Facet only modify the ConsistsOf properties, no need to check the source resource
return;
}
ODatabaseDocument targetSecurityContextODatabaseDocument = null;
try {
OVertex oVertex = getElement().getVertex(ODirection.IN);
OVertex oVertex = getElement().getVertex(ODirection.OUT);
ResourceManagement resourceManagement = new ResourceManagement();
resourceManagement.setElement(oVertex);
switch (operation) {

View File

@ -17,7 +17,6 @@ import java.util.UUID;
import org.gcube.com.fasterxml.jackson.core.JsonParseException;
import org.gcube.com.fasterxml.jackson.databind.JsonMappingException;
import org.gcube.common.authorization.library.provider.AuthorizationProvider;
import org.gcube.informationsystem.model.impl.properties.EncryptedImpl;
import org.gcube.informationsystem.model.impl.properties.HeaderImpl;
import org.gcube.informationsystem.model.impl.properties.PropagationConstraintImpl;
@ -31,11 +30,8 @@ import org.gcube.informationsystem.model.reference.relations.ConsistsOf;
import org.gcube.informationsystem.model.reference.relations.IsRelatedTo;
import org.gcube.informationsystem.resourceregistry.ContextTest;
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.facet.FacetNotFoundException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.query.InvalidQueryException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaViolationException;
import org.gcube.informationsystem.resourceregistry.instances.base.ElementManagementUtility;
import org.gcube.informationsystem.resourceregistry.instances.model.entities.FacetManagement;
import org.gcube.informationsystem.resourceregistry.instances.model.entities.ResourceManagement;
import org.gcube.informationsystem.resourceregistry.instances.model.relations.ConsistsOfManagement;
import org.gcube.informationsystem.resourceregistry.instances.model.relations.IsRelatedToManagement;
@ -53,7 +49,6 @@ import org.gcube.resourcemanagement.model.impl.entities.facets.StateFacetImpl;
import org.gcube.resourcemanagement.model.impl.entities.resources.ConfigurationImpl;
import org.gcube.resourcemanagement.model.impl.entities.resources.EServiceImpl;
import org.gcube.resourcemanagement.model.impl.entities.resources.HostingNodeImpl;
import org.gcube.resourcemanagement.model.impl.entities.resources.RunningPluginImpl;
import org.gcube.resourcemanagement.model.impl.properties.ValueSchemaImpl;
import org.gcube.resourcemanagement.model.impl.relations.consistsof.HasPersistentMemoryImpl;
import org.gcube.resourcemanagement.model.impl.relations.consistsof.HasVolatileMemoryImpl;
@ -61,7 +56,6 @@ import org.gcube.resourcemanagement.model.impl.relations.consistsof.IsIdentified
import org.gcube.resourcemanagement.model.impl.relations.isrelatedto.ActivatesImpl;
import org.gcube.resourcemanagement.model.reference.entities.facets.AccessPointFacet;
import org.gcube.resourcemanagement.model.reference.entities.facets.CPUFacet;
import org.gcube.resourcemanagement.model.reference.entities.facets.ContactFacet;
import org.gcube.resourcemanagement.model.reference.entities.facets.EventFacet;
import org.gcube.resourcemanagement.model.reference.entities.facets.IdentifierFacet;
import org.gcube.resourcemanagement.model.reference.entities.facets.IdentifierFacet.IdentificationType;
@ -72,12 +66,10 @@ import org.gcube.resourcemanagement.model.reference.entities.facets.NetworkingFa
import org.gcube.resourcemanagement.model.reference.entities.facets.SimpleFacet;
import org.gcube.resourcemanagement.model.reference.entities.facets.SoftwareFacet;
import org.gcube.resourcemanagement.model.reference.entities.facets.StateFacet;
import org.gcube.resourcemanagement.model.reference.entities.resources.Actor;
import org.gcube.resourcemanagement.model.reference.entities.resources.Configuration;
import org.gcube.resourcemanagement.model.reference.entities.resources.EService;
import org.gcube.resourcemanagement.model.reference.entities.resources.GCubeResource;
import org.gcube.resourcemanagement.model.reference.entities.resources.HostingNode;
import org.gcube.resourcemanagement.model.reference.entities.resources.RunningPlugin;
import org.gcube.resourcemanagement.model.reference.entities.resources.Service;
import org.gcube.resourcemanagement.model.reference.properties.ValueSchema;
import org.gcube.resourcemanagement.model.reference.relations.consistsof.HasPersistentMemory;
@ -187,299 +179,7 @@ public class ERManagementTest extends ContextTest {
return hostingNode;
}
@Test(expected = SchemaViolationException.class)
public void testCreateFacet() throws Exception {
CPUFacet cpuFacet = new CPUFacetImpl();
cpuFacet.setClockSpeed("1 GHz");
cpuFacet.setModel("Opteron");
cpuFacet.setVendor("AMD");
FacetManagement facetManagement = new FacetManagement();
facetManagement.setElementType(CPUFacet.NAME);
String json = ElementMapper.marshal(cpuFacet);
logger.debug("{}", json);
facetManagement.setJson(json);
/* A facet cannot be created per se */
facetManagement.create();
}
@Test
public void testCreateFacetWithEncrypted() throws Exception {
/*
* A facet cannot be created per se. Going to create a Configuration which does
* not impose any particular constraint except the IdentifierFact
*/
Configuration configuration = new ConfigurationImpl();
IdentifierFacet identifierFacet = new IdentifierFacetImpl();
identifierFacet.setType(IdentificationType.STRING);
identifierFacet.setValue("MyID");
identifierFacet.setPersistent(false);
IsIdentifiedBy<Configuration, IdentifierFacet> isIdentifiedBy = new IsIdentifiedByImpl<Configuration, IdentifierFacet>(
configuration, identifierFacet);
configuration.addFacet(isIdentifiedBy);
CPUFacet cpuFacet = new CPUFacetImpl();
cpuFacet.setClockSpeed("1 GHz");
cpuFacet.setModel("Opteron");
cpuFacet.setVendor("AMD");
Encrypted encrypted = new EncryptedImpl();
String plainValue = "plain-value";
String encryptedValue = EncryptedImpl.encrypt(plainValue);
encrypted.setEncryptedValue(encryptedValue);
cpuFacet.setAdditionalProperty("test", encrypted);
configuration.addFacet(cpuFacet);
ResourceManagement resourceManagement = new ResourceManagement();
resourceManagement.setElementType(Configuration.NAME);
String json = ElementMapper.marshal(configuration);
logger.debug("{}", json);
resourceManagement.setJson(json);
/* A facet cannot be created per se */
String configurationJsonString = resourceManagement.create();
Configuration createdConfiguration = ElementMapper.unmarshal(Configuration.class, configurationJsonString);
logger.debug("Created:\nRaw Json : {}\nUnmarshalled : {}", configurationJsonString, createdConfiguration);
CPUFacet readCpuFacet = configuration.getFacets(CPUFacet.class).get(0);
String gotEncryptedValue = ((Encrypted) readCpuFacet.getAdditionalProperty("test")).getEncryptedValue();
Assert.assertTrue(gotEncryptedValue.compareTo(encryptedValue) == 0);
String gotPlainValue = EncryptedImpl.decrypt(gotEncryptedValue);
Assert.assertTrue(gotPlainValue.compareTo(plainValue) == 0);
resourceManagement.delete();
}
@Test
public void testCreatePropertyTypeNotInSchema() throws Exception {
AccessPointFacet accessPointFacet = new AccessPointFacetImpl();
accessPointFacet.setEndpoint(new URI("https://localhost"));
accessPointFacet.setEntryName("port1");
ValueSchema authorization = new ValueSchemaImpl();
authorization.setValue("pwd");
URI uri = new URI("https://www.gcube-system.org");
authorization.setSchema(uri);
accessPointFacet.setAuthorization(authorization);
accessPointFacet.setAdditionalProperty("Test", "MyTest");
Encrypted encrypted = new EncryptedImpl();
String encryptedValue = EncryptedImpl.encrypt("Encrypted");
encrypted.setEncryptedValue(encryptedValue);
accessPointFacet.setAdditionalProperty("Enc", encrypted);
String marshalled = ElementMapper.marshal(accessPointFacet);
logger.debug(marshalled);
FacetManagement facetManagement = new FacetManagement();
facetManagement.setElementType(AccessPointFacet.NAME);
facetManagement.setJson(marshalled);
String createdJson = facetManagement.create();
logger.debug("Created:\nRaw Json : {}", createdJson);
AccessPointFacet apf = ElementMapper.unmarshal(AccessPointFacet.class, createdJson);
Assert.assertTrue(apf.getAuthorization() instanceof ValueSchema);
Assert.assertTrue(apf.getAdditionalProperty("Enc") instanceof Encrypted);
Encrypted enc = (Encrypted) apf.getAdditionalProperty("Enc");
String encValue = enc.getEncryptedValue();
Assert.assertTrue(encValue.compareTo(encryptedValue) == 0);
String decryptedValue = EncryptedImpl.decrypt(encValue);
Assert.assertTrue(decryptedValue.compareTo("Encrypted") == 0);
Assert.assertTrue(((String) apf.getAdditionalProperty("Test")).compareTo("MyTest") == 0);
UUID uuid = apf.getHeader().getUUID();
facetManagement = new FacetManagement();
facetManagement.setUUID(uuid);
boolean deleted = facetManagement.delete();
Assert.assertTrue(deleted);
}
@Test(expected = SchemaViolationException.class)
public void testCreateRunningPlugin() throws Exception {
RunningPlugin runningPlugin = new RunningPluginImpl();
SoftwareFacet softwareFacet = new SoftwareFacetImpl();
softwareFacet.setGroup("information-system");
softwareFacet.setName("is-exporter-se-plugin");
softwareFacet.setVersion("1.0.0");
IsIdentifiedBy<RunningPlugin, Facet> isIdentifiedBy = new IsIdentifiedByImpl<>(runningPlugin, softwareFacet,
null);
runningPlugin.addFacet(isIdentifiedBy);
ResourceManagement resourceManagement = new ResourceManagement();
resourceManagement.setElementType(RunningPlugin.NAME);
resourceManagement.setJson(ElementMapper.marshal(runningPlugin));
String json = resourceManagement.create();
logger.debug("Created : {}", json);
runningPlugin = ElementMapper.unmarshal(RunningPlugin.class, json);
logger.debug("Unmarshalled {} {}", RunningPlugin.NAME, runningPlugin);
resourceManagement = new ResourceManagement();
resourceManagement.setUUID(runningPlugin.getHeader().getUUID());
boolean deleted = resourceManagement.delete();
Assert.assertTrue(deleted);
}
@Test
public void testCreateEService() throws Exception {
EService eService = ERManagementTest.instantiateValidEService();
ResourceManagement resourceManagement = new ResourceManagement();
resourceManagement.setElementType(EService.NAME);
resourceManagement.setJson(ElementMapper.marshal(eService));
String json = resourceManagement.create();
logger.debug("Created : {}", json);
eService = ElementMapper.unmarshal(EService.class, json);
logger.debug("Unmarshalled {} {}", EService.NAME, eService);
resourceManagement = new ResourceManagement();
resourceManagement.setUUID(eService.getHeader().getUUID());
boolean deleted = resourceManagement.delete();
Assert.assertTrue(deleted);
}
// @Test
public void testReadResource() throws Exception {
ResourceManagement resourceManagement = new ResourceManagement();
resourceManagement.setUUID(UUID.fromString("26da57ee-33bd-4c4b-8aef-9206b61c329e"));
String read = resourceManagement.read().toString();
logger.debug(read);
}
// @Test
public void testDeleteResource() throws Exception {
ResourceManagement resourceManagement = new ResourceManagement();
resourceManagement.setUUID(UUID.fromString("64635295-7ced-4931-a55f-40fc8199b280"));
boolean deleted = resourceManagement.delete();
Assert.assertTrue(deleted);
}
@Test(expected = ResourceRegistryException.class)
public void testCreateAbstractEntity() throws Exception {
ResourceManagement resourceManagement = new ResourceManagement();
resourceManagement.setElementType(Actor.NAME);
String json = "{\"@class\":\"Actor\",\"header\":null,\"consistsOf\":[{\"@class\":\"IsIdentifiedBy\",\"header\":null,\"propagationConstraint\":{\"@class\":\"PropagationConstraint\",\"remove\":\"cascadeWhenOrphan\",\"add\":\"propagate\"},\"source\":{\"@class\":\"Actor\",\"header\":null},\"target\":{\"@class\":\"ContactFacet\",\"header\":null,\"title\":\"Dr.\",\"name\":\"Frosini\",\"middleName\":null,\"surname\":null,\"eMail\":\"luca.frosini@isti.cnr.it\"}}],\"isRelatedTo\":[]}";
logger.debug(json);
resourceManagement.setJson(json);
resourceManagement.create();
}
@Test(expected = ResourceRegistryException.class)
public void testCreateAnEntityDifferentFromDeclared() throws Exception {
SimpleFacet simpleFacet = new SimpleFacetImpl();
FacetManagement facetManagement = new FacetManagement();
facetManagement.setElementType(ContactFacet.NAME);
facetManagement.setJson(ElementMapper.marshal(simpleFacet));
facetManagement.create();
}
@Test
public void testCreateReadUpdateDeleteFacet() throws Exception {
CPUFacet cpuFacet = new CPUFacetImpl();
cpuFacet.setClockSpeed("1 GHz");
cpuFacet.setModel("Opteron");
cpuFacet.setVendor("AMD");
Encrypted encrypted = new EncryptedImpl();
encrypted.setEncryptedValue("Value");
cpuFacet.setAdditionalProperty("Enc", encrypted);
String json = ElementMapper.marshal(cpuFacet);
FacetManagement facetManagement = new FacetManagement();
facetManagement.setElementType(CPUFacet.NAME);
facetManagement.setJson(json);
String cpuFacetJson = facetManagement.create();
CPUFacet createdCpuFacet = ElementMapper.unmarshal(CPUFacet.class, cpuFacetJson);
logger.debug("Created:\nRaw Json : {}\nUnmarshalled : {}", cpuFacetJson, createdCpuFacet);
Assert.assertTrue(cpuFacet.getClockSpeed().compareTo(createdCpuFacet.getClockSpeed()) == 0);
Assert.assertTrue(cpuFacet.getModel().compareTo(createdCpuFacet.getModel()) == 0);
Assert.assertTrue(cpuFacet.getVendor().compareTo(createdCpuFacet.getVendor()) == 0);
UUID uuid = createdCpuFacet.getHeader().getUUID();
facetManagement = new FacetManagement();
facetManagement.setUUID(uuid);
String readJson = facetManagement.read().toString();
CPUFacet readCpuFacet = ElementMapper.unmarshal(CPUFacet.class, readJson);
logger.debug("Read:\nRaw Json : {}\nUnmarshalled : {}", readJson, readCpuFacet);
Assert.assertTrue(cpuFacet.getClockSpeed().compareTo(readCpuFacet.getClockSpeed()) == 0);
Assert.assertTrue(cpuFacet.getModel().compareTo(readCpuFacet.getModel()) == 0);
Assert.assertTrue(cpuFacet.getVendor().compareTo(readCpuFacet.getVendor()) == 0);
Assert.assertTrue(uuid.compareTo(readCpuFacet.getHeader().getUUID()) == 0);
ContextTest.setContextByName(DEFAULT_TEST_SCOPE_ANOTHER_USER);
String newVendor = "Intel";
String newClockSpeed = "2 GHz";
readCpuFacet.setVendor(newVendor);
readCpuFacet.setClockSpeed(newClockSpeed);
String additionPropertyKey = "My";
String additionPropertyValue = "Test";
readCpuFacet.setAdditionalProperty(additionPropertyKey, additionPropertyValue);
facetManagement = new FacetManagement();
facetManagement.setUUID(uuid);
facetManagement.setJson(ElementMapper.marshal(readCpuFacet));
String updatedJson = facetManagement.update();
CPUFacet updatedCpuFacet = ElementMapper.unmarshal(CPUFacet.class, updatedJson);
logger.debug("Updated:\nRaw Json : {}\nUnmarshalled : {}", updatedJson, updatedCpuFacet);
Assert.assertTrue(updatedCpuFacet.getClockSpeed().compareTo(newClockSpeed) == 0);
Assert.assertTrue(readCpuFacet.getModel().compareTo(updatedCpuFacet.getModel()) == 0);
Assert.assertTrue(updatedCpuFacet.getVendor().compareTo(newVendor) == 0);
Assert.assertTrue(((String) updatedCpuFacet.getAdditionalProperty(additionPropertyKey))
.compareTo((String) readCpuFacet.getAdditionalProperty(additionPropertyKey)) == 0);
Assert.assertTrue(uuid.compareTo(updatedCpuFacet.getHeader().getUUID()) == 0);
String user = AuthorizationProvider.instance.get().getClient().getId();
Assert.assertTrue(updatedCpuFacet.getHeader().getModifiedBy().compareTo(user) == 0);
facetManagement = new FacetManagement();
facetManagement.setUUID(uuid);
String readUpdatedJson = facetManagement.read().toString();
CPUFacet readUpdatedCpuFacet = ElementMapper.unmarshal(CPUFacet.class, readUpdatedJson);
logger.debug("Read Updated:\nRaw Json : {}\nUnmarshalled : {}", readUpdatedJson, readUpdatedCpuFacet);
Assert.assertTrue(updatedCpuFacet.getClockSpeed().compareTo(readUpdatedCpuFacet.getClockSpeed()) == 0);
Assert.assertTrue(updatedCpuFacet.getModel().compareTo(readUpdatedCpuFacet.getModel()) == 0);
Assert.assertTrue(updatedCpuFacet.getVendor().compareTo(readUpdatedCpuFacet.getVendor()) == 0);
Assert.assertTrue(((String) updatedCpuFacet.getAdditionalProperty(additionPropertyKey))
.compareTo((String) readUpdatedCpuFacet.getAdditionalProperty(additionPropertyKey)) == 0);
Assert.assertTrue(uuid.compareTo(updatedCpuFacet.getHeader().getUUID()) == 0);
facetManagement = new FacetManagement();
facetManagement.setUUID(uuid);
boolean deleted = facetManagement.delete();
Assert.assertTrue(deleted);
}
public Map<String, Resource> createHostingNodeAndEService() throws Exception {
public static Map<String, Resource> createHostingNodeAndEService() throws Exception {
Map<String, Resource> map = new HashMap<>();
EService eService = ERManagementTest.instantiateValidEService();
@ -487,8 +187,8 @@ public class ERManagementTest extends ContextTest {
ResourceManagement resourceManagement = new ResourceManagement();
resourceManagement.setElementType(EService.NAME);
resourceManagement.setJson(ElementMapper.marshal(eService));
String json = resourceManagement.create();
logger.debug("Created : {}", json);
eService = ElementMapper.unmarshal(EService.class, json);
logger.debug("Unmarshalled {} {}", EService.NAME, eService);
@ -514,10 +214,169 @@ public class ERManagementTest extends ContextTest {
return map;
}
public static Configuration instantiateValidConfiguration() throws Exception {
Configuration configuration = new ConfigurationImpl();
IdentifierFacet identifierFacet = new IdentifierFacetImpl();
identifierFacet.setType(IdentificationType.STRING);
identifierFacet.setValue("MyID");
identifierFacet.setPersistent(false);
IsIdentifiedBy<Configuration, IdentifierFacet> isIdentifiedBy = new IsIdentifiedByImpl<Configuration, IdentifierFacet>(
configuration, identifierFacet);
configuration.addFacet(isIdentifiedBy);
return configuration;
}
@Test
public void testCreateFacetWithAdditionlEncryptedField() throws Exception {
/*
* A facet cannot be created per se. Going to create a Configuration which does
* not impose any particular constraint except the IdentifierFact
*/
Configuration configuration = instantiateValidConfiguration();
CPUFacet cpuFacet = new CPUFacetImpl();
cpuFacet.setClockSpeed("1 GHz");
cpuFacet.setModel("Opteron");
cpuFacet.setVendor("AMD");
Encrypted encrypted = new EncryptedImpl();
String plainValue = "plain-value";
String encryptedValue = EncryptedImpl.encrypt(plainValue);
encrypted.setEncryptedValue(encryptedValue);
cpuFacet.setAdditionalProperty("test", encrypted);
configuration.addFacet(cpuFacet);
ResourceManagement resourceManagement = new ResourceManagement();
resourceManagement.setElementType(Configuration.NAME);
String json = ElementMapper.marshal(configuration);
logger.debug("{}", json);
resourceManagement.setJson(json);
String configurationJsonString = resourceManagement.create();
Configuration createdConfiguration = ElementMapper.unmarshal(Configuration.class, configurationJsonString);
logger.debug("Created:\nRaw Json : {}\nUnmarshalled : {}", configurationJsonString, createdConfiguration);
CPUFacet readCpuFacet = configuration.getFacets(CPUFacet.class).get(0);
String gotEncryptedValue = ((Encrypted) readCpuFacet.getAdditionalProperty("test")).getEncryptedValue();
Assert.assertTrue(gotEncryptedValue.compareTo(encryptedValue) == 0);
String gotPlainValue = EncryptedImpl.decrypt(gotEncryptedValue);
Assert.assertTrue(gotPlainValue.compareTo(plainValue) == 0);
boolean deleted = resourceManagement.delete();
Assert.assertTrue(deleted);
}
@Test
public void testCreatePropertyTypeNotInSchema() throws Exception {
/*
* A facet cannot be created per se. Going to create a Configuration which does
* not impose any particular constraint except the IdentifierFact
*/
Configuration configuration = instantiateValidConfiguration();
AccessPointFacet accessPointFacet = new AccessPointFacetImpl();
accessPointFacet.setEndpoint(new URI("https://localhost"));
accessPointFacet.setEntryName("port1");
ValueSchema authorization = new ValueSchemaImpl();
authorization.setValue("pwd");
URI uri = new URI("https://www.gcube-system.org");
authorization.setSchema(uri);
accessPointFacet.setAuthorization(authorization);
String additionlaPropertyKey = "Test";
String additionlaPropertyValue = "MyTest";
accessPointFacet.setAdditionalProperty(additionlaPropertyKey, additionlaPropertyValue);
Encrypted encrypted = new EncryptedImpl();
String plainValue = "Encrypted";
String encryptedValue = EncryptedImpl.encrypt(plainValue);
encrypted.setEncryptedValue(encryptedValue);
String encryptedKey = "Enc";
accessPointFacet.setAdditionalProperty(encryptedKey, encrypted);
configuration.addFacet(accessPointFacet);
String marshalled = ElementMapper.marshal(configuration);
logger.debug(marshalled);
ResourceManagement resourceManagement = new ResourceManagement();
resourceManagement.setElementType(Configuration.NAME);
String json = ElementMapper.marshal(configuration);
logger.debug("{}", json);
resourceManagement.setJson(json);
String configurationJsonString = resourceManagement.create();
Configuration createdConfiguration = ElementMapper.unmarshal(Configuration.class, configurationJsonString);
logger.debug("Created:\nRaw Json : {}\nUnmarshalled : {}", configurationJsonString, createdConfiguration);
AccessPointFacet apf = configuration.getFacets(AccessPointFacet.class).get(0);
Assert.assertTrue(apf.getAuthorization() instanceof ValueSchema);
Assert.assertTrue(apf.getAdditionalProperty(encryptedKey) instanceof Encrypted);
Encrypted enc = (Encrypted) apf.getAdditionalProperty(encryptedKey);
String encValue = enc.getEncryptedValue();
Assert.assertTrue(encValue.compareTo(encryptedValue) == 0);
String decryptedValue = EncryptedImpl.decrypt(encValue);
Assert.assertTrue(decryptedValue.compareTo(plainValue) == 0);
Assert.assertTrue(((String) apf.getAdditionalProperty(additionlaPropertyKey)).compareTo(additionlaPropertyValue) == 0);
boolean deleted = resourceManagement.delete();
Assert.assertTrue(deleted);
}
@Test
public void testCreateEService() throws Exception {
EService eService = ERManagementTest.instantiateValidEService();
ResourceManagement resourceManagement = new ResourceManagement();
resourceManagement.setElementType(EService.NAME);
resourceManagement.setJson(ElementMapper.marshal(eService));
String json = resourceManagement.create();
logger.debug("Created : {}", json);
eService = ElementMapper.unmarshal(EService.class, json);
logger.debug("Unmarshalled {} {}", EService.NAME, eService);
resourceManagement = new ResourceManagement();
resourceManagement.setUUID(eService.getHeader().getUUID());
boolean deleted = resourceManagement.delete();
Assert.assertTrue(deleted);
}
/*
@Test
public void testReadResource() throws Exception {
ResourceManagement resourceManagement = new ResourceManagement();
resourceManagement.setUUID(UUID.fromString("26da57ee-33bd-4c4b-8aef-9206b61c329e"));
String read = resourceManagement.read().toString();
logger.debug(read);
}
*/
/*
@Test
public void testDeleteResource() throws Exception {
ResourceManagement resourceManagement = new ResourceManagement();
resourceManagement.setUUID(UUID.fromString("64635295-7ced-4931-a55f-40fc8199b280"));
boolean deleted = resourceManagement.delete();
Assert.assertTrue(deleted);
}
*/
@Test
public void testCreateHostingNodeAndEService() throws Exception {
Map<String, Resource> map = createHostingNodeAndEService();
Map<String, Resource> map = ERManagementTest.createHostingNodeAndEService();
ResourceManagement resourceManagement = new ResourceManagement();
resourceManagement.setUUID(map.get(EService.NAME).getHeader().getUUID());
@ -532,7 +391,7 @@ public class ERManagementTest extends ContextTest {
@Test
public void testCreateConsistsOfBeetweenResources() throws Exception {
Map<String, Resource> map = createHostingNodeAndEService();
Map<String, Resource> map = ERManagementTest.createHostingNodeAndEService();
UUID hostingNodeUUID = map.get(HostingNode.NAME).getHeader().getUUID();
UUID eServiceUUID = map.get(EService.NAME).getHeader().getUUID();
@ -543,8 +402,7 @@ public class ERManagementTest extends ContextTest {
SimpleFacet fakeEServiceAsSimpleFacet = new SimpleFacetImpl();
fakeEServiceAsSimpleFacet.setHeader(new HeaderImpl(eServiceUUID));
ConsistsOf<Resource, Facet> consistsOf = new ConsistsOfImpl<Resource, Facet>(hostingNode,
fakeEServiceAsSimpleFacet, null);
ConsistsOf<HostingNode, SimpleFacet> consistsOf = new ConsistsOfImpl<HostingNode, SimpleFacet>(hostingNode, fakeEServiceAsSimpleFacet);
try {
ConsistsOfManagement consistsOfManagement = new ConsistsOfManagement();
@ -572,47 +430,6 @@ public class ERManagementTest extends ContextTest {
}
@Test
public void testCreateHostingNodeAndEServiceWithSharedFacet() throws Exception {
Map<String, Resource> map = createHostingNodeAndEService();
EService eService = (EService) map.get(EService.NAME);
HostingNode hostingNode = (HostingNode) map.get(HostingNode.NAME);
Facet shared = hostingNode.getConsistsOf().get(0).getTarget();
ConsistsOfManagement consistsOfManagement = new ConsistsOfManagement();
consistsOfManagement.setElementType(ConsistsOf.NAME);
consistsOfManagement.setJson("{}");
ConsistsOf<EService, Facet> consistsOf = new ConsistsOfImpl<>(eService, shared, null);
consistsOfManagement.setJson(ElementMapper.marshal(consistsOf));
String json = consistsOfManagement.create();
logger.debug("Created : {}", json);
ResourceManagement resourceManagement = new ResourceManagement();
resourceManagement.setUUID(eService.getHeader().getUUID());
boolean deleted = resourceManagement.delete();
Assert.assertTrue(deleted);
resourceManagement = new ResourceManagement();
resourceManagement.setUUID(hostingNode.getHeader().getUUID());
deleted = resourceManagement.delete();
Assert.assertTrue(deleted);
FacetManagement facetManagement = new FacetManagement();
UUID sharedFacetUUID = shared.getHeader().getUUID();
facetManagement.setUUID(sharedFacetUUID);
try {
String read = facetManagement.read().toString();
logger.debug("Read facet is : {}", read);
throw new Exception(String.format("Shared Facet %s was not deleted", shared));
} catch (FacetNotFoundException e) {
logger.debug("Shared Facet was not foud as expected");
}
}
/*
* @Test public void testCreateResourceAndFacet() throws Exception {
* ResourceManagement resourceManagement = new ResourceManagement();
@ -666,7 +483,7 @@ public class ERManagementTest extends ContextTest {
int typeNumber = 0;
for (int i = 0; i < MAX; i++) {
Map<String, Resource> map = createHostingNodeAndEService();
Map<String, Resource> map = ERManagementTest.createHostingNodeAndEService();
if (typeNumber == 0) {
typeNumber = map.size();
}
@ -747,7 +564,7 @@ public class ERManagementTest extends ContextTest {
@Test
public void testGetAllFrom() throws Exception {
Map<String, Resource> map = createHostingNodeAndEService();
Map<String, Resource> map = ERManagementTest.createHostingNodeAndEService();
EService eService = (EService) map.get(EService.NAME);
UUID eServiceUUID = eService.getHeader().getUUID();

View File

@ -1,20 +1,50 @@
package org.gcube.informationsystem.resourceregistry.instances;
import java.util.Map;
import java.util.UUID;
import org.gcube.common.authorization.library.provider.AuthorizationProvider;
import org.gcube.informationsystem.model.impl.properties.EncryptedImpl;
import org.gcube.informationsystem.model.impl.relations.ConsistsOfImpl;
import org.gcube.informationsystem.model.reference.entities.Facet;
import org.gcube.informationsystem.model.reference.entities.Resource;
import org.gcube.informationsystem.model.reference.properties.Encrypted;
import org.gcube.informationsystem.model.reference.relations.ConsistsOf;
import org.gcube.informationsystem.resourceregistry.ContextTest;
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaViolationException;
import org.gcube.informationsystem.resourceregistry.instances.model.entities.FacetManagement;
import org.gcube.informationsystem.resourceregistry.instances.model.entities.ResourceManagement;
import org.gcube.informationsystem.resourceregistry.instances.model.relations.ConsistsOfManagement;
import org.gcube.informationsystem.resourceregistry.instances.model.relations.IsRelatedToManagement;
import org.gcube.informationsystem.utils.ElementMapper;
import org.gcube.resourcemanagement.model.impl.entities.facets.CPUFacetImpl;
import org.gcube.resourcemanagement.model.impl.entities.facets.SoftwareFacetImpl;
import org.gcube.resourcemanagement.model.impl.entities.resources.RunningPluginImpl;
import org.gcube.resourcemanagement.model.impl.relations.consistsof.IsIdentifiedByImpl;
import org.gcube.resourcemanagement.model.reference.entities.facets.CPUFacet;
import org.gcube.resourcemanagement.model.reference.entities.facets.SoftwareFacet;
import org.gcube.resourcemanagement.model.reference.entities.resources.Actor;
import org.gcube.resourcemanagement.model.reference.entities.resources.Configuration;
import org.gcube.resourcemanagement.model.reference.entities.resources.EService;
import org.gcube.resourcemanagement.model.reference.entities.resources.HostingNode;
import org.gcube.resourcemanagement.model.reference.entities.resources.RunningPlugin;
import org.gcube.resourcemanagement.model.reference.entities.resources.Service;
import org.gcube.resourcemanagement.model.reference.relations.consistsof.IsIdentifiedBy;
import org.gcube.resourcemanagement.model.reference.relations.isrelatedto.Activates;
import org.junit.Assert;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class InvalidInstancesTest extends ContextTest {
private static Logger logger = LoggerFactory.getLogger(InvalidInstancesTest.class);
public static final String ESERVICE = SmartgearResourcesTest.ESERVICE;
public static final String ACTIVATES = "{\"header\": {\"@class\": \"Header\",\"creator\": \"luca.frosini\",\"creationTime\": \"2021-02-23 16:45:58.358 +0100\",\"modifiedBy\": \"luca.frosini\",\"uuid\": \"83e9ece1-326c-4d24-a515-0fc6e68f31ef\",\"lastUpdateTime\": \"2021-02-23 16:45:58.358 +0100\"},\"propagationConstraint\": {\"@class\": \"PropagationConstraint\",\"add\": \"propagate\",\"remove\": \"cascade\"},\"@class\": \"Activates\",\"@superClasses\": [\"IsRelatedTo\"],\"source\": {\"header\": {\"@class\": \"Header\",\"creator\": \"luca.frosini\",\"creationTime\": \"2021-02-23 16:45:58.297 +0100\",\"modifiedBy\": \"luca.frosini\",\"uuid\": \"bf665e49-7c54-4984-bafe-a021757a7423\",\"lastUpdateTime\": \"2021-02-23 16:45:58.297 +0100\"},\"@class\": \"Configuration\"},\"target\": {\"header\": {\"@class\": \"Header\",\"creator\": \"luca.frosini\",\"creationTime\": \"2021-02-23 16:45:58.128 +0100\",\"modifiedBy\": \"luca.frosini\",\"uuid\": \"3ace4bd0-e5cd-49a3-97a8-a0a9468ce6d4\",\"lastUpdateTime\": \"2021-02-23 16:45:58.128 +0100\"},\"@class\": \"EService\"}}";
public static final String CONFIGURATION = "{\"header\":{\"@class\":\"Header\",\"creator\":\"luca.frosini\",\"creationTime\":\"2021-02-23 16:45:58.382 +0100\",\"modifiedBy\":\"luca.frosini\",\"uuid\":\"bf665e49-7c54-4984-bafe-a021757a7423\",\"lastUpdateTime\":\"2021-02-23 16:45:58.382 +0100\"},\"@class\":\"Configuration\",\"@superClasses\":[\"ConfigurationTemplate\",\"GCubeResource\",\"Resource\"],\"consistsOf\":[{\"header\":{\"@class\":\"Header\",\"creator\":\"luca.frosini\",\"creationTime\":\"2021-02-23 16:45:58.378 +0100\",\"modifiedBy\":\"luca.frosini\",\"uuid\":\"2233f303-497f-433d-9338-6ca16de34c1a\",\"lastUpdateTime\":\"2021-02-23 16:45:58.378 +0100\"},\"propagationConstraint\":{\"@class\":\"PropagationConstraint\",\"add\":\"propagate\",\"remove\":\"cascadeWhenOrphan\"},\"@class\":\"IsIdentifiedBy\",\"@superClasses\":[\"ConsistsOf\"],\"source\":{\"header\":{\"@class\":\"Header\",\"creator\":\"luca.frosini\",\"creationTime\":\"2021-02-23 16:45:58.382 +0100\",\"modifiedBy\":\"luca.frosini\",\"uuid\":\"bf665e49-7c54-4984-bafe-a021757a7423\",\"lastUpdateTime\":\"2021-02-23 16:45:58.382 +0100\"},\"@class\":\"Configuration\",\"@superClasses\":[\"ConfigurationTemplate\",\"GCubeResource\",\"Resource\"]},\"target\":{\"header\":{\"@class\":\"Header\",\"creator\":\"luca.frosini\",\"creationTime\":\"2021-02-23 16:45:58.375 +0100\",\"modifiedBy\":\"luca.frosini\",\"uuid\":\"5efc4c1f-f784-4682-a694-896bd7a3f321\",\"lastUpdateTime\":\"2021-02-23 16:45:58.375 +0100\"},\"type\":\"STRING\",\"persistent\":\"false\",\"value\":\"TEST\",\"@class\":\"IdentifierFacet\",\"@superClasses\":[\"ConsistsOf\"]}},{\"header\":{\"@class\":\"Header\",\"creator\":\"luca.frosini\",\"creationTime\":\"2021-02-23 16:45:58.381 +0100\",\"modifiedBy\":\"luca.frosini\",\"uuid\":\"15055c47-32a1-412c-b6d8-c0d4c831cb95\",\"lastUpdateTime\":\"2021-02-23 16:45:58.381 +0100\"},\"propagationConstraint\":{\"@class\":\"PropagationConstraint\",\"add\":\"propagate\",\"remove\":\"cascadeWhenOrphan\"},\"@class\":\"ConsistsOf\",\"@superClasses\":[\"ConsistsOf\"],\"source\":{\"header\":{\"@class\":\"Header\",\"creator\":\"luca.frosini\",\"creationTime\":\"2021-02-23 16:45:58.382 +0100\",\"modifiedBy\":\"luca.frosini\",\"uuid\":\"bf665e49-7c54-4984-bafe-a021757a7423\",\"lastUpdateTime\":\"2021-02-23 16:45:58.382 +0100\"},\"@class\":\"Configuration\",\"@superClasses\":[\"ConfigurationTemplate\",\"GCubeResource\",\"Resource\"]},\"target\":{\"name\":\"test\",\"header\":{\"@class\":\"Header\",\"creator\":\"luca.frosini\",\"creationTime\":\"2021-02-23 16:45:58.380 +0100\",\"modifiedBy\":\"luca.frosini\",\"uuid\":\"9b71f04c-6f5d-4133-87aa-f37445e206b6\",\"lastUpdateTime\":\"2021-02-23 16:45:58.380 +0100\"},\"value\":\"test\",\"@class\":\"SimplePropertyFacet\",\"@superClasses\":[\"ConsistsOf\"]}}]}";
public static final String ACTOR = "{\"@class\":\"Actor\",\"header\":null,\"consistsOf\":[{\"@class\":\"IsIdentifiedBy\",\"header\":null,\"propagationConstraint\":{\"@class\":\"PropagationConstraint\",\"remove\":\"cascadeWhenOrphan\",\"add\":\"propagate\"},\"source\":{\"@class\":\"Actor\",\"header\":null},\"target\":{\"@class\":\"ContactFacet\",\"header\":null,\"title\":\"Dr.\",\"name\":\"Frosini\",\"middleName\":null,\"surname\":null,\"eMail\":\"luca.frosini@isti.cnr.it\"}}],\"isRelatedTo\":[]}";
@Test(expected = SchemaViolationException.class)
public void createInvalidIsRealtedTo() throws Exception {
@ -51,4 +81,174 @@ public class InvalidInstancesTest extends ContextTest {
}
@Test(expected = SchemaViolationException.class)
public void testCreateStandAloneFacet() throws Exception {
CPUFacet cpuFacet = new CPUFacetImpl();
cpuFacet.setClockSpeed("1 GHz");
cpuFacet.setModel("Opteron");
cpuFacet.setVendor("AMD");
FacetManagement facetManagement = new FacetManagement();
facetManagement.setElementType(CPUFacet.NAME);
String json = ElementMapper.marshal(cpuFacet);
logger.debug("{}", json);
facetManagement.setJson(json);
/* A facet cannot be created per se */
facetManagement.create();
}
@Test(expected = SchemaViolationException.class)
public void testCreateInvalidRunningPlugin() throws Exception {
RunningPlugin runningPlugin = new RunningPluginImpl();
SoftwareFacet softwareFacet = new SoftwareFacetImpl();
softwareFacet.setGroup("information-system");
softwareFacet.setName("is-exporter-se-plugin");
softwareFacet.setVersion("1.0.0");
IsIdentifiedBy<RunningPlugin, SoftwareFacet> isIdentifiedBy = new IsIdentifiedByImpl<>(runningPlugin, softwareFacet);
runningPlugin.addFacet(isIdentifiedBy);
ResourceManagement resourceManagement = new ResourceManagement();
resourceManagement.setElementType(RunningPlugin.NAME);
resourceManagement.setJson(ElementMapper.marshal(runningPlugin));
resourceManagement.create();
}
@Test(expected = ResourceRegistryException.class)
public void testCreateAnEntityDifferentFromDeclared() throws Exception {
EService eService = ERManagementTest.instantiateValidEService();
ResourceManagement resourceManagement = new ResourceManagement();
resourceManagement.setElementType(Service.NAME);
resourceManagement.setJson(ElementMapper.marshal(eService));
resourceManagement.create();
}
@Test(expected = ResourceRegistryException.class)
public void testCreateAbstractEntity() throws Exception {
ResourceManagement resourceManagement = new ResourceManagement();
resourceManagement.setElementType(Actor.NAME);
resourceManagement.setJson(ACTOR);
resourceManagement.create();
}
@Test(expected = SchemaViolationException.class)
public void testCreateReadUpdateDeleteFacet() throws Exception {
CPUFacet cpuFacet = new CPUFacetImpl();
cpuFacet.setClockSpeed("1 GHz");
cpuFacet.setModel("Opteron");
cpuFacet.setVendor("AMD");
Encrypted encrypted = new EncryptedImpl();
encrypted.setEncryptedValue("Value");
cpuFacet.setAdditionalProperty("Enc", encrypted);
String json = ElementMapper.marshal(cpuFacet);
FacetManagement facetManagement = new FacetManagement();
facetManagement.setElementType(CPUFacet.NAME);
facetManagement.setJson(json);
String cpuFacetJson = facetManagement.create();
CPUFacet createdCpuFacet = ElementMapper.unmarshal(CPUFacet.class, cpuFacetJson);
logger.debug("Created:\nRaw Json : {}\nUnmarshalled : {}", cpuFacetJson, createdCpuFacet);
Assert.assertTrue(cpuFacet.getClockSpeed().compareTo(createdCpuFacet.getClockSpeed()) == 0);
Assert.assertTrue(cpuFacet.getModel().compareTo(createdCpuFacet.getModel()) == 0);
Assert.assertTrue(cpuFacet.getVendor().compareTo(createdCpuFacet.getVendor()) == 0);
UUID uuid = createdCpuFacet.getHeader().getUUID();
facetManagement = new FacetManagement();
facetManagement.setUUID(uuid);
String readJson = facetManagement.read().toString();
CPUFacet readCpuFacet = ElementMapper.unmarshal(CPUFacet.class, readJson);
logger.debug("Read:\nRaw Json : {}\nUnmarshalled : {}", readJson, readCpuFacet);
Assert.assertTrue(cpuFacet.getClockSpeed().compareTo(readCpuFacet.getClockSpeed()) == 0);
Assert.assertTrue(cpuFacet.getModel().compareTo(readCpuFacet.getModel()) == 0);
Assert.assertTrue(cpuFacet.getVendor().compareTo(readCpuFacet.getVendor()) == 0);
Assert.assertTrue(uuid.compareTo(readCpuFacet.getHeader().getUUID()) == 0);
ContextTest.setContextByName(DEFAULT_TEST_SCOPE_ANOTHER_USER);
String newVendor = "Intel";
String newClockSpeed = "2 GHz";
readCpuFacet.setVendor(newVendor);
readCpuFacet.setClockSpeed(newClockSpeed);
String additionPropertyKey = "My";
String additionPropertyValue = "Test";
readCpuFacet.setAdditionalProperty(additionPropertyKey, additionPropertyValue);
facetManagement = new FacetManagement();
facetManagement.setUUID(uuid);
facetManagement.setJson(ElementMapper.marshal(readCpuFacet));
String updatedJson = facetManagement.update();
CPUFacet updatedCpuFacet = ElementMapper.unmarshal(CPUFacet.class, updatedJson);
logger.debug("Updated:\nRaw Json : {}\nUnmarshalled : {}", updatedJson, updatedCpuFacet);
Assert.assertTrue(updatedCpuFacet.getClockSpeed().compareTo(newClockSpeed) == 0);
Assert.assertTrue(readCpuFacet.getModel().compareTo(updatedCpuFacet.getModel()) == 0);
Assert.assertTrue(updatedCpuFacet.getVendor().compareTo(newVendor) == 0);
Assert.assertTrue(((String) updatedCpuFacet.getAdditionalProperty(additionPropertyKey))
.compareTo((String) readCpuFacet.getAdditionalProperty(additionPropertyKey)) == 0);
Assert.assertTrue(uuid.compareTo(updatedCpuFacet.getHeader().getUUID()) == 0);
String user = AuthorizationProvider.instance.get().getClient().getId();
Assert.assertTrue(updatedCpuFacet.getHeader().getModifiedBy().compareTo(user) == 0);
facetManagement = new FacetManagement();
facetManagement.setUUID(uuid);
String readUpdatedJson = facetManagement.read().toString();
CPUFacet readUpdatedCpuFacet = ElementMapper.unmarshal(CPUFacet.class, readUpdatedJson);
logger.debug("Read Updated:\nRaw Json : {}\nUnmarshalled : {}", readUpdatedJson, readUpdatedCpuFacet);
Assert.assertTrue(updatedCpuFacet.getClockSpeed().compareTo(readUpdatedCpuFacet.getClockSpeed()) == 0);
Assert.assertTrue(updatedCpuFacet.getModel().compareTo(readUpdatedCpuFacet.getModel()) == 0);
Assert.assertTrue(updatedCpuFacet.getVendor().compareTo(readUpdatedCpuFacet.getVendor()) == 0);
Assert.assertTrue(((String) updatedCpuFacet.getAdditionalProperty(additionPropertyKey))
.compareTo((String) readUpdatedCpuFacet.getAdditionalProperty(additionPropertyKey)) == 0);
Assert.assertTrue(uuid.compareTo(updatedCpuFacet.getHeader().getUUID()) == 0);
facetManagement = new FacetManagement();
facetManagement.setUUID(uuid);
boolean deleted = facetManagement.delete();
Assert.assertTrue(deleted);
}
@Test(expected = SchemaViolationException.class)
public void testCreateHostingNodeAndEServiceWithSharedFacet() throws Exception {
Map<String, Resource> map = ERManagementTest.createHostingNodeAndEService();
EService eService = (EService) map.get(EService.NAME);
HostingNode hostingNode = (HostingNode) map.get(HostingNode.NAME);
try {
Facet shared = hostingNode.getConsistsOf().get(0).getTarget();
ConsistsOfManagement consistsOfManagement = new ConsistsOfManagement();
consistsOfManagement.setElementType(ConsistsOf.NAME);
consistsOfManagement.setJson("{}");
ConsistsOf<EService, Facet> consistsOf = new ConsistsOfImpl<>(eService, shared);
String consistsOfJsonString = ElementMapper.marshal(consistsOf);
consistsOfManagement.setJson(consistsOfJsonString);
String json = consistsOfManagement.create();
logger.debug("Created : {}", json);
} finally {
ResourceManagement resourceManagement = new ResourceManagement();
resourceManagement.setUUID(eService.getHeader().getUUID());
boolean deleted = resourceManagement.delete();
Assert.assertTrue(deleted);
resourceManagement = new ResourceManagement();
resourceManagement.setUUID(hostingNode.getHeader().getUUID());
deleted = resourceManagement.delete();
Assert.assertTrue(deleted);
}
}
}