Improved Tests
This commit is contained in:
parent
c1f0a03de4
commit
8cec58eae8
|
@ -19,6 +19,7 @@ import java.util.UUID;
|
||||||
import org.gcube.com.fasterxml.jackson.core.JsonParseException;
|
import org.gcube.com.fasterxml.jackson.core.JsonParseException;
|
||||||
import org.gcube.com.fasterxml.jackson.databind.JsonMappingException;
|
import org.gcube.com.fasterxml.jackson.databind.JsonMappingException;
|
||||||
import org.gcube.common.authorization.library.provider.AuthorizationProvider;
|
import org.gcube.common.authorization.library.provider.AuthorizationProvider;
|
||||||
|
import org.gcube.informationsystem.base.reference.Element;
|
||||||
import org.gcube.informationsystem.base.reference.IdentifiableElement;
|
import org.gcube.informationsystem.base.reference.IdentifiableElement;
|
||||||
import org.gcube.informationsystem.model.impl.properties.EncryptedImpl;
|
import org.gcube.informationsystem.model.impl.properties.EncryptedImpl;
|
||||||
import org.gcube.informationsystem.model.impl.properties.PropagationConstraintImpl;
|
import org.gcube.informationsystem.model.impl.properties.PropagationConstraintImpl;
|
||||||
|
@ -147,7 +148,7 @@ public class ERManagementTest extends ContextTest {
|
||||||
return eService;
|
return eService;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static HostingNode instantiateValidHostinNode() throws Exception {
|
public static HostingNode instantiateValidHostingNode() throws Exception {
|
||||||
HostingNode hostingNode = new HostingNodeImpl();
|
HostingNode hostingNode = new HostingNodeImpl();
|
||||||
|
|
||||||
NetworkingFacet networkingFacet = new NetworkingFacetImpl();
|
NetworkingFacet networkingFacet = new NetworkingFacetImpl();
|
||||||
|
@ -198,43 +199,6 @@ public class ERManagementTest extends ContextTest {
|
||||||
return hostingNode;
|
return hostingNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Map<String, Resource> createHostingNodeAndEService() throws Exception {
|
|
||||||
Map<String, Resource> map = new HashMap<>();
|
|
||||||
|
|
||||||
EService eService = ERManagementTest.instantiateValidEService();
|
|
||||||
|
|
||||||
ResourceManagement resourceManagement = new ResourceManagement();
|
|
||||||
resourceManagement.setElementType(EService.NAME);
|
|
||||||
resourceManagement.setJson(ElementMapper.marshal(eService));
|
|
||||||
String json = resourceManagement.create();
|
|
||||||
|
|
||||||
logger.debug("Created : {}", json);
|
|
||||||
eService = ElementMapper.unmarshal(EService.class, json);
|
|
||||||
logger.debug("Unmarshalled {} {}", EService.NAME, eService);
|
|
||||||
map.put(EService.NAME, eService);
|
|
||||||
|
|
||||||
HostingNode hostingNode = ERManagementTest.instantiateValidHostinNode();
|
|
||||||
|
|
||||||
PropagationConstraint propagationConstraint = new PropagationConstraintImpl();
|
|
||||||
propagationConstraint.setRemoveConstraint(RemoveConstraint.cascade);
|
|
||||||
Activates<HostingNode, EService> activates = new ActivatesImpl<HostingNode, EService>(hostingNode, eService,
|
|
||||||
propagationConstraint);
|
|
||||||
hostingNode.attachResource(activates);
|
|
||||||
|
|
||||||
resourceManagement = new ResourceManagement();
|
|
||||||
resourceManagement.setElementType(HostingNode.NAME);
|
|
||||||
resourceManagement.setJson(ElementMapper.marshal(hostingNode));
|
|
||||||
|
|
||||||
json = resourceManagement.create();
|
|
||||||
logger.debug("Created : {}", json);
|
|
||||||
hostingNode = ElementMapper.unmarshal(HostingNode.class, json);
|
|
||||||
logger.debug("Unmarshalled {} {}", HostingNode.NAME, hostingNode);
|
|
||||||
map.put(HostingNode.NAME, hostingNode);
|
|
||||||
|
|
||||||
return map;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static void checkHeader(IdentifiableElement identifiableElement, IdentifiableElement createdIdentifiableElement) {
|
public static void checkHeader(IdentifiableElement identifiableElement, IdentifiableElement createdIdentifiableElement) {
|
||||||
Header createdHeader = createdIdentifiableElement.getHeader();
|
Header createdHeader = createdIdentifiableElement.getHeader();
|
||||||
Assert.assertTrue(createdHeader!=null);
|
Assert.assertTrue(createdHeader!=null);
|
||||||
|
@ -253,6 +217,7 @@ public class ERManagementTest extends ContextTest {
|
||||||
|
|
||||||
Date lastUpdateTime = createdHeader.getLastUpdateTime();
|
Date lastUpdateTime = createdHeader.getLastUpdateTime();
|
||||||
Assert.assertTrue(lastUpdateTime!=null);
|
Assert.assertTrue(lastUpdateTime!=null);
|
||||||
|
Assert.assertTrue(lastUpdateTime.equals(creationTime) || lastUpdateTime.equals(lastUpdateTime));
|
||||||
|
|
||||||
Header header = identifiableElement.getHeader();
|
Header header = identifiableElement.getHeader();
|
||||||
if(header!=null) {
|
if(header!=null) {
|
||||||
|
@ -267,44 +232,76 @@ public class ERManagementTest extends ContextTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
if(header.getLastUpdateBy()!=null) {
|
if(header.getLastUpdateBy()!=null) {
|
||||||
|
Assert.assertTrue(lastUpdateBy.compareTo(header.getLastUpdateBy())==0);
|
||||||
|
}else {
|
||||||
|
Assert.assertTrue(lastUpdateBy.compareTo(HeaderUtility.getUser())==0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(header.getCreationTime()!=null) {
|
if(header.getCreationTime()!=null) {
|
||||||
|
Assert.assertTrue(creationTime.equals(header.getCreationTime()));
|
||||||
}
|
}
|
||||||
|
|
||||||
if(header.getLastUpdateTime()!=null) {
|
if(header.getLastUpdateTime()!=null) {
|
||||||
|
Assert.assertTrue(lastUpdateTime.after(header.getLastUpdateTime()));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected <R extends Resource> void testResourceCreation(R resource, R createdResource) {
|
public static void checkPropagationConstraint(PropagationConstraint propagationConstraint, PropagationConstraint gotPropagationConstraint) {
|
||||||
Assert.assertTrue(resource.getClass() == createdResource.getClass());
|
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());
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static <R extends Resource> void testResource(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>> resourceConsistsOf = resource.getConsistsOf();
|
||||||
List<ConsistsOf<? extends Resource, ? extends Facet>> createdResourceConsistsOf = createdResource.getConsistsOf();
|
List<ConsistsOf<? extends Resource, ? extends Facet>> gotResourceConsistsOf = gotResource.getConsistsOf();
|
||||||
Assert.assertTrue(resourceConsistsOf.size() == createdResourceConsistsOf.size());
|
Assert.assertTrue(resourceConsistsOf.size() == gotResourceConsistsOf.size());
|
||||||
|
|
||||||
for(ConsistsOf<? extends Resource, ? extends Facet> consistsOf : resourceConsistsOf) {
|
for(ConsistsOf<? extends Resource, ? extends Facet> consistsOf : resourceConsistsOf) {
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
ConsistsOf<? extends Resource, ? extends Facet> createdConsistsOf = (ConsistsOf<? extends Resource, ? extends Facet>) createdResource.getConsistsOf(consistsOf.getClass(), consistsOf.getTarget().getClass());
|
ConsistsOf<? extends Resource, ? extends Facet> gotConsistsOf = (ConsistsOf<? extends Resource, ? extends Facet>) gotResource.getConsistsOf(consistsOf.getClass(), consistsOf.getTarget().getClass()).get(0);
|
||||||
PropagationConstraint propagationConstraint = createdConsistsOf.getPropagationConstraint();
|
checkConsistOf(consistsOf, gotConsistsOf);
|
||||||
Assert.assertTrue(propagationConstraint.getAddConstraint()==AddConstraint.propagate);
|
|
||||||
Assert.assertTrue(propagationConstraint.getRemoveConstraint()==RemoveConstraint.cascade);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Facet facet = consistsOf.getTarget();
|
||||||
|
Facet gotFacet = gotConsistsOf.getTarget();
|
||||||
|
checkFacet(facet, gotFacet);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -319,9 +316,49 @@ public class ERManagementTest extends ContextTest {
|
||||||
|
|
||||||
EService createdEService = ElementMapper.unmarshal(EService.class, json);
|
EService createdEService = ElementMapper.unmarshal(EService.class, json);
|
||||||
|
|
||||||
|
testResource(eService, createdEService);
|
||||||
|
|
||||||
return createdEService;
|
return createdEService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static HostingNode createHostingNode() throws Exception {
|
||||||
|
return createHostingNode(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static HostingNode createHostingNode(EService eService) throws Exception {
|
||||||
|
HostingNode hostingNode = ERManagementTest.instantiateValidHostingNode();
|
||||||
|
if(eService!=null) {
|
||||||
|
PropagationConstraint propagationConstraint = new PropagationConstraintImpl();
|
||||||
|
propagationConstraint.setRemoveConstraint(RemoveConstraint.cascade);
|
||||||
|
Activates<HostingNode, EService> activates = new ActivatesImpl<HostingNode, EService>(hostingNode, eService,
|
||||||
|
propagationConstraint);
|
||||||
|
hostingNode.attachResource(activates);
|
||||||
|
}
|
||||||
|
|
||||||
|
ResourceManagement resourceManagement = new ResourceManagement();
|
||||||
|
resourceManagement.setElementType(HostingNode.NAME);
|
||||||
|
resourceManagement.setJson(ElementMapper.marshal(hostingNode));
|
||||||
|
String json = resourceManagement.create();
|
||||||
|
|
||||||
|
HostingNode createdHostingNode = ElementMapper.unmarshal(HostingNode.class, json);
|
||||||
|
|
||||||
|
testResource(hostingNode, createdHostingNode);
|
||||||
|
|
||||||
|
return createdHostingNode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCreateEService() throws Exception {
|
public void testCreateEService() throws Exception {
|
||||||
|
@ -358,7 +395,23 @@ public class ERManagementTest extends ContextTest {
|
||||||
Assert.assertTrue(deleted);
|
Assert.assertTrue(deleted);
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCreateHostingNode() throws Exception {
|
||||||
|
HostingNode hostingNode = null;
|
||||||
|
try {
|
||||||
|
hostingNode = createHostingNode();
|
||||||
|
}finally {
|
||||||
|
if(hostingNode!=null) {
|
||||||
|
ResourceManagement resourceManagement = new ResourceManagement();
|
||||||
|
resourceManagement.setElementType(HostingNode.NAME);
|
||||||
|
resourceManagement.setUUID(hostingNode.getHeader().getUUID());
|
||||||
|
resourceManagement.delete();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCreateHostingNodeAndEService() throws Exception {
|
public void testCreateHostingNodeAndEService() throws Exception {
|
||||||
Map<String, Resource> map = ERManagementTest.createHostingNodeAndEService();
|
Map<String, Resource> map = ERManagementTest.createHostingNodeAndEService();
|
||||||
|
|
|
@ -188,7 +188,7 @@ public class BasicTest extends MultiContextTest {
|
||||||
eServiceInstances.put(consistsOf.getTarget().getHeader().getUUID(), consistsOf.getTarget());
|
eServiceInstances.put(consistsOf.getTarget().getHeader().getUUID(), consistsOf.getTarget());
|
||||||
}
|
}
|
||||||
|
|
||||||
HostingNode hostingNode = ERManagementTest.instantiateValidHostinNode();
|
HostingNode hostingNode = ERManagementTest.instantiateValidHostingNode();
|
||||||
|
|
||||||
resourceManagement = new ResourceManagement();
|
resourceManagement = new ResourceManagement();
|
||||||
resourceManagement.setElementType(HostingNode.NAME);
|
resourceManagement.setElementType(HostingNode.NAME);
|
||||||
|
|
Loading…
Reference in New Issue