Search in sources :

Example 96 with Document

use of org.apache.chemistry.opencmis.client.api.Document in project copper-cms by PogeyanOSS.

the class NameCharsetTest method run.

@Override
public void run(Session session) {
    CmisTestResult f;
    // create a test folder
    Folder testFolder = createTestFolder(session);
    try {
        for (int i = 0; i < NAMES.length; i++) {
            Document doc = null;
            Document doc2 = null;
            try {
                doc = null;
                doc = createDocument(session, testFolder, NAMES[i], NAMES[i]);
                // get the newly created object by path
                String path = doc.getPaths().get(0);
                doc2 = (Document) session.getObjectByPath(path, SELECT_ALL_NO_CACHE_OC);
                addResult(checkObject(session, doc2, getAllProperties(doc2), "New document object spec compliance"));
                f = createResult(FAILURE, "Names of the created and the fetched document don't match!");
                assertEquals(NAMES[i], doc2.getName(), null, f);
                ContentStream contentStream = doc.getContentStream();
                f = createResult(FAILURE, "Document has no content!");
                assertNotNull(contentStream, null, f);
                IOUtils.consumeAndClose(contentStream.getStream());
            } catch (Exception e) {
                addResult(createResult(WARNING, "The name '" + NAMES[i] + "' raised this exception: " + e, e, false));
            } finally {
                if (doc != null) {
                    // delete it
                    try {
                        doc.delete(true);
                    } catch (Exception e) {
                    // ignore
                    }
                }
            }
        }
        addResult(createInfoResult("Tested " + NAMES.length + " different names."));
    } finally {
        // delete the test folder
        deleteTestFolder();
    }
}
Also used : ContentStream(org.apache.chemistry.opencmis.commons.data.ContentStream) CmisTestResult(org.apache.chemistry.opencmis.tck.CmisTestResult) Folder(org.apache.chemistry.opencmis.client.api.Folder) Document(org.apache.chemistry.opencmis.client.api.Document)

Example 97 with Document

use of org.apache.chemistry.opencmis.client.api.Document in project copper-cms by PogeyanOSS.

the class PropertyFilterTest method run.

@Override
public void run(Session session) {
    CmisTestResult f;
    // filter with MIME type
    OperationContext testContext1 = OperationContextUtils.createMinimumOperationContext();
    Set<String> testfilter1 = new HashSet<String>(testContext1.getFilter());
    testfilter1.add(PropertyIds.CONTENT_STREAM_MIME_TYPE);
    testContext1.setFilter(testfilter1);
    // filter with path
    OperationContext testContext2 = OperationContextUtils.createMinimumOperationContext();
    Set<String> testfilter2 = new HashSet<String>(testContext2.getFilter());
    testfilter2.add(PropertyIds.PATH);
    testContext2.setFilter(testfilter2);
    // filter with invalid property
    OperationContext testContext3 = OperationContextUtils.createMinimumOperationContext();
    Set<String> testfilter3 = new HashSet<String>(testContext3.getFilter());
    testfilter3.add(INVALID_PROPERTY);
    testContext3.setFilter(testfilter3);
    // create a test folder
    Folder testFolder = createTestFolder(session);
    try {
        Document doc = createDocument(session, testFolder, "doc", CONTENT);
        Document doc1 = (Document) session.getObject(doc, testContext1);
        // check document
        f = createResult(FAILURE, "Document should have the property " + PropertyIds.CONTENT_STREAM_MIME_TYPE + "!");
        addResult(assertNotNull(doc1.getProperty(PropertyIds.CONTENT_STREAM_MIME_TYPE), null, f));
        f = createResult(FAILURE, "Document should not have the property " + PropertyIds.PATH + "!");
        addResult(assertNull(doc1.getProperty(PropertyIds.PATH), null, f));
        f = createResult(FAILURE, "Document should not have the property " + INVALID_PROPERTY + "!");
        addResult(assertNull(doc1.getProperty(INVALID_PROPERTY), null, f));
        Document doc2 = (Document) session.getObject(doc, testContext2);
        f = createResult(WARNING, "Document should not have the property " + PropertyIds.CONTENT_STREAM_MIME_TYPE + "!");
        addResult(assertNull(doc2.getProperty(PropertyIds.CONTENT_STREAM_MIME_TYPE), null, f));
        // f = createResult(FAILURE, "Document should not have the property " + PropertyIds.PATH + "!");
        // addResult(assertNull(doc2.getProperty(PropertyIds.PATH), null, f));
        f = createResult(FAILURE, "Document should not have the property " + INVALID_PROPERTY + "!");
        addResult(assertNull(doc2.getProperty(INVALID_PROPERTY), null, f));
        Document doc3 = (Document) session.getObject(doc, testContext3);
        f = createResult(WARNING, "Document should not have the property" + PropertyIds.CONTENT_STREAM_MIME_TYPE + "!");
        addResult(assertNull(doc3.getProperty(PropertyIds.CONTENT_STREAM_MIME_TYPE), null, f));
        f = createResult(FAILURE, "Document should not have the property" + PropertyIds.PATH + "!");
        addResult(assertNull(doc3.getProperty(PropertyIds.PATH), null, f));
        f = createResult(FAILURE, "Document should not have the property" + INVALID_PROPERTY + "!");
        addResult(assertNull(doc3.getProperty(INVALID_PROPERTY), null, f));
        // check folder
        Folder folder1 = (Folder) session.getObject(testFolder, testContext1);
        f = createResult(FAILURE, "Folder should not have the property " + PropertyIds.CONTENT_STREAM_MIME_TYPE + "!");
        addResult(assertNull(folder1.getProperty(PropertyIds.CONTENT_STREAM_MIME_TYPE), null, f));
        f = createResult(WARNING, "Folder should not have the property " + PropertyIds.PATH + "!");
        addResult(assertNull(folder1.getProperty(PropertyIds.PATH), null, f));
        f = createResult(FAILURE, "Folder should not have the property " + INVALID_PROPERTY + "!");
        addResult(assertNull(folder1.getProperty(INVALID_PROPERTY), null, f));
        Folder folder2 = (Folder) session.getObject(testFolder, testContext2);
        f = createResult(FAILURE, "Folder should not have the property " + PropertyIds.CONTENT_STREAM_MIME_TYPE + "!");
        addResult(assertNull(folder2.getProperty(PropertyIds.CONTENT_STREAM_MIME_TYPE), null, f));
        f = createResult(FAILURE, "Folder should have the property " + PropertyIds.PATH + "!");
        addResult(assertNotNull(folder2.getProperty(PropertyIds.PATH), null, f));
        f = createResult(FAILURE, "Folder should not have the property " + INVALID_PROPERTY + "!");
        addResult(assertNull(folder2.getProperty(INVALID_PROPERTY), null, f));
        Folder folder3 = (Folder) session.getObject(testFolder, testContext3);
        f = createResult(FAILURE, "Folder should not have the property " + PropertyIds.CONTENT_STREAM_MIME_TYPE + "!");
        addResult(assertNull(folder3.getProperty(PropertyIds.CONTENT_STREAM_MIME_TYPE), null, f));
        f = createResult(WARNING, "Folder should not have the property " + PropertyIds.PATH + "!");
        addResult(assertNull(folder3.getProperty(PropertyIds.PATH), null, f));
        f = createResult(FAILURE, "Folder should not have the property " + INVALID_PROPERTY + "!");
        addResult(assertNull(folder3.getProperty(INVALID_PROPERTY), null, f));
        // check children
        CmisObject obj1 = testFolder.getChildren(testContext1).iterator().next();
        f = createResult(WARNING, "Child should have the property " + PropertyIds.CONTENT_STREAM_MIME_TYPE + "!");
        addResult(assertNotNull(obj1.getProperty(PropertyIds.CONTENT_STREAM_MIME_TYPE), null, f));
        f = createResult(WARNING, "Child should not have the property " + PropertyIds.PATH + "!");
        addResult(assertNull(obj1.getProperty(PropertyIds.PATH), null, f));
        f = createResult(FAILURE, "Child should not have the property " + INVALID_PROPERTY + "!");
        addResult(assertNull(obj1.getProperty(INVALID_PROPERTY), null, f));
        CmisObject obj2 = testFolder.getChildren(testContext2).iterator().next();
        f = createResult(WARNING, "Child should not have the property " + PropertyIds.CONTENT_STREAM_MIME_TYPE + "!");
        addResult(assertNull(obj2.getProperty(PropertyIds.CONTENT_STREAM_MIME_TYPE), null, f));
        f = createResult(WARNING, "Child should not have the property " + PropertyIds.PATH + "!");
        addResult(assertNull(obj2.getProperty(PropertyIds.PATH), null, f));
        f = createResult(FAILURE, "Child should not have the property " + INVALID_PROPERTY + "!");
        addResult(assertNull(obj2.getProperty(INVALID_PROPERTY), null, f));
        CmisObject obj3 = testFolder.getChildren(testContext3).iterator().next();
        f = createResult(WARNING, "Child should not have the property" + PropertyIds.CONTENT_STREAM_MIME_TYPE + "!");
        addResult(assertNull(obj3.getProperty(PropertyIds.CONTENT_STREAM_MIME_TYPE), null, f));
        f = createResult(WARNING, "Child should not have the property" + PropertyIds.PATH + "!");
        addResult(assertNull(obj3.getProperty(PropertyIds.PATH), null, f));
        f = createResult(FAILURE, "Child should not have the property" + INVALID_PROPERTY + "!");
        addResult(assertNull(obj3.getProperty(INVALID_PROPERTY), null, f));
    } finally {
        // delete the test folder
        deleteTestFolder();
    }
}
Also used : OperationContext(org.apache.chemistry.opencmis.client.api.OperationContext) CmisTestResult(org.apache.chemistry.opencmis.tck.CmisTestResult) CmisObject(org.apache.chemistry.opencmis.client.api.CmisObject) Folder(org.apache.chemistry.opencmis.client.api.Folder) Document(org.apache.chemistry.opencmis.client.api.Document) HashSet(java.util.HashSet)

Example 98 with Document

use of org.apache.chemistry.opencmis.client.api.Document in project copper-cms by PogeyanOSS.

the class UpdateSmokeTest method updateDocument.

private void updateDocument(Session session, Folder testFolder) {
    CmisTestResult f;
    // create document
    Document doc1 = createDocument(session, testFolder, DOC_NAME1, "rename me!");
    Document workDoc = doc1;
    f = createResult(FAILURE, "Document name doesn't match the given name!");
    addResult(assertEquals(DOC_NAME1, doc1.getName(), null, f));
    // test if check out is required
    boolean checkedout = false;
    DocumentTypeDefinition type = (DocumentTypeDefinition) doc1.getType();
    PropertyDefinition<?> namePropDef = type.getPropertyDefinitions().get(PropertyIds.NAME);
    if (namePropDef.getUpdatability() == Updatability.WHENCHECKEDOUT || (!doc1.getAllowableActions().getAllowableActions().contains(Action.CAN_UPDATE_PROPERTIES) && Boolean.TRUE.equals(type.isVersionable()))) {
        workDoc = (Document) session.getObject(doc1.checkOut(), SELECT_ALL_NO_CACHE_OC);
        checkedout = true;
    }
    // update
    Map<String, Object> properties = new HashMap<String, Object>();
    properties.put(PropertyIds.NAME, DOC_NAME2);
    ObjectId newId = workDoc.updateProperties(properties, false);
    Document doc2 = (Document) session.getObject(newId, SELECT_ALL_NO_CACHE_OC);
    addResult(checkObject(session, doc2, getAllProperties(doc2), "Updated document compliance"));
    f = createResult(FAILURE, "Document name doesn't match updated value!");
    addResult(assertEquals(DOC_NAME2, doc2.getName(), null, f));
    // delete
    if (!workDoc.getId().equals(doc2.getId())) {
        deleteObject(doc2);
    }
    // cancel a possible check out
    if (checkedout) {
        workDoc.cancelCheckOut();
    }
    if (!doc1.getId().equals(doc2.getId())) {
        if (exists(doc1)) {
            deleteObject(doc1);
        }
    }
}
Also used : DocumentTypeDefinition(org.apache.chemistry.opencmis.commons.definitions.DocumentTypeDefinition) HashMap(java.util.HashMap) ObjectId(org.apache.chemistry.opencmis.client.api.ObjectId) CmisTestResult(org.apache.chemistry.opencmis.tck.CmisTestResult) Document(org.apache.chemistry.opencmis.client.api.Document)

Example 99 with Document

use of org.apache.chemistry.opencmis.client.api.Document in project copper-cms by PogeyanOSS.

the class AsyncCreateAndDeleteDocumentTest method run.

@Override
public void run(Session session) {
    CmisTestResult f;
    int numOfDocuments = 100;
    String mimeType = "text/plain";
    byte[] contentBytes = new byte[64 * 1024];
    for (int i = 0; i < contentBytes.length; i++) {
        contentBytes[i] = (byte) ('0' + i % 10);
    }
    // create an async session
    AsyncSession asyncSession = AsyncSessionFactoryImpl.newInstance().createAsyncSession(session, 10);
    // create a test folder
    Folder testFolder = createTestFolder(session);
    try {
        // create documents
        List<Future<ObjectId>> docFutures = new ArrayList<Future<ObjectId>>();
        for (int i = 0; i < numOfDocuments; i++) {
            String name = "asyncdoc" + i + ".txt";
            Map<String, Object> properties = new HashMap<String, Object>();
            properties.put(PropertyIds.NAME, name);
            properties.put(PropertyIds.OBJECT_TYPE_ID, getDocumentTestTypeId());
            ContentStream contentStream = new ContentStreamImpl(name, BigInteger.valueOf(contentBytes.length), mimeType, new ByteArrayInputStream(contentBytes));
            Future<ObjectId> newDocument = asyncSession.createDocument(properties, testFolder, contentStream, null);
            docFutures.add(newDocument);
        }
        // wait for all document being created
        List<ObjectId> docIds = new ArrayList<ObjectId>();
        try {
            for (Future<ObjectId> docFuture : docFutures) {
                ObjectId id = docFuture.get();
                docIds.add(id);
            }
        } catch (Exception e) {
            addResult(createResult(UNEXPECTED_EXCEPTION, "Documents could not been created! Exception: " + e.getMessage(), e, true));
        }
        // check children of the test folder
        int count = countChildren(testFolder);
        f = createResult(FAILURE, "Test folder should have " + numOfDocuments + " children but has " + count + "!");
        addResult(assertEquals(count, numOfDocuments, null, f));
        // simple children test
        addResult(checkChildren(session, testFolder, "Test folder children check"));
        // get documents
        Map<String, Future<CmisObject>> getObjectFutures = new HashMap<String, Future<CmisObject>>();
        Map<String, Future<ContentStream>> contentStreamFutures = new HashMap<String, Future<ContentStream>>();
        Map<String, ByteArrayOutputStream> content = new HashMap<String, ByteArrayOutputStream>();
        for (ObjectId docId : docIds) {
            Future<CmisObject> getObjectFuture = asyncSession.getObject(docId, SELECT_ALL_NO_CACHE_OC);
            getObjectFutures.put(docId.getId(), getObjectFuture);
            ByteArrayOutputStream out = new ByteArrayOutputStream(contentBytes.length);
            content.put(docId.getId(), out);
            Future<ContentStream> contentStreamFuture = asyncSession.storeContentStream(docId, out);
            contentStreamFutures.put(docId.getId(), contentStreamFuture);
        }
        // wait for all document being fetched
        try {
            for (Map.Entry<String, Future<CmisObject>> getObjectFuture : getObjectFutures.entrySet()) {
                CmisObject object = getObjectFuture.getValue().get();
                f = createResult(FAILURE, "Fetching document failed!");
                addResult(assertIsTrue(object instanceof Document, null, f));
                if (object != null) {
                    f = createResult(FAILURE, "Fetched wrong document!");
                    addResult(assertEquals(getObjectFuture.getKey(), object.getId(), null, f));
                }
            }
        } catch (Exception e) {
            addResult(createResult(UNEXPECTED_EXCEPTION, "Documents could not been fetched! Exception: " + e.getMessage(), e, true));
        }
        // wait for all document content being fetched
        try {
            for (Map.Entry<String, Future<ContentStream>> contentStreamFuture : contentStreamFutures.entrySet()) {
                ContentStream contentStream = contentStreamFuture.getValue().get();
                f = createResult(FAILURE, "Fetching document content failed!");
                addResult(assertNotNull(contentStream, null, f));
                if (contentStream != null) {
                    if (contentStream.getMimeType() == null) {
                        addResult(createResult(FAILURE, "Content MIME type is null!"));
                    } else {
                        f = createResult(WARNING, "Content MIME types don't match!");
                        addResult(assertIsTrue(contentStream.getMimeType().trim().toLowerCase(Locale.ENGLISH).startsWith(mimeType.toLowerCase(Locale.ENGLISH)), null, f));
                    }
                }
                ByteArrayOutputStream out = content.get(contentStreamFuture.getKey());
                byte[] readBytes = out.toByteArray();
                f = createResult(FAILURE, "Read content length doesn't match document content length!");
                addResult(assertEquals(contentBytes.length, readBytes.length, null, f));
                f = createResult(FAILURE, "Read content doesn't match document content!");
                addResult(assertEqualArray(contentBytes, readBytes, null, f));
            }
        } catch (Exception e) {
            addResult(createResult(UNEXPECTED_EXCEPTION, "Document content could not been fetched! Exception: " + e.getMessage(), e, true));
        }
        // delete documents
        List<Future<?>> delFutures = new ArrayList<Future<?>>();
        for (ObjectId docId : docIds) {
            Future<?> delFuture = asyncSession.delete(docId);
            delFutures.add(delFuture);
        }
        // wait for all document being deleted
        try {
            for (Future<?> delFuture : delFutures) {
                delFuture.get();
            }
        } catch (Exception e) {
            addResult(createResult(UNEXPECTED_EXCEPTION, "Documents could not been deleted! Exception: " + e.getMessage(), e, true));
        }
        // check children of the test folder
        count = countChildren(testFolder);
        f = createResult(FAILURE, "Test folder should be empty but has " + count + " children!");
        addResult(assertEquals(count, 0, null, f));
    } finally {
        // delete the test folder
        deleteTestFolder();
        if (asyncSession instanceof AbstractExecutorServiceAsyncSession<?>) {
            ((AbstractExecutorServiceAsyncSession<?>) asyncSession).shutdown();
        }
    }
    addResult(createInfoResult("Tested the parallel creation and deletion of " + numOfDocuments + " documents."));
}
Also used : ContentStreamImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.ContentStreamImpl) HashMap(java.util.HashMap) AbstractExecutorServiceAsyncSession(org.apache.chemistry.opencmis.client.runtime.async.AbstractExecutorServiceAsyncSession) AsyncSession(org.apache.chemistry.opencmis.client.api.AsyncSession) ArrayList(java.util.ArrayList) Folder(org.apache.chemistry.opencmis.client.api.Folder) Document(org.apache.chemistry.opencmis.client.api.Document) ContentStream(org.apache.chemistry.opencmis.commons.data.ContentStream) CmisTestResult(org.apache.chemistry.opencmis.tck.CmisTestResult) CmisObject(org.apache.chemistry.opencmis.client.api.CmisObject) ObjectId(org.apache.chemistry.opencmis.client.api.ObjectId) ByteArrayOutputStream(java.io.ByteArrayOutputStream) AbstractExecutorServiceAsyncSession(org.apache.chemistry.opencmis.client.runtime.async.AbstractExecutorServiceAsyncSession) ByteArrayInputStream(java.io.ByteArrayInputStream) Future(java.util.concurrent.Future) CmisObject(org.apache.chemistry.opencmis.client.api.CmisObject) HashMap(java.util.HashMap) Map(java.util.Map)

Example 100 with Document

use of org.apache.chemistry.opencmis.client.api.Document in project copper-cms by PogeyanOSS.

the class AsyncCreateAndDeleteDocumentTest method countChildren.

private int countChildren(Folder folder) {
    int count = 0;
    ItemIterable<CmisObject> children = folder.getChildren(SELECT_ALL_NO_CACHE_OC);
    for (CmisObject child : children) {
        if (child instanceof Document) {
            count++;
        }
    }
    return count;
}
Also used : CmisObject(org.apache.chemistry.opencmis.client.api.CmisObject) Document(org.apache.chemistry.opencmis.client.api.Document)

Aggregations

Document (org.apache.chemistry.opencmis.client.api.Document)110 Folder (org.apache.chemistry.opencmis.client.api.Folder)64 HashMap (java.util.HashMap)43 CmisObject (org.apache.chemistry.opencmis.client.api.CmisObject)43 CmisTestResult (org.apache.chemistry.opencmis.tck.CmisTestResult)40 ContentStream (org.apache.chemistry.opencmis.commons.data.ContentStream)37 ContentStreamImpl (org.apache.chemistry.opencmis.commons.impl.dataobjects.ContentStreamImpl)32 CmisObjectNotFoundException (org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException)29 ByteArrayInputStream (java.io.ByteArrayInputStream)27 ObjectId (org.apache.chemistry.opencmis.client.api.ObjectId)25 DocumentTypeDefinition (org.apache.chemistry.opencmis.commons.definitions.DocumentTypeDefinition)23 CmisConstraintException (org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException)21 CmisInvalidArgumentException (org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException)20 IOException (java.io.IOException)19 InputStream (java.io.InputStream)19 ArrayList (java.util.ArrayList)19 Session (org.apache.chemistry.opencmis.client.api.Session)19 CmisPermissionDeniedException (org.apache.chemistry.opencmis.commons.exceptions.CmisPermissionDeniedException)19 Test (org.junit.Test)19 NodeRef (org.alfresco.service.cmr.repository.NodeRef)17