Fixed tests to comply with new validation made by the service

This commit is contained in:
Luca Frosini 2021-02-23 11:33:57 +01:00
parent 30be493f4a
commit 3756439c72
7 changed files with 136 additions and 18 deletions

View File

@ -224,7 +224,20 @@ public abstract class ElementManagement<El extends OElement, T extends Type> {
}
}
public String getTypeName() {
public String getTypeName() throws NotFoundException, AvailableInAnotherContextException, ResourceRegistryException {
if(typeName==null) {
if(element!=null) {
typeName = element.getProperty(Element.CLASS_PROPERTY);
}
if(typeName==null && jsonNode!=null) {
this.typeName = getClassProperty(jsonNode);
}
if(typeName==null) {
typeName = getOClass().getName();
}
}
return typeName;
}

View File

@ -29,7 +29,6 @@ import org.gcube.informationsystem.model.reference.properties.PropagationConstra
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;
import org.gcube.informationsystem.model.reference.relations.Relation;
import org.gcube.informationsystem.resourceregistry.ContextTest;
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.facet.FacetNotFoundException;
@ -41,7 +40,6 @@ import org.gcube.informationsystem.resourceregistry.instances.model.entities.Res
import org.gcube.informationsystem.resourceregistry.instances.model.relations.ConsistsOfManagement;
import org.gcube.informationsystem.resourceregistry.instances.model.relations.IsRelatedToManagement;
import org.gcube.informationsystem.utils.ElementMapper;
import org.gcube.informationsystem.utils.Utility;
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;
@ -312,9 +310,11 @@ public class ERManagementTest extends ContextTest {
encrypted.setEncryptedValue("Value");
cpuFacet.setAdditionalProperty("Enc", encrypted);
String json = ElementMapper.marshal(cpuFacet);
FacetManagement facetManagement = new FacetManagement();
facetManagement.setElementType(CPUFacet.NAME);
facetManagement.setJson(ElementMapper.marshal(cpuFacet));
facetManagement.setJson(json);
String cpuFacetJson = facetManagement.create();
CPUFacet createdCpuFacet = ElementMapper.unmarshal(CPUFacet.class,
@ -626,6 +626,7 @@ public class ERManagementTest extends ContextTest {
}
}
/*
@Test
public void testCreateResourceAndFacet() throws Exception {
ResourceManagement resourceManagement = new ResourceManagement();
@ -677,7 +678,7 @@ public class ERManagementTest extends ContextTest {
boolean deleted = resourceManagement.delete();
Assert.assertTrue(deleted);
}
*/
@Test
public void testGetAll() throws Exception{

View File

@ -172,8 +172,8 @@ public class SmartgearResourcesTest extends ContextTest {
resourceManagement = new ResourceManagement();
resourceManagement.setUUID(eServiceUUID);
String read = resourceManagement.read().toString();
logger.debug("Read {} {}", EService.NAME, read);
EService readEService = ElementMapper.unmarshal(EService.class, read);
logger.debug("Read {} {}", EService.NAME, readEService);
Assert.assertTrue(eServiceUUID.compareTo(readEService.getHeader()
.getUUID()) == 0);

View File

@ -1,7 +1,10 @@
package org.gcube.informationsystem.resourceregistry.instances.model.entity;
import java.io.IOException;
import java.net.URI;
import java.net.URL;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
@ -19,17 +22,29 @@ import org.gcube.informationsystem.resourceregistry.instances.base.ElementManage
import org.gcube.informationsystem.resourceregistry.instances.base.ElementManagementUtility;
import org.gcube.informationsystem.resourceregistry.instances.model.entities.ResourceManagement;
import org.gcube.informationsystem.utils.ElementMapper;
import org.gcube.resourcemanagement.model.impl.entities.facets.AccessPointFacetImpl;
import org.gcube.resourcemanagement.model.impl.entities.facets.EventFacetImpl;
import org.gcube.resourcemanagement.model.impl.entities.facets.IdentifierFacetImpl;
import org.gcube.resourcemanagement.model.impl.entities.facets.LicenseFacetImpl;
import org.gcube.resourcemanagement.model.impl.entities.facets.SimplePropertyFacetImpl;
import org.gcube.resourcemanagement.model.impl.entities.facets.StateFacetImpl;
import org.gcube.resourcemanagement.model.impl.entities.resources.ConfigurationImpl;
import org.gcube.resourcemanagement.model.impl.entities.resources.EServiceImpl;
import org.gcube.resourcemanagement.model.impl.properties.ValueSchemaImpl;
import org.gcube.resourcemanagement.model.impl.relations.consistsof.IsIdentifiedByImpl;
import org.gcube.resourcemanagement.model.reference.entities.facets.AccessPointFacet;
import org.gcube.resourcemanagement.model.reference.entities.facets.EventFacet;
import org.gcube.resourcemanagement.model.reference.entities.facets.IdentifierFacet;
import org.gcube.resourcemanagement.model.reference.entities.facets.LicenseFacet;
import org.gcube.resourcemanagement.model.reference.entities.facets.SimplePropertyFacet;
import org.gcube.resourcemanagement.model.reference.entities.facets.IdentifierFacet.IdentificationType;
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.ConfigurationTemplate;
import org.gcube.resourcemanagement.model.reference.entities.resources.EService;
import org.gcube.resourcemanagement.model.reference.entities.resources.Service;
import org.gcube.resourcemanagement.model.reference.properties.ValueSchema;
import org.gcube.resourcemanagement.model.reference.relations.consistsof.IsIdentifiedBy;
import org.junit.Assert;
import org.junit.Test;
@ -59,12 +74,36 @@ public class ResourceManagementTest extends ContextTest {
/* Creating EService*/
EService eService = new EServiceImpl();
SoftwareFacet softwareFacet = FacetManagementTest.getSoftwareFacet();
IsIdentifiedBy<EService, Facet> isIdentifiedBy = new IsIdentifiedByImpl<EService, 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.setValue("Created");
event.setSchema(new URI(""));
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);
ResourceManagement resourceManagement = new ResourceManagement();
resourceManagement.setElementType(EService.NAME);
resourceManagement.setJson(ElementMapper.marshal(eService));
@ -146,6 +185,12 @@ public class ResourceManagementTest extends ContextTest {
IsIdentifiedBy<Configuration, IdentifierFacet> isIdentifiedBy = new IsIdentifiedByImpl<Configuration, IdentifierFacet>(configuration, identifierFacet);
configuration.addFacet(isIdentifiedBy);
SimplePropertyFacet simplePropertyFacet = new SimplePropertyFacetImpl();
simplePropertyFacet.setName("test");
simplePropertyFacet.setName("test");
configuration.addFacet(simplePropertyFacet);
ResourceManagement resourceManagement = new ResourceManagement();
resourceManagement.setElementType(Configuration.NAME);
resourceManagement.setJson(ElementMapper.marshal(configuration));

View File

@ -311,6 +311,18 @@ public class BasicTest extends MultiContextTest {
activates.setHeader(new HeaderImpl(activatedUUID));
hostingNode.attachResource(activates);
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);
resourceManagement = new ResourceManagement();
resourceManagement.setElementType(HostingNode.NAME);
resourceManagement.setJson(ElementMapper.marshal(hostingNode));
@ -422,13 +434,26 @@ public class BasicTest extends MultiContextTest {
/* Creating HostingNode */
HostingNode hostingNode = ElementMapper.unmarshal(HostingNode.class, SmartgearResourcesTest.HOSTING_NODE);
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);
String json = ElementMapper.marshal(hostingNode);
logger.trace("Going to create {}", json);
ResourceManagement resourceManagement = new ResourceManagement();
resourceManagement.setElementType(HostingNode.NAME);
resourceManagement.setJson(SmartgearResourcesTest.HOSTING_NODE);
resourceManagement.setJson(json);
String hnJson = resourceManagement.create();
logger.debug("Created : {}", hnJson);
HostingNode hostingNode = ElementMapper.unmarshal(HostingNode.class, hnJson);
hostingNode = ElementMapper.unmarshal(HostingNode.class, hnJson);
logger.debug("Unmarshalled {} {}", HostingNode.NAME, hostingNode);
UUID hnUUID = hostingNode.getHeader().getUUID();
@ -436,13 +461,25 @@ public class BasicTest extends MultiContextTest {
/* Creating EService */
EService eService = ElementMapper.unmarshal(EService.class, SmartgearResourcesTest.ESERVICE);
StateFacet stateFacet = new StateFacetImpl();
stateFacet.setValue("ready");
eService.addFacet(stateFacet);
EventFacet eventFacet = new EventFacetImpl();
eventFacet.setDate(Calendar.getInstance().getTime());
ValueSchema event = new ValueSchemaImpl();
event.setValue("Created");
eventFacet.setEvent(event);
eService.addFacet(eventFacet);
resourceManagement = new ResourceManagement();
resourceManagement.setElementType(EService.NAME);
resourceManagement.setJson(SmartgearResourcesTest.ESERVICE);
resourceManagement.setJson(ElementMapper.marshal(eService));
String eservicejson = resourceManagement.create();
logger.debug("Created : {}", eservicejson);
EService eService = ElementMapper.unmarshal(EService.class, eservicejson);
eService = ElementMapper.unmarshal(EService.class, eservicejson);
logger.debug("Unmarshalled {} {}", EService.NAME, eService);
UUID eServiceUUID = eService.getHeader().getUUID();

View File

@ -152,25 +152,47 @@ public class EnhancedTest extends MultiContextTest {
ContextCache contextCache = ContextCache.getInstance();
contextCache.setContextCacheRenewal(contextCacheRenewal);
HostingNode hostingNode = ElementMapper.unmarshal(HostingNode.class, SmartgearResourcesTest.HOSTING_NODE);
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);
ResourceManagement hostingNodeManagement = new ResourceManagement();
hostingNodeManagement.setElementType(HostingNode.NAME);
hostingNodeManagement.setJson(SmartgearResourcesTest.HOSTING_NODE);
hostingNodeManagement.setJson(ElementMapper.marshal(hostingNode));
String hnJson = hostingNodeManagement.create();
logger.debug("Created : {}", hnJson);
HostingNode hostingNode = ElementMapper.unmarshal(HostingNode.class, hnJson);
hostingNode = ElementMapper.unmarshal(HostingNode.class, hnJson);
logger.debug("Unmarshalled {} {}", HostingNode.NAME, hostingNode);
/* Creating EService */
EService eService = ElementMapper.unmarshal(EService.class, SmartgearResourcesTest.ESERVICE);
StateFacet stateFacet = new StateFacetImpl();
stateFacet.setValue("ready");
eService.addFacet(stateFacet);
EventFacet eventFacet = new EventFacetImpl();
eventFacet.setDate(Calendar.getInstance().getTime());
ValueSchema event = new ValueSchemaImpl();
event.setValue("Created");
eventFacet.setEvent(event);
eService.addFacet(eventFacet);
ResourceManagement eServiceManagement = new ResourceManagement();
eServiceManagement.setElementType(EService.NAME);
eServiceManagement.setJson(SmartgearResourcesTest.ESERVICE);
eServiceManagement.setJson(ElementMapper.marshal(eService));
String eservicejson = eServiceManagement.create();
logger.debug("Created : {}", eservicejson);
EService eService = ElementMapper.unmarshal(EService.class, eservicejson);
eService = ElementMapper.unmarshal(EService.class, eservicejson);
logger.debug("Unmarshalled {} {}", EService.NAME, eService);

View File

@ -17,8 +17,8 @@ public class TypesCacheTest {
private static Logger logger = LoggerFactory.getLogger(TypesCacheTest.class);
protected CachedType getCachedType(TypesCache typesCache, String typeName) throws Exception {
CachedType cachedType = typesCache.getCachedType(typeName);
protected CachedType<?> getCachedType(TypesCache typesCache, String typeName) throws Exception {
CachedType<?> cachedType = typesCache.getCachedType(typeName);
OClass oClass = cachedType.getOClass();
AccessType accessType = cachedType.getAccessType();
Type type = cachedType.getType();
@ -29,7 +29,7 @@ public class TypesCacheTest {
public void testCacheType(String typeName) throws Exception {
TypesCache typesCache = TypesCache.getInstance();
CachedType cachedType = getCachedType(typesCache, typeName);
CachedType<?> cachedType = getCachedType(typesCache, typeName);
List<String> superTypes = cachedType.getSuperTypes();
logger.debug("{} superTypes are {}", typeName, superTypes);