Fixing tests
This commit is contained in:
parent
3a6f3cc59b
commit
23d0486f64
|
@ -159,7 +159,7 @@ public abstract class RelationElementManagement<SEM extends EntityElementManagem
|
||||||
errorMessage.append(sourceEntityManagement.getAccessType().getName());
|
errorMessage.append(sourceEntityManagement.getAccessType().getName());
|
||||||
errorMessage.append(" and ");
|
errorMessage.append(" and ");
|
||||||
errorMessage.append(targetEntityManagement.getAccessType().getName());
|
errorMessage.append(targetEntityManagement.getAccessType().getName());
|
||||||
throw new ResourceRegistryException(errorMessage.toString(), e);
|
throw new SchemaViolationException(errorMessage.toString(), e);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -17,8 +17,8 @@ import java.util.UUID;
|
||||||
|
|
||||||
import org.gcube.com.fasterxml.jackson.core.JsonParseException;
|
import org.gcube.com.fasterxml.jackson.core.JsonParseException;
|
||||||
import org.gcube.com.fasterxml.jackson.databind.JsonMappingException;
|
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.EncryptedImpl;
|
||||||
import org.gcube.informationsystem.model.impl.properties.HeaderImpl;
|
|
||||||
import org.gcube.informationsystem.model.impl.properties.PropagationConstraintImpl;
|
import org.gcube.informationsystem.model.impl.properties.PropagationConstraintImpl;
|
||||||
import org.gcube.informationsystem.model.impl.relations.ConsistsOfImpl;
|
import org.gcube.informationsystem.model.impl.relations.ConsistsOfImpl;
|
||||||
import org.gcube.informationsystem.model.reference.entities.Facet;
|
import org.gcube.informationsystem.model.reference.entities.Facet;
|
||||||
|
@ -31,8 +31,6 @@ import org.gcube.informationsystem.model.reference.relations.IsRelatedTo;
|
||||||
import org.gcube.informationsystem.resourceregistry.ContextTest;
|
import org.gcube.informationsystem.resourceregistry.ContextTest;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.query.InvalidQueryException;
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.query.InvalidQueryException;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaViolationException;
|
|
||||||
import org.gcube.informationsystem.resourceregistry.contexts.ContextUtility;
|
|
||||||
import org.gcube.informationsystem.resourceregistry.instances.base.ElementManagementUtility;
|
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.FacetManagement;
|
||||||
import org.gcube.informationsystem.resourceregistry.instances.model.entities.ResourceManagement;
|
import org.gcube.informationsystem.resourceregistry.instances.model.entities.ResourceManagement;
|
||||||
|
@ -46,7 +44,6 @@ import org.gcube.resourcemanagement.model.impl.entities.facets.IdentifierFacetIm
|
||||||
import org.gcube.resourcemanagement.model.impl.entities.facets.LicenseFacetImpl;
|
import org.gcube.resourcemanagement.model.impl.entities.facets.LicenseFacetImpl;
|
||||||
import org.gcube.resourcemanagement.model.impl.entities.facets.MemoryFacetImpl;
|
import org.gcube.resourcemanagement.model.impl.entities.facets.MemoryFacetImpl;
|
||||||
import org.gcube.resourcemanagement.model.impl.entities.facets.NetworkingFacetImpl;
|
import org.gcube.resourcemanagement.model.impl.entities.facets.NetworkingFacetImpl;
|
||||||
import org.gcube.resourcemanagement.model.impl.entities.facets.SimpleFacetImpl;
|
|
||||||
import org.gcube.resourcemanagement.model.impl.entities.facets.SoftwareFacetImpl;
|
import org.gcube.resourcemanagement.model.impl.entities.facets.SoftwareFacetImpl;
|
||||||
import org.gcube.resourcemanagement.model.impl.entities.facets.StateFacetImpl;
|
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.ConfigurationImpl;
|
||||||
|
@ -66,7 +63,6 @@ import org.gcube.resourcemanagement.model.reference.entities.facets.LicenseFacet
|
||||||
import org.gcube.resourcemanagement.model.reference.entities.facets.MemoryFacet;
|
import org.gcube.resourcemanagement.model.reference.entities.facets.MemoryFacet;
|
||||||
import org.gcube.resourcemanagement.model.reference.entities.facets.MemoryFacet.MemoryUnit;
|
import org.gcube.resourcemanagement.model.reference.entities.facets.MemoryFacet.MemoryUnit;
|
||||||
import org.gcube.resourcemanagement.model.reference.entities.facets.NetworkingFacet;
|
import org.gcube.resourcemanagement.model.reference.entities.facets.NetworkingFacet;
|
||||||
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.SoftwareFacet;
|
||||||
import org.gcube.resourcemanagement.model.reference.entities.facets.StateFacet;
|
import org.gcube.resourcemanagement.model.reference.entities.facets.StateFacet;
|
||||||
import org.gcube.resourcemanagement.model.reference.entities.resources.Configuration;
|
import org.gcube.resourcemanagement.model.reference.entities.resources.Configuration;
|
||||||
|
@ -92,7 +88,22 @@ import com.orientechnologies.orient.core.record.ODirection;
|
||||||
public class ERManagementTest extends ContextTest {
|
public class ERManagementTest extends ContextTest {
|
||||||
|
|
||||||
private static Logger logger = LoggerFactory.getLogger(ERManagementTest.class);
|
private static Logger logger = LoggerFactory.getLogger(ERManagementTest.class);
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
public static EService instantiateValidEService() throws Exception {
|
public static EService instantiateValidEService() throws Exception {
|
||||||
EService eService = new EServiceImpl();
|
EService eService = new EServiceImpl();
|
||||||
|
|
||||||
|
@ -217,146 +228,147 @@ public class ERManagementTest extends ContextTest {
|
||||||
|
|
||||||
return map;
|
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
|
@Test
|
||||||
public void testCreateEServiceAndDeleteRequiredFacet() throws Exception {
|
public void testCreateEService() throws Exception {
|
||||||
EService eService = instantiateValidEService();
|
EService eService = ERManagementTest.instantiateValidEService();
|
||||||
|
|
||||||
ResourceManagement resourceManagement = new ResourceManagement();
|
ResourceManagement resourceManagement = new ResourceManagement();
|
||||||
resourceManagement.setElementType(EService.NAME);
|
resourceManagement.setElementType(EService.NAME);
|
||||||
resourceManagement.setJson(ElementMapper.marshal(eService));
|
resourceManagement.setJson(ElementMapper.marshal(eService));
|
||||||
String createEServiceString = resourceManagement.create();
|
|
||||||
EService createEService = ElementMapper.unmarshal(EService.class, createEServiceString);
|
String json = resourceManagement.create();
|
||||||
|
logger.debug("Created : {}", json);
|
||||||
@SuppressWarnings("unchecked")
|
eService = ElementMapper.unmarshal(EService.class, json);
|
||||||
IsIdentifiedBy<EService, SoftwareFacet> isIdentifiedBy = (IsIdentifiedBy<EService, SoftwareFacet>) createEService.getConsistsOf(IsIdentifiedBy.class).get(0);
|
logger.debug("Unmarshalled {} {}", EService.NAME, eService);
|
||||||
ConsistsOfManagement consistsOfManagement = new ConsistsOfManagement();
|
|
||||||
consistsOfManagement.setElementType(IsIdentifiedBy.NAME);
|
resourceManagement = new ResourceManagement();
|
||||||
consistsOfManagement.setUUID(isIdentifiedBy.getHeader().getUUID());
|
resourceManagement.setUUID(eService.getHeader().getUUID());
|
||||||
|
|
||||||
try {
|
resourceManagement.delete();
|
||||||
consistsOfManagement.delete();
|
}
|
||||||
throw new Exception("You should not be able to delete a mandatory ConsistsOf");
|
|
||||||
}catch (SchemaViolationException e) {
|
/*
|
||||||
// As expected
|
@Test
|
||||||
}catch (Exception e) {
|
public void testReadResource() throws Exception {
|
||||||
resourceManagement.delete();
|
ResourceManagement resourceManagement = new ResourceManagement();
|
||||||
throw e;
|
resourceManagement.setUUID(UUID.fromString("26da57ee-33bd-4c4b-8aef-9206b61c329e"));
|
||||||
}
|
String read = resourceManagement.read().toString();
|
||||||
|
logger.debug(read);
|
||||||
SoftwareFacet softwareFacet = isIdentifiedBy.getTarget();
|
}
|
||||||
FacetManagement facetManagement = new FacetManagement();
|
*/
|
||||||
facetManagement.setElementType(SoftwareFacet.NAME);
|
|
||||||
facetManagement.setUUID(softwareFacet.getHeader().getUUID());
|
/*
|
||||||
|
@Test
|
||||||
try {
|
public void testDeleteResource() throws Exception {
|
||||||
facetManagement.delete();
|
ResourceManagement resourceManagement = new ResourceManagement();
|
||||||
throw new Exception("You should not be able to delete a mandatory Facet");
|
resourceManagement.setUUID(UUID.fromString("64635295-7ced-4931-a55f-40fc8199b280"));
|
||||||
}catch (SchemaViolationException e) {
|
boolean deleted = resourceManagement.delete();
|
||||||
// As expected
|
Assert.assertTrue(deleted);
|
||||||
}catch (Exception e) {
|
}
|
||||||
resourceManagement.delete();
|
*/
|
||||||
throw e;
|
|
||||||
}
|
@Test
|
||||||
|
public void testCreateHostingNodeAndEService() throws Exception {
|
||||||
|
Map<String, Resource> map = ERManagementTest.createHostingNodeAndEService();
|
||||||
|
|
||||||
|
ResourceManagement resourceManagement = new ResourceManagement();
|
||||||
|
resourceManagement.setUUID(map.get(EService.NAME).getHeader().getUUID());
|
||||||
|
resourceManagement.delete();
|
||||||
|
|
||||||
|
resourceManagement = new ResourceManagement();
|
||||||
|
resourceManagement.setUUID(map.get(HostingNode.NAME).getHeader().getUUID());
|
||||||
resourceManagement.delete();
|
resourceManagement.delete();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCreateEServiceAndRemoveFromContextRequiredFacet() throws Exception {
|
public void testCreateReadUpdateDeleteFacet() throws Exception {
|
||||||
EService eService = instantiateValidEService();
|
EService eService = instantiateValidEService();
|
||||||
|
|
||||||
ResourceManagement resourceManagement = new ResourceManagement();
|
ResourceManagement resourceManagement = new ResourceManagement();
|
||||||
resourceManagement.setElementType(EService.NAME);
|
resourceManagement.setElementType(EService.NAME);
|
||||||
resourceManagement.setJson(ElementMapper.marshal(eService));
|
resourceManagement.setJson(ElementMapper.marshal(eService));
|
||||||
String createEServiceString = resourceManagement.create();
|
String createdEServiceString = resourceManagement.create();
|
||||||
EService createEService = ElementMapper.unmarshal(EService.class, createEServiceString);
|
EService createdEService = ElementMapper.unmarshal(EService.class, createdEServiceString);
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
IsIdentifiedBy<EService, SoftwareFacet> isIdentifiedBy = (IsIdentifiedBy<EService, SoftwareFacet>) createEService.getConsistsOf(IsIdentifiedBy.class).get(0);
|
|
||||||
ConsistsOfManagement consistsOfManagement = new ConsistsOfManagement();
|
|
||||||
consistsOfManagement.setElementType(IsIdentifiedBy.NAME);
|
|
||||||
consistsOfManagement.setUUID(isIdentifiedBy.getHeader().getUUID());
|
|
||||||
|
|
||||||
try {
|
|
||||||
consistsOfManagement.removeFromContext(ContextUtility.getCurrentSecurityContext().getUUID());
|
|
||||||
throw new Exception("You should not be able to delete a mandatory ConsistsOf");
|
|
||||||
}catch (SchemaViolationException e) {
|
|
||||||
// As expected
|
|
||||||
}catch (Exception e) {
|
|
||||||
resourceManagement.delete();
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
|
|
||||||
SoftwareFacet softwareFacet = isIdentifiedBy.getTarget();
|
|
||||||
FacetManagement facetManagement = new FacetManagement();
|
|
||||||
facetManagement.setElementType(SoftwareFacet.NAME);
|
|
||||||
facetManagement.setUUID(softwareFacet.getHeader().getUUID());
|
|
||||||
|
|
||||||
try {
|
|
||||||
facetManagement.removeFromContext(ContextUtility.getCurrentSecurityContext().getUUID());
|
|
||||||
throw new Exception("You should not be able to delete a mandatory Facet");
|
|
||||||
}catch (SchemaViolationException e) {
|
|
||||||
// As expected
|
|
||||||
}catch (Exception e) {
|
|
||||||
resourceManagement.delete();
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
|
|
||||||
resourceManagement.delete();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@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 cpuFacet = new CPUFacetImpl();
|
||||||
cpuFacet.setClockSpeed("1 GHz");
|
cpuFacet.setClockSpeed("1 GHz");
|
||||||
cpuFacet.setModel("Opteron");
|
cpuFacet.setModel("Opteron");
|
||||||
cpuFacet.setVendor("AMD");
|
cpuFacet.setVendor("AMD");
|
||||||
Encrypted encrypted = new EncryptedImpl();
|
|
||||||
String plainValue = "plain-value";
|
ConsistsOf<EService, CPUFacet> consistsOf = new ConsistsOfImpl<EService, CPUFacet>(createdEService, cpuFacet);
|
||||||
String encryptedValue = EncryptedImpl.encrypt(plainValue);
|
|
||||||
encrypted.setEncryptedValue(encryptedValue);
|
ConsistsOfManagement consistsOfManagement = new ConsistsOfManagement();
|
||||||
cpuFacet.setAdditionalProperty("test", encrypted);
|
consistsOfManagement.setElementType(ConsistsOf.NAME);
|
||||||
configuration.addFacet(cpuFacet);
|
consistsOfManagement.setJson(ElementMapper.marshal(consistsOf));
|
||||||
|
String createdConsistsOfString = consistsOfManagement.create();
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
ConsistsOf<EService, CPUFacet> createdConsistsOf = ElementMapper.unmarshal(ConsistsOf.class, createdConsistsOfString);
|
||||||
|
|
||||||
|
CPUFacet createdCpuFacet = createdConsistsOf.getTarget();
|
||||||
|
|
||||||
|
Assert.assertTrue(cpuFacet.getClockSpeed().compareTo(createdCpuFacet.getClockSpeed()) == 0);
|
||||||
|
Assert.assertTrue(cpuFacet.getModel().compareTo(createdCpuFacet.getModel()) == 0);
|
||||||
|
Assert.assertTrue(cpuFacet.getVendor().compareTo(createdCpuFacet.getVendor()) == 0);
|
||||||
|
|
||||||
ResourceManagement resourceManagement = new ResourceManagement();
|
UUID uuid = createdCpuFacet.getHeader().getUUID();
|
||||||
resourceManagement.setElementType(Configuration.NAME);
|
|
||||||
String json = ElementMapper.marshal(configuration);
|
|
||||||
logger.debug("{}", json);
|
|
||||||
resourceManagement.setJson(json);
|
|
||||||
|
|
||||||
String configurationJsonString = resourceManagement.create();
|
FacetManagement facetManagement = new FacetManagement();
|
||||||
|
facetManagement.setUUID(uuid);
|
||||||
|
|
||||||
Configuration createdConfiguration = ElementMapper.unmarshal(Configuration.class, configurationJsonString);
|
String readJson = facetManagement.read().toString();
|
||||||
logger.debug("Created:\nRaw Json : {}\nUnmarshalled : {}", configurationJsonString, createdConfiguration);
|
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);
|
||||||
|
|
||||||
CPUFacet readCpuFacet = configuration.getFacets(CPUFacet.class).get(0);
|
String newVendor = "Intel";
|
||||||
String gotEncryptedValue = ((Encrypted) readCpuFacet.getAdditionalProperty("test")).getEncryptedValue();
|
String newClockSpeed = "2 GHz";
|
||||||
Assert.assertTrue(gotEncryptedValue.compareTo(encryptedValue) == 0);
|
readCpuFacet.setVendor(newVendor);
|
||||||
String gotPlainValue = EncryptedImpl.decrypt(gotEncryptedValue);
|
readCpuFacet.setClockSpeed(newClockSpeed);
|
||||||
Assert.assertTrue(gotPlainValue.compareTo(plainValue) == 0);
|
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
facetManagement.delete();
|
||||||
|
|
||||||
resourceManagement.delete();
|
resourceManagement.delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -419,144 +431,7 @@ public class ERManagementTest extends ContextTest {
|
||||||
resourceManagement.delete();
|
resourceManagement.delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@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());
|
|
||||||
|
|
||||||
resourceManagement.delete();
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
@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 = ERManagementTest.createHostingNodeAndEService();
|
|
||||||
|
|
||||||
ResourceManagement resourceManagement = new ResourceManagement();
|
|
||||||
resourceManagement.setUUID(map.get(EService.NAME).getHeader().getUUID());
|
|
||||||
resourceManagement.delete();
|
|
||||||
|
|
||||||
resourceManagement = new ResourceManagement();
|
|
||||||
resourceManagement.setUUID(map.get(HostingNode.NAME).getHeader().getUUID());
|
|
||||||
resourceManagement.delete();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testCreateConsistsOfBeetweenResources() throws Exception {
|
|
||||||
Map<String, Resource> map = ERManagementTest.createHostingNodeAndEService();
|
|
||||||
|
|
||||||
UUID hostingNodeUUID = map.get(HostingNode.NAME).getHeader().getUUID();
|
|
||||||
UUID eServiceUUID = map.get(EService.NAME).getHeader().getUUID();
|
|
||||||
|
|
||||||
HostingNode hostingNode = new HostingNodeImpl();
|
|
||||||
hostingNode.setHeader(new HeaderImpl(hostingNodeUUID));
|
|
||||||
|
|
||||||
SimpleFacet fakeEServiceAsSimpleFacet = new SimpleFacetImpl();
|
|
||||||
fakeEServiceAsSimpleFacet.setHeader(new HeaderImpl(eServiceUUID));
|
|
||||||
|
|
||||||
ConsistsOf<HostingNode, SimpleFacet> consistsOf = new ConsistsOfImpl<HostingNode, SimpleFacet>(hostingNode, fakeEServiceAsSimpleFacet);
|
|
||||||
|
|
||||||
try {
|
|
||||||
ConsistsOfManagement consistsOfManagement = new ConsistsOfManagement();
|
|
||||||
String json = ElementMapper.marshal(consistsOf);
|
|
||||||
json = json.replaceAll(SimpleFacet.NAME, EService.NAME);
|
|
||||||
|
|
||||||
consistsOfManagement.setJson(json);
|
|
||||||
|
|
||||||
consistsOfManagement.create();
|
|
||||||
logger.debug("The creation terminated correctly. This should not happen");
|
|
||||||
|
|
||||||
} catch (ResourceRegistryException e) {
|
|
||||||
logger.error("Sounds good. A {} cannot be created between two resources", ConsistsOf.NAME, e);
|
|
||||||
} finally {
|
|
||||||
ResourceManagement resourceManagement = new ResourceManagement();
|
|
||||||
resourceManagement.setUUID(eServiceUUID);
|
|
||||||
resourceManagement.delete();
|
|
||||||
|
|
||||||
resourceManagement = new ResourceManagement();
|
|
||||||
resourceManagement.setUUID(hostingNodeUUID);
|
|
||||||
resourceManagement.delete();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* @Test public void testCreateResourceAndFacet() throws Exception {
|
|
||||||
* ResourceManagement resourceManagement = new ResourceManagement();
|
|
||||||
* resourceManagement.setElementType(HostingNode.NAME);
|
|
||||||
* resourceManagement.setJson("{}");
|
|
||||||
*
|
|
||||||
* String json = resourceManagement.create(); HostingNode hostingNode =
|
|
||||||
* ElementMapper.unmarshal(HostingNode.class, json); UUID resourceUUID =
|
|
||||||
* hostingNode.getHeader().getUUID();
|
|
||||||
*
|
|
||||||
* CPUFacet cpuFacet = new CPUFacetImpl(); cpuFacet.setClockSpeed("1 GHz");
|
|
||||||
* cpuFacet.setModel("Opteron"); cpuFacet.setVendor("AMD");
|
|
||||||
*
|
|
||||||
* FacetManagement facetManagement = new FacetManagement();
|
|
||||||
* facetManagement.setJson(ElementMapper.marshal(cpuFacet));
|
|
||||||
* facetManagement.setElementType(CPUFacet.NAME); json =
|
|
||||||
* facetManagement.create(); CPUFacet createdCPUFacet =
|
|
||||||
* ElementMapper.unmarshal(CPUFacet.class, json);
|
|
||||||
*
|
|
||||||
* ConsistsOfManagement consistsOfManagement = new ConsistsOfManagement();
|
|
||||||
* consistsOfManagement.setElementType(ConsistsOf.NAME); ConsistsOf<HostingNode,
|
|
||||||
* CPUFacet> consistsOf = new ConsistsOfImpl<>(hostingNode, createdCPUFacet,
|
|
||||||
* null); consistsOfManagement.setJson(ElementMapper.marshal(consistsOf)); json
|
|
||||||
* = consistsOfManagement.create();
|
|
||||||
*
|
|
||||||
* logger.debug("Facet attached : {}", json);
|
|
||||||
*
|
|
||||||
* UUID consistOfUUID = Utility.getUUIDFromJSONString(json);
|
|
||||||
*
|
|
||||||
* consistsOfManagement = new ConsistsOfManagement();
|
|
||||||
* consistsOfManagement.setUUID(consistOfUUID);
|
|
||||||
*
|
|
||||||
* boolean detached = consistsOfManagement.delete();
|
|
||||||
*
|
|
||||||
* if (detached) { logger.trace("{} {} with uuid {} removed successfully",
|
|
||||||
* ConsistsOf.NAME, Relation.NAME, consistOfUUID); } else { String error =
|
|
||||||
* String.format("Unable to remove %s %s with uuid %s", ConsistsOf.NAME,
|
|
||||||
* Relation.NAME, consistOfUUID); logger.error(error); throw new
|
|
||||||
* Exception(error); }
|
|
||||||
*
|
|
||||||
* resourceManagement = new ResourceManagement();
|
|
||||||
* resourceManagement.setUUID(resourceUUID); boolean deleted =
|
|
||||||
* resourceManagement.delete(); Assert.assertTrue(deleted); }
|
|
||||||
*/
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetAll() throws Exception {
|
public void testGetAll() throws Exception {
|
||||||
Map<String, List<Resource>> resources = new HashMap<>();
|
Map<String, List<Resource>> resources = new HashMap<>();
|
||||||
|
@ -800,26 +675,6 @@ public class ERManagementTest extends ContextTest {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Test
|
|
||||||
public void readSingleResource()
|
|
||||||
throws ResourceRegistryException, JsonParseException, JsonMappingException, IOException {
|
|
||||||
UUID uuid = UUID.fromString("");
|
|
||||||
|
|
||||||
ResourceManagement resourceManagement = new ResourceManagement();
|
|
||||||
resourceManagement.setUUID(uuid);
|
|
||||||
String res = resourceManagement.read().toString();
|
|
||||||
logger.debug(res);
|
|
||||||
|
|
||||||
Configuration configuration = ElementMapper.unmarshal(Configuration.class, res);
|
|
||||||
|
|
||||||
resourceManagement = new ResourceManagement();
|
|
||||||
resourceManagement.setUUID(configuration.getHeader().getUUID());
|
|
||||||
resourceManagement.setJson(ElementMapper.marshal(configuration));
|
|
||||||
|
|
||||||
resourceManagement.update();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCreateUpdateDeleteEService() throws Exception {
|
public void testCreateUpdateDeleteEService() throws Exception {
|
||||||
EService eService = ERManagementTest.instantiateValidEService();
|
EService eService = ERManagementTest.instantiateValidEService();
|
||||||
|
|
|
@ -6,15 +6,24 @@ import org.gcube.informationsystem.model.impl.properties.EncryptedImpl;
|
||||||
import org.gcube.informationsystem.model.reference.properties.Encrypted;
|
import org.gcube.informationsystem.model.reference.properties.Encrypted;
|
||||||
import org.gcube.informationsystem.resourceregistry.ContextTest;
|
import org.gcube.informationsystem.resourceregistry.ContextTest;
|
||||||
import org.gcube.informationsystem.resourceregistry.dbinitialization.DatabaseEnvironment;
|
import org.gcube.informationsystem.resourceregistry.dbinitialization.DatabaseEnvironment;
|
||||||
|
import org.gcube.informationsystem.resourceregistry.instances.model.entities.ResourceManagement;
|
||||||
|
import org.gcube.informationsystem.utils.ElementMapper;
|
||||||
|
import org.gcube.resourcemanagement.model.impl.entities.facets.CPUFacetImpl;
|
||||||
|
import org.gcube.resourcemanagement.model.reference.entities.facets.CPUFacet;
|
||||||
|
import org.gcube.resourcemanagement.model.reference.entities.resources.Configuration;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Luca Frosini (ISTI - CNR)
|
* @author Luca Frosini (ISTI - CNR)
|
||||||
*/
|
*/
|
||||||
public class EncryptionTest extends ContextTest {
|
public class EncryptionTest extends ContextTest {
|
||||||
|
|
||||||
public static final String PLAIN_VALUE = "my-test";
|
private static Logger logger = LoggerFactory.getLogger(EncryptionTest.class);
|
||||||
|
|
||||||
|
public static final String PLAIN_VALUE = "plain-value";
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test() throws Exception {
|
public void test() throws Exception {
|
||||||
|
@ -46,4 +55,43 @@ public class EncryptionTest extends ContextTest {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@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 = ERManagementTest.instantiateValidConfiguration();
|
||||||
|
|
||||||
|
CPUFacet cpuFacet = new CPUFacetImpl();
|
||||||
|
cpuFacet.setClockSpeed("1 GHz");
|
||||||
|
cpuFacet.setModel("Opteron");
|
||||||
|
cpuFacet.setVendor("AMD");
|
||||||
|
Encrypted encrypted = new EncryptedImpl();
|
||||||
|
String encryptedValue = EncryptedImpl.encrypt(PLAIN_VALUE);
|
||||||
|
encrypted.setEncryptedValue(encryptedValue);
|
||||||
|
String additionalKey = "test";
|
||||||
|
cpuFacet.setAdditionalProperty(additionalKey, 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(additionalKey)).getEncryptedValue();
|
||||||
|
Assert.assertTrue(gotEncryptedValue.compareTo(encryptedValue) == 0);
|
||||||
|
String gotPlainValue = EncryptedImpl.decrypt(gotEncryptedValue);
|
||||||
|
Assert.assertTrue(gotPlainValue.compareTo(PLAIN_VALUE) == 0);
|
||||||
|
|
||||||
|
resourceManagement.delete();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,26 +3,28 @@ package org.gcube.informationsystem.resourceregistry.instances;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.gcube.common.authorization.library.provider.AuthorizationProvider;
|
import org.gcube.informationsystem.model.impl.properties.HeaderImpl;
|
||||||
import org.gcube.informationsystem.model.impl.properties.EncryptedImpl;
|
|
||||||
import org.gcube.informationsystem.model.impl.relations.ConsistsOfImpl;
|
import org.gcube.informationsystem.model.impl.relations.ConsistsOfImpl;
|
||||||
import org.gcube.informationsystem.model.reference.entities.Facet;
|
import org.gcube.informationsystem.model.reference.entities.Facet;
|
||||||
import org.gcube.informationsystem.model.reference.entities.Resource;
|
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.model.reference.relations.ConsistsOf;
|
||||||
import org.gcube.informationsystem.resourceregistry.ContextTest;
|
import org.gcube.informationsystem.resourceregistry.ContextTest;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaViolationException;
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaViolationException;
|
||||||
|
import org.gcube.informationsystem.resourceregistry.contexts.ContextUtility;
|
||||||
import org.gcube.informationsystem.resourceregistry.instances.model.entities.FacetManagement;
|
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.entities.ResourceManagement;
|
||||||
import org.gcube.informationsystem.resourceregistry.instances.model.relations.ConsistsOfManagement;
|
import org.gcube.informationsystem.resourceregistry.instances.model.relations.ConsistsOfManagement;
|
||||||
import org.gcube.informationsystem.resourceregistry.instances.model.relations.IsRelatedToManagement;
|
import org.gcube.informationsystem.resourceregistry.instances.model.relations.IsRelatedToManagement;
|
||||||
import org.gcube.informationsystem.utils.ElementMapper;
|
import org.gcube.informationsystem.utils.ElementMapper;
|
||||||
import org.gcube.resourcemanagement.model.impl.entities.facets.CPUFacetImpl;
|
import org.gcube.resourcemanagement.model.impl.entities.facets.CPUFacetImpl;
|
||||||
|
import org.gcube.resourcemanagement.model.impl.entities.facets.SimpleFacetImpl;
|
||||||
import org.gcube.resourcemanagement.model.impl.entities.facets.SoftwareFacetImpl;
|
import org.gcube.resourcemanagement.model.impl.entities.facets.SoftwareFacetImpl;
|
||||||
|
import org.gcube.resourcemanagement.model.impl.entities.resources.HostingNodeImpl;
|
||||||
import org.gcube.resourcemanagement.model.impl.entities.resources.RunningPluginImpl;
|
import org.gcube.resourcemanagement.model.impl.entities.resources.RunningPluginImpl;
|
||||||
import org.gcube.resourcemanagement.model.impl.relations.consistsof.IsIdentifiedByImpl;
|
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.CPUFacet;
|
||||||
|
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.SoftwareFacet;
|
||||||
import org.gcube.resourcemanagement.model.reference.entities.resources.Actor;
|
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.Configuration;
|
||||||
|
@ -32,7 +34,6 @@ import org.gcube.resourcemanagement.model.reference.entities.resources.RunningPl
|
||||||
import org.gcube.resourcemanagement.model.reference.entities.resources.Service;
|
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.consistsof.IsIdentifiedBy;
|
||||||
import org.gcube.resourcemanagement.model.reference.relations.isrelatedto.Activates;
|
import org.gcube.resourcemanagement.model.reference.relations.isrelatedto.Activates;
|
||||||
import org.junit.Assert;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
@ -127,7 +128,7 @@ public class InvalidInstancesTest extends ContextTest {
|
||||||
resourceManagement.create();
|
resourceManagement.create();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = ResourceRegistryException.class)
|
@Test(expected = SchemaViolationException.class)
|
||||||
public void testCreateAbstractEntity() throws Exception {
|
public void testCreateAbstractEntity() throws Exception {
|
||||||
ResourceManagement resourceManagement = new ResourceManagement();
|
ResourceManagement resourceManagement = new ResourceManagement();
|
||||||
resourceManagement.setElementType(Actor.NAME);
|
resourceManagement.setElementType(Actor.NAME);
|
||||||
|
@ -135,90 +136,6 @@ public class InvalidInstancesTest extends ContextTest {
|
||||||
resourceManagement.create();
|
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);
|
|
||||||
|
|
||||||
facetManagement.delete();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test(expected = SchemaViolationException.class)
|
@Test(expected = SchemaViolationException.class)
|
||||||
public void testCreateHostingNodeAndEServiceWithSharedFacet() throws Exception {
|
public void testCreateHostingNodeAndEServiceWithSharedFacet() throws Exception {
|
||||||
Map<String, Resource> map = ERManagementTest.createHostingNodeAndEService();
|
Map<String, Resource> map = ERManagementTest.createHostingNodeAndEService();
|
||||||
|
@ -248,4 +165,155 @@ public class InvalidInstancesTest extends ContextTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test(expected = SchemaViolationException.class)
|
||||||
|
public void testCreateEServiceAndDeleteRequiredConsistsOf() throws Exception {
|
||||||
|
EService eService = ERManagementTest.instantiateValidEService();
|
||||||
|
ResourceManagement resourceManagement = new ResourceManagement();
|
||||||
|
resourceManagement.setElementType(EService.NAME);
|
||||||
|
resourceManagement.setJson(ElementMapper.marshal(eService));
|
||||||
|
String createEServiceString = resourceManagement.create();
|
||||||
|
EService createEService = ElementMapper.unmarshal(EService.class, createEServiceString);
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
IsIdentifiedBy<EService, SoftwareFacet> isIdentifiedBy = (IsIdentifiedBy<EService, SoftwareFacet>) createEService.getConsistsOf(IsIdentifiedBy.class).get(0);
|
||||||
|
ConsistsOfManagement consistsOfManagement = new ConsistsOfManagement();
|
||||||
|
consistsOfManagement.setElementType(IsIdentifiedBy.NAME);
|
||||||
|
consistsOfManagement.setUUID(isIdentifiedBy.getHeader().getUUID());
|
||||||
|
|
||||||
|
try {
|
||||||
|
consistsOfManagement.delete();
|
||||||
|
throw new Exception("You should not be able to delete a mandatory ConsistsOf");
|
||||||
|
}catch (SchemaViolationException e) {
|
||||||
|
// As expected
|
||||||
|
throw e;
|
||||||
|
}catch (Exception e) {
|
||||||
|
throw e;
|
||||||
|
}finally {
|
||||||
|
resourceManagement.delete();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = SchemaViolationException.class)
|
||||||
|
public void testCreateEServiceAndDeleteRequiredFacet() throws Exception {
|
||||||
|
EService eService = ERManagementTest.instantiateValidEService();
|
||||||
|
ResourceManagement resourceManagement = new ResourceManagement();
|
||||||
|
resourceManagement.setElementType(EService.NAME);
|
||||||
|
resourceManagement.setJson(ElementMapper.marshal(eService));
|
||||||
|
String createEServiceString = resourceManagement.create();
|
||||||
|
EService createEService = ElementMapper.unmarshal(EService.class, createEServiceString);
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
IsIdentifiedBy<EService, SoftwareFacet> isIdentifiedBy = (IsIdentifiedBy<EService, SoftwareFacet>) createEService.getConsistsOf(IsIdentifiedBy.class).get(0);
|
||||||
|
ConsistsOfManagement consistsOfManagement = new ConsistsOfManagement();
|
||||||
|
consistsOfManagement.setElementType(IsIdentifiedBy.NAME);
|
||||||
|
consistsOfManagement.setUUID(isIdentifiedBy.getHeader().getUUID());
|
||||||
|
|
||||||
|
SoftwareFacet softwareFacet = isIdentifiedBy.getTarget();
|
||||||
|
FacetManagement facetManagement = new FacetManagement();
|
||||||
|
facetManagement.setElementType(SoftwareFacet.NAME);
|
||||||
|
facetManagement.setUUID(softwareFacet.getHeader().getUUID());
|
||||||
|
|
||||||
|
try {
|
||||||
|
facetManagement.delete();
|
||||||
|
throw new Exception("You should not be able to delete a mandatory Facet");
|
||||||
|
}catch (SchemaViolationException e) {
|
||||||
|
// As expected
|
||||||
|
throw e;
|
||||||
|
}catch (Exception e) {
|
||||||
|
throw e;
|
||||||
|
}finally {
|
||||||
|
resourceManagement.delete();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCreateEServiceAndRemoveFromContextRequiredFacet() throws Exception {
|
||||||
|
EService eService = ERManagementTest.instantiateValidEService();
|
||||||
|
ResourceManagement resourceManagement = new ResourceManagement();
|
||||||
|
resourceManagement.setElementType(EService.NAME);
|
||||||
|
resourceManagement.setJson(ElementMapper.marshal(eService));
|
||||||
|
String createEServiceString = resourceManagement.create();
|
||||||
|
EService createEService = ElementMapper.unmarshal(EService.class, createEServiceString);
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
IsIdentifiedBy<EService, SoftwareFacet> isIdentifiedBy = (IsIdentifiedBy<EService, SoftwareFacet>) createEService.getConsistsOf(IsIdentifiedBy.class).get(0);
|
||||||
|
ConsistsOfManagement consistsOfManagement = new ConsistsOfManagement();
|
||||||
|
consistsOfManagement.setElementType(IsIdentifiedBy.NAME);
|
||||||
|
consistsOfManagement.setUUID(isIdentifiedBy.getHeader().getUUID());
|
||||||
|
|
||||||
|
try {
|
||||||
|
consistsOfManagement.removeFromContext(ContextUtility.getCurrentSecurityContext().getUUID());
|
||||||
|
throw new Exception("You should not be able to delete a mandatory ConsistsOf");
|
||||||
|
}catch (SchemaViolationException e) {
|
||||||
|
// As expected
|
||||||
|
}catch (Exception e) {
|
||||||
|
resourceManagement.delete();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
|
||||||
|
SoftwareFacet softwareFacet = isIdentifiedBy.getTarget();
|
||||||
|
FacetManagement facetManagement = new FacetManagement();
|
||||||
|
facetManagement.setElementType(SoftwareFacet.NAME);
|
||||||
|
facetManagement.setUUID(softwareFacet.getHeader().getUUID());
|
||||||
|
|
||||||
|
try {
|
||||||
|
facetManagement.removeFromContext(ContextUtility.getCurrentSecurityContext().getUUID());
|
||||||
|
throw new Exception("You should not be able to delete a mandatory Facet");
|
||||||
|
}catch (SchemaViolationException e) {
|
||||||
|
// As expected
|
||||||
|
}catch (Exception e) {
|
||||||
|
resourceManagement.delete();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
|
||||||
|
resourceManagement.delete();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test(expected = SchemaViolationException.class)
|
||||||
|
public void testCreateConsistsOfBeetweenResources() throws Exception {
|
||||||
|
Map<String, Resource> map = ERManagementTest.createHostingNodeAndEService();
|
||||||
|
|
||||||
|
UUID hostingNodeUUID = map.get(HostingNode.NAME).getHeader().getUUID();
|
||||||
|
UUID eServiceUUID = map.get(EService.NAME).getHeader().getUUID();
|
||||||
|
|
||||||
|
HostingNode hostingNode = new HostingNodeImpl();
|
||||||
|
hostingNode.setHeader(new HeaderImpl(hostingNodeUUID));
|
||||||
|
|
||||||
|
SimpleFacet fakeEServiceAsSimpleFacet = new SimpleFacetImpl();
|
||||||
|
fakeEServiceAsSimpleFacet.setHeader(new HeaderImpl(eServiceUUID));
|
||||||
|
|
||||||
|
ConsistsOf<HostingNode, SimpleFacet> consistsOf = new ConsistsOfImpl<HostingNode, SimpleFacet>(hostingNode, fakeEServiceAsSimpleFacet);
|
||||||
|
|
||||||
|
try {
|
||||||
|
ConsistsOfManagement consistsOfManagement = new ConsistsOfManagement();
|
||||||
|
consistsOfManagement.setElementType(ConsistsOf.NAME);
|
||||||
|
|
||||||
|
String json = ElementMapper.marshal(consistsOf);
|
||||||
|
json = json.replaceAll(SimpleFacet.NAME, EService.NAME);
|
||||||
|
consistsOfManagement.setJson(json);
|
||||||
|
|
||||||
|
consistsOfManagement.create();
|
||||||
|
throw new Exception("A ConsistsOf has been created between two resoures. This should not happen");
|
||||||
|
|
||||||
|
} catch (ResourceRegistryException e) {
|
||||||
|
logger.error("Sounds good. A {} cannot be created between two resources", ConsistsOf.NAME, e);
|
||||||
|
throw e;
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw e;
|
||||||
|
} finally {
|
||||||
|
ResourceManagement resourceManagement = new ResourceManagement();
|
||||||
|
resourceManagement.setUUID(eServiceUUID);
|
||||||
|
resourceManagement.delete();
|
||||||
|
|
||||||
|
resourceManagement = new ResourceManagement();
|
||||||
|
resourceManagement.setUUID(hostingNodeUUID);
|
||||||
|
resourceManagement.delete();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue