2016-11-10 15:13:51 +01:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
2016-12-27 11:27:01 +01:00
|
|
|
package org.gcube.informationsystem.resourceregistry.context;
|
2016-11-10 15:13:51 +01:00
|
|
|
|
|
|
|
import java.net.URI;
|
|
|
|
import java.net.URL;
|
|
|
|
import java.util.Calendar;
|
|
|
|
import java.util.UUID;
|
|
|
|
|
2016-12-19 14:59:27 +01:00
|
|
|
import org.codehaus.jettison.json.JSONObject;
|
2017-03-23 13:37:15 +01:00
|
|
|
import org.gcube.informationsystem.impl.embedded.PropagationConstraintImpl;
|
2016-11-10 15:13:51 +01:00
|
|
|
import org.gcube.informationsystem.impl.entity.facet.AccessPointFacetImpl;
|
|
|
|
import org.gcube.informationsystem.impl.entity.facet.CPUFacetImpl;
|
|
|
|
import org.gcube.informationsystem.impl.entity.facet.EventFacetImpl;
|
|
|
|
import org.gcube.informationsystem.impl.entity.facet.LicenseFacetImpl;
|
|
|
|
import org.gcube.informationsystem.impl.entity.facet.MemoryFacetImpl;
|
|
|
|
import org.gcube.informationsystem.impl.entity.facet.NetworkingFacetImpl;
|
|
|
|
import org.gcube.informationsystem.impl.entity.facet.ServiceStateFacetImpl;
|
|
|
|
import org.gcube.informationsystem.impl.entity.facet.SoftwareFacetImpl;
|
|
|
|
import org.gcube.informationsystem.impl.entity.resource.EServiceImpl;
|
|
|
|
import org.gcube.informationsystem.impl.entity.resource.HostingNodeImpl;
|
|
|
|
import org.gcube.informationsystem.impl.relation.IsIdentifiedByImpl;
|
|
|
|
import org.gcube.informationsystem.impl.relation.consistsof.HasPersistentMemoryImpl;
|
|
|
|
import org.gcube.informationsystem.impl.relation.consistsof.HasVolatileMemoryImpl;
|
|
|
|
import org.gcube.informationsystem.impl.relation.isrelatedto.HostsImpl;
|
2017-01-30 11:43:18 +01:00
|
|
|
import org.gcube.informationsystem.impl.utils.ISMapper;
|
2016-12-19 14:59:27 +01:00
|
|
|
import org.gcube.informationsystem.model.embedded.Header;
|
2017-03-23 13:37:15 +01:00
|
|
|
import org.gcube.informationsystem.model.embedded.PropagationConstraint;
|
|
|
|
import org.gcube.informationsystem.model.embedded.PropagationConstraint.AddConstraint;
|
|
|
|
import org.gcube.informationsystem.model.embedded.PropagationConstraint.RemoveConstraint;
|
2016-12-19 14:59:27 +01:00
|
|
|
import org.gcube.informationsystem.model.entity.Entity;
|
2016-11-10 15:13:51 +01:00
|
|
|
import org.gcube.informationsystem.model.entity.Facet;
|
|
|
|
import org.gcube.informationsystem.model.entity.facet.AccessPointFacet;
|
|
|
|
import org.gcube.informationsystem.model.entity.facet.CPUFacet;
|
|
|
|
import org.gcube.informationsystem.model.entity.facet.EventFacet;
|
|
|
|
import org.gcube.informationsystem.model.entity.facet.LicenseFacet;
|
|
|
|
import org.gcube.informationsystem.model.entity.facet.MemoryFacet;
|
|
|
|
import org.gcube.informationsystem.model.entity.facet.MemoryFacet.MemoryUnit;
|
|
|
|
import org.gcube.informationsystem.model.entity.facet.NetworkingFacet;
|
|
|
|
import org.gcube.informationsystem.model.entity.facet.ServiceStateFacet;
|
|
|
|
import org.gcube.informationsystem.model.entity.facet.SoftwareFacet;
|
|
|
|
import org.gcube.informationsystem.model.entity.resource.EService;
|
|
|
|
import org.gcube.informationsystem.model.entity.resource.HostingNode;
|
|
|
|
import org.gcube.informationsystem.model.relation.IsIdentifiedBy;
|
|
|
|
import org.gcube.informationsystem.model.relation.consistsof.HasPersistentMemory;
|
|
|
|
import org.gcube.informationsystem.model.relation.consistsof.HasVolatileMemory;
|
|
|
|
import org.gcube.informationsystem.model.relation.isrelatedto.Hosts;
|
2016-12-19 14:59:27 +01:00
|
|
|
import org.gcube.informationsystem.resourceregistry.ScopedTest;
|
2016-11-10 15:13:51 +01:00
|
|
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
|
|
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.context.ContextNotFoundException;
|
2017-03-29 16:14:03 +02:00
|
|
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.facet.FacetAvailableInAnotherContextException;
|
|
|
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.resource.ResourceAvailableInAnotherContextException;
|
2016-11-28 18:17:14 +01:00
|
|
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.resource.ResourceNotFoundException;
|
2017-03-29 16:14:03 +02:00
|
|
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.relation.RelationAvailableInAnotherContextException;
|
2017-03-23 13:37:15 +01:00
|
|
|
import org.gcube.informationsystem.resourceregistry.er.SmartgearResourcesTest;
|
2016-12-27 11:27:01 +01:00
|
|
|
import org.gcube.informationsystem.resourceregistry.er.entity.FacetManagement;
|
|
|
|
import org.gcube.informationsystem.resourceregistry.er.entity.ResourceManagement;
|
2017-03-23 13:37:15 +01:00
|
|
|
import org.gcube.informationsystem.resourceregistry.er.relation.IsRelatedToManagement;
|
2016-11-14 12:02:51 +01:00
|
|
|
import org.junit.Assert;
|
2016-11-10 15:13:51 +01:00
|
|
|
import org.junit.Test;
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @author Luca Frosini (ISTI - CNR)
|
2016-11-28 09:13:20 +01:00
|
|
|
*
|
2016-11-10 15:13:51 +01:00
|
|
|
*/
|
2016-12-19 14:59:27 +01:00
|
|
|
public class MultiContextTest extends ScopedTest {
|
2016-11-10 15:13:51 +01:00
|
|
|
|
|
|
|
private static Logger logger = LoggerFactory
|
2016-12-19 16:28:46 +01:00
|
|
|
.getLogger(MultiContextTest.class);
|
2016-11-10 15:13:51 +01:00
|
|
|
|
2016-12-19 14:59:27 +01:00
|
|
|
@Test
|
|
|
|
public void testDifferentScopes() throws Exception {
|
|
|
|
CPUFacet cpuFacet = new CPUFacetImpl();
|
|
|
|
cpuFacet.setClockSpeed("1 GHz");
|
|
|
|
cpuFacet.setModel("Opteron");
|
|
|
|
cpuFacet.setVendor("AMD");
|
2016-11-10 15:13:51 +01:00
|
|
|
|
2016-12-19 14:59:27 +01:00
|
|
|
FacetManagement facetManagement = new FacetManagement();
|
2017-01-30 11:43:18 +01:00
|
|
|
facetManagement.setJSON(ISMapper.marshal(cpuFacet));
|
2016-12-30 17:31:12 +01:00
|
|
|
facetManagement.setElementType(CPUFacet.NAME);
|
2016-12-19 14:59:27 +01:00
|
|
|
|
|
|
|
String json = facetManagement.create();
|
|
|
|
logger.debug("Created : {}", json);
|
|
|
|
|
|
|
|
JSONObject jsonObject = new JSONObject(json);
|
|
|
|
JSONObject header = jsonObject.getJSONObject(Entity.HEADER_PROPERTY);
|
|
|
|
UUID uuid = UUID.fromString(header.getString(Header.UUID_PROPERTY));
|
|
|
|
|
|
|
|
facetManagement = new FacetManagement();
|
|
|
|
facetManagement.setUUID(uuid);
|
|
|
|
|
|
|
|
String readJson = facetManagement.read();
|
|
|
|
logger.debug("Read : {}", readJson);
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------------ */
|
|
|
|
|
|
|
|
logger.debug("Switching to another scope");
|
|
|
|
ScopedTest.setContext(ScopedTest.ALTERNATIVE_TEST_SCOPE);
|
|
|
|
try {
|
|
|
|
facetManagement = new FacetManagement();
|
|
|
|
facetManagement.setUUID(uuid);
|
|
|
|
readJson = facetManagement.read();
|
|
|
|
logger.debug("You should not be able to read Facet with UUID {}",
|
|
|
|
uuid);
|
|
|
|
throw new Exception(
|
|
|
|
"You should not be able to read Facet with UUID " + uuid);
|
2017-03-29 16:14:03 +02:00
|
|
|
} catch (FacetAvailableInAnotherContextException e) {
|
|
|
|
logger.debug("Good the facet created in the default context is not visible in an alternative context");
|
2016-12-19 14:59:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
cpuFacet.setAdditionalProperty("My", "Test");
|
|
|
|
|
|
|
|
try {
|
|
|
|
facetManagement = new FacetManagement();
|
|
|
|
facetManagement.setUUID(uuid);
|
2017-01-30 11:43:18 +01:00
|
|
|
facetManagement.setJSON(ISMapper.marshal(cpuFacet));
|
2016-12-19 14:59:27 +01:00
|
|
|
readJson = facetManagement.update();
|
|
|
|
logger.debug("You should not be able to update Facet with UUID {}",
|
|
|
|
uuid);
|
|
|
|
throw new Exception(
|
|
|
|
"You should not be able to read Facet with UUID " + uuid);
|
2017-03-29 16:14:03 +02:00
|
|
|
} catch (FacetAvailableInAnotherContextException e) {
|
|
|
|
logger.debug("Good the Facet created in the default context cannot be updated in an alternative context");
|
2016-12-19 14:59:27 +01:00
|
|
|
}
|
2016-11-28 09:13:20 +01:00
|
|
|
|
2016-12-19 14:59:27 +01:00
|
|
|
try {
|
|
|
|
facetManagement = new FacetManagement();
|
|
|
|
facetManagement.setUUID(uuid);
|
|
|
|
facetManagement.delete();
|
|
|
|
logger.debug("You should not be able to delete Facet with UUID {}",
|
|
|
|
uuid);
|
|
|
|
throw new Exception(
|
|
|
|
"You should not be able to delete Facet with UUID " + uuid);
|
2017-03-29 16:14:03 +02:00
|
|
|
} catch (FacetAvailableInAnotherContextException e) {
|
|
|
|
logger.debug("Good the Facet created in the default context cannot be deleted in an alternative context");
|
2016-12-19 14:59:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------------ */
|
|
|
|
|
|
|
|
logger.debug("Setting back default scope");
|
|
|
|
ScopedTest.setContext(ScopedTest.DEFAULT_TEST_SCOPE);
|
|
|
|
|
|
|
|
facetManagement = new FacetManagement();
|
|
|
|
facetManagement.setUUID(uuid);
|
2017-01-30 11:43:18 +01:00
|
|
|
facetManagement.setJSON(ISMapper.marshal(cpuFacet));
|
2016-12-19 14:59:27 +01:00
|
|
|
readJson = facetManagement.update();
|
|
|
|
logger.debug("Updated : {}", readJson);
|
|
|
|
|
|
|
|
facetManagement = new FacetManagement();
|
|
|
|
facetManagement.setUUID(uuid);
|
|
|
|
readJson = facetManagement.read();
|
|
|
|
logger.debug("Read Updated : {}", readJson);
|
|
|
|
|
|
|
|
facetManagement = new FacetManagement();
|
|
|
|
facetManagement.setUUID(uuid);
|
|
|
|
boolean deleted = facetManagement.delete();
|
|
|
|
Assert.assertTrue(deleted);
|
|
|
|
}
|
|
|
|
|
2016-11-10 15:13:51 +01:00
|
|
|
@Test
|
2016-11-11 11:54:41 +01:00
|
|
|
public void testCreateEServiceHostingNode() throws Exception {
|
2016-11-10 15:13:51 +01:00
|
|
|
EService eService = new EServiceImpl();
|
2016-11-28 09:13:20 +01:00
|
|
|
|
2016-11-10 15:13:51 +01:00
|
|
|
SoftwareFacet softwareFacet = new SoftwareFacetImpl();
|
|
|
|
softwareFacet.setGroup("InformationSystem");
|
|
|
|
softwareFacet.setName("resource-registry");
|
|
|
|
softwareFacet.setVersion("1.1.0");
|
2016-11-28 09:13:20 +01:00
|
|
|
IsIdentifiedBy<EService, Facet> isIdentifiedBy = new IsIdentifiedByImpl<EService, Facet>(
|
|
|
|
eService, softwareFacet, null);
|
2016-11-10 15:13:51 +01:00
|
|
|
eService.addFacet(isIdentifiedBy);
|
2016-11-28 09:13:20 +01:00
|
|
|
|
2016-11-10 15:13:51 +01:00
|
|
|
AccessPointFacet accessPointFacet = new AccessPointFacetImpl();
|
|
|
|
accessPointFacet.setEndpoint(new URI("http://localhost"));
|
|
|
|
accessPointFacet.setEntryName("port1");
|
|
|
|
eService.addFacet(accessPointFacet);
|
2016-11-28 09:13:20 +01:00
|
|
|
|
2016-11-10 15:13:51 +01:00
|
|
|
EventFacet eventFacet = new EventFacetImpl();
|
|
|
|
eventFacet.setDate(Calendar.getInstance().getTime());
|
|
|
|
eventFacet.setValue("Created");
|
|
|
|
eService.addFacet(eventFacet);
|
2016-11-28 09:13:20 +01:00
|
|
|
|
2016-11-10 15:13:51 +01:00
|
|
|
ServiceStateFacet serviceStateFacet = new ServiceStateFacetImpl();
|
|
|
|
serviceStateFacet.setValue("ready");
|
|
|
|
eService.addFacet(serviceStateFacet);
|
2016-11-28 09:13:20 +01:00
|
|
|
|
2016-11-10 15:13:51 +01:00
|
|
|
LicenseFacet licenseFacet = new LicenseFacetImpl();
|
|
|
|
licenseFacet.setName("EUPL");
|
2016-11-28 09:13:20 +01:00
|
|
|
licenseFacet
|
|
|
|
.setTextURL(new URL(
|
|
|
|
"https://joinup.ec.europa.eu/community/eupl/og_page/european-union-public-licence-eupl-v11"));
|
2016-11-10 15:13:51 +01:00
|
|
|
eService.addFacet(licenseFacet);
|
2016-12-19 14:59:27 +01:00
|
|
|
|
|
|
|
|
|
|
|
ResourceManagement resourceManagement = new ResourceManagement();
|
2016-12-30 17:31:12 +01:00
|
|
|
resourceManagement.setElementType(EService.NAME);
|
2017-01-30 11:43:18 +01:00
|
|
|
resourceManagement.setJSON(ISMapper.marshal(eService));
|
2016-11-28 09:13:20 +01:00
|
|
|
|
2016-12-19 14:59:27 +01:00
|
|
|
String json = resourceManagement.create();
|
2016-11-10 15:13:51 +01:00
|
|
|
logger.debug("Created : {}", json);
|
2017-01-30 11:43:18 +01:00
|
|
|
eService = ISMapper.unmarshal(EService.class, json);
|
2016-11-10 15:13:51 +01:00
|
|
|
logger.debug("Unmarshalled {} {}", EService.NAME, eService);
|
2016-11-28 09:13:20 +01:00
|
|
|
|
|
|
|
|
2016-11-10 15:13:51 +01:00
|
|
|
HostingNode hostingNode = new HostingNodeImpl();
|
2016-11-28 09:13:20 +01:00
|
|
|
|
2016-11-10 15:13:51 +01:00
|
|
|
NetworkingFacet networkingFacet = new NetworkingFacetImpl();
|
|
|
|
networkingFacet.setIPAddress("146.48.87.183");
|
|
|
|
networkingFacet.setHostName("pc-frosini.isti.cnr.it");
|
|
|
|
networkingFacet.setDomainName("isti.cnr.it");
|
|
|
|
networkingFacet.setMask("255.255.248.0");
|
|
|
|
networkingFacet.setBroadcastAddress("146.48.87.255");
|
2016-11-28 09:13:20 +01:00
|
|
|
|
|
|
|
IsIdentifiedBy<HostingNode, NetworkingFacet> isIdentifiedByHNNF = new IsIdentifiedByImpl<HostingNode, NetworkingFacet>(
|
|
|
|
hostingNode, networkingFacet, null);
|
2016-11-11 11:54:41 +01:00
|
|
|
hostingNode.addFacet(isIdentifiedByHNNF);
|
2016-11-28 09:13:20 +01:00
|
|
|
|
2016-11-10 15:13:51 +01:00
|
|
|
CPUFacet cpuFacet = new CPUFacetImpl();
|
|
|
|
cpuFacet.setClockSpeed("1 GHz");
|
|
|
|
cpuFacet.setModel("Opteron");
|
|
|
|
cpuFacet.setVendor("AMD");
|
|
|
|
hostingNode.addFacet(cpuFacet);
|
2016-11-28 09:13:20 +01:00
|
|
|
|
2016-11-10 15:13:51 +01:00
|
|
|
MemoryFacet ram = new MemoryFacetImpl();
|
|
|
|
ram.setSize(8);
|
|
|
|
ram.setUnit(MemoryUnit.GB);
|
|
|
|
ram.setUsed(2);
|
2016-11-28 09:13:20 +01:00
|
|
|
|
|
|
|
HasVolatileMemory<HostingNode, MemoryFacet> hasVolatileMemory = new HasVolatileMemoryImpl<HostingNode, MemoryFacet>(
|
|
|
|
hostingNode, ram, null);
|
2016-11-10 15:13:51 +01:00
|
|
|
hostingNode.addFacet(hasVolatileMemory);
|
2016-11-28 09:13:20 +01:00
|
|
|
|
2016-11-10 15:13:51 +01:00
|
|
|
MemoryFacet disk = new MemoryFacetImpl();
|
|
|
|
disk.setSize(256);
|
|
|
|
disk.setUnit(MemoryUnit.GB);
|
|
|
|
disk.setUsed(120);
|
2016-11-28 09:13:20 +01:00
|
|
|
|
|
|
|
HasPersistentMemory<HostingNode, MemoryFacet> hasPersistentMemory = new HasPersistentMemoryImpl<HostingNode, MemoryFacet>(
|
|
|
|
hostingNode, disk, null);
|
2016-11-10 15:13:51 +01:00
|
|
|
hostingNode.addFacet(hasPersistentMemory);
|
2016-11-28 09:13:20 +01:00
|
|
|
|
|
|
|
Hosts<HostingNode, EService> hosts = new HostsImpl<HostingNode, EService>(
|
|
|
|
hostingNode, eService, null);
|
2016-11-10 15:13:51 +01:00
|
|
|
hostingNode.attachResource(hosts);
|
2016-11-28 09:13:20 +01:00
|
|
|
|
2016-12-19 14:59:27 +01:00
|
|
|
resourceManagement = new ResourceManagement();
|
2016-12-30 17:31:12 +01:00
|
|
|
resourceManagement.setElementType(HostingNode.NAME);
|
2017-01-30 11:43:18 +01:00
|
|
|
resourceManagement.setJSON(ISMapper.marshal(hostingNode));
|
2016-12-19 14:59:27 +01:00
|
|
|
|
|
|
|
String hnJson = resourceManagement.create();
|
2016-11-11 11:54:41 +01:00
|
|
|
logger.debug("Created : {}", hnJson);
|
2017-01-30 11:43:18 +01:00
|
|
|
hostingNode = ISMapper.unmarshal(HostingNode.class, hnJson);
|
2016-11-11 11:54:41 +01:00
|
|
|
logger.debug("Unmarshalled {} {}", HostingNode.NAME, hostingNode);
|
2016-11-14 12:02:51 +01:00
|
|
|
UUID uuid = hostingNode.getHeader().getUUID();
|
2016-12-19 14:59:27 +01:00
|
|
|
|
|
|
|
/* ------------------------------------------------------------------ */
|
|
|
|
|
|
|
|
logger.debug("Switching to another scope");
|
|
|
|
ScopedTest.setContext(ScopedTest.ALTERNATIVE_TEST_SCOPE);
|
|
|
|
|
|
|
|
resourceManagement = new ResourceManagement();
|
|
|
|
resourceManagement.setUUID(uuid);
|
|
|
|
|
|
|
|
boolean addedToContext = resourceManagement.addToContext();
|
2016-11-14 12:02:51 +01:00
|
|
|
Assert.assertTrue(addedToContext);
|
2016-11-28 09:13:20 +01:00
|
|
|
|
2016-12-19 14:59:27 +01:00
|
|
|
resourceManagement = new ResourceManagement();
|
|
|
|
resourceManagement.setUUID(uuid);
|
|
|
|
|
|
|
|
String hnString = resourceManagement.read();
|
2017-01-30 11:43:18 +01:00
|
|
|
HostingNode readHN = ISMapper.unmarshal(HostingNode.class, hnString);
|
2016-11-28 09:13:20 +01:00
|
|
|
Assert.assertTrue(readHN.getHeader().getUUID().compareTo(uuid) == 0);
|
|
|
|
|
2016-11-14 12:02:51 +01:00
|
|
|
UUID eServiceUUID = eService.getHeader().getUUID();
|
|
|
|
try {
|
2016-12-19 14:59:27 +01:00
|
|
|
resourceManagement = new ResourceManagement();
|
|
|
|
resourceManagement.setUUID(eServiceUUID);
|
|
|
|
resourceManagement.read();
|
2017-03-29 16:14:03 +02:00
|
|
|
} catch (ResourceAvailableInAnotherContextException e) {
|
2016-11-28 09:13:20 +01:00
|
|
|
logger.debug("Resource with {} Not Found as Expected",
|
2016-12-19 14:59:27 +01:00
|
|
|
eServiceUUID);
|
2016-11-28 09:13:20 +01:00
|
|
|
}
|
|
|
|
try {
|
2016-12-19 14:59:27 +01:00
|
|
|
resourceManagement = new ResourceManagement();
|
|
|
|
resourceManagement.setUUID(eServiceUUID);
|
|
|
|
resourceManagement.delete();
|
2017-03-29 16:14:03 +02:00
|
|
|
} catch (ResourceAvailableInAnotherContextException e) {
|
2016-12-27 15:31:39 +01:00
|
|
|
logger.debug("Resource with {} Not Deleted as Expected",
|
2016-12-19 14:59:27 +01:00
|
|
|
eServiceUUID);
|
2016-11-28 09:13:20 +01:00
|
|
|
}
|
|
|
|
|
2016-12-19 14:59:27 +01:00
|
|
|
resourceManagement = new ResourceManagement();
|
|
|
|
resourceManagement.setUUID(uuid);
|
|
|
|
boolean deleted = resourceManagement.delete();
|
|
|
|
Assert.assertTrue(deleted);
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------------ */
|
|
|
|
|
|
|
|
logger.debug("Setting back default scope");
|
|
|
|
ScopedTest.setContext(ScopedTest.DEFAULT_TEST_SCOPE);
|
|
|
|
|
|
|
|
resourceManagement = new ResourceManagement();
|
|
|
|
resourceManagement.setUUID(eServiceUUID);
|
|
|
|
deleted = resourceManagement.delete();
|
|
|
|
Assert.assertTrue(deleted);
|
2016-12-27 15:31:39 +01:00
|
|
|
|
2016-12-19 14:59:27 +01:00
|
|
|
|
2016-11-10 15:13:51 +01:00
|
|
|
}
|
2016-11-28 09:13:20 +01:00
|
|
|
|
|
|
|
// @Test
|
|
|
|
public void addTest() throws ResourceNotFoundException,
|
|
|
|
ContextNotFoundException, ResourceRegistryException {
|
2016-12-19 14:59:27 +01:00
|
|
|
ResourceManagement resourceManagement = new ResourceManagement();
|
|
|
|
resourceManagement.setUUID(UUID.fromString(""));
|
|
|
|
resourceManagement.addToContext();
|
2016-11-10 15:13:51 +01:00
|
|
|
}
|
2017-03-23 13:37:15 +01:00
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testAddAndRemoveFromContext() throws Exception {
|
|
|
|
|
|
|
|
/* Creating HostingNode */
|
|
|
|
|
|
|
|
ResourceManagement resourceManagement = new ResourceManagement();
|
|
|
|
resourceManagement.setElementType(HostingNode.NAME);
|
|
|
|
resourceManagement.setJSON(SmartgearResourcesTest.HOSTING_NODE);
|
|
|
|
|
|
|
|
String hnJson = resourceManagement.create();
|
|
|
|
logger.debug("Created : {}", hnJson);
|
|
|
|
HostingNode hostingNode = ISMapper.unmarshal(HostingNode.class, hnJson);
|
|
|
|
logger.debug("Unmarshalled {} {}", HostingNode.NAME, hostingNode);
|
|
|
|
|
|
|
|
UUID hnUUID = hostingNode.getHeader().getUUID();
|
|
|
|
|
|
|
|
|
|
|
|
/* Creating EService */
|
|
|
|
|
|
|
|
resourceManagement = new ResourceManagement();
|
|
|
|
resourceManagement.setElementType(EService.NAME);
|
|
|
|
resourceManagement.setJSON(SmartgearResourcesTest.ESERVICE);
|
|
|
|
|
|
|
|
String eservicejson = resourceManagement.create();
|
|
|
|
logger.debug("Created : {}", eservicejson);
|
|
|
|
EService eService = ISMapper.unmarshal(EService.class, eservicejson);
|
|
|
|
logger.debug("Unmarshalled {} {}", EService.NAME, eService);
|
|
|
|
|
|
|
|
UUID eServiceUUID = eService.getHeader().getUUID();
|
|
|
|
|
|
|
|
|
|
|
|
/* Creating Hosts Relation */
|
|
|
|
|
|
|
|
PropagationConstraint propagationConstraint = new PropagationConstraintImpl();
|
|
|
|
propagationConstraint
|
|
|
|
.setRemoveConstraint(RemoveConstraint.cascade);
|
|
|
|
propagationConstraint
|
|
|
|
.setAddConstraint(AddConstraint.propagate);
|
|
|
|
|
|
|
|
|
|
|
|
Hosts<HostingNode, EService> hosts = new HostsImpl<>(hostingNode, eService,
|
|
|
|
propagationConstraint);
|
|
|
|
|
|
|
|
IsRelatedToManagement isRelatedToManagement = new IsRelatedToManagement();
|
|
|
|
isRelatedToManagement.setElementType(Hosts.NAME);
|
|
|
|
String hostsJson = ISMapper.marshal(hosts);
|
|
|
|
isRelatedToManagement.setJSON(hostsJson);
|
|
|
|
|
|
|
|
String createdHostsJson = isRelatedToManagement.create(hnUUID, eServiceUUID);
|
|
|
|
logger.debug("Created : {}", createdHostsJson);
|
|
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
Hosts<HostingNode, EService> createdHosts = ISMapper.unmarshal(Hosts.class, createdHostsJson);
|
|
|
|
UUID hostsUUID = createdHosts.getHeader().getUUID();
|
|
|
|
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------------ */
|
|
|
|
|
|
|
|
logger.debug("Switching to alternative scope");
|
|
|
|
ScopedTest.setContext(ScopedTest.ALTERNATIVE_TEST_SCOPE);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* resourceManagement = new ResourceManagement();
|
|
|
|
* resourceManagement.setUUID(hnUUID);
|
|
|
|
* resourceManagement.addToContext();
|
|
|
|
|
|
|
|
* resourceManagement = new ResourceManagement();
|
|
|
|
* resourceManagement.setUUID(eServiceUUID);
|
|
|
|
* resourceManagement.addToContext();
|
|
|
|
*
|
|
|
|
* This code is commented because the addToContext
|
|
|
|
* on relation enforce addToContext both on source
|
|
|
|
* and target
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
isRelatedToManagement = new IsRelatedToManagement();
|
|
|
|
isRelatedToManagement.setUUID(hostsUUID);
|
|
|
|
isRelatedToManagement.addToContext();
|
|
|
|
|
|
|
|
/* The addTocontext on the relation adds the source and target too.
|
|
|
|
* So that I MUST be able to read HostinNode and EService
|
|
|
|
*/
|
|
|
|
|
|
|
|
resourceManagement = new ResourceManagement();
|
|
|
|
resourceManagement.setUUID(hnUUID);
|
|
|
|
resourceManagement.read();
|
|
|
|
|
|
|
|
resourceManagement = new ResourceManagement();
|
|
|
|
resourceManagement.setUUID(eServiceUUID);
|
|
|
|
resourceManagement.read();
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------------ */
|
|
|
|
logger.debug("Setting back default scope");
|
|
|
|
ScopedTest.setContext(ScopedTest.DEFAULT_TEST_SCOPE);
|
|
|
|
|
|
|
|
resourceManagement = new ResourceManagement();
|
|
|
|
resourceManagement.setUUID(hnUUID);
|
|
|
|
boolean removed = resourceManagement.removeFromContext();
|
|
|
|
Assert.assertTrue(removed);
|
|
|
|
|
|
|
|
/* The cascading MUST remove the relation and the target so that
|
|
|
|
* I MUST not be able to read Hosts relation and EService
|
|
|
|
*/
|
|
|
|
|
|
|
|
resourceManagement = new ResourceManagement();
|
|
|
|
resourceManagement.setUUID(eServiceUUID);
|
|
|
|
try {
|
|
|
|
resourceManagement.read();
|
|
|
|
String error = String.format("{} with UUID {} should not be visible.", EService.NAME, eServiceUUID);
|
|
|
|
logger.trace(error);
|
|
|
|
throw new Exception(error);
|
2017-03-29 16:14:03 +02:00
|
|
|
}catch (ResourceAvailableInAnotherContextException e) {
|
2017-03-23 13:37:15 +01:00
|
|
|
// OK
|
|
|
|
}
|
|
|
|
|
|
|
|
isRelatedToManagement = new IsRelatedToManagement();
|
|
|
|
isRelatedToManagement.setUUID(hostsUUID);
|
|
|
|
try {
|
|
|
|
isRelatedToManagement.read();
|
|
|
|
String error = String.format("{} with UUID {} should not be visible.", Hosts.NAME, hostsUUID);
|
|
|
|
logger.trace(error);
|
|
|
|
throw new Exception(error);
|
2017-03-29 16:14:03 +02:00
|
|
|
}catch (RelationAvailableInAnotherContextException e) {
|
2017-03-23 13:37:15 +01:00
|
|
|
// OK
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------------ */
|
|
|
|
logger.debug("Switching to alternative scope again");
|
|
|
|
ScopedTest.setContext(ScopedTest.ALTERNATIVE_TEST_SCOPE);
|
|
|
|
// TODO checks here
|
|
|
|
|
|
|
|
resourceManagement = new ResourceManagement();
|
|
|
|
resourceManagement.setUUID(hnUUID);
|
|
|
|
boolean deleted = resourceManagement.delete();
|
|
|
|
Assert.assertTrue(deleted);
|
|
|
|
}
|
2016-11-28 09:13:20 +01:00
|
|
|
|
2016-11-10 15:13:51 +01:00
|
|
|
}
|