From 71ad45f72b338cf8c16be5e645f2643e32826f81 Mon Sep 17 00:00:00 2001 From: Luca Frosini Date: Mon, 8 Mar 2021 17:08:39 +0100 Subject: [PATCH] Cleaning the env before launching the test --- .../resourceregistry/instances/QueryTest.java | 28 +++++++++++++++++-- 1 file changed, 25 insertions(+), 3 deletions(-) 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 35c2261..46d045c 100644 --- a/src/test/java/org/gcube/informationsystem/resourceregistry/instances/QueryTest.java +++ b/src/test/java/org/gcube/informationsystem/resourceregistry/instances/QueryTest.java @@ -14,7 +14,6 @@ import org.gcube.informationsystem.model.reference.entities.Resource; import org.gcube.informationsystem.model.reference.relations.ConsistsOf; import org.gcube.informationsystem.model.reference.relations.IsRelatedTo; import org.gcube.informationsystem.resourceregistry.ContextTest; -import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException; import org.gcube.informationsystem.resourceregistry.api.exceptions.query.InvalidQueryException; import org.gcube.informationsystem.resourceregistry.api.utils.Utility; import org.gcube.informationsystem.resourceregistry.instances.base.ElementManagement; @@ -54,7 +53,6 @@ public class QueryTest extends ContextTest { private static final String EXTRA = "EXTRA"; - @Test public void testGetAll() throws Exception { @@ -152,6 +150,14 @@ public class QueryTest extends ContextTest { @Test public void testGetAllFrom() 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 map = ERManagementTest.createHostingNodeAndEService(); EService eService = (EService) map.get(EService.NAME); HostingNode hostingNode = (HostingNode) map.get(HostingNode.NAME); @@ -292,7 +298,15 @@ public class QueryTest extends ContextTest { } @Test - public void testQuery() throws ResourceRegistryException { + public void testQuery() 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); + } + String relationType = ConsistsOf.NAME; String facetType = SoftwareFacet.NAME; @@ -343,6 +357,14 @@ public class QueryTest extends ContextTest { @Test public void getAllResourcesHavingFacet() throws ObjectNotFound, 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); + } + String[] names = new String[]{"MyTest", "MyTest", "Aux", "MyID", "MyID"}; Object[] additionalProperties = new Object[] {5, 5.0, false, "test", null};