Search in sources :

Example 16 with DocumentTypeDefinition

use of org.apache.chemistry.opencmis.commons.definitions.DocumentTypeDefinition in project copper-cms by PogeyanOSS.

the class CheckedOutTest method run.

@Override
public void run(Session session) {
    CmisTestResult f;
    boolean supportsOrderByName = isOrderByNameSupported(session);
    OperationContext orderContext = (supportsOrderByName ? SELECT_ALL_NO_CACHE_OC_ORDER_BY_NAME : SELECT_ALL_NO_CACHE_OC);
    Document pwc = null;
    try {
        // create folder and a checked-out document
        Folder testFolder = createTestFolder(session);
        Document doc = createDocument(session, testFolder, "checkedouttest.txt", "checked out");
        DocumentTypeDefinition docType = (DocumentTypeDefinition) doc.getType();
        if (!docType.isVersionable()) {
            addResult(createResult(WARNING, "Test type is not versionable. Check out skipped!"));
        } else {
            ObjectId pwcId = doc.checkOut();
            pwc = (Document) session.getObject(pwcId, SELECT_ALL_NO_CACHE_OC);
        }
        // test all checked-out documents
        int sessionCheckedOut = checkPWCs(session, session.getCheckedOutDocs(orderContext), supportsOrderByName);
        addResult(createInfoResult(sessionCheckedOut + " checked out document(s) overall."));
        if (pwc != null) {
            f = createResult(FAILURE, "There should be at least one checked out document in the repository!");
            addResult(assertIsTrue(sessionCheckedOut >= 1, null, f));
        }
        // test checked-out documents in the test folder
        int testFolderCheckedOut = checkPWCs(session, testFolder.getCheckedOutDocs(orderContext), supportsOrderByName);
        addResult(createInfoResult(testFolderCheckedOut + " checked out document(s) in the test folder."));
        if (pwc != null) {
            f = createResult(FAILURE, "There should be at least one checked out document in the test folder!");
            addResult(assertIsTrue(testFolderCheckedOut >= 1, null, f));
        }
        // remove the PWC and document
        if (pwc != null) {
            pwc.cancelCheckOut();
            pwc = null;
        }
        deleteObject(doc);
    } finally {
        if (pwc != null) {
            pwc.cancelCheckOut();
        }
        deleteTestFolder();
    }
}
Also used : OperationContext(org.apache.chemistry.opencmis.client.api.OperationContext) DocumentTypeDefinition(org.apache.chemistry.opencmis.commons.definitions.DocumentTypeDefinition) ObjectId(org.apache.chemistry.opencmis.client.api.ObjectId) CmisTestResult(org.apache.chemistry.opencmis.tck.CmisTestResult) Document(org.apache.chemistry.opencmis.client.api.Document) Folder(org.apache.chemistry.opencmis.client.api.Folder)

Example 17 with DocumentTypeDefinition

use of org.apache.chemistry.opencmis.commons.definitions.DocumentTypeDefinition in project copper-cms by PogeyanOSS.

the class VersioningStateCreateTest method run.

@Override
public void run(Session session) {
    CmisTestResult f;
    try {
        // create folder and document
        Folder testFolder = createTestFolder(session);
        DocumentTypeDefinition docType = (DocumentTypeDefinition) session.getTypeDefinition(getDocumentTestTypeId());
        if (!docType.isVersionable()) {
            addResult(createResult(SKIPPED, "Test type is not versionable. Test skipped!"));
            return;
        }
        // major version
        Document docMajor = testFolder.createDocument(getProperties("major.txt"), getContentStream(), VersioningState.MAJOR, null, null, null, SELECT_ALL_NO_CACHE_OC);
        addResult(checkObject(session, docMajor, getAllProperties(docMajor), "Major version compliance"));
        f = createResult(FAILURE, "Document should be major version.");
        addResult(assertIsTrue(docMajor.isMajorVersion(), null, f));
        List<Document> versions = docMajor.getAllVersions();
        f = createResult(FAILURE, "Version series should have one version but has " + versions.size() + ".");
        addResult(assertEquals(1, versions.size(), null, f));
        deleteObject(docMajor);
        // minor version
        try {
            Document docMinor = testFolder.createDocument(getProperties("minor.txt"), getContentStream(), VersioningState.MINOR, null, null, null, SELECT_ALL_NO_CACHE_OC);
            addResult(checkObject(session, docMinor, getAllProperties(docMinor), "Minor version compliance"));
            f = createResult(FAILURE, "Document should be minor version.");
            addResult(assertIsFalse(docMinor.isMajorVersion(), null, f));
            versions = docMinor.getAllVersions();
            f = createResult(FAILURE, "Version series should have one version but has " + versions.size() + ".");
            addResult(assertEquals(1, versions.size(), null, f));
            deleteObject(docMinor);
        } catch (CmisConstraintException ce) {
            addResult(createResult(WARNING, "Creating a minor version failed! " + "The repository might not support minor versions. Exception: " + ce, ce, false));
        } catch (CmisInvalidArgumentException iae) {
            addResult(createResult(WARNING, "Creating a minor version failed! " + "The repository might not support minor versions.  Exception: " + iae, iae, false));
        }
        // checked out version
        try {
            Document docCheckedOut = testFolder.createDocument(getProperties("checkout.txt"), getContentStream(), VersioningState.CHECKEDOUT, null, null, null, SELECT_ALL_NO_CACHE_OC);
            addResult(checkObject(session, docCheckedOut, getAllProperties(docCheckedOut), "Checked out version compliance"));
            f = createResult(FAILURE, "Version series should be checked out.");
            addResult(assertIsTrue(docCheckedOut.isVersionSeriesCheckedOut(), null, f));
            versions = docCheckedOut.getAllVersions();
            f = createResult(FAILURE, "Version series should have one version but has " + versions.size() + ".");
            addResult(assertEquals(1, versions.size(), null, f));
            docCheckedOut.cancelCheckOut();
        } catch (CmisConstraintException ce) {
            addResult(createResult(WARNING, "Creating a checked out version failed! " + "The repository might not support creating checked out versions. Exception: " + ce, ce, false));
        } catch (CmisInvalidArgumentException iae) {
            addResult(createResult(WARNING, "Creating a checked out version failed! " + "The repository might not  support creating checked out versions.  Exception: " + iae, iae, false));
        }
    } finally {
        deleteTestFolder();
    }
}
Also used : DocumentTypeDefinition(org.apache.chemistry.opencmis.commons.definitions.DocumentTypeDefinition) CmisConstraintException(org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException) CmisTestResult(org.apache.chemistry.opencmis.tck.CmisTestResult) CmisInvalidArgumentException(org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException) Folder(org.apache.chemistry.opencmis.client.api.Folder) Document(org.apache.chemistry.opencmis.client.api.Document)

Example 18 with DocumentTypeDefinition

use of org.apache.chemistry.opencmis.commons.definitions.DocumentTypeDefinition in project copper-cms by PogeyanOSS.

the class CreateBigDocument method run.

@Override
public void run(Session session) {
    CmisTestResult f;
    // create a test folder
    Folder testFolder = createTestFolder(session);
    try {
        String name = "bigdoc";
        String objectTypeId = getDocumentTestTypeId();
        String mimetype = "application/octet-stream";
        // 10 MiB
        final long size = 10 * 1024 * 1024;
        InputStream in = new InputStream() {

            private int counter = -1;

            @Override
            public int read() throws IOException {
                counter++;
                if (counter >= size) {
                    return -1;
                }
                return '0' + (counter / 10);
            }
        };
        // create stream and properties
        ContentStream contentStream = session.getObjectFactory().createContentStream(name, size, mimetype, in);
        Map<String, Object> properties = new HashMap<String, Object>();
        properties.put(PropertyIds.NAME, name);
        properties.put(PropertyIds.OBJECT_TYPE_ID, objectTypeId);
        // check type
        TypeDefinition type = session.getTypeDefinition(objectTypeId);
        if (!(type instanceof DocumentTypeDefinition)) {
            addResult(createResult(FAILURE, "Type is not a document type! Type: " + objectTypeId, true));
            return;
        }
        DocumentTypeDefinition docType = (DocumentTypeDefinition) type;
        VersioningState versioningState = (Boolean.TRUE.equals(docType.isVersionable()) ? VersioningState.MAJOR : VersioningState.NONE);
        // create and fetch the document
        ObjectId id = session.createDocument(properties, testFolder, contentStream, versioningState);
        Document doc = (Document) session.getObject(id, SELECT_ALL_NO_CACHE_OC);
        // check the new document
        addResult(checkObject(session, doc, getAllProperties(doc), "New document object spec compliance"));
        // check the size
        f = createResult(FAILURE, "Content stream length doesn't match the uploaded content!", true);
        assertEquals(size, doc.getContentStreamLength(), null, f);
    // delete it
    // doc.delete(true);
    } finally {
    // delete the test folder
    // deleteTestFolder();
    }
}
Also used : DocumentTypeDefinition(org.apache.chemistry.opencmis.commons.definitions.DocumentTypeDefinition) HashMap(java.util.HashMap) ObjectId(org.apache.chemistry.opencmis.client.api.ObjectId) InputStream(java.io.InputStream) Folder(org.apache.chemistry.opencmis.client.api.Folder) Document(org.apache.chemistry.opencmis.client.api.Document) TypeDefinition(org.apache.chemistry.opencmis.commons.definitions.TypeDefinition) DocumentTypeDefinition(org.apache.chemistry.opencmis.commons.definitions.DocumentTypeDefinition) ContentStream(org.apache.chemistry.opencmis.commons.data.ContentStream) CmisTestResult(org.apache.chemistry.opencmis.tck.CmisTestResult) VersioningState(org.apache.chemistry.opencmis.commons.enums.VersioningState)

Aggregations

DocumentTypeDefinition (org.apache.chemistry.opencmis.commons.definitions.DocumentTypeDefinition)18 Document (org.apache.chemistry.opencmis.client.api.Document)16 CmisTestResult (org.apache.chemistry.opencmis.tck.CmisTestResult)14 Folder (org.apache.chemistry.opencmis.client.api.Folder)10 ObjectId (org.apache.chemistry.opencmis.client.api.ObjectId)7 HashMap (java.util.HashMap)6 ContentStream (org.apache.chemistry.opencmis.commons.data.ContentStream)5 CmisObjectNotFoundException (org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 IOException (java.io.IOException)4 CmisBaseException (org.apache.chemistry.opencmis.commons.exceptions.CmisBaseException)4 CmisInvalidArgumentException (org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException)4 CmisNotSupportedException (org.apache.chemistry.opencmis.commons.exceptions.CmisNotSupportedException)4 ArrayList (java.util.ArrayList)3 CmisObject (org.apache.chemistry.opencmis.client.api.CmisObject)3 VersioningState (org.apache.chemistry.opencmis.commons.enums.VersioningState)3 InputStream (java.io.InputStream)2 FileableCmisObject (org.apache.chemistry.opencmis.client.api.FileableCmisObject)2 TypeDefinition (org.apache.chemistry.opencmis.commons.definitions.TypeDefinition)2 CmisConstraintException (org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException)2