Search in sources :

Example 31 with CmisTestResult

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

the class LatestAccessibleStateIdTest method run.

@Override
public void run(Session session) {
    CmisTestResult f;
    try {
        // create folder and document
        Folder testFolder = createTestFolder(session);
        Document doc = createDocument(session, testFolder, "lateststate.txt", "latest state");
        DocumentTypeDefinition docType = (DocumentTypeDefinition) doc.getType();
        if (!docType.getPropertyDefinitions().containsKey(PropertyIds.LATEST_ACCESSIBLE_STATE_ID)) {
            addResult(createResult(SKIPPED, "Repository does not support the Latest State Identifier feature extension. Test skipped!"));
            doc.delete(true);
            return;
        }
        // check latest accessible state ID
        f = createResult(FAILURE, "Latest Accessible State ID is not set!");
        addResult(assertStringNotEmpty(doc.getLatestAccessibleStateId(), null, f));
        // get document with latest accessible state ID
        try {
            CmisObject latestStateObject = session.getObject(doc.getLatestAccessibleStateId(), SELECT_ALL_NO_CACHE_OC);
            if (latestStateObject instanceof Document) {
                f = createResult(FAILURE, "Latest Accessible State IDs of the orignal and the retrieved document don't match!");
                addResult(assertEquals(doc.getLatestAccessibleStateId(), ((Document) latestStateObject).getLatestAccessibleStateId(), null, f));
            } else {
                addResult(createResult(FAILURE, "Object retrieved with the Latest Accessible State ID is not a document!"));
            }
        } catch (CmisObjectNotFoundException onf) {
            addResult(createResult(FAILURE, "Document could not be retrieved with the Latest Accessible State ID!"));
        }
        doc.delete(true);
    } finally {
        // delete the test folder
        deleteTestFolder();
    }
}
Also used : DocumentTypeDefinition(org.apache.chemistry.opencmis.commons.definitions.DocumentTypeDefinition) CmisObjectNotFoundException(org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException) 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)

Example 32 with CmisTestResult

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

the class VersionDeleteTest method createVersion.

private Document createVersion(Session session, Document doc, String content, int version) {
    CmisTestResult f;
    // check out
    ObjectId pwcId = doc.checkOut();
    Document pwc = (Document) session.getObject(pwcId, SELECT_ALL_NO_CACHE_OC);
    addResult(checkObject(session, pwc, getAllProperties(pwc), "PWC " + version + " compliance"));
    // check in
    byte[] contentBytes = IOUtils.toUTF8Bytes(content);
    ContentStream contentStream = new ContentStreamImpl(doc.getName(), BigInteger.valueOf(contentBytes.length), "text/plain", new ByteArrayInputStream(contentBytes));
    ObjectId newVersionId = pwc.checkIn(true, null, contentStream, "test version " + version);
    IOUtils.closeQuietly(contentStream);
    Document newVersion = (Document) session.getObject(newVersionId, SELECT_ALL_NO_CACHE_OC);
    addResult(checkObject(session, newVersion, getAllProperties(newVersion), "Version " + version + " compliance"));
    // check version history
    List<Document> versions = doc.getAllVersions();
    f = createResult(FAILURE, "Version series should have " + version + " versions but has " + versions.size() + "!");
    addResult(assertEquals(version, versions.size(), null, f));
    if (!versions.isEmpty()) {
        f = createResult(FAILURE, "Newly created version " + version + " is not the latest version!");
        addResult(assertEquals(newVersion.getId(), versions.get(0).getId(), null, f));
        if (versions.size() > 1) {
            f = createResult(FAILURE, "The previous version of version " + version + " is not the document it has been created from!");
            addResult(assertEquals(doc.getId(), versions.get(1).getId(), null, f));
        }
    }
    return newVersion;
}
Also used : ContentStreamImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.ContentStreamImpl) 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) Document(org.apache.chemistry.opencmis.client.api.Document)

Example 33 with CmisTestResult

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

the class VersioningSmokeTest method run.

@Override
public void run(Session session) {
    CmisTestResult f;
    try {
        // create folder and document
        Folder testFolder = createTestFolder(session);
        Document doc = createDocument(session, testFolder, "versioningtest.txt", "versioning");
        DocumentTypeDefinition docType = (DocumentTypeDefinition) doc.getType();
        if (!docType.isVersionable()) {
            addResult(createResult(SKIPPED, "Test type is not versionable. Test skipped!"));
            doc.delete(true);
            return;
        }
        // gather properties for later
        String[] propertiesToCheck = new String[doc.getType().getPropertyDefinitions().size()];
        int i = 0;
        for (String propId : doc.getType().getPropertyDefinitions().keySet()) {
            propertiesToCheck[i++] = propId;
        }
        Map<String, Object> writableProperties = new HashMap<String, Object>();
        for (Property<?> property : doc.getProperties()) {
            if (property.getDefinition().getUpdatability() == Updatability.READWRITE) {
                writableProperties.put(property.getId(), property.getValue());
            }
        }
        // check out
        ObjectId pwcId = doc.checkOut();
        Document pwc = (Document) session.getObject(pwcId, SELECT_ALL_NO_CACHE_OC);
        addResult(checkObject(session, pwc, getAllProperties(pwc), "PWC spec compliance - test 1"));
        checkCheckedOut(pwc);
        // check version series
        addResult(checkVersionSeries(session, pwc.getAllVersions(SELECT_ALL_NO_CACHE_OC), propertiesToCheck, "Test version series after check out"));
        // cancel checkout
        pwc.cancelCheckOut();
        doc.refresh();
        checkCheckedIn(doc);
        // check out again
        pwcId = doc.checkOut();
        pwc = (Document) session.getObject(pwcId, SELECT_ALL_NO_CACHE_OC);
        addResult(checkObject(session, pwc, getAllProperties(pwc), "PWC spec compliance - test 2"));
        checkCheckedOut(pwc);
        // check in
        ObjectId newVersionId = pwc.checkIn(true, null, null, "Test Version 2");
        Document newVersion = (Document) session.getObject(newVersionId, SELECT_ALL_NO_CACHE_OC);
        addResult(checkObject(session, newVersion, getAllProperties(newVersion), "New version compliance"));
        checkCheckedIn(newVersion);
        // check version history
        List<Document> versions = newVersion.getAllVersions(SELECT_ALL_NO_CACHE_OC);
        f = createResult(FAILURE, "Version series should have 2 versions but has " + versions.size() + "!");
        addResult(assertEquals(2, versions.size(), null, f));
        if (!versions.isEmpty()) {
            f = createResult(FAILURE, "Version history order is incorrect! The first version should be the new version.");
            addResult(assertEquals(newVersion.getId(), versions.get(0).getId(), null, f));
            f = createResult(FAILURE, "The new version should be the latest version, but cmis:isLatestVersion is not TRUE.");
            addResult(assertEquals(true, versions.get(0).isLatestVersion(), null, f));
            f = createResult(FAILURE, "The new version should be the latest major version, but cmis:isLatestMajorVersion is not TRUE.");
            addResult(assertEquals(true, versions.get(0).isLatestMajorVersion(), null, f));
        }
        if (versions.size() > 1) {
            f = createResult(FAILURE, "Version history order is incorrect! The second version should be the origin document.");
            addResult(assertEquals(doc.getId(), versions.get(1).getId(), null, f));
        }
        // check version series
        addResult(checkVersionSeries(session, versions, propertiesToCheck, "Test version series after check in"));
        // check out again
        pwcId = newVersion.checkOut();
        pwc = (Document) session.getObject(pwcId, SELECT_ALL_NO_CACHE_OC);
        addResult(checkObject(session, pwc, getAllProperties(pwc), "PWC spec compliance - test 3"));
        checkCheckedOut(pwc);
        // check in giving back all updateable properties
        ObjectId thirdVersionId = pwc.checkIn(true, writableProperties, null, "Test Version 3");
        Document thirdVersion = (Document) session.getObject(thirdVersionId, SELECT_ALL_NO_CACHE_OC);
        addResult(checkObject(session, thirdVersion, getAllProperties(thirdVersion), "New version compliance"));
        // check out again
        pwcId = thirdVersion.checkOut();
        pwc = (Document) session.getObject(pwcId, SELECT_ALL_NO_CACHE_OC);
        addResult(checkObject(session, pwc, getAllProperties(pwc), "PWC spec compliance - test 4"));
        checkCheckedOut(pwc);
        // check in giving a new content stream
        String fourthContent = "new content";
        byte[] fourthContentBytes = IOUtils.toUTF8Bytes(fourthContent);
        ContentStream fourthContentStream = new ContentStreamImpl("version4", BigInteger.valueOf(fourthContentBytes.length), "text/plain", new ByteArrayInputStream(fourthContentBytes));
        ObjectId fourthVersionId = pwc.checkIn(true, null, fourthContentStream, "Test Version 5");
        Document fourthVersion = (Document) session.getObject(fourthVersionId, SELECT_ALL_NO_CACHE_OC);
        addResult(checkObject(session, fourthVersion, getAllProperties(fourthVersion), "New version compliance"));
        checkCheckedIn(fourthVersion);
        // check out again
        pwcId = fourthVersion.checkOut();
        pwc = (Document) session.getObject(pwcId, SELECT_ALL_NO_CACHE_OC);
        addResult(checkObject(session, pwc, getAllProperties(pwc), "PWC spec compliance - test 5"));
        checkCheckedOut(pwc);
        // check in giving properties and a new content stream
        String fifthContent = "brand-new content";
        byte[] fifthContentBytes = IOUtils.toUTF8Bytes(fifthContent);
        ContentStream fifthContentStream = new ContentStreamImpl("version5", BigInteger.valueOf(fifthContentBytes.length), "text/plain", new ByteArrayInputStream(fifthContentBytes));
        ObjectId fifthVersionId = pwc.checkIn(true, writableProperties, fifthContentStream, "Test Version 5");
        Document fifthVersion = (Document) session.getObject(fifthVersionId, SELECT_ALL_NO_CACHE_OC);
        addResult(checkObject(session, fifthVersion, getAllProperties(fifthVersion), "New version compliance"));
        checkCheckedIn(fifthVersion);
        // test the latest version
        Document latest = session.getLatestDocumentVersion(doc, SELECT_ALL_NO_CACHE_OC);
        f = createResult(FAILURE, "getObjectOfLatestVersion() did not return the expected version!");
        addResult(assertEquals(fifthVersion.getId(), latest.getId(), null, f));
        // repository
        try {
            pwcId = doc.checkOut();
            pwc = (Document) session.getObject(pwcId, SELECT_ALL_NO_CACHE_OC);
            pwc.cancelCheckOut();
            addResult(createInfoResult("Repository allows check out on a version that is not the latest version."));
        } catch (CmisBaseException e) {
            addResult(createInfoResult("Repository only support check out on the latest version."));
        }
        // remove the document
        deleteObject(doc);
        // test if all versions have been deleted
        f = createResult(FAILURE, "Version 2 has not been deleted!");
        addResult(assertIsFalse(session.exists(newVersion), null, f));
        f = createResult(FAILURE, "Version 3 has not been deleted!");
        addResult(assertIsFalse(session.exists(thirdVersion), null, f));
        f = createResult(FAILURE, "Version 4 has not been deleted!");
        addResult(assertIsFalse(session.exists(fourthVersion), null, f));
        f = createResult(FAILURE, "Version 5 has not been deleted!");
        addResult(assertIsFalse(session.exists(fifthVersion), null, f));
    } finally {
        deleteTestFolder();
    }
}
Also used : ContentStreamImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.ContentStreamImpl) DocumentTypeDefinition(org.apache.chemistry.opencmis.commons.definitions.DocumentTypeDefinition) HashMap(java.util.HashMap) ObjectId(org.apache.chemistry.opencmis.client.api.ObjectId) Folder(org.apache.chemistry.opencmis.client.api.Folder) Document(org.apache.chemistry.opencmis.client.api.Document) ContentStream(org.apache.chemistry.opencmis.commons.data.ContentStream) ByteArrayInputStream(java.io.ByteArrayInputStream) CmisBaseException(org.apache.chemistry.opencmis.commons.exceptions.CmisBaseException) CmisTestResult(org.apache.chemistry.opencmis.tck.CmisTestResult)

Example 34 with CmisTestResult

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

the class VersioningSmokeTest method checkCheckedOut.

private void checkCheckedOut(Document pwc) {
    CmisTestResult f;
    f = createResult(FAILURE, "Version series has a PWC but cmis:isVersionSeriesCheckedOut is not TRUE!");
    addResult(assertIsTrue(pwc.isVersionSeriesCheckedOut(), null, f));
    if (pwc.getVersionSeriesCheckedOutId() == null) {
        addResult(createResult(WARNING, "cmis:versionSeriesCheckedOutId is not set!"));
    } else {
        f = createResult(FAILURE, "PWC id and cmis:versionSeriesCheckedOutId don't match!");
        addResult(assertEquals(pwc.getId(), pwc.getVersionSeriesCheckedOutId(), null, f));
    }
    f = createResult(WARNING, "PWC does not have a value for cmis:versionSeriesCheckedOutBy!");
    addResult(assertStringNotEmpty(pwc.getVersionSeriesCheckedOutBy(), null, f));
}
Also used : CmisTestResult(org.apache.chemistry.opencmis.tck.CmisTestResult)

Example 35 with CmisTestResult

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

the class VersioningSmokeTest method checkCheckedIn.

private void checkCheckedIn(Document doc) {
    CmisTestResult f;
    f = createResult(FAILURE, "Version series is not checked out but cmis:isVersionSeriesCheckedOut is not FALSE!");
    addResult(assertIsFalse(doc.isVersionSeriesCheckedOut(), null, f));
    f = createResult(FAILURE, "Version series is not checked out but cmis:versionSeriesCheckedOutId has a value!");
    addResult(assertNull(doc.getVersionSeriesCheckedOutId(), null, f));
    f = createResult(FAILURE, "Version series is not checked out but cmis:versionSeriesCheckedOutBy has a value!");
    addResult(assertNull(doc.getVersionSeriesCheckedOutBy(), null, f));
}
Also used : CmisTestResult(org.apache.chemistry.opencmis.tck.CmisTestResult)

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