2017-11-15 19:31:49 +01:00
|
|
|
package org.gcube.informationsystem.resourceregistry.context;
|
|
|
|
|
2017-11-23 09:39:21 +01:00
|
|
|
import java.io.IOException;
|
2017-11-15 19:31:49 +01:00
|
|
|
import java.util.List;
|
|
|
|
import java.util.UUID;
|
|
|
|
|
2019-10-25 17:45:59 +02:00
|
|
|
import org.gcube.informationsystem.base.impl.properties.HeaderImpl;
|
|
|
|
import org.gcube.informationsystem.context.impl.entities.ContextImpl;
|
|
|
|
import org.gcube.informationsystem.context.reference.entities.Context;
|
|
|
|
import org.gcube.informationsystem.context.reference.relations.IsParentOf;
|
2019-10-28 15:06:31 +01:00
|
|
|
import org.gcube.informationsystem.resourceregistry.ContextTest;
|
2017-11-23 09:39:21 +01:00
|
|
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
|
|
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.context.ContextAlreadyPresentException;
|
|
|
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.context.ContextException;
|
|
|
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.context.ContextNotFoundException;
|
2019-11-04 18:01:20 +01:00
|
|
|
import org.gcube.informationsystem.resourceregistry.instances.context.ContextUtility;
|
|
|
|
import org.gcube.informationsystem.resourceregistry.instances.context.entities.ContextManagement;
|
2019-11-06 12:13:19 +01:00
|
|
|
import org.gcube.informationsystem.resourceregistry.instances.model.entity.FacetManagementTest;
|
2019-11-04 18:01:20 +01:00
|
|
|
import org.gcube.informationsystem.resourceregistry.security.ContextSecurityContext;
|
|
|
|
import org.gcube.informationsystem.resourceregistry.security.SecurityContext;
|
|
|
|
import org.gcube.informationsystem.resourceregistry.security.SecurityContext.PermissionMode;
|
|
|
|
import org.gcube.informationsystem.resourceregistry.security.SecurityContext.SecurityType;
|
2019-02-13 12:33:29 +01:00
|
|
|
import org.gcube.informationsystem.utils.ISMapper;
|
2017-11-15 19:31:49 +01:00
|
|
|
import org.junit.Assert;
|
|
|
|
import org.junit.Test;
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
2017-11-23 09:39:21 +01:00
|
|
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
2019-11-05 18:36:44 +01:00
|
|
|
import com.orientechnologies.orient.core.db.document.ODatabaseDocument;
|
2017-11-28 17:34:43 +01:00
|
|
|
import com.orientechnologies.orient.core.metadata.security.ORole;
|
|
|
|
import com.orientechnologies.orient.core.metadata.security.OSecurity;
|
|
|
|
import com.orientechnologies.orient.core.metadata.security.OUser;
|
2017-11-23 09:39:21 +01:00
|
|
|
|
2019-10-28 15:06:31 +01:00
|
|
|
public class ContextManagementTest extends ContextTest {
|
2019-02-13 16:53:17 +01:00
|
|
|
|
2017-11-23 09:39:21 +01:00
|
|
|
private static Logger logger = LoggerFactory.getLogger(ContextManagementTest.class);
|
2019-02-13 16:53:17 +01:00
|
|
|
|
2017-11-23 09:39:21 +01:00
|
|
|
public static final String CTX_NAME_A = "A";
|
|
|
|
public static final String CTX_NAME_B = "B";
|
|
|
|
public static final String CTX_NAME_C = "C";
|
2019-02-13 16:53:17 +01:00
|
|
|
|
2017-11-30 18:06:08 +01:00
|
|
|
protected void assertions(Context pre, Context post, boolean checkParent, boolean create)
|
|
|
|
throws ResourceRegistryException {
|
2019-02-13 16:53:17 +01:00
|
|
|
if(checkParent) {
|
|
|
|
if(pre.getHeader() != null) {
|
2017-11-23 09:39:21 +01:00
|
|
|
FacetManagementTest.checkHeader(post, pre.getHeader().getUUID(), create);
|
|
|
|
} else {
|
|
|
|
FacetManagementTest.checkHeader(post, null, create);
|
|
|
|
}
|
|
|
|
}
|
2019-02-13 16:53:17 +01:00
|
|
|
|
2017-11-23 09:39:21 +01:00
|
|
|
Assert.assertTrue(pre.getName().compareTo(post.getName()) == 0);
|
2019-02-13 16:53:17 +01:00
|
|
|
if(checkParent && pre.getParent() != null && post.getParent() != null) {
|
2017-11-23 09:39:21 +01:00
|
|
|
Context preParent = pre.getParent().getSource();
|
|
|
|
Context postParent = post.getParent().getSource();
|
|
|
|
assertions(preParent, postParent, false, false);
|
|
|
|
}
|
2019-02-13 16:53:17 +01:00
|
|
|
|
2017-11-28 17:34:43 +01:00
|
|
|
}
|
2019-02-13 16:53:17 +01:00
|
|
|
|
2017-12-05 10:10:34 +01:00
|
|
|
protected void roleUserAssertions(UUID uuid, UUID oldParentUUID, boolean deleted) throws ResourceRegistryException {
|
2017-11-28 17:34:43 +01:00
|
|
|
ContextSecurityContext contextSecurityContext = new ContextSecurityContext();
|
2017-12-05 10:10:34 +01:00
|
|
|
ContextUtility.getInstance().addSecurityContext(contextSecurityContext.getUUID().toString(),
|
2017-11-30 18:06:08 +01:00
|
|
|
contextSecurityContext);
|
2019-02-13 16:53:17 +01:00
|
|
|
|
2019-11-05 18:36:44 +01:00
|
|
|
ODatabaseDocument oDatabaseDocument = contextSecurityContext.getDatabaseDocument(PermissionMode.READER);
|
|
|
|
OSecurity oSecurity = oDatabaseDocument.getMetadata().getSecurity();
|
2017-12-05 10:10:34 +01:00
|
|
|
|
|
|
|
SecurityContext securityContext = null;
|
|
|
|
if(deleted) {
|
|
|
|
securityContext = new SecurityContext(uuid);
|
|
|
|
} else {
|
|
|
|
securityContext = ContextUtility.getInstance().getSecurityContextByUUID(uuid);
|
|
|
|
}
|
2019-02-13 16:53:17 +01:00
|
|
|
|
|
|
|
boolean[] booleanArray = new boolean[] {false, true};
|
|
|
|
for(boolean hierarchic : booleanArray) {
|
|
|
|
for(PermissionMode permissionMode : PermissionMode.values()) {
|
2017-11-30 18:06:08 +01:00
|
|
|
String role = securityContext.getSecurityRoleOrUserName(permissionMode, SecurityType.ROLE, hierarchic);
|
|
|
|
ORole oRole = oSecurity.getRole(role);
|
|
|
|
Assert.assertEquals(oRole == null, deleted);
|
2019-02-13 16:53:17 +01:00
|
|
|
|
2017-11-30 18:06:08 +01:00
|
|
|
String user = securityContext.getSecurityRoleOrUserName(permissionMode, SecurityType.USER, hierarchic);
|
|
|
|
OUser oUser = oSecurity.getUser(user);
|
|
|
|
Assert.assertEquals(oUser == null, deleted);
|
2019-02-13 16:53:17 +01:00
|
|
|
if(oUser != null) {
|
2017-12-05 10:10:34 +01:00
|
|
|
Assert.assertTrue(oUser.hasRole(oRole.getName(), false));
|
|
|
|
}
|
|
|
|
|
|
|
|
if(hierarchic) {
|
|
|
|
SecurityContext parent = null;
|
2019-02-13 16:53:17 +01:00
|
|
|
if(deleted) {
|
|
|
|
if(oldParentUUID != null) {
|
2017-12-05 10:10:34 +01:00
|
|
|
parent = ContextUtility.getInstance().getSecurityContextByUUID(oldParentUUID);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
parent = securityContext.getParentSecurityContext();
|
2019-02-13 16:53:17 +01:00
|
|
|
while(parent != null) {
|
|
|
|
String parentUser = parent.getSecurityRoleOrUserName(permissionMode, SecurityType.USER,
|
|
|
|
hierarchic);
|
2017-12-05 10:10:34 +01:00
|
|
|
OUser parentOUser = oSecurity.getUser(parentUser);
|
|
|
|
Assert.assertTrue(parentOUser != null);
|
|
|
|
Assert.assertEquals(parentOUser.hasRole(oRole.getName(), false), !deleted);
|
|
|
|
parent = parent.getParentSecurityContext();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-30 18:06:08 +01:00
|
|
|
}
|
2017-11-28 17:34:43 +01:00
|
|
|
}
|
2017-11-23 09:39:21 +01:00
|
|
|
}
|
2019-02-13 16:53:17 +01:00
|
|
|
|
2017-11-23 09:39:21 +01:00
|
|
|
protected Context read(UUID uuid) throws ResourceRegistryException, IOException {
|
|
|
|
ContextManagement contextManagement = new ContextManagement();
|
|
|
|
contextManagement.setUUID(uuid);
|
|
|
|
String contextString = contextManagement.read();
|
|
|
|
logger.debug("Read {}", contextString);
|
2017-12-05 10:10:34 +01:00
|
|
|
roleUserAssertions(uuid, null, false);
|
2017-11-23 09:39:21 +01:00
|
|
|
return ISMapper.unmarshal(Context.class, contextString);
|
|
|
|
}
|
2019-02-13 16:53:17 +01:00
|
|
|
|
2017-11-23 09:39:21 +01:00
|
|
|
protected Context create(Context context) throws ResourceRegistryException, IOException {
|
|
|
|
ContextManagement contextManagement = new ContextManagement();
|
2019-02-13 12:33:29 +01:00
|
|
|
contextManagement.setJson(ISMapper.marshal(context));
|
2017-11-23 09:39:21 +01:00
|
|
|
String contextString = contextManagement.create();
|
|
|
|
logger.debug("Created {}", contextString);
|
|
|
|
Context c = ISMapper.unmarshal(Context.class, contextString);
|
|
|
|
assertions(context, c, true, true);
|
2017-12-05 10:10:34 +01:00
|
|
|
roleUserAssertions(c.getHeader().getUUID(), null, false);
|
2017-11-23 09:39:21 +01:00
|
|
|
return c;
|
|
|
|
}
|
2019-02-13 16:53:17 +01:00
|
|
|
|
2017-11-23 09:39:21 +01:00
|
|
|
protected Context update(Context context) throws ResourceRegistryException, IOException {
|
|
|
|
ContextManagement contextManagement = new ContextManagement();
|
2019-02-13 12:33:29 +01:00
|
|
|
contextManagement.setJson(ISMapper.marshal(context));
|
2017-11-23 09:39:21 +01:00
|
|
|
String contextString = contextManagement.update();
|
|
|
|
logger.debug("Updated {}", contextString);
|
|
|
|
Context c = ISMapper.unmarshal(Context.class, contextString);
|
|
|
|
assertions(context, c, true, false);
|
2017-12-05 10:10:34 +01:00
|
|
|
roleUserAssertions(c.getHeader().getUUID(), null, false);
|
2017-11-23 09:39:21 +01:00
|
|
|
return c;
|
|
|
|
}
|
2019-02-13 16:53:17 +01:00
|
|
|
|
2017-11-23 09:39:21 +01:00
|
|
|
protected boolean delete(UUID uuid) throws ResourceRegistryException {
|
|
|
|
ContextManagement contextManagement = new ContextManagement();
|
|
|
|
contextManagement.setUUID(uuid);
|
2017-12-05 10:10:34 +01:00
|
|
|
|
|
|
|
SecurityContext securityContext = ContextUtility.getInstance().getSecurityContextByUUID(uuid);
|
|
|
|
|
|
|
|
UUID oldParentUUID = null;
|
2019-02-13 16:53:17 +01:00
|
|
|
if(securityContext.getParentSecurityContext() != null) {
|
2017-12-05 10:10:34 +01:00
|
|
|
oldParentUUID = securityContext.getParentSecurityContext().getUUID();
|
|
|
|
}
|
|
|
|
|
2017-11-23 09:39:21 +01:00
|
|
|
boolean deleted = contextManagement.delete();
|
|
|
|
Assert.assertTrue(deleted);
|
2017-12-05 10:10:34 +01:00
|
|
|
roleUserAssertions(uuid, oldParentUUID, true);
|
2017-11-23 09:39:21 +01:00
|
|
|
logger.debug("Deleted {} with UUID {}", Context.NAME, uuid);
|
|
|
|
return deleted;
|
|
|
|
}
|
2019-02-13 16:53:17 +01:00
|
|
|
|
2017-11-23 09:39:21 +01:00
|
|
|
protected boolean delete(Context context) throws ResourceRegistryException {
|
|
|
|
return delete(context.getHeader().getUUID());
|
|
|
|
}
|
2019-02-13 16:53:17 +01:00
|
|
|
|
2017-11-23 09:39:21 +01:00
|
|
|
protected void invalidCreate(Context context) throws ResourceRegistryException, IOException {
|
|
|
|
try {
|
|
|
|
Context c = create(context);
|
|
|
|
throw new RuntimeException(ISMapper.marshal(c) + " was created successfully. This is not what we expected");
|
2019-02-13 16:53:17 +01:00
|
|
|
} catch(ContextAlreadyPresentException e) {
|
2017-11-23 09:39:21 +01:00
|
|
|
logger.debug("As expected {} cannot be created.", ISMapper.marshal(context));
|
|
|
|
}
|
|
|
|
}
|
2019-02-13 16:53:17 +01:00
|
|
|
|
2017-11-23 09:39:21 +01:00
|
|
|
protected void invalidUpdate(Context context) throws ResourceRegistryException, IOException {
|
|
|
|
try {
|
|
|
|
Context c = update(context);
|
|
|
|
throw new RuntimeException(ISMapper.marshal(c) + " was updated successfully. This is not what we expected");
|
2019-02-13 16:53:17 +01:00
|
|
|
} catch(ContextAlreadyPresentException e) {
|
2017-11-23 09:39:21 +01:00
|
|
|
logger.debug("As expected {} cannot be updated.", ISMapper.marshal(context));
|
|
|
|
}
|
|
|
|
}
|
2019-02-13 16:53:17 +01:00
|
|
|
|
2017-11-23 09:39:21 +01:00
|
|
|
protected void invalidDelete(Context context) throws ResourceRegistryException, JsonProcessingException {
|
|
|
|
String contextString = ISMapper.marshal(context);
|
|
|
|
try {
|
|
|
|
delete(context);
|
|
|
|
throw new RuntimeException(contextString + " was deleted successfully. This is not what we expected");
|
2019-02-13 16:53:17 +01:00
|
|
|
} catch(ContextException e) {
|
2017-11-23 09:39:21 +01:00
|
|
|
logger.debug("As expected {} cannot be deleted.", contextString);
|
|
|
|
}
|
|
|
|
}
|
2017-12-05 10:10:34 +01:00
|
|
|
|
2017-11-23 09:39:21 +01:00
|
|
|
@Test
|
|
|
|
public void completeTest() throws Exception {
|
|
|
|
Context contextA1 = new ContextImpl(CTX_NAME_A);
|
|
|
|
contextA1 = create(contextA1);
|
|
|
|
// ________A1________
|
2019-02-13 16:53:17 +01:00
|
|
|
|
2017-11-23 09:39:21 +01:00
|
|
|
Context contextA2 = new ContextImpl(CTX_NAME_A);
|
|
|
|
contextA2.setParent(contextA1);
|
|
|
|
contextA2 = create(contextA2);
|
|
|
|
// ________A1________
|
|
|
|
// ___A2
|
2019-02-13 16:53:17 +01:00
|
|
|
|
2017-11-23 09:39:21 +01:00
|
|
|
Context contextB3 = new ContextImpl(CTX_NAME_B);
|
|
|
|
contextB3.setParent(contextA2);
|
|
|
|
contextB3 = create(contextB3);
|
|
|
|
// ________A1________
|
|
|
|
// ___A2
|
|
|
|
// B3
|
2019-02-13 16:53:17 +01:00
|
|
|
|
2017-11-23 09:39:21 +01:00
|
|
|
Context contextB4 = new ContextImpl(CTX_NAME_B);
|
|
|
|
contextB4.setParent(contextA1);
|
|
|
|
contextB4 = create(contextB4);
|
|
|
|
// ________A1________
|
|
|
|
// ___A2_______B4____
|
|
|
|
// B3
|
2019-02-13 16:53:17 +01:00
|
|
|
|
2017-11-23 09:39:21 +01:00
|
|
|
Context contextA5 = new ContextImpl(CTX_NAME_A);
|
|
|
|
contextA5.setParent(contextB4);
|
|
|
|
contextA5 = create(contextA5);
|
|
|
|
// ________A1________
|
|
|
|
// ___A2_______B4____
|
|
|
|
// B3______________A5
|
2019-02-13 16:53:17 +01:00
|
|
|
|
2017-11-23 09:39:21 +01:00
|
|
|
invalidCreate(contextA1); // Trying to recreate A1. Fails
|
|
|
|
invalidCreate(contextA2); // Trying to recreate A2. Fails
|
|
|
|
invalidCreate(contextB3); // Trying to recreate B3. Fails
|
|
|
|
invalidCreate(contextB4); // Trying to recreate B4. Fails
|
|
|
|
invalidCreate(contextA5); // Trying to recreate A5. Fails
|
2019-02-13 12:33:29 +01:00
|
|
|
|
2017-11-23 09:39:21 +01:00
|
|
|
Context nullContext = null;
|
2019-02-13 12:33:29 +01:00
|
|
|
// Trying to move A5 as root. It fails due to A1.
|
2017-11-23 09:39:21 +01:00
|
|
|
contextA5.setParent(nullContext);
|
|
|
|
invalidUpdate(contextA5);
|
|
|
|
contextA5.setParent(contextB4);
|
|
|
|
// ________A1________
|
|
|
|
// ___A2_______B4____
|
|
|
|
// B3______________A5
|
2019-02-13 12:33:29 +01:00
|
|
|
|
2017-11-23 09:39:21 +01:00
|
|
|
nullContext = null;
|
|
|
|
contextB4.setParent(nullContext);
|
|
|
|
update(contextB4);
|
|
|
|
// _____A1____B4_____
|
|
|
|
// __A2__________A5__
|
|
|
|
// B3
|
2019-02-13 16:53:17 +01:00
|
|
|
|
2017-11-23 09:39:21 +01:00
|
|
|
contextB4.setParent(contextA1);
|
|
|
|
update(contextB4);
|
|
|
|
// ________A1________
|
|
|
|
// ___A2_______B4____
|
|
|
|
// B3______________A5
|
2019-02-13 16:53:17 +01:00
|
|
|
|
2017-11-23 09:39:21 +01:00
|
|
|
// Trying to rename with the new name A. It fails due to A5.
|
|
|
|
contextB3.setName(CTX_NAME_A);
|
|
|
|
update(contextB3);
|
|
|
|
// ________A1________
|
|
|
|
// ___A2_______B4____
|
|
|
|
// A3______________A5
|
2019-02-13 16:53:17 +01:00
|
|
|
|
2017-11-23 09:39:21 +01:00
|
|
|
// After Restoring name B, trying to move B3 as child of A1. It fails due to B4.
|
|
|
|
contextB3.setName(CTX_NAME_B);
|
|
|
|
contextB3.setParent(contextA1);
|
|
|
|
invalidUpdate(contextB3);
|
|
|
|
// ________A1________
|
|
|
|
// ___A2_______B4____
|
|
|
|
// A3______________A5
|
2019-02-13 16:53:17 +01:00
|
|
|
|
2017-11-23 09:39:21 +01:00
|
|
|
// Restoring A3 (was B3) as B3 and with parent A2.OK.
|
|
|
|
contextB3.setName(CTX_NAME_B);
|
|
|
|
contextB3.setParent(contextA2);
|
|
|
|
update(contextB3);
|
|
|
|
// ________A1________
|
|
|
|
// ___A2_______B4____
|
|
|
|
// B3______________A5
|
2019-02-13 16:53:17 +01:00
|
|
|
|
2017-11-23 09:39:21 +01:00
|
|
|
// This update should not has eny effects except updating the lastUpdateTime.
|
|
|
|
contextB3.setName(CTX_NAME_B);
|
|
|
|
contextB3.setParent(contextA2);
|
|
|
|
update(contextB3);
|
2019-02-13 16:53:17 +01:00
|
|
|
|
2017-11-23 09:39:21 +01:00
|
|
|
// Trying to move A5 as child of A1. It fails due to A2.
|
|
|
|
contextA5.setParent(contextA1);
|
|
|
|
invalidUpdate(contextA5);
|
|
|
|
// Restoring A5
|
|
|
|
contextA5.setParent(contextB4);
|
|
|
|
// ________A1________
|
|
|
|
// ___A2_______B4____
|
|
|
|
// B3______________A5
|
2019-02-13 16:53:17 +01:00
|
|
|
|
2017-11-23 09:39:21 +01:00
|
|
|
// Moving B3 as child of B4. OK.
|
|
|
|
contextB3.setParent(contextB4);
|
|
|
|
update(contextB3);
|
|
|
|
// ________A1________
|
|
|
|
// ___A2_______B4____
|
|
|
|
// ________B3______A5
|
2019-02-13 16:53:17 +01:00
|
|
|
|
2017-11-23 09:39:21 +01:00
|
|
|
// Restoring the initial situation by moving B3 as child of A2. OK.
|
|
|
|
contextB3.setParent(contextA2);
|
|
|
|
update(contextB3);
|
|
|
|
// ________A1________
|
|
|
|
// ___A2_______B4____
|
|
|
|
// B3______________A5
|
2019-02-13 16:53:17 +01:00
|
|
|
|
2017-11-23 09:39:21 +01:00
|
|
|
// Renaming B3 as C3. OK.
|
|
|
|
contextB3.setName(CTX_NAME_C);
|
|
|
|
update(contextB3);
|
|
|
|
// ________A1________
|
|
|
|
// ___A2_______B4____
|
|
|
|
// C3______________A5
|
2019-02-13 16:53:17 +01:00
|
|
|
|
2017-11-23 09:39:21 +01:00
|
|
|
// Moving C3 (was B3) as child of A1. Now it is possible. OK.
|
|
|
|
contextB3.setParent(contextA1);
|
|
|
|
update(contextB3);
|
|
|
|
// ________A1________
|
|
|
|
// ___A2___C3___B4___
|
|
|
|
// ________________A5
|
2019-02-13 16:53:17 +01:00
|
|
|
|
2017-11-23 09:39:21 +01:00
|
|
|
// Trying to rename C3 (was B3) newly to B3. Fails due to B4.
|
|
|
|
contextB3.setName(CTX_NAME_B);
|
|
|
|
invalidUpdate(contextB3);
|
|
|
|
// ________A1________
|
|
|
|
// ___A2___C3___B4___
|
|
|
|
// ________________A5
|
2019-02-13 16:53:17 +01:00
|
|
|
|
2017-11-23 09:39:21 +01:00
|
|
|
// Moving back C3 (was B3) as child of A2. OK.
|
|
|
|
contextB3.setParent(contextA2);
|
|
|
|
update(contextB3);
|
|
|
|
// ________A1________
|
|
|
|
// ___A2_______B4____
|
|
|
|
// C3______________A5
|
2019-02-13 16:53:17 +01:00
|
|
|
|
2017-11-23 09:39:21 +01:00
|
|
|
// Renaming C3 (was B3) to B3. OK.
|
|
|
|
contextB3.setName(CTX_NAME_B);
|
|
|
|
update(contextB3);
|
|
|
|
// ________A1________
|
|
|
|
// ___A2_______B4____
|
|
|
|
// B3______________A5
|
2017-12-05 10:10:34 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
// This updates (move) has been made to test HRoles and HUsers
|
|
|
|
|
|
|
|
contextA2.setParent(contextA5);
|
|
|
|
update(contextA2);
|
|
|
|
// __A1______________
|
|
|
|
// _____B4___________
|
|
|
|
// ________A5________
|
|
|
|
// ___________A2_____
|
|
|
|
// ______________B3__
|
|
|
|
|
|
|
|
|
|
|
|
contextA5.setParent(contextA1);
|
|
|
|
update(contextA5);
|
|
|
|
// _________A1________
|
|
|
|
// ______A5_____B4____
|
|
|
|
// ___A2______________
|
|
|
|
// B3_________________
|
|
|
|
|
|
|
|
|
|
|
|
contextA5.setParent(contextB4);
|
|
|
|
update(contextA5);
|
|
|
|
// __A1______________
|
|
|
|
// _____B4___________
|
|
|
|
// ________A5________
|
|
|
|
// ___________A2_____
|
|
|
|
// ______________B3__
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
contextA2.setParent(contextA1);
|
|
|
|
update(contextA2);
|
|
|
|
// ________A1________
|
|
|
|
// ___A2_______B4____
|
|
|
|
// B3______________A5
|
|
|
|
*/
|
|
|
|
|
2017-11-23 09:39:21 +01:00
|
|
|
// The following delete are not allowed because they are not child contexts
|
|
|
|
invalidDelete(contextA1);
|
|
|
|
invalidDelete(contextA2);
|
|
|
|
invalidDelete(contextB4);
|
2017-12-07 13:51:57 +01:00
|
|
|
|
2017-11-23 09:39:21 +01:00
|
|
|
delete(contextA5);
|
|
|
|
// ________A1________
|
|
|
|
// ___A2_______B4____
|
|
|
|
// B3
|
2019-02-13 16:53:17 +01:00
|
|
|
|
2017-11-23 09:39:21 +01:00
|
|
|
try {
|
|
|
|
delete(contextA5);
|
2019-02-13 16:53:17 +01:00
|
|
|
} catch(ContextNotFoundException e) {
|
2017-11-23 09:39:21 +01:00
|
|
|
logger.debug("The context with uuid {} was not found. (Was already deleted)",
|
|
|
|
contextA5.getHeader().getUUID());
|
|
|
|
}
|
2019-02-13 16:53:17 +01:00
|
|
|
|
2017-11-23 09:39:21 +01:00
|
|
|
delete(contextB3);
|
|
|
|
// ________A1________
|
|
|
|
// ___A2_______B4____
|
2019-02-13 16:53:17 +01:00
|
|
|
|
2017-11-23 09:39:21 +01:00
|
|
|
delete(contextB4);
|
|
|
|
// ________A1________
|
|
|
|
// ___A2
|
2019-02-13 16:53:17 +01:00
|
|
|
|
2017-11-23 09:39:21 +01:00
|
|
|
delete(contextA2);
|
|
|
|
// ________A1________
|
2019-02-13 16:53:17 +01:00
|
|
|
|
2017-11-23 09:39:21 +01:00
|
|
|
Context contextC = new ContextImpl(CTX_NAME_C);
|
|
|
|
contextC.setHeader(new HeaderImpl(contextA1.getHeader().getUUID()));
|
|
|
|
invalidCreate(contextC);
|
2019-02-13 16:53:17 +01:00
|
|
|
|
2017-11-23 09:39:21 +01:00
|
|
|
delete(contextA1);
|
|
|
|
logger.debug("The DB should be now clean");
|
|
|
|
}
|
2017-12-05 10:10:34 +01:00
|
|
|
|
2019-02-13 16:53:17 +01:00
|
|
|
private List<Context> getAll() throws Exception {
|
2017-12-05 10:10:34 +01:00
|
|
|
ContextManagement contextManagement = new ContextManagement();
|
|
|
|
String allString = contextManagement.all(false);
|
|
|
|
logger.trace(allString);
|
|
|
|
List<Context> all = ISMapper.unmarshalList(Context.class, allString);
|
|
|
|
return all;
|
|
|
|
}
|
|
|
|
|
2017-12-07 13:51:57 +01:00
|
|
|
/*
|
2017-12-05 10:10:34 +01:00
|
|
|
// @Test
|
|
|
|
public void deleteAll() throws Exception {
|
|
|
|
List<Context> all = getAll();
|
|
|
|
while(all.size()>0) {
|
|
|
|
for (Context context : all) {
|
|
|
|
logger.trace(ISMapper.marshal(context));
|
|
|
|
List<IsParentOf<Context, Context>> children = context.getChildren();
|
|
|
|
if(children==null || children.size()==0) {
|
|
|
|
// delete(context);
|
|
|
|
}
|
|
|
|
}
|
2019-02-13 12:33:29 +01:00
|
|
|
all = getAll();
|
2017-12-05 10:10:34 +01:00
|
|
|
}
|
|
|
|
}
|
2017-12-07 13:51:57 +01:00
|
|
|
*/
|
2017-12-05 10:10:34 +01:00
|
|
|
|
2017-11-23 16:25:16 +01:00
|
|
|
@Test
|
|
|
|
public void testGetAll() throws Exception {
|
2017-12-05 10:10:34 +01:00
|
|
|
List<Context> contexts = getAll();
|
2019-02-13 16:53:17 +01:00
|
|
|
for(Context context : contexts) {
|
2017-11-30 18:06:08 +01:00
|
|
|
logger.trace(ISMapper.marshal(context));
|
2019-11-04 18:01:20 +01:00
|
|
|
List<IsParentOf> children = context.getChildren();
|
|
|
|
for(IsParentOf child : children) {
|
2017-11-28 17:34:43 +01:00
|
|
|
Assert.assertTrue(child.getSource() == context);
|
|
|
|
Context childContext = child.getTarget();
|
|
|
|
Assert.assertTrue(childContext.getParent().getSource() == context);
|
|
|
|
}
|
2017-12-05 10:10:34 +01:00
|
|
|
roleUserAssertions(context.getHeader().getUUID(), null, false);
|
2017-11-23 16:25:16 +01:00
|
|
|
}
|
|
|
|
}
|
2019-02-13 16:53:17 +01:00
|
|
|
|
2019-07-30 16:48:18 +02:00
|
|
|
// @Test
|
2017-12-05 10:10:34 +01:00
|
|
|
public void readContext() throws ResourceRegistryException, IOException {
|
2019-07-30 16:48:18 +02:00
|
|
|
Context context = read(UUID.fromString(""));
|
2017-12-05 10:10:34 +01:00
|
|
|
logger.debug("{}", context);
|
|
|
|
}
|
|
|
|
|
2017-11-28 17:34:43 +01:00
|
|
|
// @Test
|
|
|
|
public void deleteContext() throws ResourceRegistryException, IOException {
|
|
|
|
Context context = read(UUID.fromString(""));
|
|
|
|
delete(context);
|
|
|
|
}
|
2019-02-13 16:53:17 +01:00
|
|
|
|
2017-11-15 19:31:49 +01:00
|
|
|
}
|