2016-12-19 14:59:27 +01:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
2019-11-06 12:13:19 +01:00
|
|
|
package org.gcube.informationsystem.resourceregistry.instances;
|
2016-12-19 14:59:27 +01:00
|
|
|
|
2017-06-16 11:23:03 +02:00
|
|
|
import java.io.File;
|
|
|
|
import java.io.FileInputStream;
|
|
|
|
import java.io.IOException;
|
2016-12-19 14:59:27 +01:00
|
|
|
import java.net.URI;
|
|
|
|
import java.net.URL;
|
2017-01-11 17:11:28 +01:00
|
|
|
import java.util.ArrayList;
|
2016-12-19 14:59:27 +01:00
|
|
|
import java.util.Calendar;
|
|
|
|
import java.util.HashMap;
|
2017-01-11 17:11:28 +01:00
|
|
|
import java.util.List;
|
2016-12-19 14:59:27 +01:00
|
|
|
import java.util.Map;
|
|
|
|
import java.util.UUID;
|
|
|
|
|
2020-07-07 17:15:22 +02:00
|
|
|
import org.gcube.com.fasterxml.jackson.core.JsonParseException;
|
|
|
|
import org.gcube.com.fasterxml.jackson.databind.JsonMappingException;
|
2019-02-13 12:33:29 +01:00
|
|
|
import org.gcube.informationsystem.model.impl.properties.EncryptedImpl;
|
2020-01-20 10:29:56 +01:00
|
|
|
import org.gcube.informationsystem.model.impl.properties.HeaderImpl;
|
2019-02-13 12:33:29 +01:00
|
|
|
import org.gcube.informationsystem.model.impl.properties.PropagationConstraintImpl;
|
|
|
|
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.properties.PropagationConstraint;
|
|
|
|
import org.gcube.informationsystem.model.reference.properties.PropagationConstraint.RemoveConstraint;
|
|
|
|
import org.gcube.informationsystem.model.reference.relations.ConsistsOf;
|
|
|
|
import org.gcube.informationsystem.model.reference.relations.IsRelatedTo;
|
2019-10-28 15:06:31 +01:00
|
|
|
import org.gcube.informationsystem.resourceregistry.ContextTest;
|
2017-03-28 16:27:56 +02:00
|
|
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
2018-06-08 15:05:47 +02:00
|
|
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.query.InvalidQueryException;
|
2021-03-04 21:57:01 +01:00
|
|
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaViolationException;
|
|
|
|
import org.gcube.informationsystem.resourceregistry.contexts.ContextUtility;
|
2020-01-30 11:04:16 +01:00
|
|
|
import org.gcube.informationsystem.resourceregistry.instances.base.ElementManagementUtility;
|
2021-03-04 21:57:01 +01:00
|
|
|
import org.gcube.informationsystem.resourceregistry.instances.model.entities.FacetManagement;
|
2019-11-06 12:13:19 +01:00
|
|
|
import org.gcube.informationsystem.resourceregistry.instances.model.entities.ResourceManagement;
|
2019-11-06 12:14:27 +01:00
|
|
|
import org.gcube.informationsystem.resourceregistry.instances.model.relations.ConsistsOfManagement;
|
|
|
|
import org.gcube.informationsystem.resourceregistry.instances.model.relations.IsRelatedToManagement;
|
2020-02-03 10:52:09 +01:00
|
|
|
import org.gcube.informationsystem.utils.ElementMapper;
|
2019-02-13 12:33:29 +01:00
|
|
|
import org.gcube.resourcemanagement.model.impl.entities.facets.AccessPointFacetImpl;
|
|
|
|
import org.gcube.resourcemanagement.model.impl.entities.facets.CPUFacetImpl;
|
|
|
|
import org.gcube.resourcemanagement.model.impl.entities.facets.EventFacetImpl;
|
2021-03-02 16:39:21 +01:00
|
|
|
import org.gcube.resourcemanagement.model.impl.entities.facets.IdentifierFacetImpl;
|
2019-02-13 12:33:29 +01:00
|
|
|
import org.gcube.resourcemanagement.model.impl.entities.facets.LicenseFacetImpl;
|
2021-02-22 16:36:19 +01:00
|
|
|
import org.gcube.resourcemanagement.model.impl.entities.facets.MemoryFacetImpl;
|
2019-02-13 12:33:29 +01:00
|
|
|
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.StateFacetImpl;
|
2021-03-02 16:39:21 +01:00
|
|
|
import org.gcube.resourcemanagement.model.impl.entities.resources.ConfigurationImpl;
|
2019-02-13 12:33:29 +01:00
|
|
|
import org.gcube.resourcemanagement.model.impl.entities.resources.EServiceImpl;
|
|
|
|
import org.gcube.resourcemanagement.model.impl.entities.resources.HostingNodeImpl;
|
|
|
|
import org.gcube.resourcemanagement.model.impl.properties.ValueSchemaImpl;
|
2021-02-22 16:36:19 +01:00
|
|
|
import org.gcube.resourcemanagement.model.impl.relations.consistsof.HasPersistentMemoryImpl;
|
|
|
|
import org.gcube.resourcemanagement.model.impl.relations.consistsof.HasVolatileMemoryImpl;
|
2019-12-05 12:09:23 +01:00
|
|
|
import org.gcube.resourcemanagement.model.impl.relations.consistsof.IsIdentifiedByImpl;
|
2019-02-13 12:33:29 +01:00
|
|
|
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.EventFacet;
|
2021-03-02 16:39:21 +01:00
|
|
|
import org.gcube.resourcemanagement.model.reference.entities.facets.IdentifierFacet;
|
|
|
|
import org.gcube.resourcemanagement.model.reference.entities.facets.IdentifierFacet.IdentificationType;
|
2019-02-13 12:33:29 +01:00
|
|
|
import org.gcube.resourcemanagement.model.reference.entities.facets.LicenseFacet;
|
2021-02-22 16:36:19 +01:00
|
|
|
import org.gcube.resourcemanagement.model.reference.entities.facets.MemoryFacet;
|
|
|
|
import org.gcube.resourcemanagement.model.reference.entities.facets.MemoryFacet.MemoryUnit;
|
2019-02-13 12:33:29 +01:00
|
|
|
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.StateFacet;
|
|
|
|
import org.gcube.resourcemanagement.model.reference.entities.resources.Configuration;
|
|
|
|
import org.gcube.resourcemanagement.model.reference.entities.resources.EService;
|
2019-12-05 12:09:23 +01:00
|
|
|
import org.gcube.resourcemanagement.model.reference.entities.resources.GCubeResource;
|
2019-02-13 12:33:29 +01:00
|
|
|
import org.gcube.resourcemanagement.model.reference.entities.resources.HostingNode;
|
|
|
|
import org.gcube.resourcemanagement.model.reference.entities.resources.Service;
|
|
|
|
import org.gcube.resourcemanagement.model.reference.properties.ValueSchema;
|
2021-02-22 16:36:19 +01:00
|
|
|
import org.gcube.resourcemanagement.model.reference.relations.consistsof.HasPersistentMemory;
|
|
|
|
import org.gcube.resourcemanagement.model.reference.relations.consistsof.HasVolatileMemory;
|
2019-12-05 12:09:23 +01:00
|
|
|
import org.gcube.resourcemanagement.model.reference.relations.consistsof.IsIdentifiedBy;
|
2019-02-13 12:33:29 +01:00
|
|
|
import org.gcube.resourcemanagement.model.reference.relations.isrelatedto.Activates;
|
2016-12-19 14:59:27 +01:00
|
|
|
import org.junit.Assert;
|
|
|
|
import org.junit.Test;
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
2019-11-05 18:36:44 +01:00
|
|
|
import com.orientechnologies.orient.core.record.ODirection;
|
2017-01-12 11:13:09 +01:00
|
|
|
|
2016-12-19 14:59:27 +01:00
|
|
|
/**
|
|
|
|
* @author Luca Frosini (ISTI - CNR)
|
|
|
|
*/
|
2019-10-28 15:06:31 +01:00
|
|
|
public class ERManagementTest extends ContextTest {
|
2016-12-19 14:59:27 +01:00
|
|
|
|
2021-03-02 16:55:42 +01:00
|
|
|
private static Logger logger = LoggerFactory.getLogger(ERManagementTest.class);
|
|
|
|
|
|
|
|
public static EService instantiateValidEService() throws Exception {
|
|
|
|
EService eService = new EServiceImpl();
|
|
|
|
|
|
|
|
SoftwareFacet softwareFacet = new SoftwareFacetImpl();
|
|
|
|
softwareFacet.setGroup("InformationSystem");
|
|
|
|
softwareFacet.setName("resource-registry");
|
|
|
|
softwareFacet.setVersion("1.1.0");
|
|
|
|
|
|
|
|
IsIdentifiedBy<Resource, Facet> isIdentifiedBy = new IsIdentifiedByImpl<Resource, Facet>(eService,
|
|
|
|
softwareFacet, null);
|
|
|
|
eService.addFacet(isIdentifiedBy);
|
|
|
|
|
|
|
|
AccessPointFacet accessPointFacet = new AccessPointFacetImpl();
|
|
|
|
accessPointFacet.setEndpoint(new URI("https://localhost"));
|
|
|
|
accessPointFacet.setEntryName("port1");
|
|
|
|
eService.addFacet(accessPointFacet);
|
|
|
|
|
|
|
|
EventFacet eventFacet = new EventFacetImpl();
|
|
|
|
eventFacet.setDate(Calendar.getInstance().getTime());
|
|
|
|
ValueSchema event = new ValueSchemaImpl();
|
|
|
|
event.setSchema(new URI("Schema"));
|
|
|
|
event.setValue("Created");
|
|
|
|
eventFacet.setEvent(event);
|
|
|
|
eService.addFacet(eventFacet);
|
|
|
|
|
|
|
|
StateFacet stateFacet = new StateFacetImpl();
|
|
|
|
stateFacet.setValue("ready");
|
|
|
|
eService.addFacet(stateFacet);
|
|
|
|
|
|
|
|
LicenseFacet licenseFacet = new LicenseFacetImpl();
|
|
|
|
licenseFacet.setName("EUPL");
|
|
|
|
licenseFacet.setTextURL(
|
|
|
|
new URL("https://joinup.ec.europa.eu/community/eupl/og_page/european-union-public-licence-eupl-v11"));
|
|
|
|
eService.addFacet(licenseFacet);
|
|
|
|
|
|
|
|
return eService;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static HostingNode instantiateValidHostinNode() throws Exception {
|
|
|
|
HostingNode hostingNode = new HostingNodeImpl();
|
|
|
|
|
|
|
|
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");
|
|
|
|
|
|
|
|
IsIdentifiedBy<HostingNode, NetworkingFacet> isIdentifiedBy = new IsIdentifiedByImpl<HostingNode, NetworkingFacet>(
|
|
|
|
hostingNode, networkingFacet);
|
|
|
|
hostingNode.addFacet(isIdentifiedBy);
|
|
|
|
|
|
|
|
CPUFacet cpuFacet = new CPUFacetImpl();
|
|
|
|
cpuFacet.setClockSpeed("1 GHz");
|
|
|
|
cpuFacet.setModel("Opteron");
|
|
|
|
cpuFacet.setVendor("AMD");
|
|
|
|
hostingNode.addFacet(cpuFacet);
|
|
|
|
|
|
|
|
MemoryFacet persistentMemoryFacet = new MemoryFacetImpl();
|
|
|
|
persistentMemoryFacet.setSize(1024);
|
|
|
|
persistentMemoryFacet.setUnit(MemoryUnit.GB);
|
|
|
|
persistentMemoryFacet.setUsed(512);
|
|
|
|
HasPersistentMemory<HostingNode, MemoryFacet> hasPersistentMemory = new HasPersistentMemoryImpl<HostingNode, MemoryFacet>(
|
|
|
|
hostingNode, persistentMemoryFacet);
|
|
|
|
hostingNode.addFacet(hasPersistentMemory);
|
|
|
|
|
|
|
|
MemoryFacet volatileMemoryFacet = new MemoryFacetImpl();
|
|
|
|
volatileMemoryFacet.setSize(8);
|
|
|
|
volatileMemoryFacet.setUnit(MemoryUnit.GB);
|
|
|
|
volatileMemoryFacet.setUsed(4);
|
|
|
|
HasVolatileMemory<HostingNode, MemoryFacet> hasVolatileMemory = new HasVolatileMemoryImpl<HostingNode, MemoryFacet>(
|
|
|
|
hostingNode, volatileMemoryFacet);
|
|
|
|
hostingNode.addFacet(hasVolatileMemory);
|
|
|
|
|
|
|
|
StateFacet hnStateFacet = new StateFacetImpl();
|
|
|
|
hnStateFacet.setValue("certified");
|
|
|
|
hostingNode.addFacet(hnStateFacet);
|
|
|
|
|
|
|
|
EventFacet hnEventFacet = new EventFacetImpl();
|
|
|
|
hnEventFacet.setDate(Calendar.getInstance().getTime());
|
|
|
|
ValueSchema hnEvent = new ValueSchemaImpl();
|
|
|
|
hnEvent.setSchema(new URI("Schema"));
|
|
|
|
hnEvent.setValue("Created");
|
|
|
|
hnEventFacet.setEvent(hnEvent);
|
|
|
|
hostingNode.addFacet(hnEventFacet);
|
|
|
|
|
|
|
|
return hostingNode;
|
|
|
|
}
|
2016-12-19 14:59:27 +01:00
|
|
|
|
2021-03-03 17:18:36 +01:00
|
|
|
public static Map<String, Resource> createHostingNodeAndEService() throws Exception {
|
|
|
|
Map<String, Resource> map = new HashMap<>();
|
2021-03-02 16:55:42 +01:00
|
|
|
|
2021-03-03 17:18:36 +01:00
|
|
|
EService eService = ERManagementTest.instantiateValidEService();
|
2021-03-02 16:55:42 +01:00
|
|
|
|
2021-03-03 17:18:36 +01:00
|
|
|
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);
|
|
|
|
map.put(EService.NAME, eService);
|
2019-02-13 12:33:29 +01:00
|
|
|
|
2021-03-03 17:18:36 +01:00
|
|
|
HostingNode hostingNode = ERManagementTest.instantiateValidHostinNode();
|
2021-03-02 16:55:42 +01:00
|
|
|
|
2021-03-03 17:18:36 +01:00
|
|
|
PropagationConstraint propagationConstraint = new PropagationConstraintImpl();
|
|
|
|
propagationConstraint.setRemoveConstraint(RemoveConstraint.cascade);
|
|
|
|
Activates<HostingNode, EService> activates = new ActivatesImpl<HostingNode, EService>(hostingNode, eService,
|
|
|
|
propagationConstraint);
|
|
|
|
hostingNode.attachResource(activates);
|
2021-03-02 16:55:42 +01:00
|
|
|
|
2021-03-03 17:18:36 +01:00
|
|
|
resourceManagement = new ResourceManagement();
|
|
|
|
resourceManagement.setElementType(HostingNode.NAME);
|
|
|
|
resourceManagement.setJson(ElementMapper.marshal(hostingNode));
|
|
|
|
|
|
|
|
json = resourceManagement.create();
|
|
|
|
logger.debug("Created : {}", json);
|
|
|
|
hostingNode = ElementMapper.unmarshal(HostingNode.class, json);
|
|
|
|
logger.debug("Unmarshalled {} {}", HostingNode.NAME, hostingNode);
|
|
|
|
map.put(HostingNode.NAME, hostingNode);
|
|
|
|
|
|
|
|
return map;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static Configuration instantiateValidConfiguration() throws Exception {
|
2021-03-02 16:39:21 +01:00
|
|
|
Configuration configuration = new ConfigurationImpl();
|
2021-03-02 16:55:42 +01:00
|
|
|
|
2021-03-02 16:39:21 +01:00
|
|
|
IdentifierFacet identifierFacet = new IdentifierFacetImpl();
|
|
|
|
identifierFacet.setType(IdentificationType.STRING);
|
|
|
|
identifierFacet.setValue("MyID");
|
|
|
|
identifierFacet.setPersistent(false);
|
2021-03-02 16:55:42 +01:00
|
|
|
|
|
|
|
IsIdentifiedBy<Configuration, IdentifierFacet> isIdentifiedBy = new IsIdentifiedByImpl<Configuration, IdentifierFacet>(
|
|
|
|
configuration, identifierFacet);
|
2021-03-02 16:39:21 +01:00
|
|
|
configuration.addFacet(isIdentifiedBy);
|
2021-03-03 17:18:36 +01:00
|
|
|
|
|
|
|
return configuration;
|
|
|
|
}
|
|
|
|
|
2021-03-04 21:57:01 +01:00
|
|
|
@Test
|
|
|
|
public void testCreateEServiceAndDeleteRequiredFacet() throws Exception {
|
|
|
|
EService eService = 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
|
|
|
|
}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.delete();
|
|
|
|
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 testCreateEServiceAndRemoveFromContextRequiredFacet() throws Exception {
|
|
|
|
EService eService = 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();
|
|
|
|
|
|
|
|
}
|
2021-03-03 17:18:36 +01:00
|
|
|
|
|
|
|
@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();
|
2021-03-02 16:55:42 +01:00
|
|
|
|
2021-03-02 16:39:21 +01:00
|
|
|
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();
|
2021-03-02 16:55:42 +01:00
|
|
|
|
|
|
|
Configuration createdConfiguration = ElementMapper.unmarshal(Configuration.class, configurationJsonString);
|
|
|
|
logger.debug("Created:\nRaw Json : {}\nUnmarshalled : {}", configurationJsonString, createdConfiguration);
|
|
|
|
|
2021-03-02 16:39:21 +01:00
|
|
|
CPUFacet readCpuFacet = configuration.getFacets(CPUFacet.class).get(0);
|
|
|
|
String gotEncryptedValue = ((Encrypted) readCpuFacet.getAdditionalProperty("test")).getEncryptedValue();
|
2021-03-02 16:55:42 +01:00
|
|
|
Assert.assertTrue(gotEncryptedValue.compareTo(encryptedValue) == 0);
|
2021-03-02 16:39:21 +01:00
|
|
|
String gotPlainValue = EncryptedImpl.decrypt(gotEncryptedValue);
|
2021-03-02 16:55:42 +01:00
|
|
|
Assert.assertTrue(gotPlainValue.compareTo(plainValue) == 0);
|
|
|
|
|
2021-03-03 17:18:36 +01:00
|
|
|
boolean deleted = resourceManagement.delete();
|
|
|
|
Assert.assertTrue(deleted);
|
2019-02-13 12:33:29 +01:00
|
|
|
}
|
2021-03-02 16:55:42 +01:00
|
|
|
|
2019-02-13 12:33:29 +01:00
|
|
|
@Test
|
|
|
|
public void testCreatePropertyTypeNotInSchema() throws Exception {
|
2021-03-03 17:18:36 +01:00
|
|
|
/*
|
|
|
|
* 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();
|
|
|
|
|
2019-02-13 12:33:29 +01:00
|
|
|
AccessPointFacet accessPointFacet = new AccessPointFacetImpl();
|
2021-02-22 09:46:00 +01:00
|
|
|
accessPointFacet.setEndpoint(new URI("https://localhost"));
|
2019-02-13 12:33:29 +01:00
|
|
|
accessPointFacet.setEntryName("port1");
|
|
|
|
|
|
|
|
ValueSchema authorization = new ValueSchemaImpl();
|
|
|
|
authorization.setValue("pwd");
|
2021-02-22 09:46:00 +01:00
|
|
|
URI uri = new URI("https://www.gcube-system.org");
|
2020-12-21 23:09:57 +01:00
|
|
|
authorization.setSchema(uri);
|
2019-02-13 12:33:29 +01:00
|
|
|
accessPointFacet.setAuthorization(authorization);
|
2021-03-02 16:55:42 +01:00
|
|
|
|
2021-03-03 17:18:36 +01:00
|
|
|
String additionlaPropertyKey = "Test";
|
|
|
|
String additionlaPropertyValue = "MyTest";
|
|
|
|
accessPointFacet.setAdditionalProperty(additionlaPropertyKey, additionlaPropertyValue);
|
2021-03-02 16:55:42 +01:00
|
|
|
|
2019-02-13 12:33:29 +01:00
|
|
|
Encrypted encrypted = new EncryptedImpl();
|
2021-03-03 17:18:36 +01:00
|
|
|
String plainValue = "Encrypted";
|
|
|
|
String encryptedValue = EncryptedImpl.encrypt(plainValue);
|
2019-02-13 12:33:29 +01:00
|
|
|
encrypted.setEncryptedValue(encryptedValue);
|
2021-03-03 17:18:36 +01:00
|
|
|
String encryptedKey = "Enc";
|
|
|
|
accessPointFacet.setAdditionalProperty(encryptedKey, encrypted);
|
|
|
|
|
|
|
|
configuration.addFacet(accessPointFacet);
|
2021-03-02 16:55:42 +01:00
|
|
|
|
2021-03-03 17:18:36 +01:00
|
|
|
String marshalled = ElementMapper.marshal(configuration);
|
2019-02-13 12:33:29 +01:00
|
|
|
logger.debug(marshalled);
|
2021-03-02 16:55:42 +01:00
|
|
|
|
2021-03-03 17:18:36 +01:00
|
|
|
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);
|
2021-03-02 16:55:42 +01:00
|
|
|
|
2021-03-03 17:18:36 +01:00
|
|
|
AccessPointFacet apf = configuration.getFacets(AccessPointFacet.class).get(0);
|
|
|
|
|
2019-02-13 12:33:29 +01:00
|
|
|
Assert.assertTrue(apf.getAuthorization() instanceof ValueSchema);
|
2021-03-03 17:18:36 +01:00
|
|
|
Assert.assertTrue(apf.getAdditionalProperty(encryptedKey) instanceof Encrypted);
|
|
|
|
Encrypted enc = (Encrypted) apf.getAdditionalProperty(encryptedKey);
|
2019-02-13 12:33:29 +01:00
|
|
|
String encValue = enc.getEncryptedValue();
|
2021-03-02 16:55:42 +01:00
|
|
|
Assert.assertTrue(encValue.compareTo(encryptedValue) == 0);
|
2019-02-13 12:33:29 +01:00
|
|
|
String decryptedValue = EncryptedImpl.decrypt(encValue);
|
2021-03-03 17:18:36 +01:00
|
|
|
Assert.assertTrue(decryptedValue.compareTo(plainValue) == 0);
|
|
|
|
Assert.assertTrue(((String) apf.getAdditionalProperty(additionlaPropertyKey)).compareTo(additionlaPropertyValue) == 0);
|
2021-03-02 16:55:42 +01:00
|
|
|
|
2021-03-03 17:18:36 +01:00
|
|
|
boolean deleted = resourceManagement.delete();
|
2019-02-13 12:33:29 +01:00
|
|
|
Assert.assertTrue(deleted);
|
|
|
|
}
|
2021-03-02 16:55:42 +01:00
|
|
|
|
2021-01-29 16:13:33 +01:00
|
|
|
|
2021-03-02 16:55:42 +01:00
|
|
|
|
2016-12-19 14:59:27 +01:00
|
|
|
@Test
|
|
|
|
public void testCreateEService() throws Exception {
|
2021-03-02 16:55:42 +01:00
|
|
|
EService eService = ERManagementTest.instantiateValidEService();
|
2016-12-19 14:59:27 +01:00
|
|
|
|
|
|
|
ResourceManagement resourceManagement = new ResourceManagement();
|
2016-12-30 17:31:12 +01:00
|
|
|
resourceManagement.setElementType(EService.NAME);
|
2020-02-03 10:52:09 +01:00
|
|
|
resourceManagement.setJson(ElementMapper.marshal(eService));
|
2016-12-19 14:59:27 +01:00
|
|
|
|
|
|
|
String json = resourceManagement.create();
|
|
|
|
logger.debug("Created : {}", json);
|
2020-02-03 10:52:09 +01:00
|
|
|
eService = ElementMapper.unmarshal(EService.class, json);
|
2016-12-19 14:59:27 +01:00
|
|
|
logger.debug("Unmarshalled {} {}", EService.NAME, eService);
|
|
|
|
|
|
|
|
resourceManagement = new ResourceManagement();
|
|
|
|
resourceManagement.setUUID(eService.getHeader().getUUID());
|
2021-03-02 16:55:42 +01:00
|
|
|
|
2016-12-19 14:59:27 +01:00
|
|
|
boolean deleted = resourceManagement.delete();
|
|
|
|
Assert.assertTrue(deleted);
|
|
|
|
}
|
2021-03-02 16:55:42 +01:00
|
|
|
|
2021-03-03 17:18:36 +01:00
|
|
|
/*
|
|
|
|
@Test
|
2017-03-29 16:14:03 +02:00
|
|
|
public void testReadResource() throws Exception {
|
|
|
|
ResourceManagement resourceManagement = new ResourceManagement();
|
|
|
|
resourceManagement.setUUID(UUID.fromString("26da57ee-33bd-4c4b-8aef-9206b61c329e"));
|
2021-03-02 16:55:42 +01:00
|
|
|
String read = resourceManagement.read().toString();
|
2017-03-29 16:14:03 +02:00
|
|
|
logger.debug(read);
|
|
|
|
}
|
2021-03-03 17:18:36 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
@Test
|
2016-12-19 14:59:27 +01:00
|
|
|
public void testDeleteResource() throws Exception {
|
|
|
|
ResourceManagement resourceManagement = new ResourceManagement();
|
2021-03-02 16:55:42 +01:00
|
|
|
resourceManagement.setUUID(UUID.fromString("64635295-7ced-4931-a55f-40fc8199b280"));
|
2016-12-19 14:59:27 +01:00
|
|
|
boolean deleted = resourceManagement.delete();
|
|
|
|
Assert.assertTrue(deleted);
|
|
|
|
}
|
2021-03-03 17:18:36 +01:00
|
|
|
*/
|
2021-03-02 16:55:42 +01:00
|
|
|
|
2016-12-19 14:59:27 +01:00
|
|
|
@Test
|
|
|
|
public void testCreateHostingNodeAndEService() throws Exception {
|
2021-03-03 17:18:36 +01:00
|
|
|
Map<String, Resource> map = ERManagementTest.createHostingNodeAndEService();
|
2021-03-02 16:55:42 +01:00
|
|
|
|
2016-12-19 14:59:27 +01:00
|
|
|
ResourceManagement resourceManagement = new ResourceManagement();
|
|
|
|
resourceManagement.setUUID(map.get(EService.NAME).getHeader().getUUID());
|
|
|
|
boolean deleted = resourceManagement.delete();
|
|
|
|
Assert.assertTrue(deleted);
|
2021-03-02 16:55:42 +01:00
|
|
|
|
2016-12-19 14:59:27 +01:00
|
|
|
resourceManagement = new ResourceManagement();
|
|
|
|
resourceManagement.setUUID(map.get(HostingNode.NAME).getHeader().getUUID());
|
|
|
|
deleted = resourceManagement.delete();
|
|
|
|
Assert.assertTrue(deleted);
|
|
|
|
}
|
2021-03-02 16:55:42 +01:00
|
|
|
|
2017-11-17 11:42:37 +01:00
|
|
|
@Test
|
|
|
|
public void testCreateConsistsOfBeetweenResources() throws Exception {
|
2021-03-03 17:18:36 +01:00
|
|
|
Map<String, Resource> map = ERManagementTest.createHostingNodeAndEService();
|
2021-03-02 16:55:42 +01:00
|
|
|
|
2017-11-17 11:42:37 +01:00
|
|
|
UUID hostingNodeUUID = map.get(HostingNode.NAME).getHeader().getUUID();
|
|
|
|
UUID eServiceUUID = map.get(EService.NAME).getHeader().getUUID();
|
2021-03-02 16:55:42 +01:00
|
|
|
|
2017-11-17 11:42:37 +01:00
|
|
|
HostingNode hostingNode = new HostingNodeImpl();
|
|
|
|
hostingNode.setHeader(new HeaderImpl(hostingNodeUUID));
|
2021-03-02 16:55:42 +01:00
|
|
|
|
2017-11-17 11:42:37 +01:00
|
|
|
SimpleFacet fakeEServiceAsSimpleFacet = new SimpleFacetImpl();
|
|
|
|
fakeEServiceAsSimpleFacet.setHeader(new HeaderImpl(eServiceUUID));
|
2021-03-02 16:55:42 +01:00
|
|
|
|
2021-03-03 17:18:36 +01:00
|
|
|
ConsistsOf<HostingNode, SimpleFacet> consistsOf = new ConsistsOfImpl<HostingNode, SimpleFacet>(hostingNode, fakeEServiceAsSimpleFacet);
|
2021-03-02 16:55:42 +01:00
|
|
|
|
2017-11-17 11:42:37 +01:00
|
|
|
try {
|
|
|
|
ConsistsOfManagement consistsOfManagement = new ConsistsOfManagement();
|
2020-02-03 10:52:09 +01:00
|
|
|
String json = ElementMapper.marshal(consistsOf);
|
2017-11-17 11:42:37 +01:00
|
|
|
json = json.replaceAll(SimpleFacet.NAME, EService.NAME);
|
2021-03-02 16:55:42 +01:00
|
|
|
|
2019-02-13 12:33:29 +01:00
|
|
|
consistsOfManagement.setJson(json);
|
2021-03-02 16:55:42 +01:00
|
|
|
|
2017-11-17 11:42:37 +01:00
|
|
|
consistsOfManagement.create();
|
|
|
|
logger.debug("The creation terminated correctly. This should not happen");
|
2021-03-02 16:55:42 +01:00
|
|
|
|
2017-11-17 11:42:37 +01:00
|
|
|
} 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);
|
|
|
|
boolean deleted = resourceManagement.delete();
|
|
|
|
Assert.assertTrue(deleted);
|
2021-03-02 16:55:42 +01:00
|
|
|
|
2017-11-17 11:42:37 +01:00
|
|
|
resourceManagement = new ResourceManagement();
|
|
|
|
resourceManagement.setUUID(hostingNodeUUID);
|
|
|
|
deleted = resourceManagement.delete();
|
|
|
|
Assert.assertTrue(deleted);
|
|
|
|
}
|
2021-03-02 16:55:42 +01:00
|
|
|
|
2017-11-17 11:42:37 +01:00
|
|
|
}
|
2021-03-02 16:55:42 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* @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); }
|
|
|
|
*/
|
2016-12-19 14:59:27 +01:00
|
|
|
|
2017-01-11 17:11:28 +01:00
|
|
|
@Test
|
2021-03-02 16:55:42 +01:00
|
|
|
public void testGetAll() throws Exception {
|
2017-01-11 17:11:28 +01:00
|
|
|
Map<String, List<Resource>> resources = new HashMap<>();
|
2021-03-02 16:55:42 +01:00
|
|
|
|
2017-01-11 17:11:28 +01:00
|
|
|
final int MAX = 5;
|
|
|
|
int typeNumber = 0;
|
2021-03-02 16:55:42 +01:00
|
|
|
|
|
|
|
for (int i = 0; i < MAX; i++) {
|
2021-03-03 17:18:36 +01:00
|
|
|
Map<String, Resource> map = ERManagementTest.createHostingNodeAndEService();
|
2021-03-02 16:55:42 +01:00
|
|
|
if (typeNumber == 0) {
|
2017-01-11 17:11:28 +01:00
|
|
|
typeNumber = map.size();
|
|
|
|
}
|
2021-03-02 16:55:42 +01:00
|
|
|
for (String key : map.keySet()) {
|
|
|
|
if (!resources.containsKey(key)) {
|
2017-01-11 17:11:28 +01:00
|
|
|
resources.put(key, new ArrayList<Resource>());
|
|
|
|
}
|
|
|
|
resources.get(key).add(map.get(key));
|
|
|
|
}
|
|
|
|
}
|
2021-03-02 16:55:42 +01:00
|
|
|
|
|
|
|
/* Getting all instances of created specific Resources */
|
|
|
|
for (String key : resources.keySet()) {
|
2020-01-30 11:04:16 +01:00
|
|
|
ResourceManagement resourceManagement = (ResourceManagement) ElementManagementUtility.getERManagement(key);
|
2017-01-11 17:11:28 +01:00
|
|
|
String json = resourceManagement.all(false);
|
2021-03-02 16:55:42 +01:00
|
|
|
|
2020-02-03 10:52:09 +01:00
|
|
|
List<Resource> list = ElementMapper.unmarshalList(Resource.class, json);
|
2017-01-11 17:12:00 +01:00
|
|
|
logger.debug("{} are {} : {} ", key, list.size(), list);
|
2021-03-02 16:55:42 +01:00
|
|
|
Assert.assertTrue(list.size() == MAX);
|
2017-01-11 17:11:28 +01:00
|
|
|
}
|
2021-03-02 16:55:42 +01:00
|
|
|
|
2017-01-11 17:11:28 +01:00
|
|
|
/* Getting all Resources polymorphic and non polymorphic */
|
2021-03-02 16:55:42 +01:00
|
|
|
|
|
|
|
ResourceManagement resourceManagement = (ResourceManagement) ElementManagementUtility
|
|
|
|
.getERManagement(Resource.NAME);
|
|
|
|
|
2017-01-11 17:11:28 +01:00
|
|
|
String json = resourceManagement.all(true);
|
2020-02-03 10:52:09 +01:00
|
|
|
List<Resource> list = ElementMapper.unmarshalList(Resource.class, json);
|
2017-01-11 17:12:00 +01:00
|
|
|
logger.debug("{} are {} : {} ", Resource.NAME, list.size(), list);
|
2021-03-02 16:55:42 +01:00
|
|
|
Assert.assertTrue(list.size() == (MAX * typeNumber));
|
|
|
|
|
2017-01-11 17:11:28 +01:00
|
|
|
json = resourceManagement.all(false);
|
2020-02-03 10:52:09 +01:00
|
|
|
list = ElementMapper.unmarshalList(Resource.class, json);
|
2021-03-02 16:55:42 +01:00
|
|
|
Assert.assertTrue(list.size() == 0);
|
|
|
|
|
2017-01-11 17:11:28 +01:00
|
|
|
/* Getting all IsRelatedTo polymorphic and non polymorphic */
|
2021-03-02 16:55:42 +01:00
|
|
|
|
|
|
|
IsRelatedToManagement isRelatedToManagement = (IsRelatedToManagement) ElementManagementUtility
|
|
|
|
.getERManagement(IsRelatedTo.NAME);
|
|
|
|
|
2017-01-11 17:11:28 +01:00
|
|
|
json = isRelatedToManagement.all(true);
|
|
|
|
|
2020-02-03 10:52:09 +01:00
|
|
|
List<Resource> resourcesList = ElementMapper.unmarshalList(Resource.class, json);
|
2017-01-13 17:06:57 +01:00
|
|
|
logger.debug("{} are {} : {} ", IsRelatedTo.NAME, resourcesList.size(), resourcesList);
|
2021-03-02 16:55:42 +01:00
|
|
|
Assert.assertTrue(resourcesList.size() == MAX);
|
2017-01-11 17:11:28 +01:00
|
|
|
|
|
|
|
json = isRelatedToManagement.all(false);
|
2020-02-03 10:52:09 +01:00
|
|
|
resourcesList = ElementMapper.unmarshalList(Resource.class, json);
|
2021-03-02 16:55:42 +01:00
|
|
|
Assert.assertTrue(resourcesList.size() == 0);
|
|
|
|
|
2017-01-11 17:11:28 +01:00
|
|
|
/* Getting all ConsistsOf polymorphic and non polymorphic */
|
2021-03-02 16:55:42 +01:00
|
|
|
|
|
|
|
ConsistsOfManagement consistsOfManagement = (ConsistsOfManagement) ElementManagementUtility
|
|
|
|
.getERManagement(ConsistsOf.NAME);
|
|
|
|
|
2017-01-11 17:11:28 +01:00
|
|
|
json = consistsOfManagement.all(true);
|
2020-02-03 10:52:09 +01:00
|
|
|
List<Resource> consistsOfPolimorphicList = ElementMapper.unmarshalList(Resource.class, json);
|
2017-01-11 17:12:00 +01:00
|
|
|
logger.debug("{} are {} : {} ", IsRelatedTo.NAME, consistsOfPolimorphicList.size(), consistsOfPolimorphicList);
|
2017-01-11 17:11:28 +01:00
|
|
|
|
|
|
|
json = consistsOfManagement.all(false);
|
2020-02-03 10:52:09 +01:00
|
|
|
List<Resource> consistsOfNonPolimorphicList = ElementMapper.unmarshalList(Resource.class, json);
|
2021-03-02 16:55:42 +01:00
|
|
|
logger.debug("{} are {} : {} ", IsRelatedTo.NAME, consistsOfNonPolimorphicList.size(),
|
|
|
|
consistsOfNonPolimorphicList);
|
|
|
|
|
|
|
|
Assert.assertTrue(consistsOfPolimorphicList.size() >= consistsOfNonPolimorphicList.size());
|
|
|
|
|
2017-01-11 18:00:21 +01:00
|
|
|
/* Removing created Entity and Relation to have a clean DB */
|
2021-03-02 16:55:42 +01:00
|
|
|
|
2017-01-11 18:00:21 +01:00
|
|
|
List<Resource> resourceList = resources.get(HostingNode.NAME);
|
2021-03-02 16:55:42 +01:00
|
|
|
for (Resource r : resourceList) {
|
2017-01-11 17:11:28 +01:00
|
|
|
resourceManagement = new ResourceManagement();
|
|
|
|
resourceManagement.setUUID(r.getHeader().getUUID());
|
2017-01-13 17:56:28 +01:00
|
|
|
boolean deleted = resourceManagement.delete();
|
|
|
|
Assert.assertTrue(deleted);
|
2017-01-11 17:11:28 +01:00
|
|
|
}
|
|
|
|
}
|
2021-03-02 16:55:42 +01:00
|
|
|
|
2017-01-12 11:13:09 +01:00
|
|
|
@Test
|
2021-03-02 16:55:42 +01:00
|
|
|
public void testGetAllFrom() throws Exception {
|
|
|
|
|
2021-03-03 17:18:36 +01:00
|
|
|
Map<String, Resource> map = ERManagementTest.createHostingNodeAndEService();
|
2021-03-02 16:55:42 +01:00
|
|
|
|
2017-01-12 11:13:09 +01:00
|
|
|
EService eService = (EService) map.get(EService.NAME);
|
2017-01-13 17:06:57 +01:00
|
|
|
UUID eServiceUUID = eService.getHeader().getUUID();
|
2021-03-02 16:55:42 +01:00
|
|
|
|
2017-01-12 11:13:09 +01:00
|
|
|
HostingNode hostingNode = (HostingNode) map.get(HostingNode.NAME);
|
2017-01-13 17:06:57 +01:00
|
|
|
UUID hostingNodeUUID = hostingNode.getHeader().getUUID();
|
2021-03-02 16:55:42 +01:00
|
|
|
|
2018-06-08 15:05:47 +02:00
|
|
|
ResourceManagement resourceManagement = new ResourceManagement();
|
|
|
|
resourceManagement.setElementType(Service.NAME);
|
2021-03-02 16:55:42 +01:00
|
|
|
|
2021-01-28 22:53:10 +01:00
|
|
|
boolean includeRelation = false;
|
2021-03-02 16:55:42 +01:00
|
|
|
|
2018-06-08 15:05:47 +02:00
|
|
|
/* Getting Hosting Node */
|
2021-03-02 16:55:42 +01:00
|
|
|
String json = resourceManagement.query(IsRelatedTo.NAME, EService.NAME, eServiceUUID, ODirection.BOTH, true,
|
|
|
|
null, includeRelation);
|
2020-02-03 10:52:09 +01:00
|
|
|
List<Resource> resourceList = ElementMapper.unmarshalList(Resource.class, json);
|
2021-03-02 16:55:42 +01:00
|
|
|
Assert.assertTrue(resourceList.size() == 1);
|
2018-06-08 18:18:48 +02:00
|
|
|
Resource resource = resourceList.get(0);
|
2021-03-02 16:55:42 +01:00
|
|
|
Assert.assertTrue(resource.getHeader().getUUID().compareTo(hostingNodeUUID) == 0);
|
|
|
|
|
|
|
|
json = resourceManagement.query(IsRelatedTo.NAME, EService.NAME, eServiceUUID, ODirection.OUT, true, null,
|
|
|
|
includeRelation);
|
2020-02-03 10:52:09 +01:00
|
|
|
resourceList = ElementMapper.unmarshalList(Resource.class, json);
|
2021-03-02 16:55:42 +01:00
|
|
|
Assert.assertTrue(resourceList.size() == 1);
|
2018-06-08 18:18:48 +02:00
|
|
|
resource = resourceList.get(0);
|
2021-03-02 16:55:42 +01:00
|
|
|
Assert.assertTrue(resource.getHeader().getUUID().compareTo(hostingNodeUUID) == 0);
|
|
|
|
|
|
|
|
json = resourceManagement.query(IsRelatedTo.NAME, EService.NAME, eServiceUUID, ODirection.IN, true, null,
|
|
|
|
includeRelation);
|
2020-02-03 10:52:09 +01:00
|
|
|
resourceList = ElementMapper.unmarshalList(Resource.class, json);
|
2021-03-02 16:55:42 +01:00
|
|
|
Assert.assertTrue(resourceList.size() == 0);
|
|
|
|
|
|
|
|
json = resourceManagement.query(IsRelatedTo.NAME, EService.NAME, eServiceUUID, ODirection.BOTH, false, null,
|
|
|
|
includeRelation);
|
2020-02-03 10:52:09 +01:00
|
|
|
resourceList = ElementMapper.unmarshalList(Resource.class, json);
|
2021-03-02 16:55:42 +01:00
|
|
|
Assert.assertTrue(resourceList.size() == 0);
|
|
|
|
json = resourceManagement.query(IsRelatedTo.NAME, EService.NAME, eServiceUUID, ODirection.OUT, false, null,
|
|
|
|
includeRelation);
|
2020-02-03 10:52:09 +01:00
|
|
|
resourceList = ElementMapper.unmarshalList(Resource.class, json);
|
2021-03-02 16:55:42 +01:00
|
|
|
Assert.assertTrue(resourceList.size() == 0);
|
|
|
|
json = resourceManagement.query(IsRelatedTo.NAME, EService.NAME, eServiceUUID, ODirection.IN, false, null,
|
|
|
|
includeRelation);
|
2020-02-03 10:52:09 +01:00
|
|
|
resourceList = ElementMapper.unmarshalList(Resource.class, json);
|
2021-03-02 16:55:42 +01:00
|
|
|
Assert.assertTrue(resourceList.size() == 0);
|
2018-06-08 15:05:47 +02:00
|
|
|
/* END Getting Hosting Node */
|
|
|
|
|
|
|
|
/* Getting EService */
|
2021-03-02 16:55:42 +01:00
|
|
|
json = resourceManagement.query(IsRelatedTo.NAME, HostingNode.NAME, hostingNodeUUID, ODirection.BOTH, true,
|
|
|
|
null, includeRelation);
|
2020-02-03 10:52:09 +01:00
|
|
|
resourceList = ElementMapper.unmarshalList(Resource.class, json);
|
2021-03-02 16:55:42 +01:00
|
|
|
Assert.assertTrue(resourceList.size() == 1);
|
|
|
|
Assert.assertTrue(resourceList.get(0).getHeader().getUUID().compareTo(eServiceUUID) == 0);
|
|
|
|
|
|
|
|
json = resourceManagement.query(IsRelatedTo.NAME, HostingNode.NAME, hostingNodeUUID, ODirection.OUT, true, null,
|
|
|
|
includeRelation);
|
2020-02-03 10:52:09 +01:00
|
|
|
resourceList = ElementMapper.unmarshalList(Resource.class, json);
|
2021-03-02 16:55:42 +01:00
|
|
|
Assert.assertTrue(resourceList.size() == 0);
|
|
|
|
|
|
|
|
json = resourceManagement.query(IsRelatedTo.NAME, HostingNode.NAME, hostingNodeUUID, ODirection.IN, true, null,
|
|
|
|
includeRelation);
|
2020-02-03 10:52:09 +01:00
|
|
|
resourceList = ElementMapper.unmarshalList(Resource.class, json);
|
2021-03-02 16:55:42 +01:00
|
|
|
Assert.assertTrue(resourceList.size() == 1);
|
|
|
|
Assert.assertTrue(resourceList.get(0).getHeader().getUUID().compareTo(eServiceUUID) == 0);
|
|
|
|
|
|
|
|
json = resourceManagement.query(IsRelatedTo.NAME, HostingNode.NAME, hostingNodeUUID, ODirection.BOTH, false,
|
|
|
|
null, includeRelation);
|
2020-02-03 10:52:09 +01:00
|
|
|
resourceList = ElementMapper.unmarshalList(Resource.class, json);
|
2021-03-02 16:55:42 +01:00
|
|
|
Assert.assertTrue(resourceList.size() == 0);
|
|
|
|
|
|
|
|
json = resourceManagement.query(IsRelatedTo.NAME, HostingNode.NAME, hostingNodeUUID, ODirection.OUT, false,
|
|
|
|
null, includeRelation);
|
2020-02-03 10:52:09 +01:00
|
|
|
resourceList = ElementMapper.unmarshalList(Resource.class, json);
|
2021-03-02 16:55:42 +01:00
|
|
|
Assert.assertTrue(resourceList.size() == 0);
|
|
|
|
|
|
|
|
json = resourceManagement.query(IsRelatedTo.NAME, HostingNode.NAME, hostingNodeUUID, ODirection.IN, false, null,
|
|
|
|
includeRelation);
|
2020-02-03 10:52:09 +01:00
|
|
|
resourceList = ElementMapper.unmarshalList(Resource.class, json);
|
2021-03-02 16:55:42 +01:00
|
|
|
Assert.assertTrue(resourceList.size() == 0);
|
2018-06-08 15:05:47 +02:00
|
|
|
/* END Getting HostingNode */
|
2021-03-02 16:55:42 +01:00
|
|
|
|
2017-01-13 17:06:57 +01:00
|
|
|
Facet identificationFacet = eService.getIdentificationFacets().get(0);
|
|
|
|
UUID identificationFacetUUID = identificationFacet.getHeader().getUUID();
|
2021-03-02 16:55:42 +01:00
|
|
|
|
|
|
|
/* EService --ConsistsOf--> SoftwareFacet */
|
2018-06-08 15:05:47 +02:00
|
|
|
try {
|
2021-03-02 16:55:42 +01:00
|
|
|
json = resourceManagement.query(ConsistsOf.NAME, SoftwareFacet.NAME, identificationFacetUUID,
|
|
|
|
ODirection.BOTH, true, null, includeRelation);
|
|
|
|
} catch (InvalidQueryException e) {
|
2018-06-08 15:05:47 +02:00
|
|
|
// Ok expected
|
|
|
|
}
|
2021-03-02 16:55:42 +01:00
|
|
|
|
|
|
|
json = resourceManagement.query(ConsistsOf.NAME, SoftwareFacet.NAME, identificationFacetUUID, ODirection.OUT,
|
|
|
|
true, null, includeRelation);
|
2020-02-03 10:52:09 +01:00
|
|
|
resourceList = ElementMapper.unmarshalList(Resource.class, json);
|
2021-03-02 16:55:42 +01:00
|
|
|
Assert.assertTrue(resourceList.size() == 1);
|
2018-06-08 18:18:48 +02:00
|
|
|
resource = resourceList.get(0);
|
2019-12-05 12:09:23 +01:00
|
|
|
Facet targetIdentificationFacet = ((GCubeResource) resource).getIdentificationFacets().get(0);
|
2021-03-02 16:55:42 +01:00
|
|
|
Assert.assertTrue(resource.getHeader().getUUID().compareTo(eServiceUUID) == 0);
|
|
|
|
Assert.assertTrue(targetIdentificationFacet.getHeader().getUUID().compareTo(identificationFacetUUID) == 0);
|
|
|
|
|
2018-06-08 15:05:47 +02:00
|
|
|
try {
|
2021-03-02 16:55:42 +01:00
|
|
|
json = resourceManagement.query(ConsistsOf.NAME, SoftwareFacet.NAME, identificationFacetUUID, ODirection.IN,
|
|
|
|
true, null, includeRelation);
|
|
|
|
} catch (InvalidQueryException e) {
|
2018-06-08 15:05:47 +02:00
|
|
|
// Ok expected
|
|
|
|
}
|
2021-03-02 16:55:42 +01:00
|
|
|
|
2018-06-08 15:05:47 +02:00
|
|
|
try {
|
2021-03-02 16:55:42 +01:00
|
|
|
json = resourceManagement.query(ConsistsOf.NAME, SoftwareFacet.NAME, identificationFacetUUID,
|
|
|
|
ODirection.BOTH, false, null, includeRelation);
|
|
|
|
} catch (InvalidQueryException e) {
|
2018-06-08 15:05:47 +02:00
|
|
|
// Ok expected
|
|
|
|
}
|
2021-03-02 16:55:42 +01:00
|
|
|
|
|
|
|
json = resourceManagement.query(ConsistsOf.NAME, SoftwareFacet.NAME, identificationFacetUUID, ODirection.OUT,
|
|
|
|
false, null, includeRelation);
|
2020-02-03 10:52:09 +01:00
|
|
|
resourceList = ElementMapper.unmarshalList(Resource.class, json);
|
2021-03-02 16:55:42 +01:00
|
|
|
Assert.assertTrue(resourceList.size() == 0);
|
|
|
|
|
2018-06-08 15:05:47 +02:00
|
|
|
try {
|
2021-03-02 16:55:42 +01:00
|
|
|
json = resourceManagement.query(ConsistsOf.NAME, SoftwareFacet.NAME, identificationFacetUUID, ODirection.IN,
|
|
|
|
false, null, includeRelation);
|
|
|
|
} catch (InvalidQueryException e) {
|
2018-06-08 15:05:47 +02:00
|
|
|
// Ok expected
|
|
|
|
}
|
2021-03-02 16:55:42 +01:00
|
|
|
|
|
|
|
/* END EService --ConsistsOf--> SoftwareFacet */
|
|
|
|
|
2017-01-12 11:13:09 +01:00
|
|
|
/* Removing created Entity and Relation to have a clean DB */
|
2018-06-08 15:05:47 +02:00
|
|
|
resourceManagement = new ResourceManagement();
|
2017-01-12 11:13:09 +01:00
|
|
|
resourceManagement.setUUID(hostingNode.getHeader().getUUID());
|
2017-01-13 17:56:28 +01:00
|
|
|
boolean deleted = resourceManagement.delete();
|
|
|
|
Assert.assertTrue(deleted);
|
2021-03-02 16:55:42 +01:00
|
|
|
|
2017-01-12 11:13:09 +01:00
|
|
|
}
|
2021-03-02 16:55:42 +01:00
|
|
|
|
2017-06-16 11:23:03 +02:00
|
|
|
public static final String TEST_RESOURCE = "test-resource.json";
|
2021-03-02 16:55:42 +01:00
|
|
|
|
|
|
|
// @Test
|
|
|
|
public void testUpdateResourceFromFile()
|
|
|
|
throws JsonParseException, JsonMappingException, IOException, ResourceRegistryException {
|
2017-06-16 11:23:03 +02:00
|
|
|
File file = new File("src/test/resources/" + TEST_RESOURCE);
|
2021-03-02 16:55:42 +01:00
|
|
|
|
2017-06-16 11:23:03 +02:00
|
|
|
logger.debug("{}", file.getAbsolutePath());
|
2021-03-02 16:55:42 +01:00
|
|
|
|
2017-06-16 11:23:03 +02:00
|
|
|
FileInputStream fileInputStream = new FileInputStream(file);
|
2020-02-03 10:52:09 +01:00
|
|
|
EService eService = ElementMapper.unmarshal(EService.class, fileInputStream);
|
2021-03-02 16:55:42 +01:00
|
|
|
|
2017-06-16 11:23:03 +02:00
|
|
|
ResourceManagement resourceManagement = new ResourceManagement();
|
|
|
|
resourceManagement.setUUID(eService.getHeader().getUUID());
|
2020-02-03 10:52:09 +01:00
|
|
|
resourceManagement.setJson(ElementMapper.marshal(eService));
|
2021-03-02 16:55:42 +01:00
|
|
|
|
2017-06-16 11:23:03 +02:00
|
|
|
resourceManagement.update();
|
2021-03-02 16:55:42 +01:00
|
|
|
|
2017-06-16 11:23:03 +02:00
|
|
|
}
|
2021-03-02 16:55:42 +01:00
|
|
|
|
2017-06-16 11:23:03 +02:00
|
|
|
// @Test
|
2021-03-02 16:55:42 +01:00
|
|
|
public void readSingleResource()
|
|
|
|
throws ResourceRegistryException, JsonParseException, JsonMappingException, IOException {
|
2017-06-16 11:23:03 +02:00
|
|
|
UUID uuid = UUID.fromString("");
|
2021-03-02 16:55:42 +01:00
|
|
|
|
2017-06-16 11:23:03 +02:00
|
|
|
ResourceManagement resourceManagement = new ResourceManagement();
|
|
|
|
resourceManagement.setUUID(uuid);
|
2021-02-05 17:50:16 +01:00
|
|
|
String res = resourceManagement.read().toString();
|
2017-06-16 11:23:03 +02:00
|
|
|
logger.debug(res);
|
2021-03-02 16:55:42 +01:00
|
|
|
|
2020-02-03 10:52:09 +01:00
|
|
|
Configuration configuration = ElementMapper.unmarshal(Configuration.class, res);
|
2021-03-02 16:55:42 +01:00
|
|
|
|
2017-06-16 11:23:03 +02:00
|
|
|
resourceManagement = new ResourceManagement();
|
|
|
|
resourceManagement.setUUID(configuration.getHeader().getUUID());
|
2020-02-03 10:52:09 +01:00
|
|
|
resourceManagement.setJson(ElementMapper.marshal(configuration));
|
2021-03-02 16:55:42 +01:00
|
|
|
|
2017-06-16 11:23:03 +02:00
|
|
|
resourceManagement.update();
|
2021-03-02 16:55:42 +01:00
|
|
|
|
2017-06-16 11:23:03 +02:00
|
|
|
}
|
2021-03-02 16:55:42 +01:00
|
|
|
|
2017-10-05 11:44:18 +02:00
|
|
|
@Test
|
|
|
|
public void testCreateUpdateDeleteEService() throws Exception {
|
2021-03-02 16:55:42 +01:00
|
|
|
EService eService = ERManagementTest.instantiateValidEService();
|
2017-10-05 11:44:18 +02:00
|
|
|
|
|
|
|
ResourceManagement resourceManagement = new ResourceManagement();
|
|
|
|
resourceManagement.setElementType(EService.NAME);
|
2020-02-03 10:52:09 +01:00
|
|
|
resourceManagement.setJson(ElementMapper.marshal(eService));
|
2017-10-05 11:44:18 +02:00
|
|
|
String json = resourceManagement.create();
|
2021-03-02 16:55:42 +01:00
|
|
|
|
2017-10-05 11:44:18 +02:00
|
|
|
logger.trace("Created {}", json);
|
2021-03-02 16:55:42 +01:00
|
|
|
|
2020-02-03 10:52:09 +01:00
|
|
|
eService = ElementMapper.unmarshal(EService.class, json);
|
2017-11-17 18:42:30 +01:00
|
|
|
final String newVersion = "1.2.0";
|
|
|
|
eService.getFacets(SoftwareFacet.class).get(0).setVersion(newVersion);
|
2021-03-02 16:55:42 +01:00
|
|
|
|
2017-10-05 11:44:18 +02:00
|
|
|
resourceManagement = new ResourceManagement();
|
|
|
|
resourceManagement.setUUID(eService.getHeader().getUUID());
|
2020-02-03 10:52:09 +01:00
|
|
|
resourceManagement.setJson(ElementMapper.marshal(eService));
|
2021-03-02 16:55:42 +01:00
|
|
|
|
2017-10-05 11:44:18 +02:00
|
|
|
json = resourceManagement.update();
|
|
|
|
logger.trace("Updated {}", json);
|
2020-02-03 10:52:09 +01:00
|
|
|
eService = ElementMapper.unmarshal(EService.class, json);
|
2021-03-02 16:55:42 +01:00
|
|
|
|
|
|
|
Assert.assertTrue(eService.getFacets(SoftwareFacet.class).get(0).getVersion().compareTo(newVersion) == 0);
|
|
|
|
|
2017-10-05 11:44:18 +02:00
|
|
|
resourceManagement = new ResourceManagement();
|
|
|
|
resourceManagement.setUUID(eService.getHeader().getUUID());
|
2021-03-02 16:55:42 +01:00
|
|
|
|
2017-10-05 11:44:18 +02:00
|
|
|
boolean deleted = resourceManagement.delete();
|
|
|
|
Assert.assertTrue(deleted);
|
|
|
|
}
|
|
|
|
|
2016-12-19 14:59:27 +01:00
|
|
|
}
|