Search in sources :

Example 66 with CmisTestResult

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

the class BaseTypesTest method runTypeChecks.

private int runTypeChecks(Session session, List<Tree<ObjectType>> types) {
    if (types == null) {
        return 0;
    }
    int numOfTypes = 0;
    CmisTestResult failure;
    for (Tree<ObjectType> tree : types) {
        failure = createResult(FAILURE, "Types tree contains null leaf!");
        addResult(assertNotNull(tree, null, failure));
        if (tree != null) {
            numOfTypes++;
            addResult(checkTypeDefinition(session, tree.getItem(), "Type spec compliance: " + tree.getItem().getId()));
            // clear the cache to ensure that the type definition is
            // reloaded from the repository
            session.clear();
            try {
                TypeDefinition reloadedType = session.getTypeDefinition(tree.getItem().getId());
                addResult(checkTypeDefinition(session, reloadedType, "Type spec compliance: " + (reloadedType == null ? "?" : reloadedType.getId())));
                failure = createResult(FAILURE, "Type fetched via getTypeDescendants() is does not macth type fetched via getTypeDefinition(): " + tree.getItem().getId());
                addResult(assertEquals(tree.getItem(), reloadedType, null, failure));
            } catch (CmisObjectNotFoundException e) {
                addResult(createResult(FAILURE, "Type fetched via getTypeDescendants() is not available via getTypeDefinition(): " + tree.getItem().getId(), e, false));
            }
            // clear the cache again to ensure that the type definition
            // children are reloaded from the repository
            session.clear();
            try {
                ItemIterable<ObjectType> reloadedTypeChildren = session.getTypeChildren(tree.getItem().getId(), true);
                // check type children
                Map<String, ObjectType> typeChilden = new HashMap<String, ObjectType>();
                for (ObjectType childType : reloadedTypeChildren) {
                    if (childType == null) {
                        addResult(createResult(FAILURE, "The list of types contains a null entry!"));
                        continue;
                    }
                    addResult(checkTypeDefinition(session, childType, "Type spec compliance: " + childType.getId()));
                    typeChilden.put(childType.getId(), childType);
                }
                // compare type children and type descendants
                if (tree.getChildren() == null) {
                    failure = createResult(FAILURE, "Type children fetched via getTypeDescendants() don't match type children fetched via getTypeChildren(): " + tree.getItem().getId());
                    addResult(assertEquals(0, typeChilden.size(), null, failure));
                } else {
                    // collect the children
                    Map<String, ObjectType> typeDescendants = new HashMap<String, ObjectType>();
                    for (Tree<ObjectType> childType : tree.getChildren()) {
                        if ((childType != null) && (childType.getItem() != null)) {
                            typeDescendants.put(childType.getItem().getId(), childType.getItem());
                        }
                    }
                    failure = createResult(FAILURE, "Type children fetched via getTypeDescendants() don't match type children fetched via getTypeChildren(): " + tree.getItem().getId());
                    addResult(assertEquals(typeDescendants.size(), typeChilden.size(), null, failure));
                    for (ObjectType compareType : typeDescendants.values()) {
                        failure = createResult(FAILURE, "Type fetched via getTypeDescendants() doesn't match type fetched via getTypeChildren(): " + tree.getItem().getId());
                        addResult(assertEquals(compareType, typeChilden.get(compareType.getId()), null, failure));
                    }
                }
            } catch (CmisObjectNotFoundException e) {
                addResult(createResult(FAILURE, "Type children fetched via getTypeDescendants() are not available via getTypeChildren(): " + tree.getItem().getId(), e, false));
            }
            numOfTypes += runTypeChecks(session, tree.getChildren());
        }
    }
    return numOfTypes;
}
Also used : ObjectType(org.apache.chemistry.opencmis.client.api.ObjectType) CmisObjectNotFoundException(org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException) HashMap(java.util.HashMap) CmisTestResult(org.apache.chemistry.opencmis.tck.CmisTestResult) TypeDefinition(org.apache.chemistry.opencmis.commons.definitions.TypeDefinition)

Example 67 with CmisTestResult

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

the class CreateAndDeleteTypeTest method createTypeWithoutProperties.

private void createTypeWithoutProperties(Session session, ObjectType parentType) {
    CmisTestResult failure = null;
    // define the type
    DocumentTypeDefinitionImpl newTypeDef = createDocumentTypeDefinition(session, "tck:testid_without_properties", parentType);
    // create the type
    ObjectType newType = createType(session, newTypeDef);
    if (newType == null) {
        return;
    }
    // get the type
    ObjectType newType2 = null;
    try {
        newType2 = session.getTypeDefinition(newType.getId());
        // assert type definitions
        failure = createResult(FAILURE, "The type definition returned by createType() doesn't match the type definition returned by getTypeDefinition()!");
        addResult(assertEquals(newType, newType2, null, failure));
    } catch (CmisObjectNotFoundException e) {
        addResult(createResult(FAILURE, "Newly created type can not be fetched. Id: " + newType.getId(), e, false));
    }
    // delete the type
    deleteType(session, newType.getId());
}
Also used : ObjectType(org.apache.chemistry.opencmis.client.api.ObjectType) CmisObjectNotFoundException(org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException) CmisTestResult(org.apache.chemistry.opencmis.tck.CmisTestResult) DocumentTypeDefinitionImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.DocumentTypeDefinitionImpl)

Example 68 with CmisTestResult

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

the class SecondaryTypesTest method detachSecondaryType.

private void detachSecondaryType(Session session, Document doc, ObjectType secondaryTestType) {
    CmisTestResult f;
    List<String> secondaryTypesId = new ArrayList<String>();
    for (SecondaryType secType : doc.getSecondaryTypes()) {
        if (!secondaryTestType.getId().equals(secType.getId())) {
            secondaryTypesId.add(secType.getId());
        }
    }
    Map<String, Object> properties = new HashMap<String, Object>();
    properties.put(PropertyIds.SECONDARY_OBJECT_TYPE_IDS, secondaryTypesId);
    // detach secondary type
    ObjectId newId = doc.updateProperties(properties);
    Document newDoc = (Document) session.getObject(newId, SELECT_ALL_NO_CACHE_OC);
    boolean found = false;
    if (newDoc.getSecondaryTypes() != null) {
        for (SecondaryType secType : newDoc.getSecondaryTypes()) {
            if (secondaryTestType.getId().equals(secType.getId())) {
                found = true;
                break;
            }
        }
    }
    f = createResult(FAILURE, "Document still has the detached secondary type!");
    addResult(assertIsFalse(found, null, f));
    // check properties
    ObjectType primaryType = newDoc.getType();
    List<SecondaryType> secondaryTypes = newDoc.getSecondaryTypes();
    for (Property<?> prop : doc.getProperties()) {
        if (!primaryType.getPropertyDefinitions().containsKey(prop.getId())) {
            f = createResult(FAILURE, "Property '" + prop.getId() + "' is neither defined by the primary type nor by a secondary type!");
            if (secondaryTypes == null) {
                addResult(f);
            } else {
                boolean foundProperty = false;
                for (SecondaryType secondaryType : secondaryTypes) {
                    if (secondaryType.getPropertyDefinitions() != null && secondaryType.getPropertyDefinitions().containsKey(prop.getId())) {
                        foundProperty = true;
                        break;
                    }
                }
                addResult(assertIsTrue(foundProperty, null, f));
            }
        }
    }
}
Also used : SecondaryType(org.apache.chemistry.opencmis.client.api.SecondaryType) HashMap(java.util.HashMap) ObjectId(org.apache.chemistry.opencmis.client.api.ObjectId) ArrayList(java.util.ArrayList) Document(org.apache.chemistry.opencmis.client.api.Document) ObjectType(org.apache.chemistry.opencmis.client.api.ObjectType) CmisTestResult(org.apache.chemistry.opencmis.tck.CmisTestResult)

Example 69 with CmisTestResult

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

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

the class VersionDeleteTest method deleteVersion.

private void deleteVersion(Document versionDoc, Document previousDoc, int version) {
    CmisTestResult f;
    // check Allowable Action
    if (!versionDoc.hasAllowableAction(Action.CAN_DELETE_OBJECT)) {
        addResult(createResult(WARNING, "Version " + version + " does not have the Allowable Action 'canDeleteObject'."));
        return;
    }
    // get version history before delete
    List<Document> versionsBefore = versionDoc.getAllVersions();
    // delete and check
    try {
        versionDoc.delete(false);
    } catch (CmisInvalidArgumentException iae) {
        addResult(createResult(WARNING, "Deletion of version " + version + " failed with an invalidArgument exception. " + "Removing just one version doesn't seem to be supported."));
        return;
    } catch (CmisConstraintException ce) {
        addResult(createResult(WARNING, "Deletion of version " + version + " failed with an constraint exception. " + "Removing just one version doesn't seem to be supported."));
        return;
    }
    f = createResult(FAILURE, "Deleted version " + version + " still exists!");
    addResult(assertIsFalse(exists(versionDoc), null, f));
    // check version history after delete
    if (previousDoc != null) {
        List<Document> versionsAfter = previousDoc.getAllVersions();
        f = createResult(FAILURE, "After version " + version + " has been deleted, the version history should consist of " + (versionsBefore.size() - 1) + "  documents but is has " + versionsAfter.size() + " !");
        addResult(assertEquals(versionsBefore.size() - 1, versionsAfter.size(), null, f));
    }
}
Also used : CmisConstraintException(org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException) CmisTestResult(org.apache.chemistry.opencmis.tck.CmisTestResult) CmisInvalidArgumentException(org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException) 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