Search in sources :

Example 1 with SpoofedTextContentReader

use of org.alfresco.repo.content.filestore.SpoofedTextContentReader in project alfresco-remote-api by Alfresco.

the class RemoteFileFolderLoaderTest method testLoad_15_16bytes.

/**
 * Load 15 files; 1K size; 1 document sample; force binary storage
 */
@SuppressWarnings("unchecked")
public void testLoad_15_16bytes() throws Exception {
    JSONObject body = new JSONObject();
    body.put(FileFolderLoaderPost.KEY_FOLDER_PATH, loadHomePath);
    body.put(FileFolderLoaderPost.KEY_MIN_FILE_SIZE, 16L);
    body.put(FileFolderLoaderPost.KEY_MAX_FILE_SIZE, 16L);
    body.put(FileFolderLoaderPost.KEY_MAX_UNIQUE_DOCUMENTS, 1L);
    body.put(FileFolderLoaderPost.KEY_FORCE_BINARY_STORAGE, Boolean.TRUE);
    Response response = null;
    try {
        AuthenticationUtil.pushAuthentication();
        AuthenticationUtil.setFullyAuthenticatedUser("maggi");
        response = sendRequest(new PostRequest(URL, body.toString(), "application/json"), Status.STATUS_OK, "maggi");
    } finally {
        AuthenticationUtil.popAuthentication();
    }
    assertEquals("{\"count\":100}", response.getContentAsString());
    // Check file(s)
    assertEquals(100, nodeService.countChildAssocs(loadHomeNodeRef, true));
    // Consistent binary text
    String contentUrlCheck = SpoofedTextContentReader.createContentUrl(Locale.ENGLISH, 0L, 16L);
    ContentReader readerCheck = new SpoofedTextContentReader(contentUrlCheck);
    String textCheck = readerCheck.getContentString();
    // Size should be default
    List<FileInfo> fileInfos = fileFolderService.list(loadHomeNodeRef);
    for (FileInfo fileInfo : fileInfos) {
        NodeRef fileNodeRef = fileInfo.getNodeRef();
        ContentReader reader = fileFolderService.getReader(fileNodeRef);
        // Expect storage in store
        assertTrue(reader.getContentUrl().startsWith(FileContentStore.STORE_PROTOCOL));
        // Check text
        String text = reader.getContentString();
        assertEquals("Text not the same.", textCheck, text);
    }
}
Also used : Response(org.springframework.extensions.webscripts.TestWebScriptServer.Response) NodeRef(org.alfresco.service.cmr.repository.NodeRef) PostRequest(org.springframework.extensions.webscripts.TestWebScriptServer.PostRequest) JSONObject(org.json.simple.JSONObject) FileInfo(org.alfresco.service.cmr.model.FileInfo) SpoofedTextContentReader(org.alfresco.repo.content.filestore.SpoofedTextContentReader) SpoofedTextContentReader(org.alfresco.repo.content.filestore.SpoofedTextContentReader) ContentReader(org.alfresco.service.cmr.repository.ContentReader)

Aggregations

SpoofedTextContentReader (org.alfresco.repo.content.filestore.SpoofedTextContentReader)1 FileInfo (org.alfresco.service.cmr.model.FileInfo)1 ContentReader (org.alfresco.service.cmr.repository.ContentReader)1 NodeRef (org.alfresco.service.cmr.repository.NodeRef)1 JSONObject (org.json.simple.JSONObject)1 PostRequest (org.springframework.extensions.webscripts.TestWebScriptServer.PostRequest)1 Response (org.springframework.extensions.webscripts.TestWebScriptServer.Response)1