From f80eec0301ea78b387427e60bebd5d501ed7e1e6 Mon Sep 17 00:00:00 2001 From: Luca Frosini Date: Mon, 8 Mar 2021 17:05:56 +0100 Subject: [PATCH] Fixing tests --- .../instances/ERManagementTest.java | 6 ------ .../resourceregistry/instances/QueryTest.java | 9 +++++++++ .../multicontext/AddToContextTest.java | 17 +++++------------ 3 files changed, 14 insertions(+), 18 deletions(-) diff --git a/src/test/java/org/gcube/informationsystem/resourceregistry/instances/ERManagementTest.java b/src/test/java/org/gcube/informationsystem/resourceregistry/instances/ERManagementTest.java index 0637309..48a2548 100644 --- a/src/test/java/org/gcube/informationsystem/resourceregistry/instances/ERManagementTest.java +++ b/src/test/java/org/gcube/informationsystem/resourceregistry/instances/ERManagementTest.java @@ -589,8 +589,6 @@ public class ERManagementTest extends ContextTest { deleteResource(eService); } } - - // public static final String TEST_RESOURCE = "test-resource.json"; // @@ -612,8 +610,4 @@ public class ERManagementTest extends ContextTest { // // } - - - - } diff --git a/src/test/java/org/gcube/informationsystem/resourceregistry/instances/QueryTest.java b/src/test/java/org/gcube/informationsystem/resourceregistry/instances/QueryTest.java index bc19f43..35c2261 100644 --- a/src/test/java/org/gcube/informationsystem/resourceregistry/instances/QueryTest.java +++ b/src/test/java/org/gcube/informationsystem/resourceregistry/instances/QueryTest.java @@ -57,6 +57,15 @@ public class QueryTest extends ContextTest { @Test public void testGetAll() throws Exception { + + // Clean the environment first to avoid error if a previous tests fails without cleaning the env + ResourceManagement rm = (ResourceManagement) ElementManagementUtility.getERManagement(Resource.NAME); + String all = rm.all(true); + List allResources = ElementMapper.unmarshalList(Resource.class, all); + for(Resource r : allResources) { + ERManagementTest.deleteResource(r); + } + Map> resources = new HashMap<>(); try { diff --git a/src/test/java/org/gcube/informationsystem/resourceregistry/instances/multicontext/AddToContextTest.java b/src/test/java/org/gcube/informationsystem/resourceregistry/instances/multicontext/AddToContextTest.java index 8b44d1b..ca76ff7 100644 --- a/src/test/java/org/gcube/informationsystem/resourceregistry/instances/multicontext/AddToContextTest.java +++ b/src/test/java/org/gcube/informationsystem/resourceregistry/instances/multicontext/AddToContextTest.java @@ -4,9 +4,7 @@ import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.Schema import org.gcube.informationsystem.resourceregistry.contexts.ContextUtility; import org.gcube.informationsystem.resourceregistry.instances.ERManagementTest; import org.gcube.informationsystem.resourceregistry.instances.model.entities.FacetManagement; -import org.gcube.informationsystem.resourceregistry.instances.model.entities.ResourceManagement; import org.gcube.informationsystem.resourceregistry.instances.model.relations.ConsistsOfManagement; -import org.gcube.informationsystem.utils.ElementMapper; import org.gcube.resourcemanagement.model.reference.entities.facets.SoftwareFacet; import org.gcube.resourcemanagement.model.reference.entities.resources.EService; import org.gcube.resourcemanagement.model.reference.relations.consistsof.IsIdentifiedBy; @@ -16,15 +14,10 @@ public class AddToContextTest { @Test public void testCreateEServiceAndRemoveFromContextRequiredFacet() throws Exception { - EService eService = ERManagementTest.instantiateValidEService(); - ResourceManagement resourceManagement = new ResourceManagement(); - resourceManagement.setElementType(EService.NAME); - resourceManagement.setJson(ElementMapper.marshal(eService)); - String createEServiceString = resourceManagement.create(); - EService createEService = ElementMapper.unmarshal(EService.class, createEServiceString); + EService eService = ERManagementTest.createEService(); @SuppressWarnings("unchecked") - IsIdentifiedBy isIdentifiedBy = (IsIdentifiedBy) createEService.getConsistsOf(IsIdentifiedBy.class).get(0); + IsIdentifiedBy isIdentifiedBy = (IsIdentifiedBy) eService.getConsistsOf(IsIdentifiedBy.class).get(0); ConsistsOfManagement consistsOfManagement = new ConsistsOfManagement(); consistsOfManagement.setElementType(IsIdentifiedBy.NAME); consistsOfManagement.setUUID(isIdentifiedBy.getHeader().getUUID()); @@ -35,7 +28,7 @@ public class AddToContextTest { }catch (SchemaViolationException e) { // As expected }catch (Exception e) { - resourceManagement.delete(); + ERManagementTest.deleteResource(eService); throw e; } @@ -50,11 +43,11 @@ public class AddToContextTest { }catch (SchemaViolationException e) { // As expected }catch (Exception e) { - resourceManagement.delete(); + ERManagementTest.deleteResource(eService); throw e; } - resourceManagement.delete(); + ERManagementTest.deleteResource(eService); }