Harmonizing APIs

This commit is contained in:
Luca Frosini 2021-03-05 15:14:51 +01:00
parent 6b999a54ef
commit e148a0b253
10 changed files with 36 additions and 69 deletions

View File

@ -765,7 +765,7 @@ public abstract class ElementManagement<El extends OElement, T extends Type> {
} }
} }
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); logger.debug("Going to delete {} with UUID {}", accessType.getName(), uuid);
ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal(); ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal();
try { try {
@ -781,8 +781,6 @@ public abstract class ElementManagement<El extends OElement, T extends Type> {
}else { }else {
oDatabaseDocument.rollback(); oDatabaseDocument.rollback();
} }
return true;
} catch(ResourceRegistryException e) { } catch(ResourceRegistryException e) {
logger.error("Unable to delete {} with UUID {}", accessType.getName(), uuid); logger.error("Unable to delete {} with UUID {}", accessType.getName(), uuid);
if(oDatabaseDocument != null) { if(oDatabaseDocument != null) {

View File

@ -145,7 +145,7 @@ public class ContextManagementTest extends ContextTest {
return c; return c;
} }
protected boolean delete(UUID uuid) throws ResourceRegistryException { protected void delete(UUID uuid) throws ResourceRegistryException {
ContextManagement contextManagement = new ContextManagement(); ContextManagement contextManagement = new ContextManagement();
contextManagement.setUUID(uuid); contextManagement.setUUID(uuid);
@ -156,15 +156,13 @@ public class ContextManagementTest extends ContextTest {
oldParentUUID = securityContext.getParentSecurityContext().getUUID(); oldParentUUID = securityContext.getParentSecurityContext().getUUID();
} }
boolean deleted = contextManagement.delete(); contextManagement.delete();
Assert.assertTrue(deleted);
roleUserAssertions(uuid, oldParentUUID, true); roleUserAssertions(uuid, oldParentUUID, true);
logger.debug("Deleted {} with UUID {}", Context.NAME, uuid); logger.debug("Deleted {} with UUID {}", Context.NAME, uuid);
return deleted;
} }
protected boolean delete(Context context) throws ResourceRegistryException { protected void delete(Context context) throws ResourceRegistryException {
return delete(context.getHeader().getUUID()); delete(context.getHeader().getUUID());
} }
protected void invalidCreate(Context context) throws ResourceRegistryException, IOException { protected void invalidCreate(Context context) throws ResourceRegistryException, IOException {

View File

@ -358,8 +358,7 @@ public class ERManagementTest extends ContextTest {
String gotPlainValue = EncryptedImpl.decrypt(gotEncryptedValue); String gotPlainValue = EncryptedImpl.decrypt(gotEncryptedValue);
Assert.assertTrue(gotPlainValue.compareTo(plainValue) == 0); Assert.assertTrue(gotPlainValue.compareTo(plainValue) == 0);
boolean deleted = resourceManagement.delete(); resourceManagement.delete();
Assert.assertTrue(deleted);
} }
@Test @Test
@ -418,8 +417,7 @@ public class ERManagementTest extends ContextTest {
Assert.assertTrue(decryptedValue.compareTo(plainValue) == 0); Assert.assertTrue(decryptedValue.compareTo(plainValue) == 0);
Assert.assertTrue(((String) apf.getAdditionalProperty(additionlaPropertyKey)).compareTo(additionlaPropertyValue) == 0); Assert.assertTrue(((String) apf.getAdditionalProperty(additionlaPropertyKey)).compareTo(additionlaPropertyValue) == 0);
boolean deleted = resourceManagement.delete(); resourceManagement.delete();
Assert.assertTrue(deleted);
} }
@ -440,8 +438,7 @@ public class ERManagementTest extends ContextTest {
resourceManagement = new ResourceManagement(); resourceManagement = new ResourceManagement();
resourceManagement.setUUID(eService.getHeader().getUUID()); resourceManagement.setUUID(eService.getHeader().getUUID());
boolean deleted = resourceManagement.delete(); resourceManagement.delete();
Assert.assertTrue(deleted);
} }
/* /*
@ -470,13 +467,11 @@ public class ERManagementTest extends ContextTest {
ResourceManagement resourceManagement = new ResourceManagement(); ResourceManagement resourceManagement = new ResourceManagement();
resourceManagement.setUUID(map.get(EService.NAME).getHeader().getUUID()); resourceManagement.setUUID(map.get(EService.NAME).getHeader().getUUID());
boolean deleted = resourceManagement.delete(); resourceManagement.delete();
Assert.assertTrue(deleted);
resourceManagement = new ResourceManagement(); resourceManagement = new ResourceManagement();
resourceManagement.setUUID(map.get(HostingNode.NAME).getHeader().getUUID()); resourceManagement.setUUID(map.get(HostingNode.NAME).getHeader().getUUID());
deleted = resourceManagement.delete(); resourceManagement.delete();
Assert.assertTrue(deleted);
} }
@Test @Test
@ -509,13 +504,11 @@ public class ERManagementTest extends ContextTest {
} finally { } finally {
ResourceManagement resourceManagement = new ResourceManagement(); ResourceManagement resourceManagement = new ResourceManagement();
resourceManagement.setUUID(eServiceUUID); resourceManagement.setUUID(eServiceUUID);
boolean deleted = resourceManagement.delete(); resourceManagement.delete();
Assert.assertTrue(deleted);
resourceManagement = new ResourceManagement(); resourceManagement = new ResourceManagement();
resourceManagement.setUUID(hostingNodeUUID); resourceManagement.setUUID(hostingNodeUUID);
deleted = resourceManagement.delete(); resourceManagement.delete();
Assert.assertTrue(deleted);
} }
} }
@ -646,8 +639,7 @@ public class ERManagementTest extends ContextTest {
for (Resource r : resourceList) { for (Resource r : resourceList) {
resourceManagement = new ResourceManagement(); resourceManagement = new ResourceManagement();
resourceManagement.setUUID(r.getHeader().getUUID()); resourceManagement.setUUID(r.getHeader().getUUID());
boolean deleted = resourceManagement.delete(); resourceManagement.delete();
Assert.assertTrue(deleted);
} }
} }
@ -786,9 +778,7 @@ public class ERManagementTest extends ContextTest {
/* Removing created Entity and Relation to have a clean DB */ /* Removing created Entity and Relation to have a clean DB */
resourceManagement = new ResourceManagement(); resourceManagement = new ResourceManagement();
resourceManagement.setUUID(hostingNode.getHeader().getUUID()); resourceManagement.setUUID(hostingNode.getHeader().getUUID());
boolean deleted = resourceManagement.delete(); resourceManagement.delete();
Assert.assertTrue(deleted);
} }
public static final String TEST_RESOURCE = "test-resource.json"; public static final String TEST_RESOURCE = "test-resource.json";
@ -859,8 +849,7 @@ public class ERManagementTest extends ContextTest {
resourceManagement = new ResourceManagement(); resourceManagement = new ResourceManagement();
resourceManagement.setUUID(eService.getHeader().getUUID()); resourceManagement.setUUID(eService.getHeader().getUUID());
boolean deleted = resourceManagement.delete(); resourceManagement.delete();
Assert.assertTrue(deleted);
} }
} }

View File

@ -216,8 +216,7 @@ public class InvalidInstancesTest extends ContextTest {
facetManagement = new FacetManagement(); facetManagement = new FacetManagement();
facetManagement.setUUID(uuid); facetManagement.setUUID(uuid);
boolean deleted = facetManagement.delete(); facetManagement.delete();
Assert.assertTrue(deleted);
} }
@Test(expected = SchemaViolationException.class) @Test(expected = SchemaViolationException.class)
@ -241,13 +240,11 @@ public class InvalidInstancesTest extends ContextTest {
} finally { } finally {
ResourceManagement resourceManagement = new ResourceManagement(); ResourceManagement resourceManagement = new ResourceManagement();
resourceManagement.setUUID(eService.getHeader().getUUID()); resourceManagement.setUUID(eService.getHeader().getUUID());
boolean deleted = resourceManagement.delete(); resourceManagement.delete();
Assert.assertTrue(deleted);
resourceManagement = new ResourceManagement(); resourceManagement = new ResourceManagement();
resourceManagement.setUUID(hostingNode.getHeader().getUUID()); resourceManagement.setUUID(hostingNode.getHeader().getUUID());
deleted = resourceManagement.delete(); resourceManagement.delete();
Assert.assertTrue(deleted);
} }
} }

View File

@ -119,8 +119,7 @@ public class SmartgearResourcesTest extends ContextTest {
resourceManagement = new ResourceManagement(); resourceManagement = new ResourceManagement();
resourceManagement.setUUID(hnUUID); resourceManagement.setUUID(hnUUID);
boolean deleted = resourceManagement.delete(); resourceManagement.delete();
Assert.assertTrue(deleted);
} }
public void deleteResource() throws Exception { public void deleteResource() throws Exception {
@ -128,9 +127,7 @@ public class SmartgearResourcesTest extends ContextTest {
ResourceManagement resourceManagement = new ResourceManagement(); ResourceManagement resourceManagement = new ResourceManagement();
resourceManagement.setUUID(uuid); resourceManagement.setUUID(uuid);
//resourceManagement.removeFromContext(); //resourceManagement.removeFromContext();
boolean deleted = resourceManagement.delete(); resourceManagement.delete();
Assert.assertTrue(deleted);
} }
@ -159,8 +156,7 @@ public class SmartgearResourcesTest extends ContextTest {
resourceManagement = new ResourceManagement(); resourceManagement = new ResourceManagement();
resourceManagement.setUUID(eServiceUUID); resourceManagement.setUUID(eServiceUUID);
boolean deleted = resourceManagement.delete(); resourceManagement.delete();
Assert.assertTrue(deleted);
} }
@ -349,8 +345,7 @@ public class SmartgearResourcesTest extends ContextTest {
resourceManagement = new ResourceManagement(); resourceManagement = new ResourceManagement();
resourceManagement.setUUID(uuid); resourceManagement.setUUID(uuid);
boolean deleted = resourceManagement.delete(); resourceManagement.delete();
Assert.assertTrue(deleted);
} }

View File

@ -129,22 +129,19 @@ public class FacetManagementTest extends ContextTest {
return readFacet; return readFacet;
} }
protected <F extends Facet> boolean delete(F facet) throws Exception { protected <F extends Facet> void delete(F facet) throws Exception {
FacetManagement facetManagement = new FacetManagement(); FacetManagement facetManagement = new FacetManagement();
String facetType = Utility.getTypeName(facet); String facetType = Utility.getTypeName(facet);
facetManagement.setElementType(facetType); facetManagement.setElementType(facetType);
facetManagement.setUUID(facet.getHeader().getUUID()); facetManagement.setUUID(facet.getHeader().getUUID());
boolean deleted = facetManagement.delete(); facetManagement.delete();
Assert.assertTrue(deleted);
try { try {
read(facet); read(facet);
} catch(FacetNotFoundException e) { } catch(FacetNotFoundException e) {
logger.info("Facet not found as expected"); logger.info("Facet not found as expected");
} }
return deleted;
} }
protected <F extends Facet> Map<UUID,JsonNode> addToContext(F facet) throws Exception { protected <F extends Facet> Map<UUID,JsonNode> addToContext(F facet) throws Exception {

View File

@ -137,8 +137,7 @@ public class ResourceManagementTest extends ContextTest {
resourceManagement = new ResourceManagement(); resourceManagement = new ResourceManagement();
resourceManagement.setUUID(eService.getHeader().getUUID()); resourceManagement.setUUID(eService.getHeader().getUUID());
boolean deleted = resourceManagement.delete(); resourceManagement.delete();
Assert.assertTrue(deleted);
} }

View File

@ -140,8 +140,7 @@ public class BasicTest extends MultiContextTest {
facetManagement = new FacetManagement(); facetManagement = new FacetManagement();
facetManagement.setUUID(uuid); facetManagement.setUUID(uuid);
boolean deleted = facetManagement.delete(); facetManagement.delete();
Assert.assertTrue(deleted);
} }
@Test @Test
@ -167,8 +166,7 @@ public class BasicTest extends MultiContextTest {
UUID eServiceUUID = eService.getHeader().getUUID(); UUID eServiceUUID = eService.getHeader().getUUID();
resourceManagement = new ResourceManagement(); resourceManagement = new ResourceManagement();
resourceManagement.setUUID(eServiceUUID); resourceManagement.setUUID(eServiceUUID);
boolean deleted = resourceManagement.delete(); resourceManagement.delete();
Assert.assertTrue(deleted);
} }
} }
@ -273,8 +271,7 @@ public class BasicTest extends MultiContextTest {
resourceManagement = new ResourceManagement(); resourceManagement = new ResourceManagement();
resourceManagement.setUUID(hostingNodeUUID); resourceManagement.setUUID(hostingNodeUUID);
boolean deleted = resourceManagement.delete(); resourceManagement.delete();
Assert.assertTrue(deleted);
/* ------------------------------------------------------------------ */ /* ------------------------------------------------------------------ */
@ -284,7 +281,7 @@ public class BasicTest extends MultiContextTest {
try { try {
resourceManagement = new ResourceManagement(); resourceManagement = new ResourceManagement();
resourceManagement.setUUID(eServiceUUID); resourceManagement.setUUID(eServiceUUID);
deleted = resourceManagement.delete(); resourceManagement.delete();
}catch (ResourceNotFoundException e) { }catch (ResourceNotFoundException e) {
// OK // OK
} }
@ -436,8 +433,7 @@ public class BasicTest extends MultiContextTest {
resourceManagement = new ResourceManagement(); resourceManagement = new ResourceManagement();
resourceManagement.setUUID(hnUUID); resourceManagement.setUUID(hnUUID);
boolean deleted = resourceManagement.delete(); resourceManagement.delete();
Assert.assertTrue(deleted);
} }
// @Test // @Test

View File

@ -144,8 +144,7 @@ public class ComplexTest extends MultiContextTest {
Assert.assertTrue(eServiceContextFullNames.size()==1); Assert.assertTrue(eServiceContextFullNames.size()==1);
logger.debug("Contexts of {} with UUID {} are {}", EService.NAME, eServiceManagement.getUUID(), eServiceContextFullNames); logger.debug("Contexts of {} with UUID {} are {}", EService.NAME, eServiceManagement.getUUID(), eServiceContextFullNames);
boolean deleted = hostingNodeManagement.delete(); hostingNodeManagement.delete();
Assert.assertTrue(deleted);
} }
} }

View File

@ -112,8 +112,7 @@ public class RuleTest extends ContextTest {
eServiceManagement = new ResourceManagement(); eServiceManagement = new ResourceManagement();
eServiceManagement.setElementType(EService.NAME); eServiceManagement.setElementType(EService.NAME);
eServiceManagement.setJson(eServiceString); eServiceManagement.setJson(eServiceString);
boolean deleted = eServiceManagement.delete(); eServiceManagement.delete();
Assert.assertTrue(deleted);
} }
} }