Search in sources :

Example 86 with HttpResponse

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

the class DeletedNodesTest method testDownloadRendition.

/**
 * Tests download rendition.
 * <p>GET:</p>
 * {@literal <host>:<port>/alfresco/api/<networkId>/public/alfresco/versions/1/deleted-nodes/<nodeId>/renditions/<renditionId>/content}
 */
@Test
public void testDownloadRendition() throws Exception {
    setRequestContext(user1);
    // Create a folder within the site document's library
    Date now = new Date();
    String folder1 = "folder" + now.getTime() + "_1";
    Folder createdFolder = createFolder(tDocLibNodeId, folder1, null);
    assertNotNull(createdFolder);
    String f1Id = createdFolder.getId();
    // Create multipart request using an existing file
    String fileName = "quick.pdf";
    File file = getResourceFile(fileName);
    MultiPartBuilder multiPartBuilder = MultiPartBuilder.create().setFileData(new MultiPartBuilder.FileData(fileName, file));
    MultiPartBuilder.MultiPartRequest reqBody = multiPartBuilder.build();
    // Upload quick.pdf file into 'folder'
    HttpResponse response = post(getNodeChildrenUrl(f1Id), reqBody.getBody(), null, reqBody.getContentType(), 201);
    Document document = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class);
    String contentNodeId = document.getId();
    Rendition rendition = createAndGetRendition(contentNodeId, "doclib");
    assertNotNull(rendition);
    assertEquals(Rendition.RenditionStatus.CREATED, rendition.getStatus());
    deleteNode(contentNodeId);
    // Download rendition - by default with Content-Disposition header
    response = getSingle(getDeletedNodeRenditionsUrl(contentNodeId), "doclib/content", 200);
    assertNotNull(response.getResponseAsBytes());
    Map<String, String> responseHeaders = response.getHeaders();
    assertNotNull(responseHeaders);
    String contentDisposition = responseHeaders.get("Content-Disposition");
    assertNotNull(contentDisposition);
    assertTrue(contentDisposition.contains("filename=\"doclib\""));
    String contentType = responseHeaders.get("Content-Type");
    assertNotNull(contentType);
    assertTrue(contentType.startsWith(MimetypeMap.MIMETYPE_IMAGE_PNG));
    // Download rendition - without Content-Disposition header
    // (attachment=false)
    Map<String, String> params = new HashMap<>();
    params = Collections.singletonMap("attachment", "false");
    response = getSingle(getDeletedNodeRenditionsUrl(contentNodeId), "doclib/content", params, 200);
    assertNotNull(response.getResponseAsBytes());
    responseHeaders = response.getHeaders();
    assertNotNull(responseHeaders);
    assertNull(responseHeaders.get("Content-Disposition"));
    contentType = responseHeaders.get("Content-Type");
    assertNotNull(contentType);
    assertTrue(contentType.startsWith(MimetypeMap.MIMETYPE_IMAGE_PNG));
    // Download rendition - with Content-Disposition header
    // (attachment=true) same as default
    params = Collections.singletonMap("attachment", "true");
    response = getSingle(getDeletedNodeRenditionsUrl(contentNodeId), "doclib/content", params, 200);
    assertNotNull(response.getResponseAsBytes());
    responseHeaders = response.getHeaders();
    assertNotNull(responseHeaders);
    String cacheControl = responseHeaders.get("Cache-Control");
    assertNotNull(cacheControl);
    assertFalse(cacheControl.contains("must-revalidate"));
    assertTrue(cacheControl.contains("max-age=31536000"));
    contentDisposition = responseHeaders.get("Content-Disposition");
    assertNotNull(contentDisposition);
    assertTrue(contentDisposition.contains("filename=\"doclib\""));
    contentType = responseHeaders.get("Content-Type");
    assertNotNull(contentType);
    assertTrue(contentType.startsWith(MimetypeMap.MIMETYPE_IMAGE_PNG));
    // Test 304 response - doclib rendition (attachment=true)
    String lastModifiedHeader = responseHeaders.get(LAST_MODIFIED_HEADER);
    assertNotNull(lastModifiedHeader);
    Map<String, String> headers = Collections.singletonMap(IF_MODIFIED_SINCE_HEADER, lastModifiedHeader);
    getSingle(getDeletedNodeRenditionsUrl(contentNodeId), "doclib/content", params, headers, 304);
    // -ve tests
    // nodeId in the path parameter does not represent a file
    deleteNode(f1Id);
    getSingle(getDeletedNodeRenditionsUrl(f1Id), "doclib/content", 400);
    // nodeId in the path parameter does not exist
    getSingle(getDeletedNodeRenditionsUrl(UUID.randomUUID().toString()), "doclib/content", 404);
    // renditionId in the path parameter is not registered/available
    getSingle(getDeletedNodeRenditionsUrl(contentNodeId), ("renditionId" + System.currentTimeMillis() + "/content"), 404);
    // The rendition does not exist, a placeholder is not available and the
    // placeholder parameter has a value of "true"
    params = Collections.singletonMap("placeholder", "true");
    getSingle(getDeletedNodeRenditionsUrl(contentNodeId), ("renditionId" + System.currentTimeMillis() + "/content"), params, 404);
}
Also used : MultiPartBuilder(org.alfresco.rest.api.tests.util.MultiPartBuilder) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Rendition(org.alfresco.rest.api.tests.client.data.Rendition) HttpResponse(org.alfresco.rest.api.tests.client.HttpResponse) Folder(org.alfresco.rest.api.tests.client.data.Folder) Document(org.alfresco.rest.api.tests.client.data.Document) File(java.io.File) Date(java.util.Date) Test(org.junit.Test)

Example 87 with HttpResponse

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

the class BasicSearchApiIntegrationTest method testQuery.

/**
 * Tests basic api for search
 */
@Test
public void testQuery() throws Exception {
    setRequestContext(user1);
    String f1Id = null;
    try {
        // As user 1 ...
        // Try to get nodes with search term 'king*' - assume clean repo (ie. none to start with)
        HttpResponse response = post(URL_SEARCH, json, null, null, SEARCH_API_NAME, 200);
        List<Node> nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
        assertEquals(0, nodes.size());
        String myFolderNodeId = getMyNodeId();
        f1Id = createFolder(myFolderNodeId, "king").getId();
        response = post(URL_SEARCH, json, null, null, SEARCH_API_NAME, 200);
        ExpectedPaging paging = RestApiUtil.parsePaging(response.getJsonResponse());
        assertEquals(1, paging.getTotalItems().intValue());
        assertFalse(paging.getHasMoreItems());
        nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
        assertEquals(1, nodes.size());
        // Just happy if it doesn't error
        response = post(URL_SEARCH, SerializerTestHelper.JSON, null, null, SEARCH_API_NAME, 200);
    } finally {
        // some cleanup
        if (f1Id != null) {
            deleteNode(f1Id, true, 204);
        }
    }
}
Also used : Node(org.alfresco.rest.api.tests.client.data.Node) FolderNode(org.alfresco.rest.api.tests.client.data.FolderNode) HttpResponse(org.alfresco.rest.api.tests.client.HttpResponse) ExpectedPaging(org.alfresco.rest.api.tests.client.PublicApiClient.ExpectedPaging) Test(org.junit.Test) AbstractSingleNetworkSiteTest(org.alfresco.rest.AbstractSingleNetworkSiteTest)

Example 88 with HttpResponse

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

the class AbstractBaseApiTest method addSiteMember.

protected SiteMember addSiteMember(String siteId, String userId, final SiteRole siteRole) throws Exception {
    SiteMember siteMember = new SiteMember(userId, siteRole.name());
    HttpResponse response = publicApiClient.post(getScope(), "sites", siteId, "members", null, siteMember.toJSON().toString());
    checkStatus(201, response.getStatusCode());
    return SiteMember.parseSiteMember(siteMember.getSiteId(), (JSONObject) response.getJsonResponse().get("entry"));
}
Also used : SiteMember(org.alfresco.rest.api.tests.client.data.SiteMember) HttpResponse(org.alfresco.rest.api.tests.client.HttpResponse)

Example 89 with HttpResponse

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

the class AbstractBaseApiTest method createNode.

protected <T> T createNode(String parentId, String nodeName, String nodeType, Map<String, Object> props, Class<T> returnType) throws Exception {
    Node n = new Node();
    n.setName(nodeName);
    n.setNodeType(nodeType);
    n.setProperties(props);
    // create node
    HttpResponse response = post(getNodeChildrenUrl(parentId), RestApiUtil.toJsonAsStringNonNull(n), 201);
    return RestApiUtil.parseRestApiEntry(response.getJsonResponse(), returnType);
}
Also used : Node(org.alfresco.rest.api.tests.client.data.Node) HttpResponse(org.alfresco.rest.api.tests.client.HttpResponse)

Example 90 with HttpResponse

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

the class AbstractBaseApiTest method createSite.

protected Site createSite(String siteId, String siteTitle, String siteDescription, SiteVisibility siteVisibility, int expectedStatus) throws Exception {
    Site site = new Site();
    site.setId(siteId);
    site.setTitle(siteTitle);
    site.setVisibility(siteVisibility);
    site.setDescription(siteDescription);
    HttpResponse response = publicApiClient.post(getScope(), "sites", null, null, null, toJsonAsStringNonNull(site));
    checkStatus(expectedStatus, response.getStatusCode());
    return RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Site.class);
}
Also used : Site(org.alfresco.rest.api.model.Site) HttpResponse(org.alfresco.rest.api.tests.client.HttpResponse)

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