Search in sources :

Example 56 with HttpResponse

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

the class RenditionsTest method testCreateRenditionForNewVersion.

/**
 * Tests create rendition after uploading new version(s)
 */
@Test
public void testCreateRenditionForNewVersion() throws Exception {
    String PROP_LTM = "cm:lastThumbnailModification";
    String RENDITION_NAME = "imgpreview";
    String userId = userOneN1.getId();
    setRequestContext(networkN1.getId(), userOneN1.getId(), null);
    // Create a folder within the site document's library
    String folderName = "folder" + System.currentTimeMillis();
    String folder_Id = addToDocumentLibrary(userOneN1Site, folderName, TYPE_CM_FOLDER, userId);
    // Create multipart request - pdf file
    String fileName = "quick.pdf";
    File file = getResourceFile(fileName);
    MultiPartRequest reqBody = MultiPartBuilder.create().setFileData(new FileData(fileName, file)).build();
    Map<String, String> params = Collections.singletonMap("include", "properties");
    // Upload quick.pdf file into 'folder' - do not include request to create 'doclib' thumbnail
    HttpResponse response = post(getNodeChildrenUrl(folder_Id), reqBody.getBody(), params, null, "alfresco", reqBody.getContentType(), 201);
    Document document1 = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class);
    String contentNodeId = document1.getId();
    assertNotNull(document1.getProperties());
    assertNull(document1.getProperties().get(PROP_LTM));
    // pause briefly
    Thread.sleep(DELAY_IN_MS);
    // Get rendition (not created yet) information for node
    response = getSingle(getNodeRenditionsUrl(contentNodeId), RENDITION_NAME, 200);
    Rendition rendition = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Rendition.class);
    assertNotNull(rendition);
    assertEquals(RenditionStatus.NOT_CREATED, rendition.getStatus());
    params = new HashMap<>();
    params.put("placeholder", "false");
    getSingle(getNodeRenditionsUrl(contentNodeId), (RENDITION_NAME + "/content"), params, 404);
    // TODO add test to request creation of rendition as another user (that has read-only access on the content, not write)
    // Create and get 'imgpreview' rendition
    rendition = createAndGetRendition(contentNodeId, RENDITION_NAME);
    assertNotNull(rendition);
    assertEquals(RenditionStatus.CREATED, rendition.getStatus());
    ContentInfo contentInfo = rendition.getContent();
    assertNotNull(contentInfo);
    assertEquals(MimetypeMap.MIMETYPE_IMAGE_JPEG, contentInfo.getMimeType());
    assertEquals("JPEG Image", contentInfo.getMimeTypeName());
    assertNotNull(contentInfo.getEncoding());
    assertTrue(contentInfo.getSizeInBytes() > 0);
    params = new HashMap<>();
    params.put("placeholder", "false");
    response = getSingle(getNodeRenditionsUrl(contentNodeId), (RENDITION_NAME + "/content"), params, 200);
    byte[] renditionBytes1 = response.getResponseAsBytes();
    assertNotNull(renditionBytes1);
    // check node details ...
    params = Collections.singletonMap("include", "properties");
    response = getSingle(NodesEntityResource.class, contentNodeId, params, 200);
    Document document1b = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class);
    assertEquals(document1b.getModifiedAt(), document1.getModifiedAt());
    assertEquals(document1b.getModifiedByUser().getId(), document1.getModifiedByUser().getId());
    assertEquals(document1b.getModifiedByUser().getDisplayName(), document1.getModifiedByUser().getDisplayName());
    assertNotEquals(document1b.getProperties().get(PROP_LTM), document1.getProperties().get(PROP_LTM));
    // upload another version of "quick.pdf" and check again
    fileName = "quick-2.pdf";
    file = getResourceFile(fileName);
    reqBody = MultiPartBuilder.create().setFileData(new FileData("quick.pdf", file)).setOverwrite(true).build();
    response = post(getNodeChildrenUrl(folder_Id), reqBody.getBody(), null, null, "alfresco", reqBody.getContentType(), 201);
    Document document2 = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class);
    assertEquals(contentNodeId, document2.getId());
    // wait to allow new version of the rendition to be created ...
    Thread.sleep(DELAY_IN_MS * 4);
    params = new HashMap<>();
    params.put("placeholder", "false");
    response = getSingle(getNodeRenditionsUrl(contentNodeId), (RENDITION_NAME + "/content"), params, 200);
    assertNotNull(response.getResponseAsBytes());
    // check rendition binary has changed
    assertNotEquals(renditionBytes1, response.getResponseAsBytes());
    // check node details ...
    params = Collections.singletonMap("include", "properties");
    response = getSingle(NodesEntityResource.class, contentNodeId, params, 200);
    Document document2b = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class);
    assertTrue(document2b.getModifiedAt().after(document1.getModifiedAt()));
    assertEquals(document2b.getModifiedByUser().getId(), document1.getModifiedByUser().getId());
    assertEquals(document2b.getModifiedByUser().getDisplayName(), document1.getModifiedByUser().getDisplayName());
    // check last thumbnail modification property has changed ! (REPO-1644)
    assertNotEquals(document2b.getProperties().get(PROP_LTM), document1b.getProperties().get(PROP_LTM));
}
Also used : ContentInfo(org.alfresco.rest.api.tests.client.data.ContentInfo) Rendition(org.alfresco.rest.api.tests.client.data.Rendition) HttpResponse(org.alfresco.rest.api.tests.client.HttpResponse) MultiPartRequest(org.alfresco.rest.api.tests.util.MultiPartBuilder.MultiPartRequest) RestApiUtil.toJsonAsString(org.alfresco.rest.api.tests.util.RestApiUtil.toJsonAsString) NodesEntityResource(org.alfresco.rest.api.nodes.NodesEntityResource) Document(org.alfresco.rest.api.tests.client.data.Document) File(java.io.File) FileData(org.alfresco.rest.api.tests.util.MultiPartBuilder.FileData) Test(org.junit.Test)

Example 57 with HttpResponse

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

the class RenditionsTest method testDownloadRendition.

/**
 * Tests download rendition.
 * <p>GET:</p>
 * {@literal <host>:<port>/alfresco/api/<networkId>/public/alfresco/versions/1/nodes/<nodeId>/renditions/<renditionId>/content}
 */
@Test
public void testDownloadRendition() throws Exception {
    setRequestContext(networkN1.getId(), userOneN1.getId(), null);
    // Create a folder within the site document's library
    String folderName = "folder" + System.currentTimeMillis();
    String folder_Id = addToDocumentLibrary(userOneN1Site, folderName, TYPE_CM_FOLDER, userOneN1.getId());
    // Create multipart request
    String fileName = "quick.pdf";
    File file = getResourceFile(fileName);
    MultiPartBuilder multiPartBuilder = MultiPartBuilder.create().setFileData(new FileData(fileName, file));
    MultiPartRequest reqBody = multiPartBuilder.build();
    // Upload quick.pdf file into 'folder'
    HttpResponse response = post(getNodeChildrenUrl(folder_Id), reqBody.getBody(), null, reqBody.getContentType(), 201);
    Document document = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class);
    String contentNodeId = document.getId();
    // pause briefly
    Thread.sleep(DELAY_IN_MS);
    // Get rendition (not created yet) information for node
    response = getSingle(getNodeRenditionsUrl(contentNodeId), "doclib", 200);
    Rendition rendition = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Rendition.class);
    assertNotNull(rendition);
    assertEquals(RenditionStatus.NOT_CREATED, rendition.getStatus());
    // Download placeholder - by default with Content-Disposition header
    Map<String, String> params = new HashMap<>();
    params.put("placeholder", "true");
    response = getSingle(getNodeRenditionsUrl(contentNodeId), ("doclib/content"), params, 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 placeholder - without Content-Disposition header (attachment=false)
    params.put("attachment", "false");
    response = getSingle(getNodeRenditionsUrl(contentNodeId), ("doclib/content"), params, 200);
    assertNotNull(response.getResponseAsBytes());
    responseHeaders = response.getHeaders();
    assertNotNull(responseHeaders);
    String cacheControl = responseHeaders.get("Cache-Control");
    assertNotNull(cacheControl);
    assertTrue(cacheControl.contains("must-revalidate"));
    assertNull(responseHeaders.get("Content-Disposition"));
    contentType = responseHeaders.get("Content-Type");
    assertNotNull(contentType);
    assertTrue(contentType.startsWith(MimetypeMap.MIMETYPE_IMAGE_PNG));
    // Test 304 response - placeholder=true&attachment=false
    String lastModifiedHeader = responseHeaders.get(LAST_MODIFIED_HEADER);
    assertNotNull(lastModifiedHeader);
    Map<String, String> headers = Collections.singletonMap(IF_MODIFIED_SINCE_HEADER, lastModifiedHeader);
    // Currently the placeholder file is not cached.
    // As the placeholder is not a NodeRef, so we can't get the ContentModel.PROP_MODIFIED date.
    getSingle(getNodeRenditionsUrl(contentNodeId), "doclib/content", params, headers, 200);
    // Create and get 'doclib' rendition
    rendition = createAndGetRendition(contentNodeId, "doclib");
    assertNotNull(rendition);
    assertEquals(RenditionStatus.CREATED, rendition.getStatus());
    // Download rendition - by default with Content-Disposition header
    response = getSingle(getNodeRenditionsUrl(contentNodeId), "doclib/content", 200);
    assertNotNull(response.getResponseAsBytes());
    responseHeaders = response.getHeaders();
    assertNotNull(responseHeaders);
    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));
    // Download rendition - without Content-Disposition header (attachment=false)
    params = Collections.singletonMap("attachment", "false");
    response = getSingle(getNodeRenditionsUrl(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(getNodeRenditionsUrl(contentNodeId), "doclib/content", params, 200);
    assertNotNull(response.getResponseAsBytes());
    responseHeaders = response.getHeaders();
    assertNotNull(responseHeaders);
    // Check the cache settings which have been set in the RenditionsImpl#getContent()
    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)
    lastModifiedHeader = responseHeaders.get(LAST_MODIFIED_HEADER);
    assertNotNull(lastModifiedHeader);
    headers = Collections.singletonMap(IF_MODIFIED_SINCE_HEADER, lastModifiedHeader);
    getSingle(getNodeRenditionsUrl(contentNodeId), "doclib/content", params, headers, 304);
    // Here we want to overwrite/update the existing content in order to force a new rendition creation,
    // so the ContentModel.PROP_MODIFIED date would be different. Hence, we use the multipart upload by providing
    // the old fileName and setting overwrite field to true
    file = getResourceFile("quick-2.pdf");
    multiPartBuilder = MultiPartBuilder.create().setFileData(new FileData(fileName, file)).setOverwrite(true);
    reqBody = multiPartBuilder.build();
    // Update quick.pdf
    post(getNodeChildrenUrl(folder_Id), reqBody.getBody(), null, reqBody.getContentType(), 201);
    // The requested "If-Modified-Since" date is older than rendition modified date
    response = getSingleWithDelayRetry(getNodeRenditionsUrl(contentNodeId), "doclib/content", params, headers, MAX_RETRY, PAUSE_TIME, 200);
    assertNotNull(response);
    responseHeaders = response.getHeaders();
    assertNotNull(responseHeaders);
    String newLastModifiedHeader = responseHeaders.get(LAST_MODIFIED_HEADER);
    assertNotNull(newLastModifiedHeader);
    assertNotEquals(lastModifiedHeader, newLastModifiedHeader);
    // -ve tests
    // nodeId in the path parameter does not represent a file
    getSingle(getNodeRenditionsUrl(folder_Id), "doclib/content", 400);
    // nodeId in the path parameter does not exist
    getSingle(getNodeRenditionsUrl(UUID.randomUUID().toString()), "doclib/content", 404);
    // renditionId in the path parameter is not registered/available
    getSingle(getNodeRenditionsUrl(contentNodeId), ("renditionId" + System.currentTimeMillis() + "/content"), 404);
    InputStream inputStream = new ByteArrayInputStream("The quick brown fox jumps over the lazy dog".getBytes());
    file = TempFileProvider.createTempFile(inputStream, "RenditionsTest-", ".abcdef");
    reqBody = MultiPartBuilder.create().setFileData(new FileData(file.getName(), file)).build();
    // Upload temp file into 'folder'
    response = post(getNodeChildrenUrl(folder_Id), reqBody.getBody(), null, reqBody.getContentType(), 201);
    document = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class);
    contentNodeId = document.getId();
    // The content of the rendition does not exist and the placeholder parameter is not present
    getSingle(getNodeRenditionsUrl(contentNodeId), "doclib/content", 404);
    // The content of the rendition does not exist and the placeholder parameter has a value of "false"
    params = Collections.singletonMap("placeholder", "false");
    getSingle(getNodeRenditionsUrl(contentNodeId), "doclib/content", params, 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(getNodeRenditionsUrl(contentNodeId), ("renditionId" + System.currentTimeMillis() + "/content"), params, 404);
    // Create a node without any content
    String emptyContentNodeId = addToDocumentLibrary(userOneN1Site, "emptyDoc.txt", TYPE_CM_CONTENT, userOneN1.getId());
    getSingle(getNodeRenditionsUrl(emptyContentNodeId), "doclib/content", params, 200);
}
Also used : MultiPartBuilder(org.alfresco.rest.api.tests.util.MultiPartBuilder) HashMap(java.util.HashMap) ByteArrayInputStream(java.io.ByteArrayInputStream) Rendition(org.alfresco.rest.api.tests.client.data.Rendition) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) HttpResponse(org.alfresco.rest.api.tests.client.HttpResponse) MultiPartRequest(org.alfresco.rest.api.tests.util.MultiPartBuilder.MultiPartRequest) RestApiUtil.toJsonAsString(org.alfresco.rest.api.tests.util.RestApiUtil.toJsonAsString) Document(org.alfresco.rest.api.tests.client.data.Document) File(java.io.File) FileData(org.alfresco.rest.api.tests.util.MultiPartBuilder.FileData) Test(org.junit.Test)

Example 58 with HttpResponse

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

the class TestPeople method updateAvatar.

@Test
public void updateAvatar() throws PublicApiException, IOException {
    final String person1 = account1PersonIt.next();
    final String person2 = account1PersonIt.next();
    publicApiClient.setRequestContext(new RequestContext(account1.getId(), person2));
    AuthenticationUtil.setFullyAuthenticatedUser(person2);
    // Update allowed when no existing avatar
    {
        // Pre-condition: no avatar exists
        NodeRef personRef = personService.getPerson(person2, false);
        deleteAvatarDirect(personRef);
        people.getAvatar(person2, false, 404);
        // TODO: What do we expect the 200 response body to be? Currently it's the person JSON - doesn't seem right.
        ClassPathResource avatar = new ClassPathResource("publicapi/upload/quick.jpg");
        HttpResponse response = people.updateAvatar(person2, avatar.getFile(), 200);
        // TODO: ideally, this should be a "direct" retrieval to isolate update from get
        people.getAvatar(person2, false, 200);
    }
    // Update existing avatar
    {
        // Pre-condition: avatar exists
        people.getAvatar(person2, false, 200);
        ClassPathResource avatar = new ClassPathResource("test.jpg");
        HttpResponse response = people.updateAvatar(person2, avatar.getFile(), 200);
        people.getAvatar(person2, false, 200);
        // -me- alias
        people.updateAvatar(person2, avatar.getFile(), 200);
        people.getAvatar("-me-", false, 200);
    }
    // 400: invalid user ID
    {
        ClassPathResource avatar = new ClassPathResource("publicapi/upload/quick.jpg");
        people.updateAvatar("joe@@bloggs.example.com", avatar.getFile(), 404);
    }
    // 401: authentication failure
    {
        publicApiClient.setRequestContext(new RequestContext(account1.getId(), account1Admin, "Wr0ngP4ssw0rd!"));
        ClassPathResource avatar = new ClassPathResource("publicapi/upload/quick.jpg");
        people.updateAvatar(account1Admin, avatar.getFile(), 401);
    }
    // 403: permission denied
    {
        publicApiClient.setRequestContext(new RequestContext(account1.getId(), person1));
        ClassPathResource avatar = new ClassPathResource("publicapi/upload/quick.jpg");
        people.updateAvatar(person2, avatar.getFile(), 403);
        // Person can update themself
        people.updateAvatar(person1, avatar.getFile(), 200);
        // Admin can update someone else
        publicApiClient.setRequestContext(new RequestContext(account1.getId(), account1Admin, "admin"));
        people.updateAvatar(person1, avatar.getFile(), 200);
    }
    // 404: non-existent person
    {
        publicApiClient.setRequestContext(new RequestContext(account1.getId(), person1));
        // Pre-condition: non-existent person
        String nonPerson = "joebloggs@" + account1.getId();
        people.getPerson(nonPerson, 404);
        ClassPathResource avatar = new ClassPathResource("publicapi/upload/quick.jpg");
        people.updateAvatar(nonPerson, avatar.getFile(), 404);
    }
    // 413: content exceeds individual file size limit
    {
        // Test content size limit
        final ContentLimitProvider.SimpleFixedLimitProvider limitProvider = applicationContext.getBean("defaultContentLimitProvider", ContentLimitProvider.SimpleFixedLimitProvider.class);
        final long defaultSizeLimit = limitProvider.getSizeLimit();
        // 20 KB
        limitProvider.setSizeLimitString("20000");
        try {
            // ~26K
            ClassPathResource avatar = new ClassPathResource("publicapi/upload/quick.jpg");
            people.updateAvatar(person1, avatar.getFile(), 413);
        } finally {
            limitProvider.setSizeLimitString(Long.toString(defaultSizeLimit));
        }
    }
    // 501: thumbnails disabled
    {
        ThumbnailService thumbnailService = applicationContext.getBean("thumbnailService", ThumbnailService.class);
        // Disable thumbnail generation
        thumbnailService.setThumbnailsEnabled(false);
        try {
            ClassPathResource avatar = new ClassPathResource("publicapi/upload/quick.jpg");
            people.updateAvatar(person1, avatar.getFile(), 501);
        } finally {
            thumbnailService.setThumbnailsEnabled(true);
        }
    }
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) ThumbnailService(org.alfresco.service.cmr.thumbnail.ThumbnailService) HttpResponse(org.alfresco.rest.api.tests.client.HttpResponse) RequestContext(org.alfresco.rest.api.tests.client.RequestContext) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.Test)

Example 59 with HttpResponse

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

the class TestPeople method listPeople.

private PublicApiClient.ListResponse<Person> listPeople(Map<String, String> parameters, int expectedStatusCode) throws PublicApiException {
    HttpResponse response = people.getAll("people", null, null, null, parameters, "Failed to get people", expectedStatusCode);
    JSONObject jsonList = (JSONObject) response.getJsonResponse().get("list");
    if (jsonList == null) {
        return null;
    }
    return Person.parsePeople(response.getJsonResponse());
}
Also used : JSONObject(org.json.simple.JSONObject) HttpResponse(org.alfresco.rest.api.tests.client.HttpResponse)

Example 60 with HttpResponse

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

the class TestPeople method retrieveAvatar.

@Test
public void retrieveAvatar() throws Exception {
    final String person1 = account1PersonIt.next();
    publicApiClient.setRequestContext(new RequestContext(account1.getId(), person1));
    AuthenticationUtil.setFullyAuthenticatedUser(person1);
    NodeRef person1Ref = personService.getPerson(person1, false);
    // No avatar, but valid person
    {
        deleteAvatarDirect(person1Ref);
        // Pre-condition of test case
        assertNotNull(people.getPerson(person1));
        people.getAvatar(person1, false, 404);
    }
    // No avatar, but person exists and placeholder requested
    {
        // Pre-condition of test case
        assertNotNull(people.getPerson(person1));
        people.getAvatar(person1, true, 200);
    }
    // Non-existent person
    {
        String nonPerson = "i-do-not-exist";
        // Pre-condition of test case
        people.getPerson(nonPerson, 404);
        people.getAvatar(nonPerson, false, 404);
    }
    // Placeholder requested, but non-existent person
    {
        String nonPerson = "i-do-not-exist";
        // Pre-condition of test case
        people.getPerson(nonPerson, 404);
        people.getAvatar(nonPerson, true, 404);
    }
    // Avatar exists
    {
        // Create avatar - direct (i.e. not using the API, so that tests for get avatar can be separated from upload)
        // There's no significance to the image being used here, it was the most suitable I could find.
        ClassPathResource thumbRes = new ClassPathResource("test.jpg");
        deleteAvatarDirect(person1Ref);
        createAvatarDirect(person1Ref, thumbRes.getFile());
        // Get avatar - API call
        people.getAvatar(person1, false, 200);
    }
    // -me- alias
    {
        people.getAvatar("-me-", false, 200);
    }
    // If-Modified-Since behaviour
    {
        HttpResponse response = people.getAvatar(person1, false, 200);
        Map<String, String> responseHeaders = response.getHeaders();
        // Test 304 response
        String lastModified = responseHeaders.get(LAST_MODIFIED_HEADER);
        assertNotNull(lastModified);
        // Has it been modified since the time it was last modified - no!
        people.getAvatar(person1, lastModified, 304);
        // Create an updated avatar
        // ensure time has passed between updates
        waitMillis(2000);
        ClassPathResource thumbRes = new ClassPathResource("publicapi/upload/quick.jpg");
        deleteAvatarDirect(person1Ref);
        createAvatarDirect(person1Ref, thumbRes.getFile());
        people.getAvatar(person1, lastModified, 200);
    }
    // Attachment param
    {
        // No attachment parameter (default true)
        Boolean attachmentParam = null;
        HttpResponse response = people.getAvatar(person1, attachmentParam, false, null, 200);
        Map<String, String> responseHeaders = response.getHeaders();
        String contentDisposition = responseHeaders.get("Content-Disposition");
        assertNotNull(contentDisposition);
        assertTrue(contentDisposition.startsWith("attachment;"));
        // attachment=true
        attachmentParam = true;
        response = people.getAvatar(person1, attachmentParam, false, null, 200);
        responseHeaders = response.getHeaders();
        contentDisposition = responseHeaders.get("Content-Disposition");
        assertNotNull(contentDisposition);
        assertTrue(contentDisposition.startsWith("attachment;"));
        // attachment=false
        attachmentParam = false;
        response = people.getAvatar(person1, attachmentParam, false, null, 200);
        responseHeaders = response.getHeaders();
        contentDisposition = responseHeaders.get("Content-Disposition");
        assertNull(contentDisposition);
    }
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) HttpResponse(org.alfresco.rest.api.tests.client.HttpResponse) RequestContext(org.alfresco.rest.api.tests.client.RequestContext) Map(java.util.Map) HashMap(java.util.HashMap) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.Test)

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