2016-11-10 15:13:51 +01:00
/ * *
*
* /
2019-11-06 12:13:19 +01:00
package org.gcube.informationsystem.resourceregistry.instances.multicontext ;
2016-11-10 15:13:51 +01:00
2020-11-05 15:58:30 +01:00
import java.io.IOException ;
2016-11-10 15:13:51 +01:00
import java.net.URI ;
import java.net.URL ;
import java.util.Calendar ;
2020-11-09 15:45:07 +01:00
import java.util.Collection ;
2020-11-05 15:58:30 +01:00
import java.util.List ;
import java.util.Set ;
2016-11-10 15:13:51 +01:00
import java.util.UUID ;
2020-11-03 16:30:24 +01:00
import org.gcube.common.authorization.client.exceptions.ObjectNotFound ;
2020-11-05 15:58:30 +01:00
import org.gcube.informationsystem.context.reference.entities.Context ;
2019-02-13 12:33:29 +01:00
import org.gcube.informationsystem.model.impl.properties.PropagationConstraintImpl ;
import org.gcube.informationsystem.model.reference.entities.Facet ;
2020-11-09 15:45:07 +01:00
import org.gcube.informationsystem.model.reference.properties.Header ;
2019-02-13 12:33:29 +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 ;
2019-10-28 15:06:31 +01:00
import org.gcube.informationsystem.resourceregistry.ContextTest ;
2020-11-05 15:58:30 +01:00
import org.gcube.informationsystem.resourceregistry.api.contexts.ContextCache ;
import org.gcube.informationsystem.resourceregistry.api.contexts.ContextCacheRenewal ;
2020-11-09 15:45:07 +01:00
import org.gcube.informationsystem.resourceregistry.api.exceptions.AvailableInAnotherContextException ;
2016-11-10 15:13:51 +01:00
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException ;
import org.gcube.informationsystem.resourceregistry.api.exceptions.context.ContextNotFoundException ;
2017-03-29 16:14:03 +02:00
import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.facet.FacetAvailableInAnotherContextException ;
import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.resource.ResourceAvailableInAnotherContextException ;
2016-11-28 18:17:14 +01:00
import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.resource.ResourceNotFoundException ;
2017-03-29 16:14:03 +02:00
import org.gcube.informationsystem.resourceregistry.api.exceptions.relation.RelationAvailableInAnotherContextException ;
2020-11-05 15:58:30 +01:00
import org.gcube.informationsystem.resourceregistry.api.utils.Utility ;
2020-01-27 17:07:37 +01:00
import org.gcube.informationsystem.resourceregistry.contexts.ContextUtility ;
2020-11-05 15:58:30 +01:00
import org.gcube.informationsystem.resourceregistry.contexts.entities.ContextManagement ;
2019-11-06 12:13:19 +01:00
import org.gcube.informationsystem.resourceregistry.instances.SmartgearResourcesTest ;
2020-11-03 16:30:24 +01:00
import org.gcube.informationsystem.resourceregistry.instances.base.ElementManagement ;
import org.gcube.informationsystem.resourceregistry.instances.base.ElementManagementUtility ;
2019-11-06 12:13:19 +01:00
import org.gcube.informationsystem.resourceregistry.instances.model.entities.FacetManagement ;
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.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 ;
import org.gcube.resourcemanagement.model.impl.entities.facets.LicenseFacetImpl ;
import org.gcube.resourcemanagement.model.impl.entities.facets.MemoryFacetImpl ;
import org.gcube.resourcemanagement.model.impl.entities.facets.NetworkingFacetImpl ;
import org.gcube.resourcemanagement.model.impl.entities.facets.SoftwareFacetImpl ;
2020-12-21 23:09:57 +01:00
import org.gcube.resourcemanagement.model.impl.entities.facets.StateFacetImpl ;
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 ;
2020-12-21 23:09:57 +01:00
import org.gcube.resourcemanagement.model.impl.properties.ValueSchemaImpl ;
2019-02-13 12:33:29 +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 ;
import org.gcube.resourcemanagement.model.reference.entities.facets.LicenseFacet ;
import org.gcube.resourcemanagement.model.reference.entities.facets.MemoryFacet ;
2019-12-05 12:09:23 +01:00
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.SoftwareFacet ;
2020-12-21 23:09:57 +01:00
import org.gcube.resourcemanagement.model.reference.entities.facets.StateFacet ;
2019-02-13 12:33:29 +01:00
import org.gcube.resourcemanagement.model.reference.entities.resources.EService ;
import org.gcube.resourcemanagement.model.reference.entities.resources.HostingNode ;
2020-12-21 23:09:57 +01:00
import org.gcube.resourcemanagement.model.reference.properties.ValueSchema ;
2019-02-13 12:33:29 +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-11-14 12:02:51 +01:00
import org.junit.Assert ;
2016-11-10 15:13:51 +01:00
import org.junit.Test ;
import org.slf4j.Logger ;
import org.slf4j.LoggerFactory ;
/ * *
* @author Luca Frosini ( ISTI - CNR )
* /
2019-10-28 15:06:31 +01:00
public class BasicTest extends ContextTest {
2016-11-10 15:13:51 +01:00
private static Logger logger = LoggerFactory
2017-05-02 15:31:45 +02:00
. getLogger ( BasicTest . class ) ;
2016-11-10 15:13:51 +01:00
2016-12-19 14:59:27 +01:00
@Test
public void testDifferentScopes ( ) throws Exception {
2020-11-05 17:03:05 +01:00
ContextTest . setContextByName ( DEFAULT_TEST_SCOPE ) ;
2016-12-19 14:59:27 +01:00
CPUFacet cpuFacet = new CPUFacetImpl ( ) ;
cpuFacet . setClockSpeed ( " 1 GHz " ) ;
cpuFacet . setModel ( " Opteron " ) ;
cpuFacet . setVendor ( " AMD " ) ;
2016-11-10 15:13:51 +01:00
2016-12-19 14:59:27 +01:00
FacetManagement facetManagement = new FacetManagement ( ) ;
2020-02-03 10:52:09 +01:00
facetManagement . setJson ( ElementMapper . marshal ( cpuFacet ) ) ;
2016-12-30 17:31:12 +01:00
facetManagement . setElementType ( CPUFacet . NAME ) ;
2016-12-19 14:59:27 +01:00
String json = facetManagement . create ( ) ;
logger . debug ( " Created : {} " , json ) ;
2020-02-03 10:52:09 +01:00
CPUFacet createdCPUFacet = ElementMapper . unmarshal ( CPUFacet . class , json ) ;
2017-11-30 18:06:08 +01:00
UUID uuid = createdCPUFacet . getHeader ( ) . getUUID ( ) ;
2016-12-19 14:59:27 +01:00
facetManagement = new FacetManagement ( ) ;
facetManagement . setUUID ( uuid ) ;
String readJson = facetManagement . read ( ) ;
logger . debug ( " Read : {} " , readJson ) ;
/* ------------------------------------------------------------------ */
logger . debug ( " Switching to another scope " ) ;
2019-10-28 15:06:31 +01:00
ContextTest . setContextByName ( PARENT_DEFAULT_TEST_SCOPE ) ;
2016-12-19 14:59:27 +01:00
try {
facetManagement = new FacetManagement ( ) ;
facetManagement . setUUID ( uuid ) ;
readJson = facetManagement . read ( ) ;
logger . debug ( " You should not be able to read Facet with UUID {} " ,
uuid ) ;
throw new Exception (
" You should not be able to read Facet with UUID " + uuid ) ;
2017-03-29 16:14:03 +02:00
} catch ( FacetAvailableInAnotherContextException e ) {
logger . debug ( " Good the facet created in the default context is not visible in an alternative context " ) ;
2016-12-19 14:59:27 +01:00
}
2017-11-30 18:06:08 +01:00
/* ---------------- entering hierarchic mode */
2020-10-27 15:12:11 +01:00
ContextUtility . getHierarchicalMode ( ) . set ( true ) ;
2017-11-30 18:06:08 +01:00
facetManagement = new FacetManagement ( ) ;
facetManagement . setUUID ( uuid ) ;
readJson = facetManagement . read ( ) ;
logger . debug ( " You should be able to read it {} " , readJson ) ;
2020-10-27 15:12:11 +01:00
ContextUtility . getHierarchicalMode ( ) . set ( false ) ;
2017-11-30 18:06:08 +01:00
/* ---------------- leaving hierarchic mode */
2016-12-19 14:59:27 +01:00
cpuFacet . setAdditionalProperty ( " My " , " Test " ) ;
try {
facetManagement = new FacetManagement ( ) ;
facetManagement . setUUID ( uuid ) ;
2020-02-03 10:52:09 +01:00
facetManagement . setJson ( ElementMapper . marshal ( cpuFacet ) ) ;
2016-12-19 14:59:27 +01:00
readJson = facetManagement . update ( ) ;
logger . debug ( " You should not be able to update Facet with UUID {} " ,
uuid ) ;
throw new Exception (
" You should not be able to read Facet with UUID " + uuid ) ;
2017-03-29 16:14:03 +02:00
} catch ( FacetAvailableInAnotherContextException e ) {
logger . debug ( " Good the Facet created in the default context cannot be updated in an alternative context " ) ;
2016-12-19 14:59:27 +01:00
}
2016-11-28 09:13:20 +01:00
2016-12-19 14:59:27 +01:00
/* ------------------------------------------------------------------ */
logger . debug ( " Setting back default scope " ) ;
2019-10-28 15:06:31 +01:00
ContextTest . setContextByName ( DEFAULT_TEST_SCOPE ) ;
2016-12-19 14:59:27 +01:00
facetManagement = new FacetManagement ( ) ;
facetManagement . setUUID ( uuid ) ;
2020-02-03 10:52:09 +01:00
facetManagement . setJson ( ElementMapper . marshal ( cpuFacet ) ) ;
2016-12-19 14:59:27 +01:00
readJson = facetManagement . update ( ) ;
logger . debug ( " Updated : {} " , readJson ) ;
facetManagement = new FacetManagement ( ) ;
facetManagement . setUUID ( uuid ) ;
readJson = facetManagement . read ( ) ;
logger . debug ( " Read Updated : {} " , readJson ) ;
facetManagement = new FacetManagement ( ) ;
facetManagement . setUUID ( uuid ) ;
2017-11-30 18:06:08 +01:00
2016-12-19 14:59:27 +01:00
boolean deleted = facetManagement . delete ( ) ;
Assert . assertTrue ( deleted ) ;
}
2016-11-10 15:13:51 +01:00
@Test
2016-11-11 11:54:41 +01:00
public void testCreateEServiceHostingNode ( ) throws Exception {
2016-11-10 15:13:51 +01:00
EService eService = new EServiceImpl ( ) ;
2016-11-28 09:13:20 +01:00
2016-11-10 15:13:51 +01:00
SoftwareFacet softwareFacet = new SoftwareFacetImpl ( ) ;
softwareFacet . setGroup ( " InformationSystem " ) ;
softwareFacet . setName ( " resource-registry " ) ;
softwareFacet . setVersion ( " 1.1.0 " ) ;
2016-11-28 09:13:20 +01:00
IsIdentifiedBy < EService , Facet > isIdentifiedBy = new IsIdentifiedByImpl < EService , Facet > (
eService , softwareFacet , null ) ;
2016-11-10 15:13:51 +01:00
eService . addFacet ( isIdentifiedBy ) ;
2016-11-28 09:13:20 +01:00
2016-11-10 15:13:51 +01:00
AccessPointFacet accessPointFacet = new AccessPointFacetImpl ( ) ;
accessPointFacet . setEndpoint ( new URI ( " http://localhost " ) ) ;
accessPointFacet . setEntryName ( " port1 " ) ;
eService . addFacet ( accessPointFacet ) ;
2016-11-28 09:13:20 +01:00
2016-11-10 15:13:51 +01:00
EventFacet eventFacet = new EventFacetImpl ( ) ;
eventFacet . setDate ( Calendar . getInstance ( ) . getTime ( ) ) ;
2020-12-21 23:09:57 +01:00
ValueSchema event = new ValueSchemaImpl ( ) ;
event . setValue ( " Created " ) ;
eventFacet . setEvent ( event ) ;
2016-11-10 15:13:51 +01:00
eService . addFacet ( eventFacet ) ;
2016-11-28 09:13:20 +01:00
2020-12-21 23:09:57 +01:00
StateFacet stateFacet = new StateFacetImpl ( ) ;
stateFacet . setValue ( " ready " ) ;
eService . addFacet ( stateFacet ) ;
2016-11-28 09:13:20 +01:00
2016-11-10 15:13:51 +01:00
LicenseFacet licenseFacet = new LicenseFacetImpl ( ) ;
licenseFacet . setName ( " EUPL " ) ;
2016-11-28 09:13:20 +01:00
licenseFacet
. setTextURL ( new URL (
" https://joinup.ec.europa.eu/community/eupl/og_page/european-union-public-licence-eupl-v11 " ) ) ;
2016-11-10 15:13:51 +01:00
eService . addFacet ( licenseFacet ) ;
2016-12-19 14:59:27 +01:00
ResourceManagement resourceManagement = new ResourceManagement ( ) ;
2016-12-30 17:31:12 +01:00
resourceManagement . setElementType ( EService . NAME ) ;
2020-02-03 10:52:09 +01:00
resourceManagement . setJson ( ElementMapper . marshal ( eService ) ) ;
2016-11-28 09:13:20 +01:00
2016-12-19 14:59:27 +01:00
String json = resourceManagement . create ( ) ;
2016-11-10 15:13:51 +01:00
logger . debug ( " Created : {} " , json ) ;
2020-02-03 10:52:09 +01:00
eService = ElementMapper . unmarshal ( EService . class , json ) ;
2016-11-10 15:13:51 +01:00
logger . debug ( " Unmarshalled {} {} " , EService . NAME , eService ) ;
2016-11-28 09:13:20 +01:00
2016-11-10 15:13:51 +01:00
HostingNode hostingNode = new HostingNodeImpl ( ) ;
2016-11-28 09:13:20 +01:00
2016-11-10 15:13:51 +01:00
NetworkingFacet networkingFacet = new NetworkingFacetImpl ( ) ;
networkingFacet . setIPAddress ( " 146.48.87.183 " ) ;
networkingFacet . setHostName ( " pc-frosini.isti.cnr.it " ) ;
networkingFacet . setDomainName ( " isti.cnr.it " ) ;
networkingFacet . setMask ( " 255.255.248.0 " ) ;
networkingFacet . setBroadcastAddress ( " 146.48.87.255 " ) ;
2016-11-28 09:13:20 +01:00
IsIdentifiedBy < HostingNode , NetworkingFacet > isIdentifiedByHNNF = new IsIdentifiedByImpl < HostingNode , NetworkingFacet > (
hostingNode , networkingFacet , null ) ;
2016-11-11 11:54:41 +01:00
hostingNode . addFacet ( isIdentifiedByHNNF ) ;
2016-11-28 09:13:20 +01:00
2016-11-10 15:13:51 +01:00
CPUFacet cpuFacet = new CPUFacetImpl ( ) ;
cpuFacet . setClockSpeed ( " 1 GHz " ) ;
cpuFacet . setModel ( " Opteron " ) ;
cpuFacet . setVendor ( " AMD " ) ;
hostingNode . addFacet ( cpuFacet ) ;
2016-11-28 09:13:20 +01:00
2016-11-10 15:13:51 +01:00
MemoryFacet ram = new MemoryFacetImpl ( ) ;
ram . setSize ( 8 ) ;
ram . setUnit ( MemoryUnit . GB ) ;
ram . setUsed ( 2 ) ;
2016-11-28 09:13:20 +01:00
HasVolatileMemory < HostingNode , MemoryFacet > hasVolatileMemory = new HasVolatileMemoryImpl < HostingNode , MemoryFacet > (
hostingNode , ram , null ) ;
2016-11-10 15:13:51 +01:00
hostingNode . addFacet ( hasVolatileMemory ) ;
2016-11-28 09:13:20 +01:00
2016-11-10 15:13:51 +01:00
MemoryFacet disk = new MemoryFacetImpl ( ) ;
disk . setSize ( 256 ) ;
disk . setUnit ( MemoryUnit . GB ) ;
disk . setUsed ( 120 ) ;
2016-11-28 09:13:20 +01:00
HasPersistentMemory < HostingNode , MemoryFacet > hasPersistentMemory = new HasPersistentMemoryImpl < HostingNode , MemoryFacet > (
hostingNode , disk , null ) ;
2016-11-10 15:13:51 +01:00
hostingNode . addFacet ( hasPersistentMemory ) ;
2016-11-28 09:13:20 +01:00
2018-10-02 09:17:58 +02:00
Activates < HostingNode , EService > activates = new ActivatesImpl < HostingNode , EService > (
2016-11-28 09:13:20 +01:00
hostingNode , eService , null ) ;
2018-10-02 09:17:58 +02:00
hostingNode . attachResource ( activates ) ;
2016-11-28 09:13:20 +01:00
2016-12-19 14:59:27 +01:00
resourceManagement = new ResourceManagement ( ) ;
2016-12-30 17:31:12 +01:00
resourceManagement . setElementType ( HostingNode . NAME ) ;
2020-02-03 10:52:09 +01:00
resourceManagement . setJson ( ElementMapper . marshal ( hostingNode ) ) ;
2016-12-19 14:59:27 +01:00
String hnJson = resourceManagement . create ( ) ;
2016-11-11 11:54:41 +01:00
logger . debug ( " Created : {} " , hnJson ) ;
2020-02-03 10:52:09 +01:00
hostingNode = ElementMapper . unmarshal ( HostingNode . class , hnJson ) ;
2016-11-11 11:54:41 +01:00
logger . debug ( " Unmarshalled {} {} " , HostingNode . NAME , hostingNode ) ;
2016-11-14 12:02:51 +01:00
UUID uuid = hostingNode . getHeader ( ) . getUUID ( ) ;
2016-12-19 14:59:27 +01:00
/* ------------------------------------------------------------------ */
logger . debug ( " Switching to another scope " ) ;
2019-10-28 15:06:31 +01:00
ContextTest . setContextByName ( ALTERNATIVE_TEST_SCOPE ) ;
2016-12-19 14:59:27 +01:00
resourceManagement = new ResourceManagement ( ) ;
resourceManagement . setUUID ( uuid ) ;
2018-06-06 19:26:19 +02:00
boolean addedToContext = resourceManagement . addToContext ( ContextUtility . getCurrentSecurityContext ( ) . getUUID ( ) ) ;
2016-11-14 12:02:51 +01:00
Assert . assertTrue ( addedToContext ) ;
2016-11-28 09:13:20 +01:00
2016-12-19 14:59:27 +01:00
resourceManagement = new ResourceManagement ( ) ;
resourceManagement . setUUID ( uuid ) ;
String hnString = resourceManagement . read ( ) ;
2020-02-03 10:52:09 +01:00
HostingNode readHN = ElementMapper . unmarshal ( HostingNode . class , hnString ) ;
2016-11-28 09:13:20 +01:00
Assert . assertTrue ( readHN . getHeader ( ) . getUUID ( ) . compareTo ( uuid ) = = 0 ) ;
2016-11-14 12:02:51 +01:00
UUID eServiceUUID = eService . getHeader ( ) . getUUID ( ) ;
try {
2016-12-19 14:59:27 +01:00
resourceManagement = new ResourceManagement ( ) ;
resourceManagement . setUUID ( eServiceUUID ) ;
resourceManagement . read ( ) ;
2017-03-29 16:14:03 +02:00
} catch ( ResourceAvailableInAnotherContextException e ) {
2016-11-28 09:13:20 +01:00
logger . debug ( " Resource with {} Not Found as Expected " ,
2016-12-19 14:59:27 +01:00
eServiceUUID ) ;
2016-11-28 09:13:20 +01:00
}
2017-05-02 15:30:00 +02:00
/ * Commented because the behavior has been changed
2016-11-28 09:13:20 +01:00
try {
2016-12-19 14:59:27 +01:00
resourceManagement = new ResourceManagement ( ) ;
resourceManagement . setUUID ( eServiceUUID ) ;
resourceManagement . delete ( ) ;
2017-05-02 15:30:00 +02:00
logger . debug ( " You should not be able to delete EService with UUID {} " ,
uuid ) ;
throw new Exception (
" You should not be able to delete EService with UUID " + uuid ) ;
2017-03-29 16:14:03 +02:00
} catch ( ResourceAvailableInAnotherContextException e ) {
2016-12-27 15:31:39 +01:00
logger . debug ( " Resource with {} Not Deleted as Expected " ,
2016-12-19 14:59:27 +01:00
eServiceUUID ) ;
2016-11-28 09:13:20 +01:00
}
2017-05-02 15:30:00 +02:00
* /
2016-11-28 09:13:20 +01:00
2016-12-19 14:59:27 +01:00
resourceManagement = new ResourceManagement ( ) ;
resourceManagement . setUUID ( uuid ) ;
boolean deleted = resourceManagement . delete ( ) ;
Assert . assertTrue ( deleted ) ;
/* ------------------------------------------------------------------ */
logger . debug ( " Setting back default scope " ) ;
2019-10-28 15:06:31 +01:00
ContextTest . setContextByName ( DEFAULT_TEST_SCOPE ) ;
2016-12-19 14:59:27 +01:00
resourceManagement = new ResourceManagement ( ) ;
resourceManagement . setUUID ( eServiceUUID ) ;
deleted = resourceManagement . delete ( ) ;
2017-05-02 15:30:00 +02:00
Assert . assertTrue ( deleted ) ;
2016-11-10 15:13:51 +01:00
}
2016-11-28 09:13:20 +01:00
// @Test
public void addTest ( ) throws ResourceNotFoundException ,
ContextNotFoundException , ResourceRegistryException {
2016-12-19 14:59:27 +01:00
ResourceManagement resourceManagement = new ResourceManagement ( ) ;
resourceManagement . setUUID ( UUID . fromString ( " " ) ) ;
2018-06-06 19:26:19 +02:00
resourceManagement . addToContext ( ContextUtility . getCurrentSecurityContext ( ) . getUUID ( ) ) ;
2016-11-10 15:13:51 +01:00
}
2017-03-23 13:37:15 +01:00
@Test
public void testAddAndRemoveFromContext ( ) throws Exception {
/* Creating HostingNode */
ResourceManagement resourceManagement = new ResourceManagement ( ) ;
resourceManagement . setElementType ( HostingNode . NAME ) ;
2019-02-13 12:33:29 +01:00
resourceManagement . setJson ( SmartgearResourcesTest . HOSTING_NODE ) ;
2017-03-23 13:37:15 +01:00
String hnJson = resourceManagement . create ( ) ;
logger . debug ( " Created : {} " , hnJson ) ;
2020-02-03 10:52:09 +01:00
HostingNode hostingNode = ElementMapper . unmarshal ( HostingNode . class , hnJson ) ;
2017-03-23 13:37:15 +01:00
logger . debug ( " Unmarshalled {} {} " , HostingNode . NAME , hostingNode ) ;
UUID hnUUID = hostingNode . getHeader ( ) . getUUID ( ) ;
/* Creating EService */
resourceManagement = new ResourceManagement ( ) ;
resourceManagement . setElementType ( EService . NAME ) ;
2019-02-13 12:33:29 +01:00
resourceManagement . setJson ( SmartgearResourcesTest . ESERVICE ) ;
2017-03-23 13:37:15 +01:00
String eservicejson = resourceManagement . create ( ) ;
logger . debug ( " Created : {} " , eservicejson ) ;
2020-02-03 10:52:09 +01:00
EService eService = ElementMapper . unmarshal ( EService . class , eservicejson ) ;
2017-03-23 13:37:15 +01:00
logger . debug ( " Unmarshalled {} {} " , EService . NAME , eService ) ;
UUID eServiceUUID = eService . getHeader ( ) . getUUID ( ) ;
2018-10-02 09:17:58 +02:00
/* Creating Activates Relation */
2017-03-23 13:37:15 +01:00
PropagationConstraint propagationConstraint = new PropagationConstraintImpl ( ) ;
propagationConstraint
. setRemoveConstraint ( RemoveConstraint . cascade ) ;
propagationConstraint
. setAddConstraint ( AddConstraint . propagate ) ;
2018-10-02 09:17:58 +02:00
Activates < HostingNode , EService > activates = new ActivatesImpl < > ( hostingNode , eService ,
2017-03-23 13:37:15 +01:00
propagationConstraint ) ;
IsRelatedToManagement isRelatedToManagement = new IsRelatedToManagement ( ) ;
2018-10-02 09:17:58 +02:00
isRelatedToManagement . setElementType ( Activates . NAME ) ;
2020-02-03 10:52:09 +01:00
String activatesJson = ElementMapper . marshal ( activates ) ;
2019-02-13 12:33:29 +01:00
isRelatedToManagement . setJson ( activatesJson ) ;
2018-10-02 09:17:58 +02:00
String createdActivatesJson = isRelatedToManagement . create ( ) ;
logger . debug ( " Created : {} " , createdActivatesJson ) ;
2017-03-23 13:37:15 +01:00
@SuppressWarnings ( " unchecked " )
2020-02-03 10:52:09 +01:00
Activates < HostingNode , EService > createdActivates = ElementMapper . unmarshal ( Activates . class , createdActivatesJson ) ;
2018-10-02 09:17:58 +02:00
UUID activatesUUID = createdActivates . getHeader ( ) . getUUID ( ) ;
2017-03-23 13:37:15 +01:00
/* ------------------------------------------------------------------ */
logger . debug ( " Switching to alternative scope " ) ;
2019-10-28 15:06:31 +01:00
ContextTest . setContextByName ( ALTERNATIVE_TEST_SCOPE ) ;
2017-03-23 13:37:15 +01:00
/ *
* resourceManagement = new ResourceManagement ( ) ;
* resourceManagement . setUUID ( hnUUID ) ;
* resourceManagement . addToContext ( ) ;
* resourceManagement = new ResourceManagement ( ) ;
* resourceManagement . setUUID ( eServiceUUID ) ;
* resourceManagement . addToContext ( ) ;
*
* This code is commented because the addToContext
* on relation enforce addToContext both on source
* and target
*
* /
isRelatedToManagement = new IsRelatedToManagement ( ) ;
2018-10-02 09:17:58 +02:00
isRelatedToManagement . setUUID ( activatesUUID ) ;
2018-06-06 19:26:19 +02:00
isRelatedToManagement . addToContext ( ContextUtility . getCurrentSecurityContext ( ) . getUUID ( ) ) ;
2017-03-23 13:37:15 +01:00
/ * The addTocontext on the relation adds the source and target too .
* So that I MUST be able to read HostinNode and EService
* /
resourceManagement = new ResourceManagement ( ) ;
resourceManagement . setUUID ( hnUUID ) ;
resourceManagement . read ( ) ;
resourceManagement = new ResourceManagement ( ) ;
resourceManagement . setUUID ( eServiceUUID ) ;
resourceManagement . read ( ) ;
/* ------------------------------------------------------------------ */
logger . debug ( " Setting back default scope " ) ;
2019-10-28 15:06:31 +01:00
ContextTest . setContextByName ( DEFAULT_TEST_SCOPE ) ;
2017-03-23 13:37:15 +01:00
resourceManagement = new ResourceManagement ( ) ;
resourceManagement . setUUID ( hnUUID ) ;
2018-06-06 19:26:19 +02:00
boolean removed = resourceManagement . removeFromContext ( ContextUtility . getCurrentSecurityContext ( ) . getUUID ( ) ) ;
2017-03-23 13:37:15 +01:00
Assert . assertTrue ( removed ) ;
/ * The cascading MUST remove the relation and the target so that
2018-10-02 09:17:58 +02:00
* I MUST not be able to read Activates relation and EService
2017-03-23 13:37:15 +01:00
* /
resourceManagement = new ResourceManagement ( ) ;
resourceManagement . setUUID ( eServiceUUID ) ;
try {
resourceManagement . read ( ) ;
String error = String . format ( " {} with UUID {} should not be visible. " , EService . NAME , eServiceUUID ) ;
logger . trace ( error ) ;
throw new Exception ( error ) ;
2017-03-29 16:14:03 +02:00
} catch ( ResourceAvailableInAnotherContextException e ) {
2017-03-23 13:37:15 +01:00
// OK
}
isRelatedToManagement = new IsRelatedToManagement ( ) ;
2018-10-02 09:17:58 +02:00
isRelatedToManagement . setUUID ( activatesUUID ) ;
2017-03-23 13:37:15 +01:00
try {
isRelatedToManagement . read ( ) ;
2018-10-02 09:17:58 +02:00
String error = String . format ( " {} with UUID {} should not be visible. " , Activates . NAME , activatesUUID ) ;
2017-03-23 13:37:15 +01:00
logger . trace ( error ) ;
throw new Exception ( error ) ;
2017-03-29 16:14:03 +02:00
} catch ( RelationAvailableInAnotherContextException e ) {
2017-03-23 13:37:15 +01:00
// OK
}
/* ------------------------------------------------------------------ */
logger . debug ( " Switching to alternative scope again " ) ;
2019-10-28 15:06:31 +01:00
ContextTest . setContextByName ( ALTERNATIVE_TEST_SCOPE ) ;
2017-03-23 13:37:15 +01:00
// TODO checks here
resourceManagement = new ResourceManagement ( ) ;
resourceManagement . setUUID ( hnUUID ) ;
boolean deleted = resourceManagement . delete ( ) ;
Assert . assertTrue ( deleted ) ;
}
2020-11-03 16:30:24 +01:00
2020-11-05 15:58:30 +01:00
// @Test
2020-11-03 16:30:24 +01:00
public void testGetInstanceContexts ( ) throws ObjectNotFound , Exception {
2020-11-05 15:58:30 +01:00
String type = " HostingNode " ;
String instanceId = " f0460614-9ffb-4ecd-bf52-d91e8d81d604 " ;
2020-11-03 16:30:24 +01:00
@SuppressWarnings ( " rawtypes " )
ElementManagement erManagement = ElementManagementUtility . getERManagement ( type ) ;
UUID uuid = null ;
try {
uuid = UUID . fromString ( instanceId ) ;
} catch ( Exception e ) {
throw new ResourceRegistryException ( e ) ;
}
erManagement . setUUID ( uuid ) ;
String contexts = erManagement . getContexts ( ) ;
logger . debug ( " {} " , contexts ) ;
}
2020-11-05 15:58:30 +01:00
protected ContextCacheRenewal contextCacheRenewal = new ContextCacheRenewal ( ) {
@Override
public List < Context > renew ( ) throws ResourceRegistryException {
ContextManagement contextManagement = new ContextManagement ( ) ;
String contextsJsonString = contextManagement . allFromServer ( false ) ;
List < Context > contexts = null ;
try {
contexts = ElementMapper . unmarshalList ( contextsJsonString ) ;
} catch ( IOException e ) {
logger . error ( " Unable to read context from server " , e ) ;
}
return contexts ;
}
} ;
@Test
public void testGetInstancesContexts ( ) throws ResourceRegistryException , Exception {
ContextTest . setContextByName ( DEFAULT_TEST_SCOPE ) ;
/* Creating HostingNode */
ContextCache contextCache = ContextCache . getInstance ( ) ;
contextCache . setContextCacheRenewal ( contextCacheRenewal ) ;
ResourceManagement hostingNodeManagement = new ResourceManagement ( ) ;
hostingNodeManagement . setElementType ( HostingNode . NAME ) ;
hostingNodeManagement . setJson ( SmartgearResourcesTest . HOSTING_NODE ) ;
String hnJson = hostingNodeManagement . create ( ) ;
logger . debug ( " Created : {} " , hnJson ) ;
HostingNode hostingNode = ElementMapper . unmarshal ( HostingNode . class , hnJson ) ;
logger . debug ( " Unmarshalled {} {} " , HostingNode . NAME , hostingNode ) ;
/* Creating EService */
ResourceManagement eServiceManagement = new ResourceManagement ( ) ;
eServiceManagement . setElementType ( EService . NAME ) ;
eServiceManagement . setJson ( SmartgearResourcesTest . ESERVICE ) ;
String eservicejson = eServiceManagement . create ( ) ;
logger . debug ( " Created : {} " , eservicejson ) ;
EService eService = ElementMapper . unmarshal ( EService . class , eservicejson ) ;
logger . debug ( " Unmarshalled {} {} " , EService . NAME , eService ) ;
/* Creating Activates Relation */
PropagationConstraint propagationConstraint = new PropagationConstraintImpl ( ) ;
propagationConstraint
. setRemoveConstraint ( RemoveConstraint . cascade ) ;
propagationConstraint
. setAddConstraint ( AddConstraint . unpropagate ) ;
Activates < HostingNode , EService > activates = new ActivatesImpl < > ( hostingNode , eService ,
propagationConstraint ) ;
IsRelatedToManagement activatesManagement = new IsRelatedToManagement ( ) ;
activatesManagement . setElementType ( Activates . NAME ) ;
String activatesJson = ElementMapper . marshal ( activates ) ;
activatesManagement . setJson ( activatesJson ) ;
String createdActivatesJson = activatesManagement . create ( ) ;
logger . debug ( " Created : {} " , createdActivatesJson ) ;
@SuppressWarnings ( " unchecked " )
Activates < HostingNode , EService > createdActivates = ElementMapper . unmarshal ( Activates . class , createdActivatesJson ) ;
logger . debug ( " UnMarshalled {} " , createdActivates ) ;
/* ------------------------------------------------------------------ */
logger . debug ( " Switching to alternative scope " ) ;
ContextTest . setContextByName ( ALTERNATIVE_TEST_SCOPE ) ;
hostingNodeManagement = new ResourceManagement ( ) ;
hostingNodeManagement . setUUID ( hostingNode . getHeader ( ) . getUUID ( ) ) ;
hostingNodeManagement . setElementType ( Utility . getTypeName ( hostingNode . getClass ( ) ) ) ;
hostingNodeManagement . addToContext ( ContextUtility . getCurrentSecurityContext ( ) . getUUID ( ) ) ;
String hostingNodeContexts = hostingNodeManagement . getContexts ( ) ;
logger . debug ( " Contexts of {} with UUID {} have the following UUID {} " , HostingNode . NAME , hostingNodeManagement . getUUID ( ) , hostingNodeContexts ) ;
Set < UUID > hostingNodeContextsUUID = org . gcube . informationsystem . resourceregistry . api . contexts . ContextUtility . getContextUUIDSet ( hostingNodeContexts ) ;
Assert . assertTrue ( hostingNodeContextsUUID . size ( ) = = 2 ) ;
Set < String > hostingNodeContextFullNames = org . gcube . informationsystem . resourceregistry . api . contexts . ContextUtility . getContextFullNameSet ( hostingNodeContextsUUID ) ;
Assert . assertTrue ( hostingNodeContextFullNames . size ( ) = = 2 ) ;
logger . debug ( " Contexts of {} with UUID {} are {} " , HostingNode . NAME , hostingNodeManagement . getUUID ( ) , hostingNodeContextFullNames ) ;
for ( Facet facet : hostingNode . getFacets ( ) ) {
FacetManagement facetManagement = new FacetManagement ( ) ;
facetManagement . setUUID ( facet . getHeader ( ) . getUUID ( ) ) ;
String typeName = Utility . getTypeName ( facet . getClass ( ) ) ;
facetManagement . setElementType ( typeName ) ;
String facetContexts = facetManagement . getContexts ( ) ;
logger . debug ( " Contexts of {} with UUID {} have the following UUID {} " , typeName , facetManagement . getUUID ( ) , facetContexts ) ;
Set < UUID > facetContextsUUID = org . gcube . informationsystem . resourceregistry . api . contexts . ContextUtility . getContextUUIDSet ( facetContexts ) ;
Assert . assertTrue ( hostingNodeContextsUUID . size ( ) = = 2 ) ;
Assert . assertTrue ( facetContextsUUID . containsAll ( hostingNodeContextsUUID ) ) ;
Assert . assertTrue ( hostingNodeContextsUUID . containsAll ( facetContextsUUID ) ) ;
Set < String > facetContextFullNames = org . gcube . informationsystem . resourceregistry . api . contexts . ContextUtility . getContextFullNameSet ( facetContextsUUID ) ;
Assert . assertTrue ( facetContextFullNames . size ( ) = = 2 ) ;
logger . debug ( " Contexts of {} with UUID {} are {} " , typeName , facetManagement . getUUID ( ) , facetContextFullNames ) ;
}
activatesManagement = new IsRelatedToManagement ( ) ;
activatesManagement . setUUID ( createdActivates . getHeader ( ) . getUUID ( ) ) ;
activatesManagement . setElementType ( Utility . getTypeName ( createdActivates . getClass ( ) ) ) ;
String isRelatedToContexts = activatesManagement . getContexts ( ) ;
logger . debug ( " Contexts of {} with UUID {} have the following UUID {} " , Activates . NAME , activatesManagement . getUUID ( ) , isRelatedToContexts ) ;
Set < UUID > activatesContextsUUID = org . gcube . informationsystem . resourceregistry . api . contexts . ContextUtility . getContextUUIDSet ( isRelatedToContexts ) ;
Assert . assertTrue ( activatesContextsUUID . size ( ) = = 1 ) ;
Assert . assertFalse ( activatesContextsUUID . containsAll ( hostingNodeContextsUUID ) ) ;
Assert . assertTrue ( hostingNodeContextsUUID . containsAll ( activatesContextsUUID ) ) ;
Set < String > activatesContextFullNames = org . gcube . informationsystem . resourceregistry . api . contexts . ContextUtility . getContextFullNameSet ( activatesContextsUUID ) ;
Assert . assertTrue ( activatesContextFullNames . size ( ) = = 1 ) ;
logger . debug ( " Contexts of {} with UUID {} are {} " , Activates . NAME , activatesManagement . getUUID ( ) , activatesContextFullNames ) ;
eServiceManagement = new ResourceManagement ( ) ;
eServiceManagement . setUUID ( eService . getHeader ( ) . getUUID ( ) ) ;
eServiceManagement . setElementType ( Utility . getTypeName ( eService . getClass ( ) ) ) ;
String eServiceContexts = eServiceManagement . getContexts ( ) ;
logger . debug ( " Contexts of {} with UUID {} have the following UUID {} " , EService . NAME , eServiceManagement . getUUID ( ) , eServiceContexts ) ;
Set < UUID > eServiceContextsUUID = org . gcube . informationsystem . resourceregistry . api . contexts . ContextUtility . getContextUUIDSet ( eServiceContexts ) ;
Assert . assertTrue ( eServiceContextsUUID . size ( ) = = 1 ) ;
Assert . assertFalse ( eServiceContextsUUID . containsAll ( hostingNodeContextsUUID ) ) ;
Assert . assertTrue ( hostingNodeContextsUUID . containsAll ( eServiceContextsUUID ) ) ;
Set < String > eServiceContextFullNames = org . gcube . informationsystem . resourceregistry . api . contexts . ContextUtility . getContextFullNameSet ( eServiceContextsUUID ) ;
Assert . assertTrue ( eServiceContextFullNames . size ( ) = = 1 ) ;
logger . debug ( " Contexts of {} with UUID {} are {} " , EService . NAME , eServiceManagement . getUUID ( ) , eServiceContextFullNames ) ;
boolean deleted = hostingNodeManagement . delete ( ) ;
Assert . assertTrue ( deleted ) ;
}
2020-11-09 15:45:07 +01:00
@Test
public void testGetContextsInInstances ( ) throws ResourceRegistryException , Exception {
ContextTest . setContextByName ( DEFAULT_TEST_SCOPE ) ;
/* Creating HostingNode */
ContextCache contextCache = ContextCache . getInstance ( ) ;
contextCache . setContextCacheRenewal ( contextCacheRenewal ) ;
ResourceManagement hostingNodeManagement = new ResourceManagement ( ) ;
hostingNodeManagement . setElementType ( HostingNode . NAME ) ;
hostingNodeManagement . setJson ( SmartgearResourcesTest . HOSTING_NODE ) ;
String hnJson = hostingNodeManagement . create ( ) ;
logger . debug ( " Created : {} " , hnJson ) ;
HostingNode hostingNode = ElementMapper . unmarshal ( HostingNode . class , hnJson ) ;
logger . debug ( " Unmarshalled {} {} " , HostingNode . NAME , hostingNode ) ;
/* Creating EService */
ResourceManagement eServiceManagement = new ResourceManagement ( ) ;
eServiceManagement . setElementType ( EService . NAME ) ;
eServiceManagement . setJson ( SmartgearResourcesTest . ESERVICE ) ;
String eservicejson = eServiceManagement . create ( ) ;
logger . debug ( " Created : {} " , eservicejson ) ;
EService eService = ElementMapper . unmarshal ( EService . class , eservicejson ) ;
logger . debug ( " Unmarshalled {} {} " , EService . NAME , eService ) ;
/* Creating Activates Relation */
PropagationConstraint propagationConstraint = new PropagationConstraintImpl ( ) ;
propagationConstraint
. setRemoveConstraint ( RemoveConstraint . cascade ) ;
propagationConstraint
. setAddConstraint ( AddConstraint . unpropagate ) ;
Activates < HostingNode , EService > activates = new ActivatesImpl < > ( hostingNode , eService ,
propagationConstraint ) ;
IsRelatedToManagement activatesManagement = new IsRelatedToManagement ( ) ;
activatesManagement . setElementType ( Activates . NAME ) ;
String activatesJson = ElementMapper . marshal ( activates ) ;
activatesManagement . setJson ( activatesJson ) ;
String createdActivatesJson = activatesManagement . create ( ) ;
logger . debug ( " Created : {} " , createdActivatesJson ) ;
@SuppressWarnings ( " unchecked " )
Activates < HostingNode , EService > createdActivates = ElementMapper . unmarshal ( Activates . class , createdActivatesJson ) ;
logger . debug ( " UnMarshalled {} " , createdActivates ) ;
/* ------------------------------------------------------------------ */
logger . debug ( " Switching to alternative scope " ) ;
ContextTest . setContextByName ( ALTERNATIVE_TEST_SCOPE ) ;
hostingNodeManagement = new ResourceManagement ( ) ;
hostingNodeManagement . setUUID ( hostingNode . getHeader ( ) . getUUID ( ) ) ;
hostingNodeManagement . setElementType ( Utility . getTypeName ( hostingNode . getClass ( ) ) ) ;
hostingNodeManagement . addToContext ( ContextUtility . getCurrentSecurityContext ( ) . getUUID ( ) ) ;
ContextUtility . getIncludeInstanceContexts ( ) . set ( true ) ;
String hostingNodeJson = hostingNodeManagement . read ( ) ;
HostingNode hostingNodeRead = ElementMapper . unmarshal ( HostingNode . class , hostingNodeJson ) ;
logger . debug ( " Unmarshalled {} {} " , HostingNode . NAME , hostingNodeRead ) ;
@SuppressWarnings ( " unchecked " )
Collection < String > contextsCollection = ( Collection < String > ) hostingNodeRead . getHeader ( ) . getAdditionalProperty ( Header . __CONTEXTS ) ;
Assert . assertTrue ( contextsCollection . size ( ) = = 2 ) ;
Set < UUID > hostingNodeContextsUUID = org . gcube . informationsystem . resourceregistry . api . contexts . ContextUtility . getContextUUIDSet ( contextsCollection ) ;
Assert . assertTrue ( hostingNodeContextsUUID . size ( ) = = 2 ) ;
Set < String > hostingNodeContextFullNames = org . gcube . informationsystem . resourceregistry . api . contexts . ContextUtility . getContextFullNameSet ( hostingNodeContextsUUID ) ;
Assert . assertTrue ( hostingNodeContextFullNames . size ( ) = = 2 ) ;
logger . debug ( " Contexts of {} with UUID {} are {} " , HostingNode . NAME , hostingNodeManagement . getUUID ( ) , hostingNodeContextFullNames ) ;
for ( Facet facet : hostingNode . getFacets ( ) ) {
FacetManagement facetManagement = new FacetManagement ( ) ;
facetManagement . setUUID ( facet . getHeader ( ) . getUUID ( ) ) ;
String typeName = Utility . getTypeName ( facet . getClass ( ) ) ;
facetManagement . setElementType ( typeName ) ;
String facetJson = facetManagement . read ( ) ;
Facet facetRead = ElementMapper . unmarshal ( Facet . class , facetJson ) ;
logger . debug ( " Unmarshalled {} {} " , Utility . getTypeName ( facetRead . getClass ( ) ) , facetRead ) ;
@SuppressWarnings ( " unchecked " )
Collection < String > facetContextsCollection = ( Collection < String > ) facetRead . getHeader ( ) . getAdditionalProperty ( Header . __CONTEXTS ) ;
Assert . assertTrue ( contextsCollection . size ( ) = = 2 ) ;
Set < UUID > facetContextsUUID = org . gcube . informationsystem . resourceregistry . api . contexts . ContextUtility . getContextUUIDSet ( facetContextsCollection ) ;
Assert . assertTrue ( hostingNodeContextsUUID . size ( ) = = 2 ) ;
Assert . assertTrue ( facetContextsUUID . containsAll ( hostingNodeContextsUUID ) ) ;
Assert . assertTrue ( hostingNodeContextsUUID . containsAll ( facetContextsUUID ) ) ;
Set < String > facetContextFullNames = org . gcube . informationsystem . resourceregistry . api . contexts . ContextUtility . getContextFullNameSet ( facetContextsUUID ) ;
Assert . assertTrue ( facetContextFullNames . size ( ) = = 2 ) ;
logger . debug ( " Contexts of {} with UUID {} are {} " , typeName , facetManagement . getUUID ( ) , facetContextFullNames ) ;
}
activatesManagement = new IsRelatedToManagement ( ) ;
activatesManagement . setUUID ( createdActivates . getHeader ( ) . getUUID ( ) ) ;
activatesManagement . setElementType ( Utility . getTypeName ( createdActivates . getClass ( ) ) ) ;
try {
activatesManagement . read ( ) ;
String error = String . format ( " It should not be possible to read %s in %s. A %s should be raised instead " , Activates . NAME , ALTERNATIVE_TEST_SCOPE , AvailableInAnotherContextException . class . getSimpleName ( ) ) ;
throw new Exception ( error ) ;
} catch ( AvailableInAnotherContextException e ) {
// This is what we expect
}
// Restoring DEFAULT TEST SCOPE otherwise is not possible to read activates relation
// which is not available in ALTERNATIVE_TEST_SCOPE
ContextTest . setContextByName ( DEFAULT_TEST_SCOPE ) ;
activatesManagement = new IsRelatedToManagement ( ) ;
activatesManagement . setUUID ( createdActivates . getHeader ( ) . getUUID ( ) ) ;
activatesManagement . setElementType ( Utility . getTypeName ( createdActivates . getClass ( ) ) ) ;
// reading again
String activatesReadJson = activatesManagement . read ( ) ;
@SuppressWarnings ( " unchecked " )
Activates < HostingNode , EService > activatesRead = ElementMapper . unmarshal ( Activates . class , activatesReadJson ) ;
logger . debug ( " Unmarshalled {} {} " , Utility . getTypeName ( activatesRead . getClass ( ) ) , activatesRead ) ;
@SuppressWarnings ( " unchecked " )
Collection < String > activatesContextsCollection = ( Collection < String > ) activatesRead . getHeader ( ) . getAdditionalProperty ( Header . __CONTEXTS ) ;
logger . debug ( " Contexts of {} with UUID {} have the following UUID {} " , Activates . NAME , activatesManagement . getUUID ( ) , activatesContextsCollection ) ;
Set < UUID > activatesContextsUUID = org . gcube . informationsystem . resourceregistry . api . contexts . ContextUtility . getContextUUIDSet ( activatesContextsCollection ) ;
Assert . assertTrue ( activatesContextsUUID . size ( ) = = 1 ) ;
Assert . assertFalse ( activatesContextsUUID . containsAll ( hostingNodeContextsUUID ) ) ;
Assert . assertTrue ( hostingNodeContextsUUID . containsAll ( activatesContextsUUID ) ) ;
Set < String > activatesContextFullNames = org . gcube . informationsystem . resourceregistry . api . contexts . ContextUtility . getContextFullNameSet ( activatesContextsUUID ) ;
Assert . assertTrue ( activatesContextFullNames . size ( ) = = 1 ) ;
logger . debug ( " Contexts of {} with UUID {} are {} " , Activates . NAME , activatesManagement . getUUID ( ) , activatesContextFullNames ) ;
eServiceManagement = new ResourceManagement ( ) ;
eServiceManagement . setUUID ( eService . getHeader ( ) . getUUID ( ) ) ;
eServiceManagement . setElementType ( Utility . getTypeName ( eService . getClass ( ) ) ) ;
String eServiceReadJson = eServiceManagement . read ( ) ;
EService eServiceRead = ElementMapper . unmarshal ( EService . class , eServiceReadJson ) ;
logger . debug ( " Unmarshalled {} {} " , Utility . getTypeName ( eServiceRead . getClass ( ) ) , eServiceRead ) ;
@SuppressWarnings ( " unchecked " )
Collection < String > eServiceContextsCollection = ( Collection < String > ) eServiceRead . getHeader ( ) . getAdditionalProperty ( Header . __CONTEXTS ) ;
logger . debug ( " Contexts of {} with UUID {} have the following UUID {} " , EService . NAME , eServiceManagement . getUUID ( ) , eServiceContextsCollection ) ;
Set < UUID > eServiceContextsUUID = org . gcube . informationsystem . resourceregistry . api . contexts . ContextUtility . getContextUUIDSet ( eServiceContextsCollection ) ;
Assert . assertTrue ( eServiceContextsUUID . size ( ) = = 1 ) ;
Assert . assertFalse ( eServiceContextsUUID . containsAll ( hostingNodeContextsUUID ) ) ;
Assert . assertTrue ( hostingNodeContextsUUID . containsAll ( eServiceContextsUUID ) ) ;
Set < String > eServiceContextFullNames = org . gcube . informationsystem . resourceregistry . api . contexts . ContextUtility . getContextFullNameSet ( eServiceContextsUUID ) ;
Assert . assertTrue ( eServiceContextFullNames . size ( ) = = 1 ) ;
logger . debug ( " Contexts of {} with UUID {} are {} " , EService . NAME , eServiceManagement . getUUID ( ) , eServiceContextFullNames ) ;
boolean deleted = hostingNodeManagement . delete ( ) ;
Assert . assertTrue ( deleted ) ;
}
2016-11-28 09:13:20 +01:00
2016-11-10 15:13:51 +01:00
}