2021-07-05 17:31:42 +02:00
|
|
|
package org.gcube.informationsystem.resourceregistry.publisher;
|
|
|
|
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.UUID;
|
|
|
|
|
|
|
|
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.relations.ConsistsOf;
|
|
|
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
2021-10-25 10:59:52 +02:00
|
|
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.entities.resource.ResourceAlreadyPresentException;
|
|
|
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.types.SchemaViolationException;
|
2023-02-10 14:32:45 +01:00
|
|
|
import org.gcube.informationsystem.serialization.ElementMapper;
|
2021-07-05 17:31:42 +02:00
|
|
|
import org.gcube.resourcemanagement.model.impl.entities.facets.CPUFacetImpl;
|
|
|
|
import org.gcube.resourcemanagement.model.impl.entities.facets.SimpleFacetImpl;
|
|
|
|
import org.gcube.resourcemanagement.model.impl.entities.facets.SoftwareFacetImpl;
|
|
|
|
import org.gcube.resourcemanagement.model.impl.entities.resources.HostingNodeImpl;
|
|
|
|
import org.gcube.resourcemanagement.model.impl.entities.resources.RunningPluginImpl;
|
|
|
|
import org.gcube.resourcemanagement.model.impl.relations.consistsof.IsIdentifiedByImpl;
|
|
|
|
import org.gcube.resourcemanagement.model.reference.entities.facets.CPUFacet;
|
|
|
|
import org.gcube.resourcemanagement.model.reference.entities.facets.SimpleFacet;
|
|
|
|
import org.gcube.resourcemanagement.model.reference.entities.facets.SoftwareFacet;
|
|
|
|
import org.gcube.resourcemanagement.model.reference.entities.resources.Configuration;
|
|
|
|
import org.gcube.resourcemanagement.model.reference.entities.resources.EService;
|
|
|
|
import org.gcube.resourcemanagement.model.reference.entities.resources.HostingNode;
|
|
|
|
import org.gcube.resourcemanagement.model.reference.entities.resources.RunningPlugin;
|
|
|
|
import org.gcube.resourcemanagement.model.reference.relations.consistsof.IsIdentifiedBy;
|
|
|
|
import org.junit.Test;
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
|
|
public class InvalidOperationTest extends ERManagementTest {
|
|
|
|
|
|
|
|
private static Logger logger = LoggerFactory.getLogger(InvalidOperationTest.class);
|
|
|
|
|
2023-04-19 13:14:29 +02:00
|
|
|
public static final String ACTIVATES = "{\"propagationConstraint\":{\"@class\":\"PropagationConstraint\",\"add\":\"propagate\",\"remove\":\"cascade\",\"delete\":\"cascade\"},\"@class\":\"Activates\",\"source\":{\"@class\":\"Configuration\",\"@uuid\":\"CONFIGURATION_UUID\"},\"target\":{\"@uuid\":\"ESERVICE_UUID\",\"@class\":\"EService\"}}";
|
|
|
|
public static final String ACTOR = "{\"@class\":\"Actor\",\"@metadata\":null,\"consistsOf\":[{\"@class\":\"IsIdentifiedBy\",\"@metadata\":null,\"propagationConstraint\":{\"@class\":\"PropagationConstraint\",\"remove\":\"cascade\",\"delete\":\"cascade\",\"add\":\"propagate\"},\"source\":{\"@class\":\"Actor\",\"@metadata\":null},\"target\":{\"@class\":\"ContactFacet\",\"@metadata\":null,\"title\":\"Dr.\",\"name\":\"Frosini\",\"middleName\":null,\"surname\":null,\"eMail\":\"luca.frosini@isti.cnr.it\"}}],\"isRelatedTo\":[]}";
|
2021-07-05 17:31:42 +02:00
|
|
|
|
|
|
|
@Test(expected = SchemaViolationException.class)
|
|
|
|
public void createInvalidIsRealtedTo() throws Exception {
|
|
|
|
Configuration configuration = createConfiguration();
|
|
|
|
EService eService = createEService();
|
|
|
|
|
|
|
|
try {
|
|
|
|
/*
|
|
|
|
* Trying to create a relation activates between a Configuration and EService
|
|
|
|
* The creation MUST fails raising SchemaViolationException because the
|
|
|
|
* Activates relation is between two Service isntaces
|
|
|
|
*
|
|
|
|
* The only way to try to create it is using static string because Java classes
|
|
|
|
* already deny to create and instance of Activates
|
|
|
|
*
|
|
|
|
* Here we want to test how the service behave if a client does not behave properly
|
|
|
|
*/
|
|
|
|
|
2023-04-19 11:38:22 +02:00
|
|
|
String json = ACTIVATES.replace("CONFIGURATION_UUID", configuration.getUUID().toString());
|
|
|
|
json = json.replace("ESERVICE_UUID", eService.getUUID().toString());
|
2021-07-05 17:31:42 +02:00
|
|
|
|
|
|
|
resourceRegistryPublisher.create(json);
|
|
|
|
|
|
|
|
}finally {
|
|
|
|
resourceRegistryPublisher.delete(configuration);
|
|
|
|
resourceRegistryPublisher.delete(eService);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test(expected = ResourceAlreadyPresentException.class)
|
|
|
|
public void testRecreate() throws Exception {
|
|
|
|
EService eService = createEService();
|
|
|
|
try {
|
|
|
|
resourceRegistryPublisher.create(eService);
|
|
|
|
}finally {
|
|
|
|
resourceRegistryPublisher.delete(eService);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test(expected = SchemaViolationException.class)
|
|
|
|
public void testCreateStandAloneFacet() throws Exception {
|
|
|
|
CPUFacet cpuFacet = new CPUFacetImpl();
|
|
|
|
cpuFacet.setClockSpeed("1 GHz");
|
|
|
|
cpuFacet.setModel("Opteron");
|
|
|
|
cpuFacet.setVendor("AMD");
|
|
|
|
|
|
|
|
resourceRegistryPublisher.create(cpuFacet);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test(expected = SchemaViolationException.class)
|
|
|
|
public void testCreateInvalidRunningPlugin() throws Exception {
|
|
|
|
RunningPlugin runningPlugin = new RunningPluginImpl();
|
|
|
|
|
|
|
|
SoftwareFacet softwareFacet = new SoftwareFacetImpl();
|
|
|
|
softwareFacet.setGroup("information-system");
|
|
|
|
softwareFacet.setName("is-exporter-se-plugin");
|
|
|
|
softwareFacet.setVersion("1.0.0");
|
|
|
|
|
|
|
|
IsIdentifiedBy<RunningPlugin, SoftwareFacet> isIdentifiedBy = new IsIdentifiedByImpl<>(runningPlugin, softwareFacet);
|
|
|
|
runningPlugin.addFacet(isIdentifiedBy);
|
|
|
|
|
|
|
|
resourceRegistryPublisher.create(runningPlugin);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test(expected = ResourceRegistryException.class)
|
|
|
|
public void testCreateAnEntityDifferentFromDeclared() throws Exception {
|
|
|
|
EService eService = ERManagementTest.instantiateValidEService();
|
|
|
|
resourceRegistryPublisher.create(eService);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test(expected = SchemaViolationException.class)
|
|
|
|
public void testCreateAbstractEntity() throws Exception {
|
|
|
|
resourceRegistryPublisher.create(ACTOR);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test(expected = SchemaViolationException.class)
|
|
|
|
public void testCreateHostingNodeAndEServiceWithSharedFacet() throws Exception {
|
|
|
|
ERManagementTest erManagementTest = new ERManagementTest();
|
|
|
|
Map<String, Resource> map = erManagementTest.createHostingNodeAndEService();
|
|
|
|
EService eService = (EService) map.get(EService.NAME);
|
|
|
|
HostingNode hostingNode = (HostingNode) map.get(HostingNode.NAME);
|
|
|
|
try {
|
|
|
|
Facet shared = hostingNode.getConsistsOf().get(0).getTarget();
|
|
|
|
ConsistsOf<EService, Facet> consistsOf = new ConsistsOfImpl<>(eService, shared);
|
|
|
|
consistsOf = resourceRegistryPublisher.create(consistsOf);
|
|
|
|
|
|
|
|
logger.debug("Created : {}", consistsOf);
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
resourceRegistryPublisher.delete(eService);
|
|
|
|
resourceRegistryPublisher.delete(hostingNode);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test(expected = SchemaViolationException.class)
|
|
|
|
public void testCreateEServiceAndDeleteRequiredConsistsOf() throws Exception {
|
|
|
|
EService eService = null;
|
|
|
|
try {
|
|
|
|
ERManagementTest erManagementTest = new ERManagementTest();
|
|
|
|
eService = erManagementTest.createEService();
|
|
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
IsIdentifiedBy<EService, SoftwareFacet> isIdentifiedBy = (IsIdentifiedBy<EService, SoftwareFacet>) eService.getConsistsOf(IsIdentifiedBy.class).get(0);
|
|
|
|
resourceRegistryPublisher.delete(isIdentifiedBy);
|
|
|
|
}finally {
|
|
|
|
resourceRegistryPublisher.delete(eService);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test(expected = SchemaViolationException.class)
|
|
|
|
public void testCreateEServiceAndDeleteRequiredFacet() throws Exception {
|
|
|
|
ERManagementTest erManagementTest = new ERManagementTest();
|
|
|
|
EService eService = erManagementTest.createEService();
|
|
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
IsIdentifiedBy<EService, SoftwareFacet> isIdentifiedBy = (IsIdentifiedBy<EService, SoftwareFacet>) eService.getConsistsOf(IsIdentifiedBy.class).get(0);
|
|
|
|
SoftwareFacet softwareFacet = isIdentifiedBy.getTarget();
|
|
|
|
try {
|
|
|
|
resourceRegistryPublisher.delete(softwareFacet);
|
|
|
|
}finally {
|
|
|
|
resourceRegistryPublisher.delete(eService);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test(expected = SchemaViolationException.class)
|
|
|
|
public void testCreateConsistsOfBeetweenResources() throws Exception {
|
|
|
|
ERManagementTest erManagementTest = new ERManagementTest();
|
|
|
|
Map<String, Resource> map = erManagementTest.createHostingNodeAndEService();
|
|
|
|
|
2023-04-19 11:38:22 +02:00
|
|
|
UUID hostingNodeUUID = map.get(HostingNode.NAME).getUUID();
|
|
|
|
UUID eServiceUUID = map.get(EService.NAME).getUUID();
|
2021-07-05 17:31:42 +02:00
|
|
|
|
|
|
|
HostingNode hostingNode = new HostingNodeImpl();
|
2023-04-19 11:38:22 +02:00
|
|
|
hostingNode.setUUID(hostingNodeUUID);
|
2021-07-05 17:31:42 +02:00
|
|
|
|
|
|
|
SimpleFacet fakeEServiceAsSimpleFacet = new SimpleFacetImpl();
|
2023-04-19 11:38:22 +02:00
|
|
|
fakeEServiceAsSimpleFacet.setUUID(eServiceUUID);
|
2021-07-05 17:31:42 +02:00
|
|
|
|
|
|
|
ConsistsOf<HostingNode, SimpleFacet> consistsOf = new ConsistsOfImpl<HostingNode, SimpleFacet>(hostingNode, fakeEServiceAsSimpleFacet);
|
|
|
|
|
|
|
|
try {
|
|
|
|
String json = ElementMapper.marshal(consistsOf);
|
|
|
|
json = json.replaceAll(SimpleFacet.NAME, EService.NAME);
|
|
|
|
|
|
|
|
resourceRegistryPublisher.create(json);
|
|
|
|
throw new Exception("A ConsistsOf has been created between two resoures. This should not happen");
|
|
|
|
} finally {
|
|
|
|
resourceRegistryPublisher.delete(map.get(EService.NAME));
|
|
|
|
resourceRegistryPublisher.delete(map.get(HostingNode.NAME));
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|