use of org.alfresco.rest.api.tests.client.data.Association in project alfresco-remote-api by Alfresco.
the class NodeApiTest method testChildrenAssocType.
/**
* Tests creation and listing of children using assoc type other than "cm:contains".
*
* <p>POST:</p>
* {@literal <host>:<port>/alfresco/api/-default-/public/alfresco/versions/1/nodes/<nodeId>/children}
*
* <p>GET:</p>
* {@literal <host>:<port>/alfresco/api/-default-/public/alfresco/versions/1/nodes/<nodeId>/children}
*/
@Test
public void testChildrenAssocType() throws Exception {
setRequestContext(user1);
String myNodeId = getMyNodeId();
String fId = null;
try {
fId = createFolder(myNodeId, "testChildrenAssocType folder").getId();
Node nodeUpdate = new Node();
nodeUpdate.setAspectNames(Collections.singletonList(ASPECT_CM_PREFERENCES));
put(URL_NODES, fId, toJsonAsStringNonNull(nodeUpdate), null, 200);
HttpResponse response = getAll(getNodeChildrenUrl(fId), null, null, 200);
List<Node> nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
assertEquals(0, nodes.size());
Node obj = new Node();
obj.setName("c1");
obj.setNodeType(TYPE_CM_CONTENT);
// assoc type => cm:contains
response = post(getNodeChildrenUrl(fId), toJsonAsStringNonNull(obj), 201);
Node nodeResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class);
String c1Id = nodeResp.getId();
assertEquals(fId, nodeResp.getParentId());
response = getAll(getNodeChildrenUrl(fId), null, null, 200);
nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
assertEquals(1, nodes.size());
obj = new Node();
obj.setName("c2");
obj.setNodeType(TYPE_CM_CONTENT);
Association assoc = new Association();
assoc.setAssocType(ASSOC_TYPE_CM_PREFERENCE_IMAGE);
obj.setAssociation(assoc);
// assoc type => cm:preferenceImage
response = post(getNodeChildrenUrl(fId), toJsonAsStringNonNull(obj), 201);
nodeResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class);
String c2Id = nodeResp.getId();
assertEquals(fId, nodeResp.getParentId());
response = getAll(getNodeChildrenUrl(fId), null, null, 200);
nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
assertEquals(2, nodes.size());
Map<String, String> params = new HashMap<>();
params.put("where", "(assocType='" + ASSOC_TYPE_CM_CONTAINS + "')");
params.put("include", "association");
response = getAll(getNodeChildrenUrl(fId), null, params, 200);
nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
assertEquals(1, nodes.size());
assertEquals(c1Id, nodes.get(0).getId());
assertTrue(nodes.get(0).getAssociation().getIsPrimary());
params = new HashMap<>();
params.put("where", "(assocType='" + ASSOC_TYPE_CM_PREFERENCE_IMAGE + "')");
params.put("include", "association");
response = getAll(getNodeChildrenUrl(fId), null, params, 200);
nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
assertEquals(1, nodes.size());
assertEquals(c2Id, nodes.get(0).getId());
assertTrue(nodes.get(0).getAssociation().getIsPrimary());
//
// test that we can also create children below content
//
obj = new Node();
obj.setName("c3");
obj.setNodeType(TYPE_CM_CONTENT);
nodeUpdate.setAspectNames(Collections.singletonList(ASPECT_CM_PREFERENCES));
// assoc type => cm:contains
response = post(getNodeChildrenUrl(fId), toJsonAsStringNonNull(obj), 201);
nodeResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class);
String c3Id = nodeResp.getId();
obj = new Node();
obj.setName("c4");
obj.setNodeType(TYPE_CM_CONTENT);
assoc = new Association();
assoc.setAssocType(ASSOC_TYPE_CM_PREFERENCE_IMAGE);
obj.setAssociation(assoc);
// assoc type => cm:preferenceImage
response = post(getNodeChildrenUrl(c3Id), toJsonAsStringNonNull(obj), 201);
nodeResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class);
assertEquals(c3Id, nodeResp.getParentId());
// -ve test
obj = new Node();
obj.setName("c5");
obj.setNodeType(TYPE_CM_CONTENT);
assoc = new Association();
assoc.setAssocType(ASSOC_TYPE_CM_CONTAINS);
obj.setAssociation(assoc);
// assoc type => cm:contains (requires parent to be a folder !)
post(getNodeChildrenUrl(c3Id), toJsonAsStringNonNull(obj), 422);
} finally {
// some cleanup
if (fId != null) {
deleteNode(fId);
}
}
}
use of org.alfresco.rest.api.tests.client.data.Association in project alfresco-remote-api by Alfresco.
the class NodeAssociationsApiTest method testNodeSecondaryChildAssocs.
/**
* Tests basic api to manage (add, list, remove) node secondary child associations (ie. parent node -> child node)
*
* Note: refer to NodeApiTest for tests for primary child association
*
* <p>POST:</p>
* {@literal <host>:<port>/alfresco/api/<networkId>/public/alfresco/versions/1/nodes/<parentNodeId>/secondary-children}
*
* <p>DELETE:</p>
* {@literal <host>:<port>/alfresco/api/<networkId>/public/alfresco/versions/1/nodes/<parentNodeId>/secondary-children/<childNodeId>}
*
* <p>GET:</p>
* {@literal <host>:<port>/alfresco/api/<networkId>/public/alfresco/versions/1/nodes/<parentNodeId>/secondary-children}
* {@literal <host>:<port>/alfresco/api/<networkId>/public/alfresco/versions/1/nodes/<childNodeId>/parents}
*/
@Test
public void testNodeSecondaryChildAssocs() throws Exception {
setRequestContext(user1);
String myFolderNodeId = getMyNodeId();
// create folder
Node n = new Node();
n.setName("f1");
n.setNodeType(TYPE_CM_FOLDER);
n.setAspectNames(Arrays.asList(ASPECT_CM_PREFERENCES));
HttpResponse response = post(getNodeChildrenUrl(myFolderNodeId), toJsonAsStringNonNull(n), 201);
String f1Id = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class).getId();
// create content node
String o1Name = "o1";
n = new Node();
n.setName(o1Name);
n.setNodeType(TYPE_CM_CONTENT);
response = post(getNodeChildrenUrl(f1Id), toJsonAsStringNonNull(n), 201);
String o1Id = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class).getId();
// create ano' folder
String f2Id = createFolder(myFolderNodeId, "f2").getId();
// create ano' content node
String o2Name = "o2";
n = new Node();
n.setName(o2Name);
n.setNodeType(TYPE_CM_CONTENT);
response = post(getNodeChildrenUrl(f2Id), toJsonAsStringNonNull(n), 201);
String o2Id = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class).getId();
String f3Id = createFolder(myFolderNodeId, "f3").getId();
String f4Id = createFolder(myFolderNodeId, "f4").getId();
try {
// As user 1 ...
Paging paging = getPaging(0, 100);
// lists - before
response = getAll(getNodeSecondaryChildrenUrl(f1Id), paging, null, 200);
List<Node> nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
assertEquals(0, nodes.size());
// primary parent only
response = getAll(getNodeParentsUrl(o2Id), paging, null, 200);
nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
assertEquals(1, nodes.size());
assertEquals(f2Id, nodes.get(0).getId());
assertEquals(ASSOC_TYPE_CM_CONTAINS, nodes.get(0).getAssociation().getAssocType());
assertTrue(nodes.get(0).getAssociation().getIsPrimary());
// create secondary child assoc
AssocChild secChild = new AssocChild(o2Id, ASSOC_TYPE_CM_CONTAINS);
post(getNodeSecondaryChildrenUrl(f1Id), toJsonAsStringNonNull(secChild), 201);
// create ano' secondary child assoc (different type) between the same two nodes
secChild = new AssocChild(o2Id, ASSOC_TYPE_CM_PREFERENCE_IMAGE);
post(getNodeSecondaryChildrenUrl(f1Id), toJsonAsStringNonNull(secChild), 201);
response = getAll(getNodeSecondaryChildrenUrl(f1Id), paging, null, 200);
nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
int i = 0;
for (Node node : nodes) {
Association nodeAssoc = node.getAssociation();
if (nodeAssoc.getAssocType().equals(ASSOC_TYPE_CM_CONTAINS)) {
i++;
} else if (nodeAssoc.getAssocType().equals(ASSOC_TYPE_CM_PREFERENCE_IMAGE)) {
i++;
}
assertEquals(o2Id, node.getId());
assertFalse(nodeAssoc.getIsPrimary());
}
assertEquals(2, i);
response = getAll(getNodeParentsUrl(o2Id), paging, null, 200);
nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
i = 0;
for (Node node : nodes) {
String nodeId = node.getId();
Association nodeAssoc = node.getAssociation();
if (nodeId.equals(f2Id)) {
assertEquals(ASSOC_TYPE_CM_CONTAINS, nodeAssoc.getAssocType());
assertTrue(nodeAssoc.getIsPrimary());
i++;
} else if (nodeId.equals(f1Id)) {
if (nodeAssoc.getAssocType().equals(ASSOC_TYPE_CM_CONTAINS)) {
i++;
} else if (nodeAssoc.getAssocType().equals(ASSOC_TYPE_CM_PREFERENCE_IMAGE)) {
i++;
}
assertFalse(nodeAssoc.getIsPrimary());
}
}
assertEquals(3, i);
// test list filter - assocType (/secondary-children & /parents)
Map<String, String> params = new HashMap<>(1);
params.put("where", "(assocType='" + ASSOC_TYPE_CM_CONTAINS + "')");
response = getAll(getNodeSecondaryChildrenUrl(f1Id), paging, params, 200);
nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
assertEquals(1, nodes.size());
assertEquals(o2Id, nodes.get(0).getId());
assertEquals(ASSOC_TYPE_CM_CONTAINS, nodes.get(0).getAssociation().getAssocType());
response = getAll(getNodeParentsUrl(o2Id), paging, params, 200);
nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
i = 0;
for (Node node : nodes) {
String nodeId = node.getId();
Association nodeAssoc = node.getAssociation();
if (nodeId.equals(f2Id)) {
assertEquals(ASSOC_TYPE_CM_CONTAINS, nodeAssoc.getAssocType());
assertTrue(nodeAssoc.getIsPrimary());
i++;
} else if (nodeId.equals(f1Id)) {
assertEquals(ASSOC_TYPE_CM_CONTAINS, nodeAssoc.getAssocType());
assertFalse(nodeAssoc.getIsPrimary());
i++;
}
}
assertEquals(2, i);
params = new HashMap<>(1);
params.put("where", "(assocType='" + ASSOC_TYPE_CM_PREFERENCE_IMAGE + "')");
response = getAll(getNodeSecondaryChildrenUrl(f1Id), paging, params, 200);
nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
assertEquals(1, nodes.size());
assertEquals(o2Id, nodes.get(0).getId());
assertEquals(ASSOC_TYPE_CM_PREFERENCE_IMAGE, nodes.get(0).getAssociation().getAssocType());
assertFalse(nodes.get(0).getAssociation().getIsPrimary());
response = getAll(getNodeParentsUrl(o2Id), paging, params, 200);
nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
assertEquals(1, nodes.size());
assertEquals(f1Id, nodes.get(0).getId());
assertEquals(ASSOC_TYPE_CM_PREFERENCE_IMAGE, nodes.get(0).getAssociation().getAssocType());
assertFalse(nodes.get(0).getAssociation().getIsPrimary());
// test list filter - isPrimary (/children)
// note: see NodeApiTest for other filters related to /nodes/{parentId}/children filters
// note: currently collapses same nodeIds (o2Id x 2) into one - makes sense in terms of File/Folder to avoid duplicate names
response = getAll(getNodeChildrenUrl(f1Id), paging, null, 200);
nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
assertEquals(2, nodes.size());
List<String> nodeIds = Arrays.asList(new String[] { nodes.get(0).getId(), nodes.get(1).getId() });
assertTrue(nodeIds.contains(o1Id));
assertTrue(nodeIds.contains(o2Id));
params = new HashMap<>(1);
params.put("where", "(isPrimary=true)");
response = getAll(getNodeChildrenUrl(f1Id), paging, params, 200);
nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
assertEquals(1, nodes.size());
assertEquals(o1Id, nodes.get(0).getId());
params = new HashMap<>(1);
params.put("where", "(isPrimary=false)");
// note: currently collapses same nodeIds (o2Id x 2) into one - makes sense in terms of File/Folder to avoid duplicate names
response = getAll(getNodeChildrenUrl(f1Id), paging, params, 200);
nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
assertEquals(1, nodes.size());
assertEquals(o2Id, nodes.get(0).getId());
// test list filter - isPrimary (/parents)
response = getAll(getNodeParentsUrl(o2Id), paging, null, 200);
nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
assertEquals(3, nodes.size());
params = new HashMap<>(1);
params.put("where", "(isPrimary=true)");
response = getAll(getNodeParentsUrl(o2Id), paging, params, 200);
nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
assertEquals(1, nodes.size());
assertEquals(f2Id, nodes.get(0).getId());
params = new HashMap<>(1);
params.put("where", "(isPrimary=false)");
response = getAll(getNodeParentsUrl(o2Id), paging, params, 200);
nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
i = 0;
for (Node node : nodes) {
String nodeId = node.getId();
Association nodeAssoc = node.getAssociation();
if (nodeId.equals(f1Id)) {
if (nodeAssoc.getAssocType().equals(ASSOC_TYPE_CM_CONTAINS)) {
i++;
} else if (nodeAssoc.getAssocType().equals(ASSOC_TYPE_CM_PREFERENCE_IMAGE)) {
i++;
}
assertFalse(nodeAssoc.getIsPrimary());
}
}
assertEquals(2, i);
// combined filter
params = new HashMap<>(1);
params.put("where", "(isPrimary=false and assocType='" + ASSOC_TYPE_CM_PREFERENCE_IMAGE + "')");
response = getAll(getNodeParentsUrl(o2Id), paging, params, 200);
nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
assertEquals(1, nodes.size());
assertEquals(f1Id, nodes.get(0).getId());
assertFalse(nodes.get(0).getAssociation().getIsPrimary());
assertEquals(ASSOC_TYPE_CM_PREFERENCE_IMAGE, nodes.get(0).getAssociation().getAssocType());
// remove one secondary child assoc
params = new HashMap<>(1);
params.put(PARAM_ASSOC_TYPE, ASSOC_TYPE_CM_CONTAINS);
delete(getNodeSecondaryChildrenUrl(f1Id), o2Id, params, 204);
response = getAll(getNodeSecondaryChildrenUrl(f1Id), paging, null, 200);
nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
assertEquals(1, nodes.size());
response = getAll(getNodeParentsUrl(o2Id), paging, null, 200);
nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
assertEquals(2, nodes.size());
params = new HashMap<>(1);
params.put(PARAM_ASSOC_TYPE, ASSOC_TYPE_CM_PREFERENCE_IMAGE);
// remove other secondary child assoc
delete(getNodeSecondaryChildrenUrl(f1Id), o2Id, params, 204);
response = getAll(getNodeSecondaryChildrenUrl(f1Id), paging, null, 200);
nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
assertEquals(0, nodes.size());
response = getAll(getNodeParentsUrl(o2Id), paging, null, 200);
nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
assertEquals(1, nodes.size());
{
// test removal of multiple secondary child assocs (if assoc type is not specified)
response = getAll(getNodeSecondaryChildrenUrl(f1Id), paging, null, 200);
nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
assertEquals(0, nodes.size());
// re-create secondary child assoc
secChild = new AssocChild(o2Id, ASSOC_TYPE_CM_CONTAINS);
post(getNodeSecondaryChildrenUrl(f1Id), toJsonAsStringNonNull(secChild), 201);
// re-create ano' secondary child assoc (different type) between the same two nodes
secChild = new AssocChild(o2Id, ASSOC_TYPE_CM_PREFERENCE_IMAGE);
post(getNodeSecondaryChildrenUrl(f1Id), toJsonAsStringNonNull(secChild), 201);
response = getAll(getNodeSecondaryChildrenUrl(f1Id), paging, null, 200);
nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
assertEquals(2, nodes.size());
assertEquals(o2Id, nodes.get(0).getId());
assertEquals(o2Id, nodes.get(1).getId());
// now remove both secondary child assocs
delete(getNodeSecondaryChildrenUrl(f1Id), o2Id, null, 204);
response = getAll(getNodeSecondaryChildrenUrl(f1Id), paging, null, 200);
nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
assertEquals(0, nodes.size());
}
{
// sanity check paging of list of secondary children
paging = getPaging(0, 100);
response = getAll(getNodeSecondaryChildrenUrl(f3Id), paging, null, 200);
nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
assertEquals(0, nodes.size());
int childCnt = 6;
String[] childIds = new String[childCnt];
for (int j = 0; j < childCnt; j++) {
String childName = "child " + j;
n = new Node();
n.setName(childName);
n.setNodeType(TYPE_CM_CONTENT);
response = post(getNodeChildrenUrl(f2Id), toJsonAsStringNonNull(n), 201);
childIds[j] = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class).getId();
secChild = new AssocChild(childIds[j], ASSOC_TYPE_CM_CONTAINS);
post(getNodeSecondaryChildrenUrl(f3Id), toJsonAsStringNonNull(secChild), 201);
}
int skipCount = 0;
int maxItems = 100;
paging = getPaging(skipCount, maxItems);
response = getAll(getNodeSecondaryChildrenUrl(f3Id), paging, null, 200);
nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
assertEquals(childCnt, nodes.size());
PublicApiClient.ExpectedPaging expectedPaging = RestApiUtil.parsePaging(response.getJsonResponse());
assertEquals(childCnt, expectedPaging.getCount().intValue());
assertEquals(skipCount, expectedPaging.getSkipCount().intValue());
assertEquals(maxItems, expectedPaging.getMaxItems().intValue());
assertFalse(expectedPaging.getHasMoreItems().booleanValue());
skipCount = 1;
maxItems = 3;
paging = getPaging(skipCount, maxItems);
response = getAll(getNodeSecondaryChildrenUrl(f3Id), paging, null, 200);
nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
assertEquals(maxItems, nodes.size());
assertEquals(childIds[1], nodes.get(0).getId());
assertEquals(childIds[2], nodes.get(1).getId());
assertEquals(childIds[3], nodes.get(2).getId());
expectedPaging = RestApiUtil.parsePaging(response.getJsonResponse());
assertEquals(maxItems, expectedPaging.getCount().intValue());
assertEquals(skipCount, expectedPaging.getSkipCount().intValue());
assertEquals(maxItems, expectedPaging.getMaxItems().intValue());
assertTrue(expectedPaging.getHasMoreItems().booleanValue());
}
{
// sanity check paging of list of parents
String childName = "child with many parents";
n = new Node();
n.setName(childName);
n.setNodeType(TYPE_CM_CONTENT);
response = post(getNodeChildrenUrl(f4Id), toJsonAsStringNonNull(n), 201);
String childId = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class).getId();
paging = getPaging(0, 100);
response = getAll(getNodeParentsUrl(childId), paging, null, 200);
nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
assertEquals(1, nodes.size());
assertEquals(f4Id, nodes.get(0).getId());
int parentCnt = 5;
String[] parentIds = new String[parentCnt];
for (int j = 0; j < parentCnt; j++) {
String parentName = "parent " + j;
parentIds[j] = createFolder(f4Id, parentName).getId();
secChild = new AssocChild(childId, ASSOC_TYPE_CM_CONTAINS);
post(getNodeSecondaryChildrenUrl(parentIds[j]), toJsonAsStringNonNull(secChild), 201);
}
int skipCount = 0;
int maxItems = 100;
int expectedCnt = parentCnt + 1;
paging = getPaging(skipCount, maxItems);
response = getAll(getNodeParentsUrl(childId), paging, null, 200);
nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
assertEquals(expectedCnt, nodes.size());
PublicApiClient.ExpectedPaging expectedPaging = RestApiUtil.parsePaging(response.getJsonResponse());
assertEquals(expectedCnt, expectedPaging.getCount().intValue());
assertEquals(skipCount, expectedPaging.getSkipCount().intValue());
assertEquals(maxItems, expectedPaging.getMaxItems().intValue());
assertFalse(expectedPaging.getHasMoreItems().booleanValue());
params = new HashMap<>(1);
params.put("where", "(isPrimary=false)");
// TBC - order is currently undefined
List<String> expectedIds = new ArrayList<>(5);
expectedIds.addAll(Arrays.asList(parentIds));
skipCount = 0;
maxItems = 2;
paging = getPaging(skipCount, maxItems);
response = getAll(getNodeParentsUrl(childId), paging, params, 200);
nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
assertEquals(maxItems, nodes.size());
for (Node node : nodes) {
expectedIds.remove(node.getId());
}
assertEquals(3, expectedIds.size());
expectedPaging = RestApiUtil.parsePaging(response.getJsonResponse());
assertEquals(maxItems, expectedPaging.getCount().intValue());
assertEquals(skipCount, expectedPaging.getSkipCount().intValue());
assertEquals(maxItems, expectedPaging.getMaxItems().intValue());
assertTrue(expectedPaging.getHasMoreItems().booleanValue());
skipCount = 2;
maxItems = 2;
paging = getPaging(skipCount, maxItems);
response = getAll(getNodeParentsUrl(childId), paging, params, 200);
nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
assertEquals(maxItems, nodes.size());
for (Node node : nodes) {
expectedIds.remove(node.getId());
}
assertEquals(1, expectedIds.size());
expectedPaging = RestApiUtil.parsePaging(response.getJsonResponse());
assertEquals(maxItems, expectedPaging.getCount().intValue());
assertEquals(skipCount, expectedPaging.getSkipCount().intValue());
assertEquals(maxItems, expectedPaging.getMaxItems().intValue());
assertTrue(expectedPaging.getHasMoreItems().booleanValue());
skipCount = 4;
maxItems = 2;
paging = getPaging(skipCount, maxItems);
response = getAll(getNodeParentsUrl(childId), paging, params, 200);
nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
assertEquals(1, nodes.size());
for (Node node : nodes) {
expectedIds.remove(node.getId());
}
assertEquals(0, expectedIds.size());
expectedPaging = RestApiUtil.parsePaging(response.getJsonResponse());
assertEquals(1, expectedPaging.getCount().intValue());
assertEquals(skipCount, expectedPaging.getSkipCount().intValue());
assertEquals(maxItems, expectedPaging.getMaxItems().intValue());
assertFalse(expectedPaging.getHasMoreItems().booleanValue());
}
//
// -ve tests - add assoc
//
{
setRequestContext(null);
// -ve test - unauthenticated - belts-and-braces ;-)
secChild = new AssocChild(o2Id, ASSOC_TYPE_CM_CONTAINS);
post(getNodeSecondaryChildrenUrl(f1Id), toJsonAsStringNonNull(secChild), 401);
setRequestContext(user1);
// -ve test - model integrity
secChild = new AssocChild(o2Id, ASSOC_TYPE_CM_CONTAINS);
post(getNodeSecondaryChildrenUrl(o1Id), toJsonAsStringNonNull(secChild), 422);
// -ve test - duplicate assoc
secChild = new AssocChild(o2Id, ASSOC_TYPE_CM_CONTAINS);
post(getNodeSecondaryChildrenUrl(f1Id), toJsonAsStringNonNull(secChild), 201);
post(getNodeSecondaryChildrenUrl(f1Id), toJsonAsStringNonNull(secChild), 409);
// cleanup
delete(getNodeSecondaryChildrenUrl(f1Id), o2Id, null, 204);
secChild = new AssocChild(o2Id, "cm:unknowntype");
post(getNodeSecondaryChildrenUrl(f1Id), toJsonAsStringNonNull(secChild), 400);
}
//
// -ve test - list assocs
//
{
setRequestContext(null);
// -ve test - unauthenticated - belts-and-braces ;-)
getAll(getNodeSecondaryChildrenUrl(f1Id), paging, null, 401);
getAll(getNodeParentsUrl(o2Id), paging, null, 401);
setRequestContext(user1);
getAll(getNodeSecondaryChildrenUrl(UUID.randomUUID().toString()), paging, null, 404);
getAll(getNodeParentsUrl(UUID.randomUUID().toString()), paging, null, 404);
params = new HashMap<>(1);
params.put("where", "(assocType='cm:unknownassoctype')");
getAll(getNodeSecondaryChildrenUrl(o1Id), paging, params, 400);
getAll(getNodeParentsUrl(o1Id), paging, params, 400);
}
//
// -ve test - remove assoc(s)
//
{
setRequestContext(null);
// unauthenticated - belts-and-braces ;-)
delete(getNodeSecondaryChildrenUrl(f1Id), o2Id, null, 401);
setRequestContext(user1);
delete(getNodeSecondaryChildrenUrl(UUID.randomUUID().toString()), o2Id, null, 404);
delete(getNodeSecondaryChildrenUrl(f1Id), UUID.randomUUID().toString(), null, 404);
// nothing to remove - for any assoc type
delete(getNodeSecondaryChildrenUrl(f1Id), o2Id, null, 404);
// nothing to remove - for given assoc type
params = new HashMap<>(1);
params.put(PARAM_ASSOC_TYPE, ASSOC_TYPE_CM_PREFERENCE_IMAGE);
delete(getNodeSecondaryChildrenUrl(f1Id), o2Id, params, 404);
// unknown assoc type
params = new HashMap<>(1);
params.put(PARAM_ASSOC_TYPE, "cm:unknowntype");
delete(getNodeSecondaryChildrenUrl(o1Id), o2Id, params, 400);
// do not allow delete of primary child (via secondary child removal)
params = new HashMap<>(1);
params.put(PARAM_ASSOC_TYPE, "cm:contains");
delete(getNodeSecondaryChildrenUrl(f1Id), o1Id, params, 400);
}
} finally {
// some cleanup
setRequestContext(user1);
deleteNode(f1Id, true, 204);
deleteNode(f2Id, true, 204);
deleteNode(f3Id, true, 204);
deleteNode(f4Id, true, 204);
}
}
Aggregations