Search in sources :

Example 51 with CmisTestResult

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

the class AbstractSessionTest method checkPropertyDefinition.

protected CmisTestResult checkPropertyDefinition(PropertyDefinition<?> propDef, String message) {
    List<CmisTestResult> results = new ArrayList<CmisTestResult>();
    CmisTestResult f;
    f = createResult(FAILURE, "Property definition is null!");
    addResult(results, assertNotNull(propDef, null, f));
    if (propDef != null) {
        f = createResult(FAILURE, "Property ID is not set!");
        addResult(results, assertStringNotEmpty(propDef.getId(), null, f));
        f = createResult(WARNING, "Local name is not set!");
        addResult(results, assertStringNotEmpty(propDef.getLocalName(), null, f));
        // f = createResult(WARNING, "Local namespace is not set!");
        // addResult(results,
        // assertStringNotEmpty(propDef.getLocalNamespace(), null, f));
        f = createResult(FAILURE, "Query name is not set!");
        addResult(results, assertStringNotEmpty(propDef.getQueryName(), null, f));
        f = createResult(WARNING, "Display name is not set!");
        addResult(results, assertStringNotEmpty(propDef.getDisplayName(), null, f));
        f = createResult(WARNING, "Description is not set!");
        addResult(results, assertStringNotEmpty(propDef.getDescription(), null, f));
        f = createResult(FAILURE, "Property type is not set!");
        addResult(results, assertNotNull(propDef.getPropertyType(), null, f));
        f = createResult(FAILURE, "Cardinality is not set!");
        addResult(results, assertNotNull(propDef.getCardinality(), null, f));
        f = createResult(FAILURE, "Updatability is not set!");
        addResult(results, assertNotNull(propDef.getUpdatability(), null, f));
        f = createResult(FAILURE, "Inherited flag is not set!");
        addResult(results, assertNotNull(propDef.isInherited(), null, f));
        f = createResult(FAILURE, "Required flag is not set!");
        addResult(results, assertNotNull(propDef.isRequired(), null, f));
        f = createResult(FAILURE, "Queryable flag is not set!");
        addResult(results, assertNotNull(propDef.isQueryable(), null, f));
        f = createResult(FAILURE, "Orderable flag is not set!");
        addResult(results, assertNotNull(propDef.isOrderable(), null, f));
    }
    CmisTestResultImpl result = createResult(getWorst(results), message);
    result.getChildren().addAll(results);
    return result.getStatus().getLevel() <= OK.getLevel() ? null : result;
}
Also used : CmisTestResult(org.apache.chemistry.opencmis.tck.CmisTestResult) ArrayList(java.util.ArrayList)

Example 52 with CmisTestResult

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

the class AbstractSessionTest method assertEqualObjectList.

protected CmisTestResult assertEqualObjectList(List<? extends CmisObject> expected, List<? extends CmisObject> actual, CmisTestResult success, CmisTestResult failure) {
    List<CmisTestResult> results = new ArrayList<CmisTestResult>();
    CmisTestResult f;
    if ((expected == null) && (actual == null)) {
        return success;
    }
    if (expected == null) {
        f = createResult(FAILURE, "Expected list of CMIS objects is null, but actual list of CMIS objects is not!");
        addResultChild(failure, f);
        return failure;
    }
    if (actual == null) {
        f = createResult(FAILURE, "Actual list of CMIS objects is null, but expected list of CMIS objects is not!");
        addResultChild(failure, f);
        return failure;
    }
    if (expected.size() != actual.size()) {
        addResult(results, createResult(CmisTestResultStatus.INFO, "Object list sizes don't match! expected: " + expected.size() + " / actual: " + actual.size()));
    } else {
        for (int i = 0; i < expected.size(); i++) {
            f = createResult(FAILURE, "Objects at position " + i + "  dont't match!");
            addResult(results, assertEquals(expected.get(i), actual.get(i), null, f, true, false));
        }
    }
    if (getWorst(results).getLevel() <= OK.getLevel()) {
        for (CmisTestResult result : results) {
            addResultChild(success, result);
        }
        return success;
    } else {
        for (CmisTestResult result : results) {
            addResultChild(failure, result);
        }
        return failure;
    }
}
Also used : CmisTestResult(org.apache.chemistry.opencmis.tck.CmisTestResult) ArrayList(java.util.ArrayList)

Example 53 with CmisTestResult

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

the class AbstractSessionTest method checkChildren.

protected CmisTestResult checkChildren(Session session, Folder folder, String message) {
    List<CmisTestResult> results = new ArrayList<CmisTestResult>();
    CmisTestResult f;
    if (folder == null) {
        return createResult(FAILURE, "Folder is null!");
    }
    // getChildren
    boolean supportsOrderByName = isOrderByNameSupported(session);
    OperationContext orderContext = (supportsOrderByName ? SELECT_ALL_NO_CACHE_OC_ORDER_BY_NAME : SELECT_ALL_NO_CACHE_OC);
    long childrenCount = 0;
    long childrenFolderCount = 0;
    ItemIterable<CmisObject> children = folder.getChildren(orderContext);
    int orderByNameIssues = 0;
    String lastName = null;
    for (CmisObject child : children) {
        childrenCount++;
        if (child instanceof Folder) {
            childrenFolderCount++;
        }
        checkChild(session, results, folder, child);
        if (lastName != null && child.getName() != null) {
            if (child.getName().compareToIgnoreCase(lastName) < 0) {
                orderByNameIssues++;
            }
        }
        lastName = child.getName();
    }
    if (children.getTotalNumItems() >= 0) {
        f = createResult(WARNING, "Number of children doesn't match the reported total number of items!");
        addResult(results, assertEquals(childrenCount, children.getTotalNumItems(), null, f));
    } else {
        addResult(results, createResult(WARNING, "getChildren did not report the total number of items!"));
    }
    if (supportsOrderByName) {
        f = createResult(WARNING, "Children should be ordered by cmis:name, but they are not! (It might be a collation mismtach.)");
        addResult(results, assertEquals(0, orderByNameIssues, null, f));
    } else {
        addResult(results, createResult(INFO, "Repository doesn't support Order By for getChildren()."));
    }
    // test path segments
    ObjectInFolderList pathSegementChildren = session.getBinding().getNavigationService().getChildren(session.getRepositoryInfo().getId(), folder.getId(), "cmis:objectId,cmis:name", null, null, null, null, Boolean.TRUE, BigInteger.valueOf(10), BigInteger.ZERO, null);
    if (pathSegementChildren != null && pathSegementChildren.getObjects() != null) {
        for (ObjectInFolderData objectInFolder : pathSegementChildren.getObjects()) {
            String pathSegement = objectInFolder.getPathSegment();
            String objectId = (String) objectInFolder.getObject().getProperties().getProperties().get(PropertyIds.OBJECT_ID).getFirstValue();
            if (pathSegement == null) {
                addResult(results, createResult(FAILURE, "getChildren omitted path segement! ID: " + objectId));
            } else {
                CmisObject pathSegementChild = session.getObjectByPath(folder.getPath(), pathSegement);
                f = createResult(FAILURE, "Combining the path of the parent folder and the path segement of a child returns a different object! ID: " + objectId);
                addResult(results, assertEquals(objectId, pathSegementChild.getId(), null, f));
            }
        }
    }
    if (isGetDescendantsSupported(session)) {
        long descendantsCount = 0;
        List<Tree<FileableCmisObject>> descendants = folder.getDescendants(1, SELECT_ALL_NO_CACHE_OC);
        for (Tree<FileableCmisObject> child : descendants) {
            descendantsCount++;
            if (child == null) {
                addResult(results, createResult(FAILURE, "Folder descendants contain a null tree!"));
            } else {
                checkChild(session, results, folder, child.getItem());
            }
        }
        f = createResult(FAILURE, "Number of descendants doesn't match the number of children returned by getChildren!");
        addResult(results, assertEquals(childrenCount, descendantsCount, null, f));
    } else {
        addResult(results, createResult(SKIPPED, "getDescendants is not supported."));
    }
    if (isGetFolderTreeSupported(session)) {
        long folderTreeCount = 0;
        List<Tree<FileableCmisObject>> folderTree = folder.getFolderTree(1, SELECT_ALL_NO_CACHE_OC);
        for (Tree<FileableCmisObject> child : folderTree) {
            folderTreeCount++;
            if (child == null) {
                addResult(results, createResult(FAILURE, "Folder tree contains a null tree!"));
            } else {
                checkChild(session, results, folder, child.getItem());
            }
        }
        f = createResult(FAILURE, "Number of folders doesn't match the number of folders returned by getChildren!");
        addResult(results, assertEquals(childrenFolderCount, folderTreeCount, null, f));
    } else {
        addResult(results, createResult(SKIPPED, "getFolderTree is not supported."));
    }
    // --- wrap up ---
    CmisTestResultImpl result = createResult(getWorst(results), message);
    result.getChildren().addAll(results);
    return result.getStatus().getLevel() <= OK.getLevel() ? null : result;
}
Also used : OperationContext(org.apache.chemistry.opencmis.client.api.OperationContext) ArrayList(java.util.ArrayList) Folder(org.apache.chemistry.opencmis.client.api.Folder) ObjectInFolderList(org.apache.chemistry.opencmis.commons.data.ObjectInFolderList) CmisTestResult(org.apache.chemistry.opencmis.tck.CmisTestResult) Tree(org.apache.chemistry.opencmis.client.api.Tree) FileableCmisObject(org.apache.chemistry.opencmis.client.api.FileableCmisObject) CmisObject(org.apache.chemistry.opencmis.client.api.CmisObject) FileableCmisObject(org.apache.chemistry.opencmis.client.api.FileableCmisObject) ObjectInFolderData(org.apache.chemistry.opencmis.commons.data.ObjectInFolderData)

Example 54 with CmisTestResult

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

the class AbstractSessionTest method getRepositoryInfo.

protected RepositoryInfo getRepositoryInfo(Session session) {
    RepositoryInfo ri = session.getRepositoryInfo();
    CmisTestResult failure = createResult(FAILURE, "Repository info is null!", true);
    addResult(assertNotNull(ri, null, failure));
    return ri;
}
Also used : RepositoryInfo(org.apache.chemistry.opencmis.commons.data.RepositoryInfo) CmisTestResult(org.apache.chemistry.opencmis.tck.CmisTestResult)

Example 55 with CmisTestResult

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

the class AbstractSessionTest method checkChild.

private void checkChild(Session session, List<CmisTestResult> results, Folder folder, CmisObject child) {
    CmisTestResult f;
    if (child == null) {
        addResult(results, createResult(FAILURE, "Folder contains a null child!"));
    } else {
        String[] propertiesToCheck = new String[child.getType().getPropertyDefinitions().size()];
        int i = 0;
        for (String propId : child.getType().getPropertyDefinitions().keySet()) {
            propertiesToCheck[i++] = propId;
        }
        addResult(results, checkObject(session, child, propertiesToCheck, "Child check: " + child.getId()));
        addResult(results, checkVersionHistory(session, child, propertiesToCheck, "Child version history check: " + child.getId()));
        f = createResult(FAILURE, "Child is not fileable! ID: " + child.getId() + " / Type: " + child.getType().getId());
        addResult(results, assertIsTrue(child instanceof FileableCmisObject, null, f));
        if (child instanceof FileableCmisObject) {
            FileableCmisObject fileableChild = (FileableCmisObject) child;
            Set<Action> actions = fileableChild.getAllowableActions().getAllowableActions();
            boolean hasObjectParentsAction = actions.contains(Action.CAN_GET_OBJECT_PARENTS);
            boolean hasFolderParentAction = actions.contains(Action.CAN_GET_FOLDER_PARENT);
            if (hasObjectParentsAction || hasFolderParentAction) {
                List<Folder> parents = fileableChild.getParents();
                f = createResult(FAILURE, "Child has no parents! ID: " + child.getId());
                addResult(results, assertListNotEmpty(parents, null, f));
                if (child instanceof Folder) {
                    f = createResult(FAILURE, "Child is a folder and has more than one parent! ID: " + child.getId());
                    addResult(results, assertIsFalse(parents.size() > 1, null, f));
                    Folder folderParent = ((Folder) child).getFolderParent();
                    if (folderParent == null) {
                        addResult(results, createResult(FAILURE, "getFolderParent() returns null for a non-root folder object! ID: " + child.getId()));
                    } else {
                        f = createResult(FAILURE, "getFolderParent() returns wrong parent object! ID: " + child.getId());
                        addResult(results, assertEquals(folder.getId(), folderParent.getId(), null, f));
                        if (parents.size() > 0 && parents.get(0) != null) {
                            f = createResult(FAILURE, "getFolderParent() and getParents() return different parents for a folder object! ID: " + child.getId());
                            addResult(results, assertEquals(parents.get(0).getId(), folderParent.getId(), null, f));
                        }
                    }
                }
                boolean foundParent = false;
                for (Folder parent : parents) {
                    if (parent == null) {
                        f = createResult(FAILURE, "One of childs parents is null! ID: " + child.getId());
                        addResult(results, assertListNotEmpty(parents, null, f));
                    } else if (folder.getId().equals(parent.getId())) {
                        foundParent = true;
                        break;
                    }
                }
                if (!foundParent) {
                    addResult(results, createResult(FAILURE, "Parent folder is not in parents of the child! ID: " + child.getId()));
                }
            }
            // get object by ID and compare
            CmisObject objectById = session.getObject(child.getId(), SELECT_ALL_NO_CACHE_OC);
            f = createResult(FAILURE, "Child and object fetched by ID don't match! ID: " + child.getId());
            addResult(results, assertEquals(child, objectById, null, f, false, false));
            // get object by path and compare
            List<String> paths = ((FileableCmisObject) child).getPaths();
            if (isNullOrEmpty(paths)) {
                addResult(results, createResult(FAILURE, "Child has no path! " + child.getId()));
            } else {
                for (String path : paths) {
                    CmisObject objectByPath = session.getObjectByPath(path, SELECT_ALL_NO_CACHE_OC);
                    f = createResult(FAILURE, "Child and object fetched by path don't match! ID: " + child.getId() + " / Path: " + path);
                    addResult(results, assertEquals(child, objectByPath, null, f, false, false));
                    f = createResult(FAILURE, "Object fetched by id and object fetched by path don't match! ID: " + child.getId() + " / Path: " + path);
                    addResult(results, assertEquals(objectById, objectByPath, null, f, true, true));
                }
            }
        }
        if (child instanceof Folder) {
            f = createResult(WARNING, "Child has no CAN_GET_FOLDER_PARENT allowable action! ID: " + child.getId());
            addResult(results, assertAllowableAction(child, Action.CAN_GET_FOLDER_PARENT, null, f));
        } else {
            f = createResult(WARNING, "Child has no CAN_GET_OBJECT_PARENTS allowable action! ID: " + child.getId());
            addResult(results, assertAllowableAction(child, Action.CAN_GET_OBJECT_PARENTS, null, f));
        }
    }
}
Also used : Action(org.apache.chemistry.opencmis.commons.enums.Action) CmisTestResult(org.apache.chemistry.opencmis.tck.CmisTestResult) FileableCmisObject(org.apache.chemistry.opencmis.client.api.FileableCmisObject) CmisObject(org.apache.chemistry.opencmis.client.api.CmisObject) FileableCmisObject(org.apache.chemistry.opencmis.client.api.FileableCmisObject) 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