Search in sources :

Example 61 with CmisTestResult

use of org.apache.chemistry.opencmis.tck.CmisTestResult 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 62 with CmisTestResult

use of org.apache.chemistry.opencmis.tck.CmisTestResult in project copper-cms by PogeyanOSS.

the class OperationContextTest method runLowLevelApiTests.

/**
 * Checks for change events and path segments.
 */
public void runLowLevelApiTests(Session session, Folder testFolder, Document testDocument) {
    CmisTestResult f;
    String repositoryId = session.getRepositoryInfo().getId();
    String filter = "cmis:objectId,cmis:baseTypeId,cmis:objectTypeId";
    // get the object
    ObjectData doc1 = session.getBinding().getObjectService().getObject(repositoryId, testDocument.getId(), filter, Boolean.FALSE, IncludeRelationships.NONE, "cmis:none", Boolean.FALSE, Boolean.FALSE, null);
    // check for change events
    f = createResult(CmisTestResultStatus.WARNING, "getObject() delivered a change event, which doesn't make sense.");
    addResult(assertNull(doc1.getChangeEventInfo(), null, f));
    // get the test folder children
    ObjectInFolderList children = session.getBinding().getNavigationService().getChildren(repositoryId, testFolder.getId(), filter, null, Boolean.FALSE, IncludeRelationships.NONE, "cmis:none", Boolean.FALSE, null, BigInteger.ZERO, null);
    // check for path segments
    for (ObjectInFolderData child : children.getObjects()) {
        f = createResult(CmisTestResultStatus.WARNING, "getChildren() delivered a path segment, although it hasn't been requested.");
        addResult(assertNull(child.getPathSegment(), null, f));
    }
    // get the document parent
    List<ObjectParentData> parents = session.getBinding().getNavigationService().getObjectParents(repositoryId, testDocument.getId(), filter, Boolean.FALSE, IncludeRelationships.NONE, "cmis:none", Boolean.FALSE, null);
    // check for relative path segments
    for (ObjectParentData parent : parents) {
        f = createResult(CmisTestResultStatus.WARNING, "getObjectParents() delivered a relative path segment, although it hasn't been requested.");
        addResult(assertNull(parent.getRelativePathSegment(), null, f));
    }
}
Also used : ObjectParentData(org.apache.chemistry.opencmis.commons.data.ObjectParentData) ObjectInFolderList(org.apache.chemistry.opencmis.commons.data.ObjectInFolderList) CmisTestResult(org.apache.chemistry.opencmis.tck.CmisTestResult) ObjectData(org.apache.chemistry.opencmis.commons.data.ObjectData) ObjectInFolderData(org.apache.chemistry.opencmis.commons.data.ObjectInFolderData)

Example 63 with CmisTestResult

use of org.apache.chemistry.opencmis.tck.CmisTestResult 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 64 with CmisTestResult

use of org.apache.chemistry.opencmis.tck.CmisTestResult in project copper-cms by PogeyanOSS.

the class SetAndDeleteContentTest method testAppendStream.

private void testAppendStream(Session session, Folder testFolder, int bufferSize) {
    CmisTestResult f;
    // create an empty document
    Document doc = createDocument(session, testFolder, "appendstreamtest.txt", "");
    Document workDoc = doc;
    boolean checkedout = false;
    DocumentTypeDefinition docType = (DocumentTypeDefinition) doc.getType();
    if (Boolean.TRUE.equals(docType.isVersionable())) {
        workDoc = (Document) session.getObject(doc.checkOut(), SELECT_ALL_NO_CACHE_OC);
        checkedout = true;
    }
    try {
        // create an overwrite OutputStream
        OutputStream out1 = workDoc.createOverwriteOutputStream("appendstreamtest", "text/plain", bufferSize);
        out1.write(IOUtils.toUTF8Bytes("line 1\n"));
        out1.write(IOUtils.toUTF8Bytes("line 2\n"));
        out1.flush();
        out1.write(IOUtils.toUTF8Bytes("line 3\n"));
        out1.close();
        // check document content
        workDoc.refresh();
        String content1 = getStringFromContentStream(workDoc.getContentStream());
        f = createResult(FAILURE, "Overwrite OutputStream: wrong content!");
        addResult(assertEquals("line 1\nline 2\nline 3\n", content1, null, f));
        // create an append OutputStream
        OutputStream out2 = workDoc.createAppendOutputStream(bufferSize);
        out2.write(IOUtils.toUTF8Bytes("line 4\n"));
        out2.write(IOUtils.toUTF8Bytes("line 5\n"));
        out2.flush();
        out2.write(IOUtils.toUTF8Bytes("line 6\n"));
        out2.close();
        // check document content
        workDoc.refresh();
        String content2 = getStringFromContentStream(workDoc.getContentStream());
        f = createResult(FAILURE, "Overwrite OutputStream: wrong content!");
        addResult(assertEquals("line 1\nline 2\nline 3\nline 4\nline 5\nline 6\n", content2, null, f));
    } catch (IOException e) {
        addResult(createResult(UNEXPECTED_EXCEPTION, "Appending content via an OutputStream failed! Exception: " + e.getMessage(), e, false));
    } finally {
        // cancel a possible check out
        if (checkedout) {
            workDoc.cancelCheckOut();
        }
        // remove the document
        deleteObject(doc);
    }
}
Also used : DocumentTypeDefinition(org.apache.chemistry.opencmis.commons.definitions.DocumentTypeDefinition) CmisTestResult(org.apache.chemistry.opencmis.tck.CmisTestResult) OutputStream(java.io.OutputStream) IOException(java.io.IOException) Document(org.apache.chemistry.opencmis.client.api.Document)

Example 65 with CmisTestResult

use of org.apache.chemistry.opencmis.tck.CmisTestResult 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)

Aggregations

CmisTestResult (org.apache.chemistry.opencmis.tck.CmisTestResult)82 ArrayList (java.util.ArrayList)33 Folder (org.apache.chemistry.opencmis.client.api.Folder)33 Document (org.apache.chemistry.opencmis.client.api.Document)32 HashMap (java.util.HashMap)19 CmisObject (org.apache.chemistry.opencmis.client.api.CmisObject)18 DocumentTypeDefinition (org.apache.chemistry.opencmis.commons.definitions.DocumentTypeDefinition)14 CmisBaseException (org.apache.chemistry.opencmis.commons.exceptions.CmisBaseException)14 CmisObjectNotFoundException (org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException)14 ObjectId (org.apache.chemistry.opencmis.client.api.ObjectId)12 ContentStream (org.apache.chemistry.opencmis.commons.data.ContentStream)11 FileableCmisObject (org.apache.chemistry.opencmis.client.api.FileableCmisObject)8 ObjectType (org.apache.chemistry.opencmis.client.api.ObjectType)8 CmisInvalidArgumentException (org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException)8 ByteArrayInputStream (java.io.ByteArrayInputStream)7 IOException (java.io.IOException)6 HashSet (java.util.HashSet)6 CmisNotSupportedException (org.apache.chemistry.opencmis.commons.exceptions.CmisNotSupportedException)6 OperationContext (org.apache.chemistry.opencmis.client.api.OperationContext)5 TypeDefinition (org.apache.chemistry.opencmis.commons.definitions.TypeDefinition)4