Improving check in tests
This commit is contained in:
parent
d0fe1fc2ec
commit
b19539f9e5
|
@ -10,6 +10,7 @@ import java.net.URI;
|
|||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
@ -18,13 +19,16 @@ import java.util.UUID;
|
|||
import org.gcube.com.fasterxml.jackson.core.JsonParseException;
|
||||
import org.gcube.com.fasterxml.jackson.databind.JsonMappingException;
|
||||
import org.gcube.common.authorization.library.provider.AuthorizationProvider;
|
||||
import org.gcube.informationsystem.base.reference.IdentifiableElement;
|
||||
import org.gcube.informationsystem.model.impl.properties.EncryptedImpl;
|
||||
import org.gcube.informationsystem.model.impl.properties.PropagationConstraintImpl;
|
||||
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.properties.Encrypted;
|
||||
import org.gcube.informationsystem.model.reference.properties.Header;
|
||||
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;
|
||||
import org.gcube.informationsystem.model.reference.relations.ConsistsOf;
|
||||
import org.gcube.informationsystem.model.reference.relations.IsRelatedTo;
|
||||
|
@ -36,6 +40,7 @@ import org.gcube.informationsystem.resourceregistry.instances.model.entities.Fac
|
|||
import org.gcube.informationsystem.resourceregistry.instances.model.entities.ResourceManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.model.relations.ConsistsOfManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.model.relations.IsRelatedToManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.utils.HeaderUtility;
|
||||
import org.gcube.informationsystem.utils.ElementMapper;
|
||||
import org.gcube.resourcemanagement.model.impl.entities.facets.AccessPointFacetImpl;
|
||||
import org.gcube.resourcemanagement.model.impl.entities.facets.CPUFacetImpl;
|
||||
|
@ -229,23 +234,109 @@ public class ERManagementTest extends ContextTest {
|
|||
return map;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateEService() throws Exception {
|
||||
|
||||
public static void checkHeader(IdentifiableElement identifiableElement, IdentifiableElement createdIdentifiableElement) {
|
||||
Header createdHeader = createdIdentifiableElement.getHeader();
|
||||
Assert.assertTrue(createdHeader!=null);
|
||||
|
||||
UUID createdUUID = createdHeader.getUUID();
|
||||
Assert.assertTrue(createdUUID!=null);
|
||||
|
||||
String creator = createdHeader.getCreator();
|
||||
Assert.assertTrue(creator!=null);
|
||||
|
||||
String modifiedBy = createdHeader.getModifiedBy();
|
||||
Assert.assertTrue(modifiedBy!=null);
|
||||
|
||||
Date creationTime = createdHeader.getCreationTime();
|
||||
Assert.assertTrue(creationTime!=null);
|
||||
|
||||
Date lastUpdateTime = createdHeader.getLastUpdateTime();
|
||||
Assert.assertTrue(lastUpdateTime!=null);
|
||||
|
||||
Header header = identifiableElement.getHeader();
|
||||
if(header!=null) {
|
||||
if(header.getUUID()!=null) {
|
||||
Assert.assertTrue(createdUUID.compareTo(header.getUUID())==0);
|
||||
}
|
||||
|
||||
if(header.getCreator()!=null) {
|
||||
Assert.assertTrue(creator.compareTo(header.getCreator())==0);
|
||||
}else {
|
||||
Assert.assertTrue(creator.compareTo(HeaderUtility.getUser())==0);
|
||||
}
|
||||
|
||||
if(header.getModifiedBy()!=null) {
|
||||
|
||||
}
|
||||
|
||||
if(header.getCreationTime()!=null) {
|
||||
|
||||
}
|
||||
|
||||
if(header.getLastUpdateTime()!=null) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
protected <R extends Resource> void testResourceCreation(R resource, R createdResource) {
|
||||
Assert.assertTrue(resource.getClass() == createdResource.getClass());
|
||||
|
||||
|
||||
|
||||
List<ConsistsOf<? extends Resource, ? extends Facet>> resourceConsistsOf = resource.getConsistsOf();
|
||||
List<ConsistsOf<? extends Resource, ? extends Facet>> createdResourceConsistsOf = createdResource.getConsistsOf();
|
||||
Assert.assertTrue(resourceConsistsOf.size() == createdResourceConsistsOf.size());
|
||||
|
||||
for(ConsistsOf<? extends Resource, ? extends Facet> consistsOf : resourceConsistsOf) {
|
||||
@SuppressWarnings("unchecked")
|
||||
ConsistsOf<? extends Resource, ? extends Facet> createdConsistsOf = (ConsistsOf<? extends Resource, ? extends Facet>) createdResource.getConsistsOf(consistsOf.getClass(), consistsOf.getTarget().getClass());
|
||||
PropagationConstraint propagationConstraint = createdConsistsOf.getPropagationConstraint();
|
||||
Assert.assertTrue(propagationConstraint.getAddConstraint()==AddConstraint.propagate);
|
||||
Assert.assertTrue(propagationConstraint.getRemoveConstraint()==RemoveConstraint.cascade);
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static EService createEService() throws Exception {
|
||||
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);
|
||||
|
||||
resourceManagement = new ResourceManagement();
|
||||
resourceManagement.setUUID(eService.getHeader().getUUID());
|
||||
EService createdEService = ElementMapper.unmarshal(EService.class, json);
|
||||
|
||||
return createdEService;
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testCreateEService() throws Exception {
|
||||
EService eService = null;
|
||||
try {
|
||||
eService = createEService();
|
||||
}finally {
|
||||
if(eService!=null) {
|
||||
ResourceManagement resourceManagement = new ResourceManagement();
|
||||
resourceManagement.setElementType(EService.NAME);
|
||||
resourceManagement.setUUID(eService.getHeader().getUUID());
|
||||
resourceManagement.delete();
|
||||
}
|
||||
}
|
||||
|
||||
resourceManagement.delete();
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -13,16 +13,12 @@ import org.gcube.resourcemanagement.model.reference.entities.facets.CPUFacet;
|
|||
import org.gcube.resourcemanagement.model.reference.entities.resources.Configuration;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*/
|
||||
public class EncryptionTest extends ContextTest {
|
||||
|
||||
private static Logger logger = LoggerFactory.getLogger(EncryptionTest.class);
|
||||
|
||||
public static final String PLAIN_VALUE = "plain-value";
|
||||
|
||||
@Test
|
||||
|
@ -77,15 +73,13 @@ public class EncryptionTest extends ContextTest {
|
|||
ResourceManagement resourceManagement = new ResourceManagement();
|
||||
resourceManagement.setElementType(Configuration.NAME);
|
||||
String json = ElementMapper.marshal(configuration);
|
||||
logger.debug("{}", json);
|
||||
resourceManagement.setJson(json);
|
||||
|
||||
String configurationJsonString = resourceManagement.create();
|
||||
|
||||
Configuration createdConfiguration = ElementMapper.unmarshal(Configuration.class, configurationJsonString);
|
||||
logger.debug("Created:\nRaw Json : {}\nUnmarshalled : {}", configurationJsonString, createdConfiguration);
|
||||
|
||||
CPUFacet readCpuFacet = configuration.getFacets(CPUFacet.class).get(0);
|
||||
CPUFacet readCpuFacet = createdConfiguration.getFacets(CPUFacet.class).get(0);
|
||||
String gotEncryptedValue = ((Encrypted) readCpuFacet.getAdditionalProperty(additionalKey)).getEncryptedValue();
|
||||
Assert.assertTrue(gotEncryptedValue.compareTo(encryptedValue) == 0);
|
||||
String gotPlainValue = EncryptedImpl.decrypt(gotEncryptedValue);
|
||||
|
|
Loading…
Reference in New Issue