Search in sources :

Example 6 with ObjectId

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

the class ChangeTokenTest method runContentTest.

private void runContentTest(Session session, Folder testFolder) {
    if (session.getRepositoryInfo().getCapabilities().getContentStreamUpdatesCapability() != CapabilityContentStreamUpdates.ANYTIME) {
        addResult(createResult(SKIPPED, "Repository doesn't allow to replace content. Test skipped!"));
        return;
    }
    Document doc = createDocument(session, testFolder, "content1.txt", "Hello World!");
    try {
        if (doc.getChangeToken() == null) {
            addResult(createResult(SKIPPED, "Repository does not provide change tokens for documents. Test skipped!"));
            return;
        }
        if (!doc.getAllowableActions().getAllowableActions().contains(Action.CAN_SET_CONTENT_STREAM)) {
            addResult(createResult(SKIPPED, "Document content can't be changed. Test skipped!"));
            return;
        }
        byte[] contentBytes = IOUtils.toUTF8Bytes("New content");
        ContentStream contentStream = new ContentStreamImpl("content2.txt", BigInteger.valueOf(contentBytes.length), "text/plain", new ByteArrayInputStream(contentBytes));
        ObjectId newId = doc.setContentStream(contentStream, true, false);
        if (newId == null) {
            // -> get the latest id from the version series
            if (Boolean.TRUE.equals(((DocumentTypeDefinition) doc.getType()).isVersionable())) {
                List<Document> versions = doc.getAllVersions();
                if (versions == null || versions.size() < 1) {
                    addResult(createResult(FAILURE, "Repository returned an empty list of document versions!"));
                } else {
                    // the latest document is at the top of the list
                    newId = versions.get(0);
                }
            } else {
                // the document type is not versionable
                // -> the repository couldn't create a new version
                newId = doc;
            }
        }
        if (newId != null) {
            if (!doc.getId().equals(newId.getId())) {
                // the repository created a new version
                // -> a change token test does not make sense
                addResult(createResult(INFO, "The repository created a new version. Change tokens are not relevant here."));
            } else {
                try {
                    doc.setContentStream(contentStream, true, false);
                    addResult(createResult(FAILURE, "Updating content a second time with the same change token " + "should result in an UpdateConflict exception!"));
                // } catch (CmisUpdateConflictException uce) {
                } catch (CmisConstraintException e) {
                // expected exception
                }
            }
        }
    } finally {
        deleteObject(doc);
    }
}
Also used : ContentStreamImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.ContentStreamImpl) ContentStream(org.apache.chemistry.opencmis.commons.data.ContentStream) ByteArrayInputStream(java.io.ByteArrayInputStream) ObjectId(org.apache.chemistry.opencmis.client.api.ObjectId) CmisConstraintException(org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException) Document(org.apache.chemistry.opencmis.client.api.Document)

Example 7 with ObjectId

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

the class CreateDocumentWithoutContent method run.

@Override
public void run(Session session) {
    CmisTestResult f;
    String objectTypeId = getDocumentTestTypeId();
    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;
    if (docType.getContentStreamAllowed() == ContentStreamAllowed.REQUIRED) {
        addResult(createResult(SKIPPED, "The test document type does not support documents without content. Test skipped!"));
        return;
    }
    // create a test folder
    Folder testFolder = createTestFolder(session);
    try {
        String name = "nocontent";
        Map<String, Object> properties = new HashMap<String, Object>();
        properties.put(PropertyIds.NAME, name);
        properties.put(PropertyIds.OBJECT_TYPE_ID, objectTypeId);
        VersioningState versioningState = (Boolean.TRUE.equals(docType.isVersionable()) ? VersioningState.MAJOR : VersioningState.NONE);
        // create and fetch the document
        ObjectId id = session.createDocument(properties, testFolder, null, 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 MIME type
        f = createResult(FAILURE, "The document has no content but a MIME type!", true);
        assertNull(doc.getContentStreamMimeType(), null, f);
        // check the content size
        if (doc.getContentStreamLength() == 0) {
            addResult(createResult(WARNING, "The document has no content but the content length is set to 0! " + "The content length shouldn't be set."));
        } else if (doc.getContentStreamLength() > 0) {
            addResult(createResult(FAILURE, "The document has no content but the content length is set and >0! " + "(content length: " + doc.getContentStreamLength() + ")"));
        }
        // 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) CmisTestResult(org.apache.chemistry.opencmis.tck.CmisTestResult) VersioningState(org.apache.chemistry.opencmis.commons.enums.VersioningState) 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)

Example 8 with ObjectId

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

the class AsyncCreateAndDeleteFolderTest method run.

@Override
public void run(Session session) {
    CmisTestResult f;
    int numOfFolders = 100;
    // create an async session
    AsyncSession asyncSession = AsyncSessionFactoryImpl.newInstance().createAsyncSession(session, 10);
    // create a test folder
    Folder testFolder = createTestFolder(session);
    try {
        // create folders
        List<Future<ObjectId>> folderFutures = new ArrayList<Future<ObjectId>>();
        for (int i = 0; i < numOfFolders; i++) {
            String name = "asyncfolder" + i;
            Map<String, Object> properties = new HashMap<String, Object>();
            properties.put(PropertyIds.NAME, name);
            properties.put(PropertyIds.OBJECT_TYPE_ID, getFolderTestTypeId());
            Future<ObjectId> newFolder = asyncSession.createFolder(properties, testFolder);
            folderFutures.add(newFolder);
        }
        // wait for all folders being created
        List<ObjectId> folderIds = new ArrayList<ObjectId>();
        try {
            for (Future<ObjectId> folderFuture : folderFutures) {
                ObjectId id = folderFuture.get();
                folderIds.add(id);
            }
        } catch (Exception e) {
            addResult(createResult(UNEXPECTED_EXCEPTION, "Folder could not been created! Exception: " + e.getMessage(), e, true));
        }
        // check children of test folder
        int count = countChildren(testFolder);
        f = createResult(FAILURE, "Test folder should have " + numOfFolders + " children but has " + count + "!");
        addResult(assertEquals(count, numOfFolders, null, f));
        // get folders
        Map<String, Future<CmisObject>> getObjectFutures = new HashMap<String, Future<CmisObject>>();
        for (ObjectId folderId : folderIds) {
            Future<CmisObject> getObjectFuture = asyncSession.getObject(folderId, SELECT_ALL_NO_CACHE_OC);
            getObjectFutures.put(folderId.getId(), getObjectFuture);
        }
        // wait for all folders being fetched
        List<String> paths = new ArrayList<String>();
        try {
            for (Map.Entry<String, Future<CmisObject>> getObjectFuture : getObjectFutures.entrySet()) {
                CmisObject object = getObjectFuture.getValue().get();
                f = createResult(FAILURE, "Fetching folder failed!");
                addResult(assertIsTrue(object instanceof Folder, null, f));
                if (object != null) {
                    f = createResult(FAILURE, "Fetched wrong folder!");
                    addResult(assertEquals(getObjectFuture.getKey(), object.getId(), null, f));
                    paths.add(((Folder) object).getPath());
                }
            }
        } catch (Exception e) {
            addResult(createResult(UNEXPECTED_EXCEPTION, "Folders could not been fetched! Exception: " + e.getMessage(), e, true));
        }
        // get folders by path
        Map<String, Future<CmisObject>> getObjectByPathFutures = new HashMap<String, Future<CmisObject>>();
        for (String path : paths) {
            Future<CmisObject> getObjectByPathFuture = asyncSession.getObjectByPath(path, SELECT_ALL_NO_CACHE_OC);
            getObjectByPathFutures.put(path, getObjectByPathFuture);
        }
        // wait for all folders being fetched
        try {
            for (Map.Entry<String, Future<CmisObject>> getObjectByPathFuture : getObjectByPathFutures.entrySet()) {
                CmisObject object = getObjectByPathFuture.getValue().get();
                f = createResult(FAILURE, "Fetching folder failed!");
                addResult(assertIsTrue(object instanceof Folder, null, f));
                if (object != null) {
                    f = createResult(FAILURE, "Fetched wrong folder!");
                    addResult(assertEquals(getObjectByPathFuture.getKey(), ((Folder) object).getPath(), null, f));
                }
            }
        } catch (Exception e) {
            addResult(createResult(UNEXPECTED_EXCEPTION, "Folders could not been fetched! Exception: " + e.getMessage(), e, true));
        }
        // delete folders
        List<Future<?>> delFutures = new ArrayList<Future<?>>();
        for (ObjectId folderId : folderIds) {
            Future<?> delFuture = asyncSession.deleteTree(folderId, true, UnfileObject.DELETE, true);
            delFutures.add(delFuture);
        }
        // wait for all folders being deleted
        try {
            for (Future<?> delFuture : delFutures) {
                delFuture.get();
            }
        } catch (Exception e) {
            addResult(createResult(UNEXPECTED_EXCEPTION, "Folder could not been deleted! Exception: " + e.getMessage(), e, true));
        }
        // check children of 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 " + numOfFolders + " folders."));
}
Also used : ObjectId(org.apache.chemistry.opencmis.client.api.ObjectId) 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) AbstractExecutorServiceAsyncSession(org.apache.chemistry.opencmis.client.runtime.async.AbstractExecutorServiceAsyncSession) CmisTestResult(org.apache.chemistry.opencmis.tck.CmisTestResult) Future(java.util.concurrent.Future) CmisObject(org.apache.chemistry.opencmis.client.api.CmisObject) UnfileObject(org.apache.chemistry.opencmis.commons.enums.UnfileObject) CmisObject(org.apache.chemistry.opencmis.client.api.CmisObject) HashMap(java.util.HashMap) Map(java.util.Map)

Example 9 with ObjectId

use of org.apache.chemistry.opencmis.client.api.ObjectId 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 10 with ObjectId

use of org.apache.chemistry.opencmis.client.api.ObjectId 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)

Aggregations

ObjectId (org.apache.chemistry.opencmis.client.api.ObjectId)22 HashMap (java.util.HashMap)17 Document (org.apache.chemistry.opencmis.client.api.Document)17 Folder (org.apache.chemistry.opencmis.client.api.Folder)13 CmisTestResult (org.apache.chemistry.opencmis.tck.CmisTestResult)12 ContentStream (org.apache.chemistry.opencmis.commons.data.ContentStream)9 ByteArrayInputStream (java.io.ByteArrayInputStream)8 ContentStreamImpl (org.apache.chemistry.opencmis.commons.impl.dataobjects.ContentStreamImpl)8 CmisObject (org.apache.chemistry.opencmis.client.api.CmisObject)7 DocumentTypeDefinition (org.apache.chemistry.opencmis.commons.definitions.DocumentTypeDefinition)7 CmisObjectNotFoundException (org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException)7 CmisConstraintException (org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException)6 ArrayList (java.util.ArrayList)5 FileableCmisObject (org.apache.chemistry.opencmis.client.api.FileableCmisObject)5 CmisInvalidArgumentException (org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException)5 Map (java.util.Map)4 AlfrescoDocument (org.alfresco.cmis.client.AlfrescoDocument)4 AlfrescoFolder (org.alfresco.cmis.client.AlfrescoFolder)4 VersionableAspectTest (org.alfresco.repo.version.VersionableAspectTest)4 SiteInformation (org.alfresco.rest.api.tests.RepoService.SiteInformation)4