diff --git a/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeApiTest.java b/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeApiTest.java index 460af23ab4..33c583bb8f 100644 --- a/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeApiTest.java +++ b/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeApiTest.java @@ -141,6 +141,8 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest private String groupA = null; private String groupB = null; + private final static long DELAY_IN_MS = 500; + @Before public void setup() throws Exception { @@ -6367,5 +6369,112 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest getSingle(getRequestContentDirectUrl(contentNodeId), null, null, null, 405); } + + + @Test + public void testCreateRenditionForNewVersion() throws Exception + { + setRequestContext(user1); + + RepoService.TestNetwork networkN1; + RepoService.TestPerson userOneN1; + Site userOneN1Site; + + networkN1 = repoService.createNetworkWithAlias("ping", true); + networkN1.create(); + userOneN1 = networkN1.createUser(); + + setRequestContext(networkN1.getId(), userOneN1.getId(), null); + + String siteTitle = "RandomSite" + System.currentTimeMillis(); + userOneN1Site = createSite(siteTitle, SiteVisibility.PRIVATE); + + 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 parentId = getSiteContainerNodeId(userOneN1Site.getId(), "documentLibrary"); + String folder_Id = createNode(parentId, folderName, TYPE_CM_FOLDER, null).getId(); + + // Create multipart request - pdf file + String fileName = "quick.pdf"; + File file = getResourceFile(fileName); + MultiPartRequest reqBody = MultiPartBuilder.create() + .setFileData(new FileData(fileName, file)) + .build(); + Map 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()); + + // 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(Rendition.RenditionStatus.NOT_CREATED, rendition.getStatus()); + + params = new HashMap<>(); + params.put("placeholder", "false"); + getSingle(getNodeRenditionsUrl(contentNodeId), (RENDITION_NAME+"/content"), params, 404); + + // Create and get 'imgpreview' rendition + rendition = createAndGetRendition(contentNodeId, RENDITION_NAME); + assertNotNull(rendition); + + 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.getModifiedByUser().getId(), document1.getModifiedByUser().getId()); + + // 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()); + + params = Collections.singletonMap("include", "properties"); + response = getSingle(NodesEntityResource.class, contentNodeId, params, 200); + Document document2b = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class); + + String contentNodeId2b = document2b.getId(); + getSingle(getRequestContentDirectUrl(contentNodeId2b), null, null, null, 405); + + } }