From e148a0b25392a8c5f1e86a91f9afe04655606601 Mon Sep 17 00:00:00 2001 From: Luca Frosini Date: Fri, 5 Mar 2021 15:14:51 +0100 Subject: [PATCH] Harmonizing APIs --- .../instances/base/ElementManagement.java | 4 +-- .../contexts/ContextManagementTest.java | 10 +++--- .../instances/ERManagementTest.java | 33 +++++++------------ .../instances/InvalidInstancesTest.java | 11 +++---- .../instances/SmartgearResourcesTest.java | 17 ++++------ .../model/entity/FacetManagementTest.java | 7 ++-- .../model/entity/ResourceManagementTest.java | 3 +- .../instances/multicontext/BasicTest.java | 14 +++----- .../instances/multicontext/ComplexTest.java | 3 +- .../instances/multicontext/RuleTest.java | 3 +- 10 files changed, 36 insertions(+), 69 deletions(-) diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/instances/base/ElementManagement.java b/src/main/java/org/gcube/informationsystem/resourceregistry/instances/base/ElementManagement.java index 9ff90cb..0a94780 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/instances/base/ElementManagement.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/instances/base/ElementManagement.java @@ -765,7 +765,7 @@ public abstract class ElementManagement { } } - public boolean delete() throws NotFoundException, AvailableInAnotherContextException, SchemaViolationException, ResourceRegistryException { + public void delete() throws NotFoundException, AvailableInAnotherContextException, SchemaViolationException, ResourceRegistryException { logger.debug("Going to delete {} with UUID {}", accessType.getName(), uuid); ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal(); try { @@ -781,8 +781,6 @@ public abstract class ElementManagement { }else { oDatabaseDocument.rollback(); } - - return true; } catch(ResourceRegistryException e) { logger.error("Unable to delete {} with UUID {}", accessType.getName(), uuid); if(oDatabaseDocument != null) { diff --git a/src/test/java/org/gcube/informationsystem/resourceregistry/contexts/ContextManagementTest.java b/src/test/java/org/gcube/informationsystem/resourceregistry/contexts/ContextManagementTest.java index 552263d..c39f341 100644 --- a/src/test/java/org/gcube/informationsystem/resourceregistry/contexts/ContextManagementTest.java +++ b/src/test/java/org/gcube/informationsystem/resourceregistry/contexts/ContextManagementTest.java @@ -145,7 +145,7 @@ public class ContextManagementTest extends ContextTest { return c; } - protected boolean delete(UUID uuid) throws ResourceRegistryException { + protected void delete(UUID uuid) throws ResourceRegistryException { ContextManagement contextManagement = new ContextManagement(); contextManagement.setUUID(uuid); @@ -156,15 +156,13 @@ public class ContextManagementTest extends ContextTest { oldParentUUID = securityContext.getParentSecurityContext().getUUID(); } - boolean deleted = contextManagement.delete(); - Assert.assertTrue(deleted); + contextManagement.delete(); roleUserAssertions(uuid, oldParentUUID, true); logger.debug("Deleted {} with UUID {}", Context.NAME, uuid); - return deleted; } - protected boolean delete(Context context) throws ResourceRegistryException { - return delete(context.getHeader().getUUID()); + protected void delete(Context context) throws ResourceRegistryException { + delete(context.getHeader().getUUID()); } protected void invalidCreate(Context context) throws ResourceRegistryException, IOException { 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 da7cf6b..65f7a06 100644 --- a/src/test/java/org/gcube/informationsystem/resourceregistry/instances/ERManagementTest.java +++ b/src/test/java/org/gcube/informationsystem/resourceregistry/instances/ERManagementTest.java @@ -358,8 +358,7 @@ public class ERManagementTest extends ContextTest { String gotPlainValue = EncryptedImpl.decrypt(gotEncryptedValue); Assert.assertTrue(gotPlainValue.compareTo(plainValue) == 0); - boolean deleted = resourceManagement.delete(); - Assert.assertTrue(deleted); + resourceManagement.delete(); } @Test @@ -418,8 +417,7 @@ public class ERManagementTest extends ContextTest { Assert.assertTrue(decryptedValue.compareTo(plainValue) == 0); Assert.assertTrue(((String) apf.getAdditionalProperty(additionlaPropertyKey)).compareTo(additionlaPropertyValue) == 0); - boolean deleted = resourceManagement.delete(); - Assert.assertTrue(deleted); + resourceManagement.delete(); } @@ -440,8 +438,7 @@ public class ERManagementTest extends ContextTest { resourceManagement = new ResourceManagement(); resourceManagement.setUUID(eService.getHeader().getUUID()); - boolean deleted = resourceManagement.delete(); - Assert.assertTrue(deleted); + resourceManagement.delete(); } /* @@ -470,13 +467,11 @@ public class ERManagementTest extends ContextTest { ResourceManagement resourceManagement = new ResourceManagement(); resourceManagement.setUUID(map.get(EService.NAME).getHeader().getUUID()); - boolean deleted = resourceManagement.delete(); - Assert.assertTrue(deleted); + resourceManagement.delete(); resourceManagement = new ResourceManagement(); resourceManagement.setUUID(map.get(HostingNode.NAME).getHeader().getUUID()); - deleted = resourceManagement.delete(); - Assert.assertTrue(deleted); + resourceManagement.delete(); } @Test @@ -509,13 +504,11 @@ public class ERManagementTest extends ContextTest { } finally { ResourceManagement resourceManagement = new ResourceManagement(); resourceManagement.setUUID(eServiceUUID); - boolean deleted = resourceManagement.delete(); - Assert.assertTrue(deleted); - + resourceManagement.delete(); + resourceManagement = new ResourceManagement(); resourceManagement.setUUID(hostingNodeUUID); - deleted = resourceManagement.delete(); - Assert.assertTrue(deleted); + resourceManagement.delete(); } } @@ -646,8 +639,7 @@ public class ERManagementTest extends ContextTest { for (Resource r : resourceList) { resourceManagement = new ResourceManagement(); resourceManagement.setUUID(r.getHeader().getUUID()); - boolean deleted = resourceManagement.delete(); - Assert.assertTrue(deleted); + resourceManagement.delete(); } } @@ -786,9 +778,7 @@ public class ERManagementTest extends ContextTest { /* Removing created Entity and Relation to have a clean DB */ resourceManagement = new ResourceManagement(); resourceManagement.setUUID(hostingNode.getHeader().getUUID()); - boolean deleted = resourceManagement.delete(); - Assert.assertTrue(deleted); - + resourceManagement.delete(); } public static final String TEST_RESOURCE = "test-resource.json"; @@ -859,8 +849,7 @@ public class ERManagementTest extends ContextTest { resourceManagement = new ResourceManagement(); resourceManagement.setUUID(eService.getHeader().getUUID()); - boolean deleted = resourceManagement.delete(); - Assert.assertTrue(deleted); + resourceManagement.delete(); } } diff --git a/src/test/java/org/gcube/informationsystem/resourceregistry/instances/InvalidInstancesTest.java b/src/test/java/org/gcube/informationsystem/resourceregistry/instances/InvalidInstancesTest.java index 14808ea..13af614 100644 --- a/src/test/java/org/gcube/informationsystem/resourceregistry/instances/InvalidInstancesTest.java +++ b/src/test/java/org/gcube/informationsystem/resourceregistry/instances/InvalidInstancesTest.java @@ -216,8 +216,7 @@ public class InvalidInstancesTest extends ContextTest { facetManagement = new FacetManagement(); facetManagement.setUUID(uuid); - boolean deleted = facetManagement.delete(); - Assert.assertTrue(deleted); + facetManagement.delete(); } @Test(expected = SchemaViolationException.class) @@ -241,13 +240,11 @@ public class InvalidInstancesTest extends ContextTest { } finally { ResourceManagement resourceManagement = new ResourceManagement(); resourceManagement.setUUID(eService.getHeader().getUUID()); - boolean deleted = resourceManagement.delete(); - Assert.assertTrue(deleted); - + resourceManagement.delete(); + resourceManagement = new ResourceManagement(); resourceManagement.setUUID(hostingNode.getHeader().getUUID()); - deleted = resourceManagement.delete(); - Assert.assertTrue(deleted); + resourceManagement.delete(); } } diff --git a/src/test/java/org/gcube/informationsystem/resourceregistry/instances/SmartgearResourcesTest.java b/src/test/java/org/gcube/informationsystem/resourceregistry/instances/SmartgearResourcesTest.java index fc86247..3cbae48 100644 --- a/src/test/java/org/gcube/informationsystem/resourceregistry/instances/SmartgearResourcesTest.java +++ b/src/test/java/org/gcube/informationsystem/resourceregistry/instances/SmartgearResourcesTest.java @@ -119,8 +119,7 @@ public class SmartgearResourcesTest extends ContextTest { resourceManagement = new ResourceManagement(); resourceManagement.setUUID(hnUUID); - boolean deleted = resourceManagement.delete(); - Assert.assertTrue(deleted); + resourceManagement.delete(); } public void deleteResource() throws Exception { @@ -128,9 +127,7 @@ public class SmartgearResourcesTest extends ContextTest { ResourceManagement resourceManagement = new ResourceManagement(); resourceManagement.setUUID(uuid); //resourceManagement.removeFromContext(); - boolean deleted = resourceManagement.delete(); - Assert.assertTrue(deleted); - + resourceManagement.delete(); } @@ -159,9 +156,8 @@ public class SmartgearResourcesTest extends ContextTest { resourceManagement = new ResourceManagement(); resourceManagement.setUUID(eServiceUUID); - boolean deleted = resourceManagement.delete(); - Assert.assertTrue(deleted); - + resourceManagement.delete(); + } public static final String MEMORY_TYPE = "memoryType"; @@ -349,9 +345,8 @@ public class SmartgearResourcesTest extends ContextTest { resourceManagement = new ResourceManagement(); resourceManagement.setUUID(uuid); - boolean deleted = resourceManagement.delete(); - Assert.assertTrue(deleted); - + resourceManagement.delete(); + } private StateFacet getStateFacet(StateFacet stateFacet) { diff --git a/src/test/java/org/gcube/informationsystem/resourceregistry/instances/model/entity/FacetManagementTest.java b/src/test/java/org/gcube/informationsystem/resourceregistry/instances/model/entity/FacetManagementTest.java index 45b8707..6ab0aa7 100644 --- a/src/test/java/org/gcube/informationsystem/resourceregistry/instances/model/entity/FacetManagementTest.java +++ b/src/test/java/org/gcube/informationsystem/resourceregistry/instances/model/entity/FacetManagementTest.java @@ -129,22 +129,19 @@ public class FacetManagementTest extends ContextTest { return readFacet; } - protected boolean delete(F facet) throws Exception { + protected void delete(F facet) throws Exception { FacetManagement facetManagement = new FacetManagement(); String facetType = Utility.getTypeName(facet); facetManagement.setElementType(facetType); facetManagement.setUUID(facet.getHeader().getUUID()); - boolean deleted = facetManagement.delete(); - Assert.assertTrue(deleted); + facetManagement.delete(); try { read(facet); } catch(FacetNotFoundException e) { logger.info("Facet not found as expected"); } - - return deleted; } protected Map addToContext(F facet) throws Exception { diff --git a/src/test/java/org/gcube/informationsystem/resourceregistry/instances/model/entity/ResourceManagementTest.java b/src/test/java/org/gcube/informationsystem/resourceregistry/instances/model/entity/ResourceManagementTest.java index bdce956..6352562 100644 --- a/src/test/java/org/gcube/informationsystem/resourceregistry/instances/model/entity/ResourceManagementTest.java +++ b/src/test/java/org/gcube/informationsystem/resourceregistry/instances/model/entity/ResourceManagementTest.java @@ -137,8 +137,7 @@ public class ResourceManagementTest extends ContextTest { resourceManagement = new ResourceManagement(); resourceManagement.setUUID(eService.getHeader().getUUID()); - boolean deleted = resourceManagement.delete(); - Assert.assertTrue(deleted); + resourceManagement.delete(); } diff --git a/src/test/java/org/gcube/informationsystem/resourceregistry/instances/multicontext/BasicTest.java b/src/test/java/org/gcube/informationsystem/resourceregistry/instances/multicontext/BasicTest.java index 4a14bb2..482b70f 100644 --- a/src/test/java/org/gcube/informationsystem/resourceregistry/instances/multicontext/BasicTest.java +++ b/src/test/java/org/gcube/informationsystem/resourceregistry/instances/multicontext/BasicTest.java @@ -140,8 +140,7 @@ public class BasicTest extends MultiContextTest { facetManagement = new FacetManagement(); facetManagement.setUUID(uuid); - boolean deleted = facetManagement.delete(); - Assert.assertTrue(deleted); + facetManagement.delete(); } @Test @@ -167,8 +166,7 @@ public class BasicTest extends MultiContextTest { UUID eServiceUUID = eService.getHeader().getUUID(); resourceManagement = new ResourceManagement(); resourceManagement.setUUID(eServiceUUID); - boolean deleted = resourceManagement.delete(); - Assert.assertTrue(deleted); + resourceManagement.delete(); } } @@ -273,8 +271,7 @@ public class BasicTest extends MultiContextTest { resourceManagement = new ResourceManagement(); resourceManagement.setUUID(hostingNodeUUID); - boolean deleted = resourceManagement.delete(); - Assert.assertTrue(deleted); + resourceManagement.delete(); /* ------------------------------------------------------------------ */ @@ -284,7 +281,7 @@ public class BasicTest extends MultiContextTest { try { resourceManagement = new ResourceManagement(); resourceManagement.setUUID(eServiceUUID); - deleted = resourceManagement.delete(); + resourceManagement.delete(); }catch (ResourceNotFoundException e) { // OK } @@ -436,8 +433,7 @@ public class BasicTest extends MultiContextTest { resourceManagement = new ResourceManagement(); resourceManagement.setUUID(hnUUID); - boolean deleted = resourceManagement.delete(); - Assert.assertTrue(deleted); + resourceManagement.delete(); } // @Test diff --git a/src/test/java/org/gcube/informationsystem/resourceregistry/instances/multicontext/ComplexTest.java b/src/test/java/org/gcube/informationsystem/resourceregistry/instances/multicontext/ComplexTest.java index bab0e17..3347374 100644 --- a/src/test/java/org/gcube/informationsystem/resourceregistry/instances/multicontext/ComplexTest.java +++ b/src/test/java/org/gcube/informationsystem/resourceregistry/instances/multicontext/ComplexTest.java @@ -144,8 +144,7 @@ public class ComplexTest extends MultiContextTest { Assert.assertTrue(eServiceContextFullNames.size()==1); logger.debug("Contexts of {} with UUID {} are {}", EService.NAME, eServiceManagement.getUUID(), eServiceContextFullNames); - boolean deleted = hostingNodeManagement.delete(); - Assert.assertTrue(deleted); + hostingNodeManagement.delete(); } } diff --git a/src/test/java/org/gcube/informationsystem/resourceregistry/instances/multicontext/RuleTest.java b/src/test/java/org/gcube/informationsystem/resourceregistry/instances/multicontext/RuleTest.java index bc6352f..43e8ab7 100644 --- a/src/test/java/org/gcube/informationsystem/resourceregistry/instances/multicontext/RuleTest.java +++ b/src/test/java/org/gcube/informationsystem/resourceregistry/instances/multicontext/RuleTest.java @@ -112,8 +112,7 @@ public class RuleTest extends ContextTest { eServiceManagement = new ResourceManagement(); eServiceManagement.setElementType(EService.NAME); eServiceManagement.setJson(eServiceString); - boolean deleted = eServiceManagement.delete(); - Assert.assertTrue(deleted); + eServiceManagement.delete(); } }