2017-01-13 18:00:56 +01:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
package org.gcube.informationsystem.resourceregistry.publisher;
|
|
|
|
|
|
|
|
import java.net.URI;
|
|
|
|
import java.net.URL;
|
|
|
|
import java.util.Calendar;
|
2021-07-05 17:31:42 +02:00
|
|
|
import java.util.Date;
|
2017-01-13 18:00:56 +01:00
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.UUID;
|
|
|
|
|
2023-02-27 15:11:02 +01:00
|
|
|
import org.gcube.common.encryption.encrypter.StringEncrypter;
|
2021-07-05 17:31:42 +02:00
|
|
|
import org.gcube.informationsystem.base.reference.Element;
|
|
|
|
import org.gcube.informationsystem.base.reference.IdentifiableElement;
|
2019-02-05 11:21:10 +01:00
|
|
|
import org.gcube.informationsystem.model.impl.properties.PropagationConstraintImpl;
|
2023-02-27 15:11:02 +01:00
|
|
|
import org.gcube.informationsystem.model.impl.properties.VaultImpl;
|
2019-02-06 10:01:35 +01:00
|
|
|
import org.gcube.informationsystem.model.impl.relations.ConsistsOfImpl;
|
|
|
|
import org.gcube.informationsystem.model.reference.entities.Facet;
|
|
|
|
import org.gcube.informationsystem.model.reference.entities.Resource;
|
2021-07-05 17:31:42 +02:00
|
|
|
import org.gcube.informationsystem.model.reference.properties.Header;
|
2019-02-05 11:21:10 +01:00
|
|
|
import org.gcube.informationsystem.model.reference.properties.PropagationConstraint;
|
|
|
|
import org.gcube.informationsystem.model.reference.properties.PropagationConstraint.AddConstraint;
|
|
|
|
import org.gcube.informationsystem.model.reference.properties.PropagationConstraint.RemoveConstraint;
|
2023-02-27 15:11:02 +01:00
|
|
|
import org.gcube.informationsystem.model.reference.properties.Vault;
|
2019-02-06 10:01:35 +01:00
|
|
|
import org.gcube.informationsystem.model.reference.relations.ConsistsOf;
|
2021-10-25 10:59:52 +02:00
|
|
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.entities.resource.ResourceNotFoundException;
|
2023-02-10 14:32:45 +01:00
|
|
|
import org.gcube.informationsystem.serialization.ElementMapper;
|
2019-02-06 10:18:06 +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-07-05 17:31:42 +02:00
|
|
|
import org.gcube.resourcemanagement.model.impl.entities.facets.IdentifierFacetImpl;
|
2019-02-06 10:18:06 +01:00
|
|
|
import org.gcube.resourcemanagement.model.impl.entities.facets.LicenseFacetImpl;
|
2021-07-05 17:31:42 +02:00
|
|
|
import org.gcube.resourcemanagement.model.impl.entities.facets.MemoryFacetImpl;
|
2019-02-06 10:18:06 +01:00
|
|
|
import org.gcube.resourcemanagement.model.impl.entities.facets.NetworkingFacetImpl;
|
|
|
|
import org.gcube.resourcemanagement.model.impl.entities.facets.SoftwareFacetImpl;
|
2020-12-21 23:10:21 +01:00
|
|
|
import org.gcube.resourcemanagement.model.impl.entities.facets.StateFacetImpl;
|
2021-07-05 17:31:42 +02:00
|
|
|
import org.gcube.resourcemanagement.model.impl.entities.resources.ConfigurationImpl;
|
2019-02-06 10:18:06 +01:00
|
|
|
import org.gcube.resourcemanagement.model.impl.entities.resources.EServiceImpl;
|
|
|
|
import org.gcube.resourcemanagement.model.impl.entities.resources.HostingNodeImpl;
|
2020-12-21 23:10:21 +01:00
|
|
|
import org.gcube.resourcemanagement.model.impl.properties.ValueSchemaImpl;
|
2021-07-05 17:31:42 +02:00
|
|
|
import org.gcube.resourcemanagement.model.impl.relations.consistsof.HasPersistentMemoryImpl;
|
|
|
|
import org.gcube.resourcemanagement.model.impl.relations.consistsof.HasVolatileMemoryImpl;
|
2019-12-05 12:13:19 +01:00
|
|
|
import org.gcube.resourcemanagement.model.impl.relations.consistsof.IsIdentifiedByImpl;
|
2019-02-06 10:18:06 +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-07-05 17:31:42 +02:00
|
|
|
import org.gcube.resourcemanagement.model.reference.entities.facets.IdentifierFacet;
|
|
|
|
import org.gcube.resourcemanagement.model.reference.entities.facets.IdentifierFacet.IdentificationType;
|
2019-02-06 10:18:06 +01:00
|
|
|
import org.gcube.resourcemanagement.model.reference.entities.facets.LicenseFacet;
|
2021-07-05 17:31:42 +02:00
|
|
|
import org.gcube.resourcemanagement.model.reference.entities.facets.MemoryFacet;
|
|
|
|
import org.gcube.resourcemanagement.model.reference.entities.facets.MemoryFacet.MemoryUnit;
|
2019-02-06 10:18:06 +01:00
|
|
|
import org.gcube.resourcemanagement.model.reference.entities.facets.NetworkingFacet;
|
|
|
|
import org.gcube.resourcemanagement.model.reference.entities.facets.SoftwareFacet;
|
2020-12-21 23:10:21 +01:00
|
|
|
import org.gcube.resourcemanagement.model.reference.entities.facets.StateFacet;
|
2021-07-05 17:31:42 +02:00
|
|
|
import org.gcube.resourcemanagement.model.reference.entities.resources.Configuration;
|
2019-02-06 10:18:06 +01:00
|
|
|
import org.gcube.resourcemanagement.model.reference.entities.resources.EService;
|
|
|
|
import org.gcube.resourcemanagement.model.reference.entities.resources.HostingNode;
|
2020-12-21 23:10:21 +01:00
|
|
|
import org.gcube.resourcemanagement.model.reference.properties.ValueSchema;
|
2021-07-05 17:31:42 +02:00
|
|
|
import org.gcube.resourcemanagement.model.reference.relations.consistsof.HasPersistentMemory;
|
|
|
|
import org.gcube.resourcemanagement.model.reference.relations.consistsof.HasVolatileMemory;
|
2019-12-05 12:13:19 +01:00
|
|
|
import org.gcube.resourcemanagement.model.reference.relations.consistsof.IsIdentifiedBy;
|
2019-02-06 10:18:06 +01:00
|
|
|
import org.gcube.resourcemanagement.model.reference.relations.isrelatedto.Activates;
|
2021-07-05 17:31:42 +02:00
|
|
|
import org.junit.After;
|
2017-01-13 18:00:56 +01:00
|
|
|
import org.junit.Assert;
|
2021-07-05 17:31:42 +02:00
|
|
|
import org.junit.Before;
|
2017-01-13 18:00:56 +01:00
|
|
|
import org.junit.Test;
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @author Luca Frosini (ISTI - CNR)
|
|
|
|
*/
|
2019-02-13 12:23:10 +01:00
|
|
|
public class ERManagementTest extends ContextTest {
|
2021-07-05 17:31:42 +02:00
|
|
|
|
2017-10-03 17:48:37 +02:00
|
|
|
private static Logger logger = LoggerFactory.getLogger(ERManagementTest.class);
|
2018-06-12 10:02:31 +02:00
|
|
|
|
2021-07-05 17:31:42 +02:00
|
|
|
public static final String GROUP = "InformationSystem";
|
|
|
|
public static final String NAME = "resource-registry";
|
|
|
|
public static final String VERSION = "1.0.0";
|
|
|
|
public static final String NEW_VERSION = "2.0.0";
|
2019-02-12 18:05:48 +01:00
|
|
|
|
2017-01-13 18:00:56 +01:00
|
|
|
protected ResourceRegistryPublisher resourceRegistryPublisher;
|
2018-06-12 10:02:31 +02:00
|
|
|
|
2017-01-13 18:20:14 +01:00
|
|
|
public ERManagementTest() {
|
2022-07-25 11:14:50 +02:00
|
|
|
if(ContextTest.RESOURCE_REGISTRY_URL !=null && !ContextTest.RESOURCE_REGISTRY_URL.isEmpty()) {
|
|
|
|
resourceRegistryPublisher = new ResourceRegistryPublisherImpl(ContextTest.RESOURCE_REGISTRY_URL);
|
|
|
|
}else {
|
|
|
|
resourceRegistryPublisher = ResourceRegistryPublisherFactory.create();
|
|
|
|
}
|
2017-01-13 18:00:56 +01:00
|
|
|
}
|
2018-06-12 10:02:31 +02:00
|
|
|
|
2021-07-05 17:31:42 +02:00
|
|
|
|
|
|
|
@Before
|
|
|
|
@After
|
|
|
|
public void cleanInstances() throws Exception {
|
|
|
|
// Clean the environment first to avoid error if a previous tests fails without cleaning the env
|
|
|
|
List<Resource> allResources = resourceRegistryPublisher.list(Resource.class, true);
|
|
|
|
for(Resource r : allResources) {
|
2019-02-12 18:05:48 +01:00
|
|
|
try {
|
2021-07-05 17:31:42 +02:00
|
|
|
deleteResource(r);
|
|
|
|
}catch (ResourceNotFoundException e) {
|
|
|
|
// A resource could be already deleted deleting another resource giving the propagation constraint
|
2019-02-12 18:05:48 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-05 17:31:42 +02:00
|
|
|
|
|
|
|
public static SoftwareFacet getSoftwareFacet() {
|
2017-01-13 18:00:56 +01:00
|
|
|
SoftwareFacet softwareFacet = new SoftwareFacetImpl();
|
2021-07-05 17:31:42 +02:00
|
|
|
softwareFacet.setGroup(GROUP);
|
|
|
|
softwareFacet.setName(NAME);
|
|
|
|
softwareFacet.setVersion(VERSION);
|
|
|
|
return softwareFacet;
|
2017-01-13 18:00:56 +01:00
|
|
|
}
|
2018-06-12 10:02:31 +02:00
|
|
|
|
2021-07-05 17:31:42 +02:00
|
|
|
public static void checkSoftwareFacetAssertion(SoftwareFacet softwareFacet, SoftwareFacet gotSoftwareFacet) {
|
|
|
|
Assert.assertTrue(gotSoftwareFacet.getGroup().compareTo(softwareFacet.getGroup()) == 0);
|
|
|
|
Assert.assertTrue(gotSoftwareFacet.getName().compareTo(softwareFacet.getName()) == 0);
|
|
|
|
Assert.assertTrue(gotSoftwareFacet.getVersion().compareTo(softwareFacet.getVersion()) == 0);
|
2017-10-03 15:49:47 +02:00
|
|
|
}
|
2018-06-12 10:02:31 +02:00
|
|
|
|
2021-07-05 17:31:42 +02:00
|
|
|
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);
|
2018-06-12 10:02:31 +02:00
|
|
|
|
2021-07-05 17:31:42 +02:00
|
|
|
return configuration;
|
2017-10-03 15:49:47 +02:00
|
|
|
}
|
2018-06-12 10:02:31 +02:00
|
|
|
|
2021-07-05 17:31:42 +02:00
|
|
|
public static EService instantiateValidEService() throws Exception {
|
2017-10-03 15:49:47 +02:00
|
|
|
EService eService = new EServiceImpl();
|
2021-07-05 17:31:42 +02:00
|
|
|
|
|
|
|
SoftwareFacet softwareFacet = getSoftwareFacet();
|
|
|
|
|
|
|
|
IsIdentifiedBy<Resource, Facet> isIdentifiedBy = new IsIdentifiedByImpl<Resource, Facet>(eService,
|
|
|
|
softwareFacet, null);
|
2017-10-03 15:49:47 +02:00
|
|
|
eService.addFacet(isIdentifiedBy);
|
2021-07-05 17:31:42 +02:00
|
|
|
|
2017-10-03 15:49:47 +02:00
|
|
|
AccessPointFacet accessPointFacet = new AccessPointFacetImpl();
|
2021-02-22 09:47:26 +01:00
|
|
|
accessPointFacet.setEndpoint(new URI("https://localhost"));
|
2017-10-03 15:49:47 +02:00
|
|
|
accessPointFacet.setEntryName("port1");
|
|
|
|
eService.addFacet(accessPointFacet);
|
2021-07-05 17:31:42 +02:00
|
|
|
|
2017-10-03 15:49:47 +02:00
|
|
|
EventFacet eventFacet = new EventFacetImpl();
|
|
|
|
eventFacet.setDate(Calendar.getInstance().getTime());
|
2021-08-04 15:15:02 +02:00
|
|
|
eventFacet.setEvent("Created");
|
2017-10-03 15:49:47 +02:00
|
|
|
eService.addFacet(eventFacet);
|
2021-07-05 17:31:42 +02:00
|
|
|
|
2020-12-21 23:10:21 +01:00
|
|
|
StateFacet stateFacet = new StateFacetImpl();
|
|
|
|
stateFacet.setValue("ready");
|
|
|
|
eService.addFacet(stateFacet);
|
2021-07-05 17:31:42 +02:00
|
|
|
|
2017-10-03 15:49:47 +02:00
|
|
|
LicenseFacet licenseFacet = new LicenseFacetImpl();
|
|
|
|
licenseFacet.setName("EUPL");
|
2017-10-03 17:48:37 +02:00
|
|
|
licenseFacet.setTextURL(
|
|
|
|
new URL("https://joinup.ec.europa.eu/community/eupl/og_page/european-union-public-licence-eupl-v11"));
|
2017-10-03 15:49:47 +02:00
|
|
|
eService.addFacet(licenseFacet);
|
2021-07-05 17:31:42 +02:00
|
|
|
|
|
|
|
return eService;
|
2017-01-13 18:00:56 +01:00
|
|
|
}
|
2021-07-05 17:31:42 +02:00
|
|
|
|
|
|
|
public static HostingNode instantiateValidHostingNode() throws Exception {
|
|
|
|
HostingNode hostingNode = new HostingNodeImpl();
|
|
|
|
|
2017-01-13 18:00:56 +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");
|
2021-07-05 17:31:42 +02:00
|
|
|
|
|
|
|
IsIdentifiedBy<HostingNode, NetworkingFacet> isIdentifiedBy = new IsIdentifiedByImpl<HostingNode, NetworkingFacet>(
|
|
|
|
hostingNode, networkingFacet);
|
|
|
|
hostingNode.addFacet(isIdentifiedBy);
|
|
|
|
|
2017-01-13 18:00:56 +01:00
|
|
|
CPUFacet cpuFacet = new CPUFacetImpl();
|
|
|
|
cpuFacet.setClockSpeed("1 GHz");
|
|
|
|
cpuFacet.setModel("Opteron");
|
|
|
|
cpuFacet.setVendor("AMD");
|
|
|
|
hostingNode.addFacet(cpuFacet);
|
2021-07-05 17:31:42 +02:00
|
|
|
|
|
|
|
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());
|
2021-08-04 15:15:02 +02:00
|
|
|
hnEventFacet.setEvent("Created");
|
2021-07-05 17:31:42 +02:00
|
|
|
hostingNode.addFacet(hnEventFacet);
|
|
|
|
|
|
|
|
return hostingNode;
|
2017-01-13 18:00:56 +01:00
|
|
|
}
|
2018-06-12 10:02:31 +02:00
|
|
|
|
2021-07-05 17:31:42 +02:00
|
|
|
public static void checkHeader(IdentifiableElement identifiableElement, IdentifiableElement createdIdentifiableElement) {
|
|
|
|
Header createdHeader = createdIdentifiableElement.getHeader();
|
|
|
|
Assert.assertTrue(createdHeader!=null);
|
2018-06-12 10:02:31 +02:00
|
|
|
|
2021-07-05 17:31:42 +02:00
|
|
|
UUID createdUUID = createdHeader.getUUID();
|
|
|
|
Assert.assertTrue(createdUUID!=null);
|
2018-06-12 10:02:31 +02:00
|
|
|
|
2021-07-05 17:31:42 +02:00
|
|
|
String createdBy = createdHeader.getCreatedBy();
|
|
|
|
Assert.assertTrue(createdBy!=null);
|
2018-06-12 10:02:31 +02:00
|
|
|
|
2021-07-05 17:31:42 +02:00
|
|
|
String lastUpdateBy = createdHeader.getLastUpdateBy();
|
|
|
|
Assert.assertTrue(lastUpdateBy!=null);
|
2018-06-12 10:02:31 +02:00
|
|
|
|
2021-07-05 17:31:42 +02:00
|
|
|
Date creationTime = createdHeader.getCreationTime();
|
|
|
|
Assert.assertTrue(creationTime!=null);
|
2018-06-12 10:02:31 +02:00
|
|
|
|
2021-07-05 17:31:42 +02:00
|
|
|
Date lastUpdateTime = createdHeader.getLastUpdateTime();
|
|
|
|
Assert.assertTrue(lastUpdateTime!=null);
|
|
|
|
Assert.assertTrue(lastUpdateTime.equals(creationTime) || lastUpdateTime.equals(lastUpdateTime));
|
2018-06-12 10:02:31 +02:00
|
|
|
|
2021-07-05 17:31:42 +02:00
|
|
|
Header header = identifiableElement.getHeader();
|
|
|
|
if(header!=null) {
|
|
|
|
if(header.getUUID()!=null) {
|
|
|
|
Assert.assertTrue(createdUUID.compareTo(header.getUUID())==0);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(header.getCreatedBy()!=null) {
|
|
|
|
Assert.assertTrue(createdBy.compareTo(header.getCreatedBy())==0);
|
|
|
|
}else {
|
2023-02-10 14:59:03 +01:00
|
|
|
Assert.assertTrue(createdBy.compareTo(ContextTest.getUser())==0);
|
2021-07-05 17:31:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if(header.getLastUpdateBy()!=null) {
|
|
|
|
Assert.assertTrue(lastUpdateBy.compareTo(header.getLastUpdateBy())==0);
|
|
|
|
}else {
|
2023-02-10 14:59:03 +01:00
|
|
|
Assert.assertTrue(lastUpdateBy.compareTo(ContextTest.getUser())==0);
|
2021-07-05 17:31:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if(header.getLastUpdateTime()!=null) {
|
|
|
|
Assert.assertTrue(lastUpdateTime.after(header.getLastUpdateTime()));
|
|
|
|
}
|
2017-01-13 18:00:56 +01:00
|
|
|
}
|
2018-06-12 10:02:31 +02:00
|
|
|
|
2017-01-13 18:00:56 +01:00
|
|
|
}
|
2018-06-12 10:02:31 +02:00
|
|
|
|
2021-07-05 17:31:42 +02:00
|
|
|
public static void checkPropagationConstraint(PropagationConstraint propagationConstraint, PropagationConstraint gotPropagationConstraint) {
|
|
|
|
Assert.assertTrue(propagationConstraint.getAddConstraint()==gotPropagationConstraint.getAddConstraint());
|
|
|
|
Assert.assertTrue(propagationConstraint.getRemoveConstraint()==gotPropagationConstraint.getRemoveConstraint());
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void checkConsistOf(ConsistsOf<? extends Resource, ? extends Facet> consistsOf, ConsistsOf<? extends Resource, ? extends Facet> gotConsistsOf) {
|
|
|
|
checkHeader(consistsOf, gotConsistsOf);
|
|
|
|
|
|
|
|
if(consistsOf.getPropagationConstraint()==null) {
|
|
|
|
PropagationConstraint propagationConstraint = gotConsistsOf.getPropagationConstraint();
|
|
|
|
Assert.assertTrue(propagationConstraint.getAddConstraint()==AddConstraint.propagate);
|
|
|
|
Assert.assertTrue(propagationConstraint.getRemoveConstraint()==RemoveConstraint.cascade);
|
|
|
|
checkPropagationConstraint(propagationConstraint, gotConsistsOf.getPropagationConstraint());
|
|
|
|
}else {
|
|
|
|
checkPropagationConstraint(consistsOf.getPropagationConstraint(), gotConsistsOf.getPropagationConstraint());
|
2017-01-13 18:00:56 +01:00
|
|
|
}
|
2018-06-12 10:02:31 +02:00
|
|
|
|
2021-07-05 17:31:42 +02:00
|
|
|
Map<String, Object> additionalProperties = new HashMap<>(consistsOf.getAdditionalProperties());
|
|
|
|
additionalProperties.remove(Element.SUPERCLASSES_PROPERTY);
|
|
|
|
Map<String, Object> gotAdditionalProperties = new HashMap<>(gotConsistsOf.getAdditionalProperties());
|
|
|
|
gotAdditionalProperties.remove(Element.SUPERCLASSES_PROPERTY);
|
|
|
|
Assert.assertTrue(additionalProperties.size()==gotAdditionalProperties.size());
|
|
|
|
for(String key : additionalProperties.keySet()) {
|
|
|
|
Assert.assertTrue(gotAdditionalProperties.containsKey(key));
|
|
|
|
Object additionalProperty = additionalProperties.get(key);
|
|
|
|
Object gotAdditionalProperty = gotAdditionalProperties.get(key);
|
|
|
|
Assert.assertTrue(additionalProperty.getClass() == gotAdditionalProperty.getClass());
|
|
|
|
Assert.assertTrue(additionalProperty.equals(gotAdditionalProperty));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void checkFacet(Facet facet, Facet gotFacet) throws Exception {
|
|
|
|
checkHeader(facet, gotFacet);
|
|
|
|
Class<? extends Facet> clz = facet.getClass();
|
|
|
|
Class<? extends Facet> gotClz = gotFacet.getClass();
|
|
|
|
Assert.assertTrue(clz==gotClz);
|
|
|
|
|
|
|
|
if(clz == SoftwareFacet.class) {
|
|
|
|
checkSoftwareFacetAssertion((SoftwareFacet) facet, (SoftwareFacet) gotFacet);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected static <R extends Resource> void checkResource(R resource, R gotResource) throws Exception {
|
|
|
|
Assert.assertTrue(resource.getClass() == gotResource.getClass());
|
|
|
|
checkHeader(resource, gotResource);
|
|
|
|
|
|
|
|
List<ConsistsOf<? extends Resource, ? extends Facet>> resourceConsistsOf = resource.getConsistsOf();
|
|
|
|
List<ConsistsOf<? extends Resource, ? extends Facet>> gotResourceConsistsOf = gotResource.getConsistsOf();
|
|
|
|
Assert.assertTrue(resourceConsistsOf.size() == gotResourceConsistsOf.size());
|
|
|
|
|
|
|
|
for(ConsistsOf<? extends Resource, ? extends Facet> consistsOf : resourceConsistsOf) {
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
ConsistsOf<? extends Resource, ? extends Facet> gotConsistsOf = (ConsistsOf<? extends Resource, ? extends Facet>) gotResource.getConsistsOf(consistsOf.getClass(), consistsOf.getTarget().getClass()).get(0);
|
|
|
|
checkConsistOf(consistsOf, gotConsistsOf);
|
|
|
|
|
|
|
|
Facet facet = consistsOf.getTarget();
|
|
|
|
Facet gotFacet = gotConsistsOf.getTarget();
|
|
|
|
checkFacet(facet, gotFacet);
|
2017-01-13 18:00:56 +01:00
|
|
|
}
|
2018-06-12 10:02:31 +02:00
|
|
|
|
2021-07-05 17:31:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public <R extends Resource> R createResource(R r) throws Exception {
|
|
|
|
R createdR = resourceRegistryPublisher.create(r);
|
|
|
|
|
|
|
|
checkResource(r, createdR);
|
2018-06-12 10:02:31 +02:00
|
|
|
|
2021-07-05 17:31:42 +02:00
|
|
|
return createdR;
|
|
|
|
}
|
|
|
|
|
|
|
|
public EService createEService() throws Exception {
|
|
|
|
EService eService = ERManagementTest.instantiateValidEService();
|
|
|
|
return createResource(eService);
|
|
|
|
}
|
|
|
|
|
|
|
|
public HostingNode createHostingNode() throws Exception {
|
|
|
|
return createHostingNode(null);
|
|
|
|
}
|
|
|
|
|
|
|
|
public HostingNode createHostingNode(EService eService) throws Exception {
|
|
|
|
return createHostingNode(eService, RemoveConstraint.cascade);
|
|
|
|
}
|
|
|
|
|
|
|
|
public HostingNode createHostingNode(EService eService, RemoveConstraint removeConstraint) throws Exception {
|
|
|
|
HostingNode hostingNode = ERManagementTest.instantiateValidHostingNode();
|
|
|
|
if(eService!=null) {
|
|
|
|
PropagationConstraint propagationConstraint = new PropagationConstraintImpl();
|
|
|
|
propagationConstraint.setRemoveConstraint(removeConstraint);
|
|
|
|
Activates<HostingNode, EService> activates = new ActivatesImpl<HostingNode, EService>(hostingNode, eService,
|
|
|
|
propagationConstraint);
|
|
|
|
hostingNode.attachResource(activates);
|
2017-01-13 18:00:56 +01:00
|
|
|
}
|
2021-07-05 17:31:42 +02:00
|
|
|
return createResource(hostingNode);
|
2017-01-13 18:00:56 +01:00
|
|
|
}
|
2018-06-12 10:02:31 +02:00
|
|
|
|
2021-07-05 17:31:42 +02:00
|
|
|
public Configuration createConfiguration() throws Exception {
|
|
|
|
Configuration configuration = ERManagementTest.instantiateValidConfiguration();
|
|
|
|
return createResource(configuration);
|
|
|
|
}
|
|
|
|
|
|
|
|
public Map<String, Resource> createHostingNodeAndEService() throws Exception {
|
|
|
|
Map<String, Resource> map = new HashMap<>();
|
|
|
|
|
|
|
|
EService eService = createEService();
|
|
|
|
map.put(EService.NAME, eService);
|
|
|
|
|
|
|
|
HostingNode hostingNode = createHostingNode(eService);
|
|
|
|
map.put(HostingNode.NAME, hostingNode);
|
|
|
|
|
|
|
|
return map;
|
|
|
|
}
|
|
|
|
|
|
|
|
public <R extends Resource> void deleteResource(R r) throws Exception {
|
|
|
|
if(r!=null) {
|
|
|
|
resourceRegistryPublisher.delete(r);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-01-13 18:00:56 +01:00
|
|
|
@Test
|
2021-07-05 17:31:42 +02:00
|
|
|
public void testCreateEService() throws Exception {
|
|
|
|
EService eService = null;
|
|
|
|
try {
|
|
|
|
eService = createEService();
|
|
|
|
}finally {
|
|
|
|
deleteResource(eService);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
@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();
|
2017-01-13 18:00:56 +01:00
|
|
|
Assert.assertTrue(deleted);
|
|
|
|
}
|
2021-07-05 17:31:42 +02:00
|
|
|
*/
|
2018-06-12 10:02:31 +02:00
|
|
|
|
2017-05-03 17:51:37 +02:00
|
|
|
@Test
|
2021-07-05 17:31:42 +02:00
|
|
|
public void testCreateHostingNode() throws Exception {
|
|
|
|
HostingNode hostingNode = null;
|
|
|
|
try {
|
|
|
|
hostingNode = createHostingNode();
|
|
|
|
}finally {
|
|
|
|
deleteResource(hostingNode);
|
|
|
|
}
|
2018-06-12 10:02:31 +02:00
|
|
|
|
2021-07-05 17:31:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testCreateHostingNodeAndEService() throws Exception {
|
|
|
|
Map<String, Resource> map = createHostingNodeAndEService();
|
|
|
|
deleteResource(map.get(EService.NAME));
|
|
|
|
deleteResource(map.get(HostingNode.NAME));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testCreateReadUpdateDeleteFacet() throws Exception {
|
|
|
|
EService eService = createEService();
|
2018-06-12 10:02:31 +02:00
|
|
|
|
2021-07-05 17:31:42 +02:00
|
|
|
try {
|
|
|
|
CPUFacet cpuFacet = new CPUFacetImpl();
|
|
|
|
cpuFacet.setClockSpeed("1 GHz");
|
|
|
|
cpuFacet.setModel("Opteron");
|
|
|
|
cpuFacet.setVendor("AMD");
|
|
|
|
|
|
|
|
ConsistsOf<EService, CPUFacet> consistsOf = new ConsistsOfImpl<EService, CPUFacet>(eService, cpuFacet);
|
|
|
|
|
|
|
|
ConsistsOf<EService, CPUFacet> createdConsistsOf = resourceRegistryPublisher.createConsistsOf(consistsOf);
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
UUID uuid = createdCpuFacet.getHeader().getUUID();
|
|
|
|
|
|
|
|
CPUFacet readCpuFacet = resourceRegistryPublisher.read(createdCpuFacet.getClass(), uuid);
|
|
|
|
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);
|
|
|
|
|
|
|
|
String newVendor = "Intel";
|
|
|
|
String newClockSpeed = "2 GHz";
|
|
|
|
readCpuFacet.setVendor(newVendor);
|
|
|
|
readCpuFacet.setClockSpeed(newClockSpeed);
|
|
|
|
|
|
|
|
String additionPropertyKey = "My";
|
|
|
|
String additionPropertyValue = "Test";
|
|
|
|
readCpuFacet.setAdditionalProperty(additionPropertyKey, additionPropertyValue);
|
|
|
|
|
|
|
|
CPUFacet updatedCpuFacet = resourceRegistryPublisher.update(readCpuFacet);
|
|
|
|
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);
|
2023-02-10 14:59:03 +01:00
|
|
|
String user = ContextTest.getUser();
|
2021-07-05 17:31:42 +02:00
|
|
|
Assert.assertTrue(updatedCpuFacet.getHeader().getLastUpdateBy().compareTo(user) == 0);
|
|
|
|
|
|
|
|
CPUFacet readUpdatedCpuFacet = resourceRegistryPublisher.read(updatedCpuFacet);
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
resourceRegistryPublisher.delete(readCpuFacet);
|
|
|
|
} finally {
|
|
|
|
deleteResource(eService);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testCreatePropertyTypeNotInSchema() throws Exception {
|
|
|
|
/*
|
|
|
|
* A facet cannot be created per se. Going to create a Configuration which does
|
|
|
|
* not impose any particular constraint except the IdentifierFact
|
|
|
|
*/
|
|
|
|
Configuration configuration = instantiateValidConfiguration();
|
2018-06-12 10:02:31 +02:00
|
|
|
|
2021-07-05 17:31:42 +02:00
|
|
|
AccessPointFacet accessPointFacet = new AccessPointFacetImpl();
|
|
|
|
accessPointFacet.setEndpoint(new URI("https://localhost"));
|
|
|
|
accessPointFacet.setEntryName("port1");
|
|
|
|
|
|
|
|
ValueSchema authorization = new ValueSchemaImpl();
|
|
|
|
authorization.setValue("pwd");
|
|
|
|
URI uri = new URI("https://www.gcube-system.org");
|
|
|
|
authorization.setSchema(uri);
|
|
|
|
accessPointFacet.setAuthorization(authorization);
|
|
|
|
|
|
|
|
String additionlaPropertyKey = "Test";
|
|
|
|
String additionlaPropertyValue = "MyTest";
|
|
|
|
accessPointFacet.setAdditionalProperty(additionlaPropertyKey, additionlaPropertyValue);
|
|
|
|
|
2023-02-27 15:11:02 +01:00
|
|
|
Vault vault = new VaultImpl();
|
|
|
|
String plainValue = "my plain value";
|
|
|
|
String encryptedValue = StringEncrypter.getEncrypter().encrypt(plainValue);
|
|
|
|
vault.setValue(encryptedValue);
|
2021-07-05 17:31:42 +02:00
|
|
|
String encryptedKey = "Enc";
|
2023-02-27 15:11:02 +01:00
|
|
|
accessPointFacet.setAdditionalProperty(encryptedKey, vault);
|
2018-06-12 10:02:31 +02:00
|
|
|
|
2021-07-05 17:31:42 +02:00
|
|
|
configuration.addFacet(accessPointFacet);
|
|
|
|
|
|
|
|
String marshalled = ElementMapper.marshal(configuration);
|
|
|
|
logger.debug(marshalled);
|
|
|
|
|
|
|
|
Configuration createdConfiguration = createResource(configuration);
|
|
|
|
|
|
|
|
AccessPointFacet apf = configuration.getFacets(AccessPointFacet.class).get(0);
|
|
|
|
|
|
|
|
Assert.assertTrue(apf.getAuthorization() instanceof ValueSchema);
|
2023-02-27 15:11:02 +01:00
|
|
|
Assert.assertTrue(apf.getAdditionalProperty(encryptedKey) instanceof Vault);
|
|
|
|
Vault enc = (Vault) apf.getAdditionalProperty(encryptedKey);
|
|
|
|
String encValue = enc.getValue();
|
2021-07-05 17:31:42 +02:00
|
|
|
Assert.assertTrue(encValue.compareTo(encryptedValue) == 0);
|
2023-02-27 15:11:02 +01:00
|
|
|
String decryptedValue = StringEncrypter.getEncrypter().decrypt(encValue);
|
2021-07-05 17:31:42 +02:00
|
|
|
Assert.assertTrue(decryptedValue.compareTo(plainValue) == 0);
|
|
|
|
Assert.assertTrue(((String) apf.getAdditionalProperty(additionlaPropertyKey)).compareTo(additionlaPropertyValue) == 0);
|
|
|
|
|
|
|
|
deleteResource(createdConfiguration);
|
2017-05-03 17:51:37 +02:00
|
|
|
}
|
2021-07-05 17:31:42 +02:00
|
|
|
|
2018-06-12 10:02:31 +02:00
|
|
|
|
2021-07-05 17:31:42 +02:00
|
|
|
@Test
|
|
|
|
public void testUpdateFacetValue() throws Exception {
|
|
|
|
EService eService =null;
|
|
|
|
try {
|
|
|
|
eService = createEService();
|
|
|
|
|
|
|
|
final String newVersion = "1.2.0";
|
|
|
|
eService.getFacets(SoftwareFacet.class).get(0).setVersion(newVersion);
|
|
|
|
|
|
|
|
EService updatedEService = resourceRegistryPublisher.update(eService);
|
|
|
|
|
|
|
|
checkResource(eService, updatedEService);
|
|
|
|
|
|
|
|
SoftwareFacet softwareFacet = updatedEService.getFacets(SoftwareFacet.class).get(0);
|
|
|
|
Assert.assertTrue(softwareFacet.getVersion().compareTo(newVersion) == 0);
|
|
|
|
|
|
|
|
}finally {
|
|
|
|
deleteResource(eService);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// public static final String TEST_RESOURCE = "test-resource.json";
|
|
|
|
//
|
|
|
|
// // @Test
|
|
|
|
// public void testUpdateResourceFromFile()
|
|
|
|
// throws JsonParseException, JsonMappingException, IOException, ResourceRegistryException {
|
|
|
|
// File file = new File("src/test/resources/" + TEST_RESOURCE);
|
|
|
|
//
|
|
|
|
// logger.debug("{}", file.getAbsolutePath());
|
|
|
|
//
|
|
|
|
// FileInputStream fileInputStream = new FileInputStream(file);
|
|
|
|
// EService eService = ElementMapper.unmarshal(EService.class, fileInputStream);
|
|
|
|
//
|
|
|
|
// ResourceManagement resourceManagement = new ResourceManagement();
|
|
|
|
// resourceManagement.setUUID(eService.getHeader().getUUID());
|
|
|
|
// resourceManagement.setJson(ElementMapper.marshal(eService));
|
|
|
|
//
|
|
|
|
// resourceManagement.update();
|
|
|
|
//
|
|
|
|
// }
|
|
|
|
|
2017-01-13 18:00:56 +01:00
|
|
|
}
|