Search in sources :

Example 36 with CmisTestResult

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

the class DeleteTreeTest method run.

@Override
public void run(Session session) {
    CmisTestResult f;
    int numOfDocuments = 20;
    // create a test folder
    Folder testFolder = createTestFolder(session);
    Map<String, Document> documents = new HashMap<String, Document>();
    // create documents
    for (int i = 0; i < numOfDocuments; i++) {
        Document newDocument = createDocument(session, testFolder, "doc" + i, CONTENT);
        documents.put(newDocument.getId(), newDocument);
    }
    // delete tree
    List<String> failedIds = testFolder.deleteTree(true, UnfileObject.DELETE, true);
    // check failed ids
    if (failedIds != null && !failedIds.isEmpty()) {
        f = createResult(FAILURE, "deleteTree() could not delete " + failedIds.size() + " out of " + numOfDocuments + " objects in the folder!");
        addResult(assertEquals(0, failedIds.size(), null, f));
    }
    // check documents
    for (Document doc : documents.values()) {
        f = createResult(FAILURE, "Document still exists but should have been deleted. Id: " + doc.getId());
        addResult(assertIsFalse(exists(doc), null, f));
    }
    // check folder
    f = createResult(FAILURE, "Folder still exists but should have been deleted. Id: " + testFolder.getId());
    addResult(assertIsFalse(exists(testFolder), null, f));
    if (exists(testFolder)) {
        // try to clean up
        deleteObject(testFolder);
    }
}
Also used : HashMap(java.util.HashMap) CmisTestResult(org.apache.chemistry.opencmis.tck.CmisTestResult) Folder(org.apache.chemistry.opencmis.client.api.Folder) Document(org.apache.chemistry.opencmis.client.api.Document)

Example 37 with CmisTestResult

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

the class MoveTest method run.

@Override
public void run(Session session) {
    CmisTestResult f;
    try {
        // create folders
        Folder testFolder = createTestFolder(session);
        Folder folder1 = createFolder(session, testFolder, "movefolder1");
        Folder folder2 = createFolder(session, testFolder, "movefolder2");
        // create document
        Document doc1 = createDocument(session, folder1, "movetestdoc.txt", "move test");
        // move
        Document doc2 = (Document) doc1.move(folder1, folder2, SELECT_ALL_NO_CACHE_OC);
        if (doc2 == null) {
            addResult(createResult(FAILURE, "Moved document is null!"));
        } else {
            addResult(checkObject(session, doc2, getAllProperties(doc2), "Moved document check. Id: + " + doc2.getName()));
        }
        int count1 = countFolderChildren(folder1);
        f = createResult(FAILURE, "Source folder should be empty after move but has " + count1 + " children!");
        addResult(assertEquals(0, count1, null, f));
        int count2 = countFolderChildren(folder2);
        f = createResult(FAILURE, "Target folder should have exactly one child but has " + count2 + " children!");
        addResult(assertEquals(1, count2, null, f));
    } finally {
        // clean up
        deleteTestFolder();
    }
}
Also used : CmisTestResult(org.apache.chemistry.opencmis.tck.CmisTestResult) Folder(org.apache.chemistry.opencmis.client.api.Folder) Document(org.apache.chemistry.opencmis.client.api.Document)

Example 38 with CmisTestResult

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

the class OperationContextTest method runHighLevelApiTests.

/**
 * Checks for not requested properties, Allowable Actions, ACLs, renditions,
 * relationships, and policies.
 */
public void runHighLevelApiTests(Session session, Folder testFolder, Document testDocument) {
    CmisTestResult f;
    // only select some base properties
    Set<String> properties = new HashSet<String>();
    properties.add("cmis:objectId");
    properties.add("cmis:baseTypeId");
    properties.add("cmis:objectTypeId");
    OperationContext context = session.createOperationContext();
    context.setCacheEnabled(false);
    context.setFilter(properties);
    context.setIncludeAcls(false);
    context.setIncludeAllowableActions(false);
    context.setIncludePathSegments(false);
    context.setIncludePolicies(false);
    context.setIncludeRelationships(IncludeRelationships.NONE);
    context.setLoadSecondaryTypeProperties(false);
    context.setRenditionFilterString("cmis:none");
    // get the object with the OperationContext
    Document doc1 = (Document) session.getObject(testDocument, context);
    // check properties
    for (Property<?> prop : doc1.getProperties()) {
        if (!properties.contains(prop.getDefinition().getQueryName())) {
            addResult(createResult(CmisTestResultStatus.WARNING, "getObject() delivered the property '" + prop.getId() + "', although it has not been requested."));
        }
    }
    // check other details
    f = createResult(CmisTestResultStatus.WARNING, "getObject() delivered ACLs, although they have not been requested.");
    addResult(assertNull(doc1.getAcl(), null, f));
    f = createResult(CmisTestResultStatus.WARNING, "getObject() delivered Allowable Actions, although they have not been requested.");
    addResult(assertNull(doc1.getAllowableActions(), null, f));
    f = createResult(CmisTestResultStatus.WARNING, "getObject() delivered policies, although they have not been requested.");
    addResult(assertListNullOrEmpty(doc1.getPolicies(), null, f));
    f = createResult(CmisTestResultStatus.WARNING, "getObject() delivered relationships, although they have not been requested.");
    addResult(assertListNullOrEmpty(doc1.getRelationships(), null, f));
    f = createResult(CmisTestResultStatus.WARNING, "getObject() delivered renditions, although they have not been requested.");
    addResult(assertListNullOrEmpty(doc1.getRenditions(), null, f));
    // get the test folder children with the OperationContext
    for (CmisObject child : testFolder.getChildren(context)) {
        if (child.getId().equals(testDocument.getId())) {
            // check properties
            for (Property<?> prop : child.getProperties()) {
                if (!properties.contains(prop.getDefinition().getQueryName())) {
                    addResult(createResult(CmisTestResultStatus.WARNING, "getChildren() delivered the property '" + prop.getId() + "', although it has not been requested."));
                }
            }
            // check other details
            f = createResult(CmisTestResultStatus.INFO, "getChildren() delivered ACLs, which is not required.");
            addResult(assertNull(child.getAcl(), null, f));
            f = createResult(CmisTestResultStatus.WARNING, "getChildren() delivered Allowable Actions, although they have not been requested.");
            addResult(assertNull(child.getAllowableActions(), null, f));
            f = createResult(CmisTestResultStatus.INFO, "getChildren() delivered policies, which is not required.");
            addResult(assertListNullOrEmpty(child.getPolicies(), null, f));
            f = createResult(CmisTestResultStatus.WARNING, "getChildren() delivered relationships, although they have not been requested.");
            addResult(assertListNullOrEmpty(child.getRelationships(), null, f));
            f = createResult(CmisTestResultStatus.WARNING, "getChildren() delivered renditions, although they have not been requested.");
            addResult(assertListNullOrEmpty(child.getRenditions(), null, f));
            break;
        }
    }
}
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) Document(org.apache.chemistry.opencmis.client.api.Document) HashSet(java.util.HashSet)

Example 39 with CmisTestResult

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

the class SetAndDeleteContentTest method run.

@Override
public void run(Session session) {
    CmisTestResult f;
    if (getContentStreamUpdatesCapbility(session) == CapabilityContentStreamUpdates.NONE) {
        addResult(createResult(SKIPPED, "Stream updates are not supported. Test skipped!"));
        return;
    }
    try {
        // create folder and document
        Folder testFolder = createTestFolder(session);
        Document doc = createDocument(session, testFolder, "contenttest.txt", CONTENT1);
        Document workDoc = doc;
        DocumentTypeDefinition docType = (DocumentTypeDefinition) doc.getType();
        // test if check out is required and possible
        boolean checkedout = false;
        if (!doc.getAllowableActions().getAllowableActions().contains(Action.CAN_SET_CONTENT_STREAM)) {
            if (!docType.isVersionable()) {
                addResult(createResult(SKIPPED, "The test document does not accept a new content stream. Test skipped!"));
                doc.delete(true);
                return;
            } else {
                workDoc = (Document) session.getObject(doc.checkOut(), SELECT_ALL_NO_CACHE_OC);
                checkedout = true;
                if (!workDoc.getAllowableActions().getAllowableActions().contains(Action.CAN_SET_CONTENT_STREAM)) {
                    addResult(createResult(SKIPPED, "The test PWC does not accept a new content stream. Test skipped!"));
                    workDoc.cancelCheckOut();
                    doc.delete(true);
                    return;
                }
            }
        }
        // test if the content stream can be deleted
        if (docType.getContentStreamAllowed() == ContentStreamAllowed.REQUIRED) {
            addResult(createResult(SKIPPED, "A content stream is required for this document type. deleteContentStream() test skipped!"));
        } else {
            // delete content stream
            try {
                ObjectId newObjectId = workDoc.deleteContentStream(true);
                // deleteContentStream may have created a new version
                Document contentDoc = getNewVersion(session, workDoc, checkedout, newObjectId, "deleteContentStream()");
                f = createResult(FAILURE, "Document still has content after deleteContentStream() has been called!");
                addResult(assertNull(contentDoc.getContentStream(), null, f));
                f = createResult(FAILURE, "Document still has a MIME type after deleteContentStream() has been called: " + contentDoc.getContentStreamMimeType());
                addResult(assertNull(contentDoc.getContentStreamMimeType(), null, f));
                f = createResult(FAILURE, "Document still has a content length after deleteContentStream() has been called: " + contentDoc.getContentStreamLength());
                addResult(assertEquals(-1L, contentDoc.getContentStreamLength(), null, f));
                f = createResult(FAILURE, "Document still has a file name after deleteContentStream() has been called: " + contentDoc.getContentStreamFileName());
                addResult(assertNull(contentDoc.getContentStreamFileName(), null, f));
                workDoc = contentDoc;
            } catch (CmisNotSupportedException e) {
                addResult(createResult(WARNING, "deleteContentStream() is not supported!"));
            }
        }
        // set a new content stream
        byte[] contentBytes = IOUtils.toUTF8Bytes(CONTENT2);
        try {
            ContentStream contentStream = session.getObjectFactory().createContentStream(workDoc.getName(), contentBytes.length, "text/plain", new ByteArrayInputStream(contentBytes));
            ObjectId newObjectId = workDoc.setContentStream(contentStream, true, true);
            IOUtils.closeQuietly(contentStream);
            // setContentStream may have created a new version
            Document contentDoc = getNewVersion(session, workDoc, checkedout, newObjectId, "setContentStream()");
            // test new content
            try {
                String content = getStringFromContentStream(contentDoc.getContentStream());
                f = createResult(FAILURE, "Document content doesn't match the content set by setContentStream()!");
                addResult(assertEquals(CONTENT2, content, null, f));
            } catch (IOException e) {
                addResult(createResult(UNEXPECTED_EXCEPTION, "Document content couldn't be read! Exception: " + e.getMessage(), e, true));
            }
            workDoc = contentDoc;
        } catch (CmisNotSupportedException e) {
            addResult(createResult(WARNING, "setContentStream() is not supported!"));
        }
        // test appendContentStream
        if (session.getRepositoryInfo().getCmisVersion() != CmisVersion.CMIS_1_0) {
            contentBytes = IOUtils.toUTF8Bytes(CONTENT3);
            try {
                ContentStream contentStream = session.getObjectFactory().createContentStream(workDoc.getName(), contentBytes.length, "text/plain", new ByteArrayInputStream(contentBytes));
                ObjectId newObjectId = workDoc.appendContentStream(contentStream, true);
                // appendContentStream may have created a new version
                Document contentDoc = getNewVersion(session, workDoc, checkedout, newObjectId, "appendContentStream()");
                // test new content
                try {
                    String content = getStringFromContentStream(contentDoc.getContentStream());
                    f = createResult(FAILURE, "Document content doesn't match the content set by setContentStream() followed by appendContentStream()!");
                    addResult(assertEquals(CONTENT2 + CONTENT3, content, null, f));
                } catch (IOException e) {
                    addResult(createResult(UNEXPECTED_EXCEPTION, "Document content couldn't be read! Exception: " + e.getMessage(), e, true));
                }
                // test append stream
                testAppendStream(session, testFolder, 16 * 1024);
                testAppendStream(session, testFolder, 8);
                testAppendStream(session, testFolder, 0);
            } catch (CmisNotSupportedException e) {
                addResult(createResult(WARNING, "appendContentStream() is not supported!"));
            }
        }
        // cancel a possible check out
        if (checkedout) {
            workDoc.cancelCheckOut();
        }
        // remove the document
        deleteObject(doc);
    } finally {
        deleteTestFolder();
    }
}
Also used : CmisNotSupportedException(org.apache.chemistry.opencmis.commons.exceptions.CmisNotSupportedException) DocumentTypeDefinition(org.apache.chemistry.opencmis.commons.definitions.DocumentTypeDefinition) ContentStream(org.apache.chemistry.opencmis.commons.data.ContentStream) ObjectId(org.apache.chemistry.opencmis.client.api.ObjectId) ByteArrayInputStream(java.io.ByteArrayInputStream) CmisTestResult(org.apache.chemistry.opencmis.tck.CmisTestResult) IOException(java.io.IOException) Folder(org.apache.chemistry.opencmis.client.api.Folder) Document(org.apache.chemistry.opencmis.client.api.Document)

Example 40 with CmisTestResult

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

the class UpdateSmokeTest method updateFolder.

private void updateFolder(Session session, Folder testFolder) {
    CmisTestResult f;
    Folder folder = createFolder(session, testFolder, FOLDER_NAME1);
    f = createResult(FAILURE, "Folder name doesn't match the given name!");
    addResult(assertEquals(FOLDER_NAME1, folder.getName(), null, f));
    // update
    Map<String, Object> properties = new HashMap<String, Object>();
    properties.put(PropertyIds.NAME, FOLDER_NAME2);
    ObjectId newId = folder.updateProperties(properties, false);
    f = createResult(WARNING, "Folder id changed after name update! The folder id should never change!");
    addResult(assertEquals(folder.getId(), newId.getId(), null, f));
    // get the new folder object and check the new name
    folder.refresh();
    f = createResult(FAILURE, "Folder name doesn't match updated value!");
    addResult(assertEquals(FOLDER_NAME2, folder.getName(), null, f));
    // update again with the same name
    folder.rename(FOLDER_NAME2, true);
    f = createResult(FAILURE, "Folder name doesn't match updated value!");
    addResult(assertEquals(FOLDER_NAME2, folder.getName(), null, f));
    deleteObject(folder);
}
Also used : HashMap(java.util.HashMap) ObjectId(org.apache.chemistry.opencmis.client.api.ObjectId) CmisTestResult(org.apache.chemistry.opencmis.tck.CmisTestResult) Folder(org.apache.chemistry.opencmis.client.api.Folder)

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