Search in sources :

Example 41 with HttpResponse

use of org.alfresco.rest.api.tests.client.HttpResponse in project alfresco-remote-api by Alfresco.

the class NodeApiTest method testUpdateOwner.

/**
 * Tests update owner (file or folder)
 * <p>PUT:</p>
 * {@literal <host>:<port>/alfresco/api/-default-/public/alfresco/versions/1/nodes/<nodeId>}
 */
@Test
public void testUpdateOwner() throws Exception {
    setRequestContext(user1);
    // create folder f0
    String folderName = "f0-testUpdateOwner-" + RUNID;
    Folder folderResp = createFolder(Nodes.PATH_SHARED, folderName);
    String f0Id = folderResp.getId();
    // owner is implied
    assertNull(user1, folderResp.getProperties());
    // explicitly set owner to oneself
    Map<String, Object> props = new HashMap<>();
    props.put(PROP_OWNER, user1);
    Folder fUpdate = new Folder();
    fUpdate.setProperties(props);
    HttpResponse response = put(URL_NODES, f0Id, toJsonAsStringNonNull(fUpdate), null, 200);
    folderResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Folder.class);
    assertEquals(user1, ((Map) folderResp.getProperties().get(PROP_OWNER)).get("id"));
    // create doc d1
    String d1Name = "content1 " + RUNID;
    String d1Id = createTextFile(f0Id, d1Name, "The quick brown fox jumps over the lazy dog.").getId();
    // get node info
    response = getSingle(NodesEntityResource.class, d1Id, null, 200);
    Document documentResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class);
    // note: owner is implied
    assertEquals(2, documentResp.getProperties().size());
    assertEquals("1.0", documentResp.getProperties().get("cm:versionLabel"));
    assertEquals("MAJOR", documentResp.getProperties().get("cm:versionType"));
    props = new HashMap<>();
    props.put(PROP_OWNER, user1);
    Document dUpdate = new Document();
    dUpdate.setProperties(props);
    response = put(URL_NODES, d1Id, toJsonAsStringNonNull(dUpdate), null, 200);
    documentResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class);
    assertEquals(user1, ((Map) documentResp.getProperties().get(PROP_OWNER)).get("id"));
    // -ve test - cannot set owner to a nonexistent user
    props = new HashMap<>();
    props.put(PROP_OWNER, "unknownusernamedoesnotexist");
    dUpdate = new Document();
    dUpdate.setProperties(props);
    put(URL_NODES, d1Id, toJsonAsStringNonNull(dUpdate), null, 400);
    setRequestContext(user2);
    response = getSingle(URL_NODES, d1Id, 200);
    documentResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class);
    assertEquals(user1, ((Map) documentResp.getProperties().get(PROP_OWNER)).get("id"));
    // -ve test - cannot take/change ownership
    props = new HashMap<>();
    props.put(PROP_OWNER, user2);
    dUpdate = new Document();
    dUpdate.setProperties(props);
    put(URL_NODES, d1Id, toJsonAsStringNonNull(dUpdate), null, 403);
    props = new HashMap<>();
    props.put(PROP_OWNER, user1);
    dUpdate = new Document();
    dUpdate.setProperties(props);
    put(URL_NODES, d1Id, toJsonAsStringNonNull(dUpdate), null, 403);
    setRequestContext(user1);
    props = new HashMap<>();
    props.put(PROP_OWNER, user2);
    dUpdate = new Document();
    dUpdate.setProperties(props);
    response = put(URL_NODES, d1Id, toJsonAsStringNonNull(dUpdate), null, 200);
    documentResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class);
    assertEquals(user2, ((Map) documentResp.getProperties().get(PROP_OWNER)).get("id"));
    setRequestContext(user2);
    response = getSingle(URL_NODES, d1Id, 200);
    documentResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class);
    assertEquals(user2, ((Map) documentResp.getProperties().get(PROP_OWNER)).get("id"));
    // -ve test - user2 cannot delete the test folder/file - TODO is that expected ?
    setRequestContext(user2);
    deleteNode(f0Id, 403);
    setRequestContext(user1);
    deleteNode(f0Id);
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) HttpResponse(org.alfresco.rest.api.tests.client.HttpResponse) JSONObject(org.json.simple.JSONObject) NodesEntityResource(org.alfresco.rest.api.nodes.NodesEntityResource) Folder(org.alfresco.rest.api.tests.client.data.Folder) Document(org.alfresco.rest.api.tests.client.data.Document) Test(org.junit.Test) AbstractSingleNetworkSiteTest(org.alfresco.rest.AbstractSingleNetworkSiteTest)

Example 42 with HttpResponse

use of org.alfresco.rest.api.tests.client.HttpResponse in project alfresco-remote-api by Alfresco.

the class NodeApiTest method testMove.

/**
 * Tests move (file or folder)
 * <p>POST:</p>
 * {@literal <host>:<port>/alfresco/api/-default-/public/alfresco/versions/1/nodes/<nodeId>/move}
 */
@Test
public void testMove() throws Exception {
    setRequestContext(user1);
    // create folder f0
    String folder0Name = "f0-testMove-" + RUNID;
    String f0Id = createFolder(Nodes.PATH_MY, folder0Name).getId();
    // create folder f1
    Folder folderResp = createFolder(f0Id, "f1");
    String f1Id = folderResp.getId();
    // create folder f2
    folderResp = createFolder(f0Id, "f2");
    String f2Id = folderResp.getId();
    // create doc d1
    String d1Name = "content" + RUNID + "_1";
    String d1Id = createTextFile(f1Id, d1Name, "The quick brown fox jumps over the lazy dog 1.").getId();
    // create doc d2
    String d2Name = "content" + RUNID + "_2";
    String d2Id = createTextFile(f2Id, d2Name, "The quick brown fox jumps over the lazy dog 2.").getId();
    // move file (without rename)
    NodeTarget tgt = new NodeTarget();
    tgt.setTargetParentId(f2Id);
    HttpResponse response = post("nodes/" + d1Id + "/move", toJsonAsStringNonNull(tgt), null, 200);
    Document documentResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class);
    assertEquals(d1Name, documentResp.getName());
    assertEquals(f2Id, documentResp.getParentId());
    // move file (with rename)
    String d1NewName = d1Name + " updated !!";
    tgt = new NodeTarget();
    tgt.setName(d1NewName);
    tgt.setTargetParentId(f1Id);
    response = post("nodes/" + d1Id + "/move", toJsonAsStringNonNull(tgt), null, 200);
    documentResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class);
    assertEquals(d1NewName, documentResp.getName());
    assertEquals(f1Id, documentResp.getParentId());
    // -ve tests
    // missing target
    tgt = new NodeTarget();
    tgt.setName("new name");
    post("nodes/" + d1Id + "/move", toJsonAsStringNonNull(tgt), null, 400);
    // name already exists
    tgt = new NodeTarget();
    tgt.setName(d2Name);
    tgt.setTargetParentId(f2Id);
    post("nodes/" + d1Id + "/move", toJsonAsStringNonNull(tgt), null, 409);
    // unknown source nodeId
    tgt = new NodeTarget();
    tgt.setTargetParentId(f2Id);
    post("nodes/" + UUID.randomUUID().toString() + "/move", toJsonAsStringNonNull(tgt), null, 404);
    // unknown target nodeId
    tgt = new NodeTarget();
    tgt.setTargetParentId(UUID.randomUUID().toString());
    post("nodes/" + d1Id + "/move", toJsonAsStringNonNull(tgt), null, 404);
    // target is not a folder
    tgt = new NodeTarget();
    tgt.setTargetParentId(d2Id);
    post("nodes/" + d1Id + "/move", toJsonAsStringNonNull(tgt), null, 400);
    String rootNodeId = getRootNodeId();
    // create folder f3 (sub-folder of f2)
    folderResp = createFolder(f2Id, "f3");
    String f3Id = folderResp.getId();
    // can't create cycle (move into own subtree)
    tgt = new NodeTarget();
    tgt.setTargetParentId(f3Id);
    post("nodes/" + f2Id + "/move", toJsonAsStringNonNull(tgt), null, 400);
    // no (write/create) permissions to move to target
    tgt = new NodeTarget();
    tgt.setTargetParentId(rootNodeId);
    post("nodes/" + d1Id + "/move", toJsonAsStringNonNull(tgt), null, 403);
    setRequestContext(user2);
    String my2NodeId = getMyNodeId();
    // no (write/delete) permissions to move source
    tgt = new NodeTarget();
    tgt.setTargetParentId(my2NodeId);
    post("nodes/" + f1Id + "/move", toJsonAsStringNonNull(tgt), null, 403);
    // -ve - cannot move (delete) Company Home root node
    setRequestContext(networkAdmin);
    post("nodes/" + rootNodeId + "/move", toJsonAsStringNonNull(tgt), null, 403);
    setRequestContext(user1);
    Map params = new HashMap<>();
    params.put(Nodes.PARAM_RELATIVE_PATH, "/Sites");
    response = getSingle(NodesEntityResource.class, rootNodeId, params, 200);
    Node nodeResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class);
    String sitesNodeId = nodeResp.getId();
    // -ve - cannot move (delete) Sites node
    setRequestContext(networkAdmin);
    post("nodes/" + sitesNodeId + "/move", toJsonAsStringNonNull(tgt), null, 403);
    setRequestContext(user1);
    params = new HashMap<>();
    params.put(Nodes.PARAM_RELATIVE_PATH, "/Data Dictionary");
    response = getSingle(NodesEntityResource.class, rootNodeId, params, 200);
    nodeResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class);
    String ddNodeId = nodeResp.getId();
    // -ve - cannot move (delete) Data Dictionary node
    setRequestContext(networkAdmin);
    post("nodes/" + ddNodeId + "/move", toJsonAsStringNonNull(tgt), null, 403);
    // -ve test - cannot move to multiple destinations in single POST call (unsupported)
    List<NodeTarget> nodeDestinations = new ArrayList<>(2);
    NodeTarget nodeTarget = new NodeTarget();
    nodeTarget.setTargetParentId(f1Id);
    nodeDestinations.add(nodeTarget);
    nodeTarget = new NodeTarget();
    nodeTarget.setTargetParentId(f2Id);
    nodeDestinations.add(nodeTarget);
    post("nodes/" + d1Id + "/move", toJsonAsStringNonNull(nodeDestinations), null, 405);
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Node(org.alfresco.rest.api.tests.client.data.Node) ArrayList(java.util.ArrayList) NodeTarget(org.alfresco.rest.api.model.NodeTarget) HttpResponse(org.alfresco.rest.api.tests.client.HttpResponse) NodesEntityResource(org.alfresco.rest.api.nodes.NodesEntityResource) Folder(org.alfresco.rest.api.tests.client.data.Folder) Document(org.alfresco.rest.api.tests.client.data.Document) Map(java.util.Map) MimetypeMap(org.alfresco.repo.content.MimetypeMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test) AbstractSingleNetworkSiteTest(org.alfresco.rest.AbstractSingleNetworkSiteTest)

Example 43 with HttpResponse

use of org.alfresco.rest.api.tests.client.HttpResponse 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);
    }
}
Also used : HashMap(java.util.HashMap) Node(org.alfresco.rest.api.tests.client.data.Node) Paging(org.alfresco.rest.api.tests.client.PublicApiClient.Paging) AssocChild(org.alfresco.rest.api.model.AssocChild) HttpResponse(org.alfresco.rest.api.tests.client.HttpResponse) Association(org.alfresco.rest.api.tests.client.data.Association) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test) AbstractSingleNetworkSiteTest(org.alfresco.rest.AbstractSingleNetworkSiteTest)

Example 44 with HttpResponse

use of org.alfresco.rest.api.tests.client.HttpResponse in project alfresco-remote-api by Alfresco.

the class NodeAssociationsApiTest method testNodePeerAssocsPermissions.

/**
 * Tests base permissions for managing (adding, listing and removing) peer associations.
 *
 * <p>POST:</p>
 * {@literal <host>:<port>/alfresco/api/<networkId>/public/alfresco/versions/1/nodes/<sourceNodeId>/targets}
 *
 * <p>DELETE:</p>
 * {@literal <host>:<port>/alfresco/api/<networkId>/public/alfresco/versions/1/nodes/<sourceNodeId>/targets/<targetNodeId>}
 *
 * <p>GET:</p>
 * {@literal <host>:<port>/alfresco/api/<networkId>/public/alfresco/versions/1/nodes/<sourceNodeId>/targets}
 * {
 */
@Test
public void testNodePeerAssocsPermissions() throws Exception {
    setRequestContext(user1);
    // as user 1 - create folder in "Shared Files" area and content within the folder
    String sharedFolderNodeId = getSharedNodeId();
    String sf1Id = createFolder(sharedFolderNodeId, "shared folder " + RUNID).getId();
    Node n = new Node();
    n.setName("shared content " + RUNID);
    n.setNodeType(TYPE_CM_CONTENT);
    n.setAspectNames(Arrays.asList(ASPECT_CM_REFERENCING, ASPECT_CM_PARTABLE));
    HttpResponse response = post(getNodeChildrenUrl(sf1Id), toJsonAsStringNonNull(n), 201);
    String so1Id = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class).getId();
    // as user 1 - create folder in user's home (My Files) area and content within the folder
    String u1myNodeId = getMyNodeId();
    String u1f1Id = createFolder(u1myNodeId, "f1").getId();
    n = new Node();
    n.setName("o1");
    n.setNodeType(TYPE_CM_CONTENT);
    n.setAspectNames(Arrays.asList(ASPECT_CM_REFERENCING, ASPECT_CM_PARTABLE));
    response = post(getNodeChildrenUrl(u1f1Id), toJsonAsStringNonNull(n), 201);
    String u1o1Id = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class).getId();
    // as user 2 - create folder in user's home (My Files) area and content within the folder
    setRequestContext(user2);
    String u2myNodeId = getMyNodeId();
    String u2f1Id = createFolder(u2myNodeId, "f1").getId();
    n = new Node();
    n.setName("o1");
    n.setNodeType(TYPE_CM_CONTENT);
    n.setAspectNames(Arrays.asList(ASPECT_CM_REFERENCING, ASPECT_CM_PARTABLE));
    response = post(getNodeChildrenUrl(u2f1Id), toJsonAsStringNonNull(n), 201);
    String u2o1Id = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class).getId();
    try {
        Paging paging = getPaging(0, 100);
        // empty lists - before
        setRequestContext(user1);
        response = getAll(getNodeTargetsUrl(u1f1Id), paging, null, 200);
        List<Node> nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
        assertEquals(0, nodes.size());
        setRequestContext(user2);
        response = getAll(getNodeTargetsUrl(u2f1Id), paging, null, 200);
        nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
        assertEquals(0, nodes.size());
        // Create some assocs
        setRequestContext(user1);
        AssocTarget tgt = new AssocTarget(u1o1Id, ASSOC_TYPE_CM_REFERENCES);
        post(getNodeTargetsUrl(u1f1Id), toJsonAsStringNonNull(tgt), 201);
        setRequestContext(user2);
        tgt = new AssocTarget(u2o1Id, ASSOC_TYPE_CM_REFERENCES);
        post(getNodeTargetsUrl(u2f1Id), toJsonAsStringNonNull(tgt), 201);
        setRequestContext(user1);
        response = getAll(getNodeTargetsUrl(u1f1Id), paging, null, 200);
        nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
        assertEquals(1, nodes.size());
        setRequestContext(user2);
        response = getAll(getNodeTargetsUrl(u2f1Id), paging, null, 200);
        nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
        assertEquals(1, nodes.size());
        // -ve tests
        {
            // source/target not readable
            setRequestContext(user2);
            // list
            getAll(getNodeTargetsUrl(u1f1Id), paging, null, 403);
            getAll(getNodeSourcesUrl(u1o1Id), paging, null, 403);
            setRequestContext(user1);
            // create
            tgt = new AssocTarget(u2o1Id, ASSOC_TYPE_CM_REFERENCES);
            post(getNodeTargetsUrl(u1f1Id), toJsonAsStringNonNull(tgt), 403);
            tgt = new AssocTarget(u1o1Id, ASSOC_TYPE_CM_REFERENCES);
            post(getNodeTargetsUrl(u2f1Id), toJsonAsStringNonNull(tgt), 403);
            setRequestContext(user2);
            // remove
            delete(getNodeTargetsUrl(u1f1Id), u2o1Id, null, 403);
            delete(getNodeTargetsUrl(u2f1Id), u1o1Id, null, 404);
        }
        setRequestContext(user1);
        // Test listing targets (with permissions applied)
        // update permission
        // TODO refactor with remote permission api calls (use v0 until we have v1 ?) (RA-1085)
        AuthenticationUtil.setFullyAuthenticatedUser(user1);
        permissionService.setPermission(new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, sf1Id), user2, PermissionService.EDITOR, true);
        setRequestContext(networkAdmin);
        response = publicApiClient.get(getScope(), "nodes/" + sf1Id + "/targets", null, null, null, createParams(paging, null));
        checkStatus(200, response.getStatusCode());
        nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
        assertEquals(0, nodes.size());
        // user 1
        setRequestContext(user1);
        tgt = new AssocTarget(u1o1Id, ASSOC_TYPE_CM_REFERENCES);
        post(getNodeTargetsUrl(sf1Id), toJsonAsStringNonNull(tgt), 201);
        // user 2
        setRequestContext(user2);
        tgt = new AssocTarget(u2o1Id, ASSOC_TYPE_CM_REFERENCES);
        post(getNodeTargetsUrl(sf1Id), toJsonAsStringNonNull(tgt), 201);
        setRequestContext(networkAdmin);
        response = publicApiClient.get(getScope(), "nodes/" + sf1Id + "/targets", null, null, null, createParams(paging, null));
        checkStatus(200, response.getStatusCode());
        nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
        assertEquals(2, nodes.size());
        setRequestContext(user1);
        response = getAll(getNodeTargetsUrl(sf1Id), paging, null, 200);
        nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
        assertEquals(1, nodes.size());
        assertEquals(u1o1Id, nodes.get(0).getId());
        setRequestContext(user2);
        response = getAll(getNodeTargetsUrl(sf1Id), paging, null, 200);
        nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
        assertEquals(1, nodes.size());
        assertEquals(u2o1Id, nodes.get(0).getId());
        // Test listing sources (with permissions applied)
        // update permission
        // TODO refactor with remote permission api calls (use v0 until we have v1 ?)
        AuthenticationUtil.setFullyAuthenticatedUser(user1);
        permissionService.setPermission(new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, sf1Id), user2, PermissionService.EDITOR, true);
        setRequestContext(networkAdmin);
        response = publicApiClient.get(getScope(), "nodes/" + so1Id + "/sources", null, null, null, createParams(paging, null));
        checkStatus(200, response.getStatusCode());
        nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
        assertEquals(0, nodes.size());
        // user 1
        setRequestContext(user1);
        tgt = new AssocTarget(so1Id, ASSOC_TYPE_CM_REFERENCES);
        post(getNodeTargetsUrl(u1f1Id), toJsonAsStringNonNull(tgt), 201);
        // user 2
        setRequestContext(user2);
        tgt = new AssocTarget(so1Id, ASSOC_TYPE_CM_REFERENCES);
        post(getNodeTargetsUrl(u2f1Id), toJsonAsStringNonNull(tgt), 201);
        setRequestContext(networkAdmin);
        response = publicApiClient.get(getScope(), "nodes/" + so1Id + "/sources", null, null, null, createParams(paging, null));
        checkStatus(200, response.getStatusCode());
        nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
        assertEquals(2, nodes.size());
        setRequestContext(user1);
        response = getAll(getNodeSourcesUrl(so1Id), paging, null, 200);
        nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
        assertEquals(1, nodes.size());
        assertEquals(u1f1Id, nodes.get(0).getId());
        setRequestContext(user2);
        response = getAll(getNodeSourcesUrl(so1Id), paging, null, 200);
        nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
        assertEquals(1, nodes.size());
        assertEquals(u2f1Id, nodes.get(0).getId());
    } finally {
        // some cleanup
        setRequestContext(user1);
        deleteNode(u1f1Id, true, 204);
        deleteNode(sf1Id, true, 204);
        setRequestContext(user2);
        deleteNode(u2f1Id, true, 204);
    }
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) Node(org.alfresco.rest.api.tests.client.data.Node) Paging(org.alfresco.rest.api.tests.client.PublicApiClient.Paging) HttpResponse(org.alfresco.rest.api.tests.client.HttpResponse) AssocTarget(org.alfresco.rest.api.model.AssocTarget) Test(org.junit.Test) AbstractSingleNetworkSiteTest(org.alfresco.rest.AbstractSingleNetworkSiteTest)

Example 45 with HttpResponse

use of org.alfresco.rest.api.tests.client.HttpResponse in project alfresco-remote-api by Alfresco.

the class NodeAssociationsApiTest method testListChildrenConsistentParentIdWithSecondaryAssociations.

/**
 * Regardless of which parent is used to list children of a node, the node information
 * should consistently present the primary parent as a node's {@code parentId}.
 * <p>
 * See REPO-1780
 */
@Test
public void testListChildrenConsistentParentIdWithSecondaryAssociations() throws Exception {
    setRequestContext(user1);
    String myNodeId = getMyNodeId();
    // Create primary folder
    String primaryFolderName = "primary folder " + RUNID;
    String primaryFolderId = createFolder(myNodeId, primaryFolderName, null).getId();
    // Create content file
    String contentFileName = "content" + RUNID + " in folder";
    String contentId = createTextFile(primaryFolderId, contentFileName, "The quick brown fox jumps over the lazy dog.").getId();
    // Add a secondary parent for content file
    Node n = new Node();
    n.setName("secondary folder " + RUNID);
    n.setNodeType(TYPE_CM_FOLDER);
    n.setAspectNames(Arrays.asList(ASPECT_CM_PREFERENCES));
    HttpResponse response = post(getNodeChildrenUrl(myNodeId), toJsonAsStringNonNull(n), 201);
    String secondaryFolderId = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class).getId();
    AssocChild secChild = new AssocChild(contentId, ASSOC_TYPE_CM_CONTAINS);
    post(getNodeSecondaryChildrenUrl(secondaryFolderId), toJsonAsStringNonNull(secChild), 201);
    Paging paging = getPaging(0, 100);
    // Order by folders and modified date first
    Map<String, String> orderBy = Collections.singletonMap("orderBy", "isFolder DESC,modifiedAt DESC");
    // Retrieve the node via the primary parent
    String primaryChildrenUrl = getNodeChildrenUrl(primaryFolderId);
    response = getAll(primaryChildrenUrl, paging, orderBy, 200);
    List<Document> nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Document.class);
    Document node = nodes.get(0);
    assertEquals(contentId, node.getId());
    assertEquals(primaryFolderId, node.getParentId());
    // Retrieve the node via the secondary parent
    String secondaryChildrenUrl = getNodeChildrenUrl(secondaryFolderId);
    response = getAll(secondaryChildrenUrl, paging, orderBy, 200);
    nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Document.class);
    node = nodes.get(0);
    assertEquals(contentId, node.getId());
    // The parent ID must STILL be the primary parent, even when the info
    // is retrieved via the secondary parent.
    assertEquals(primaryFolderId, node.getParentId());
}
Also used : Node(org.alfresco.rest.api.tests.client.data.Node) Paging(org.alfresco.rest.api.tests.client.PublicApiClient.Paging) AssocChild(org.alfresco.rest.api.model.AssocChild) HttpResponse(org.alfresco.rest.api.tests.client.HttpResponse) Document(org.alfresco.rest.api.tests.client.data.Document) Test(org.junit.Test) AbstractSingleNetworkSiteTest(org.alfresco.rest.AbstractSingleNetworkSiteTest)

Aggregations

HttpResponse (org.alfresco.rest.api.tests.client.HttpResponse)162 Test (org.junit.Test)114 HashMap (java.util.HashMap)59 AbstractSingleNetworkSiteTest (org.alfresco.rest.AbstractSingleNetworkSiteTest)50 Document (org.alfresco.rest.api.tests.client.data.Document)49 Node (org.alfresco.rest.api.tests.client.data.Node)49 LinkedHashMap (java.util.LinkedHashMap)31 ArrayList (java.util.ArrayList)29 Paging (org.alfresco.rest.api.tests.client.PublicApiClient.Paging)27 Folder (org.alfresco.rest.api.tests.client.data.Folder)26 File (java.io.File)25 NodesEntityResource (org.alfresco.rest.api.nodes.NodesEntityResource)25 RequestContext (org.alfresco.rest.api.tests.client.RequestContext)22 CustomModel (org.alfresco.rest.api.model.CustomModel)16 ContentInfo (org.alfresco.rest.api.tests.client.data.ContentInfo)15 MultiPartBuilder (org.alfresco.rest.api.tests.util.MultiPartBuilder)15 JSONObject (org.json.simple.JSONObject)15 NodeRef (org.alfresco.service.cmr.repository.NodeRef)14 Map (java.util.Map)13 CustomAspect (org.alfresco.rest.api.model.CustomAspect)13