Search in sources :

Example 41 with CmisTestResult

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

the class BaseTypesTest method run.

@Override
public void run(Session session) {
    CmisTestResult failure;
    // check base types
    Set<String> cmisTypes = new HashSet<String>();
    cmisTypes.add(BaseTypeId.CMIS_DOCUMENT.value());
    cmisTypes.add(BaseTypeId.CMIS_FOLDER.value());
    cmisTypes.add(BaseTypeId.CMIS_RELATIONSHIP.value());
    cmisTypes.add(BaseTypeId.CMIS_POLICY.value());
    if (session.getRepositoryInfo().getCmisVersion() != CmisVersion.CMIS_1_0) {
        cmisTypes.add(BaseTypeId.CMIS_ITEM.value());
        cmisTypes.add(BaseTypeId.CMIS_SECONDARY.value());
    }
    for (TypeDefinition typeDef : session.getTypeChildren(null, false)) {
        String typeId = typeDef.getId();
        if (typeId == null || !cmisTypes.contains(typeId)) {
            addResult(createResult(FAILURE, "Base type has an invalid ID: " + typeId));
        }
        if (typeDef.getPropertyDefinitions() != null && !typeDef.getPropertyDefinitions().isEmpty()) {
            addResult(createResult(WARNING, "Property type definitions were not requested but delivered. Type ID: " + typeId));
        }
    }
    // document
    try {
        TypeDefinition documentType = session.getTypeDefinition(BaseTypeId.CMIS_DOCUMENT.value());
        addResult(checkTypeDefinition(session, documentType, "Document type spec compliance: " + documentType.getId()));
        failure = createResult(FAILURE, "Document type has the wrong base type: " + documentType.getBaseTypeId());
        addResult(assertEquals(BaseTypeId.CMIS_DOCUMENT, documentType.getBaseTypeId(), null, failure));
    } catch (CmisObjectNotFoundException e) {
        addResult(createResult(FAILURE, "Document type not available!", e, false));
    }
    // folder
    try {
        TypeDefinition folderType = session.getTypeDefinition(BaseTypeId.CMIS_FOLDER.value());
        addResult(checkTypeDefinition(session, folderType, "Folder type spec compliance: " + folderType.getId()));
        failure = createResult(FAILURE, "Folder type has the wrong base type: " + folderType.getBaseTypeId());
        addResult(assertEquals(BaseTypeId.CMIS_FOLDER, folderType.getBaseTypeId(), null, failure));
    } catch (CmisObjectNotFoundException e) {
        addResult(createResult(FAILURE, "Folder type not available!", e, false));
    }
    // relationship
    try {
        TypeDefinition relationshipType = session.getTypeDefinition(BaseTypeId.CMIS_RELATIONSHIP.value());
        addResult(checkTypeDefinition(session, relationshipType, "Relationship type spec compliance: " + relationshipType.getId()));
        failure = createResult(FAILURE, "Relationship type has the wrong base type: " + relationshipType.getBaseTypeId());
        addResult(assertEquals(BaseTypeId.CMIS_RELATIONSHIP, relationshipType.getBaseTypeId(), null, failure));
    } catch (CmisObjectNotFoundException e) {
        addResult(createResult(WARNING, "Relationship type not available!", e, false));
    }
    // policy
    try {
        TypeDefinition policyType = session.getTypeDefinition(BaseTypeId.CMIS_POLICY.value());
        addResult(checkTypeDefinition(session, policyType, "Policy type spec compliance: " + policyType.getId()));
        failure = createResult(FAILURE, "Policy type has the wrong base type: " + policyType.getBaseTypeId());
        addResult(assertEquals(BaseTypeId.CMIS_POLICY, policyType.getBaseTypeId(), null, failure));
    } catch (CmisInvalidArgumentException e) {
        addResult(createResult(WARNING, "Policy type not available!", e, false));
    } catch (CmisObjectNotFoundException e) {
        addResult(createResult(WARNING, "Policy type not available!", e, false));
    }
    // CMIS 1.1 types
    if (session.getRepositoryInfo().getCmisVersion() == CmisVersion.CMIS_1_1) {
        // item
        try {
            TypeDefinition itemType = session.getTypeDefinition(BaseTypeId.CMIS_ITEM.value());
            addResult(checkTypeDefinition(session, itemType, "Item type spec compliance: " + itemType.getId()));
            failure = createResult(FAILURE, "Item type has the wrong base type: " + itemType.getBaseTypeId());
            addResult(assertEquals(BaseTypeId.CMIS_ITEM, itemType.getBaseTypeId(), null, failure));
        } catch (CmisInvalidArgumentException e) {
            addResult(createResult(WARNING, "Item type not available!", e, false));
        } catch (CmisObjectNotFoundException e) {
            addResult(createResult(WARNING, "Item type not available!", e, false));
        }
        // secondary type
        try {
            TypeDefinition secondaryType = session.getTypeDefinition(BaseTypeId.CMIS_SECONDARY.value());
            addResult(checkTypeDefinition(session, secondaryType, "Secondary type spec compliance: " + secondaryType.getId()));
            failure = createResult(FAILURE, "Secondary type has the wrong base type: " + secondaryType.getBaseTypeId());
            addResult(assertEquals(BaseTypeId.CMIS_SECONDARY, secondaryType.getBaseTypeId(), null, failure));
        } catch (CmisInvalidArgumentException e) {
            addResult(createResult(WARNING, "Secondary type not available!", e, false));
        } catch (CmisObjectNotFoundException e) {
            addResult(createResult(WARNING, "Secondary type not available!", e, false));
        }
    } else {
        try {
            session.getTypeDefinition(BaseTypeId.CMIS_ITEM.value());
            addResult(createResult(FAILURE, "CMIS 1.0 repository returns cmis:item type definition!"));
        } catch (CmisBaseException e) {
        // expected
        }
        try {
            session.getTypeDefinition(BaseTypeId.CMIS_SECONDARY.value());
            addResult(createResult(FAILURE, "CMIS 1.0 repository returns cmis:secondary type definition!"));
        } catch (CmisBaseException e) {
        // expected
        }
    }
    // simple getTypeChildren paging test - skipping over all base types mut
    // return an empty list
    TypeDefinitionList typeDefinitionList = session.getBinding().getRepositoryService().getTypeChildren(session.getRepositoryInfo().getId(), null, false, BigInteger.valueOf(100), BigInteger.valueOf(6), null);
    if (typeDefinitionList == null) {
        addResult(createResult(FAILURE, "getTypeChildren() returned nothing!"));
    } else {
        if (typeDefinitionList.getList() != null && !typeDefinitionList.getList().isEmpty()) {
            addResult(createResult(FAILURE, "A getTypeChildren() call on the base types must retrun an empty list if skipCount is >= 6! The repository returned a list of " + typeDefinitionList.getList().size() + " elements."));
        }
        if (Boolean.TRUE.equals(typeDefinitionList.hasMoreItems())) {
            addResult(createResult(FAILURE, "A getTypeChildren() call on the base types must retrun an empty list if skipCount is >= 6! The repository returned hasMoreItems == true."));
        }
    }
    // test getTypeDescendants()
    int numOfTypes = runTypeChecks(session, session.getTypeDescendants(null, -1, true));
    addResult(createInfoResult("Checked " + numOfTypes + " type definitions."));
}
Also used : CmisObjectNotFoundException(org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException) CmisBaseException(org.apache.chemistry.opencmis.commons.exceptions.CmisBaseException) TypeDefinitionList(org.apache.chemistry.opencmis.commons.definitions.TypeDefinitionList) CmisTestResult(org.apache.chemistry.opencmis.tck.CmisTestResult) CmisInvalidArgumentException(org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException) HashSet(java.util.HashSet) TypeDefinition(org.apache.chemistry.opencmis.commons.definitions.TypeDefinition)

Example 42 with CmisTestResult

use of org.apache.chemistry.opencmis.tck.CmisTestResult in project alfresco-remote-api by Alfresco.

the class BulkUpdatePropertiesCustomTest method run.

@Override
public void run(Session session) {
    if (session.getRepositoryInfo().getCmisVersion() == CmisVersion.CMIS_1_0) {
        addResult(createResult(SKIPPED, "Bulk Update Properties is not supported by CMIS 1.0. Test skipped!"));
        return;
    }
    CmisTestResult failure = null;
    int numOfObjects = 25;
    // create a test folder
    Folder testFolder = createTestFolder(session);
    try {
        Map<String, Folder> folders = new HashMap<String, Folder>();
        Map<String, Document> documents = new HashMap<String, Document>();
        // create folders and documents
        for (int i = 0; i < numOfObjects; i++) {
            Folder newFolder = createFolder(session, testFolder, "bufolder" + i);
            folders.put(newFolder.getId(), newFolder);
            Document newDocument = createDocument(session, newFolder, "budoc" + i + ".txt", CONTENT);
            documents.put(newDocument.getId(), newDocument);
        }
        // update cmis:description of all the documents
        List<CmisObject> objects = new ArrayList<CmisObject>(documents.values());
        Map<String, Object> properties = new HashMap<String, Object>();
        properties.put(PropertyIds.DESCRIPTION, NEW_DESCRIPTION_VALUE);
        List<BulkUpdateObjectIdAndChangeToken> updatedIds = session.bulkUpdateProperties(objects, properties, null, null);
        // check the result
        if (getBinding() == BindingType.WEBSERVICES) {
            addResult(createResult(INFO, "The Web Services binding does not return the updated ids." + " This issue has to be clarified by the CMIS TC and the test to adopted later."));
        } else {
            if (updatedIds == null || updatedIds.isEmpty()) {
                addResult(createResult(FAILURE, "Bulk Update Properties did not update any documents!"));
            } else {
                failure = createResult(FAILURE, "Bulk Update Properties did not update all test documents!");
                addResult(assertEquals(documents.size(), updatedIds.size(), null, failure));
            }
        }
        // check all documents
        for (Folder folder : folders.values()) {
            List<CmisObject> children = new ArrayList<CmisObject>();
            for (CmisObject child : folder.getChildren(SELECT_ALL_NO_CACHE_OC)) {
                children.add(child);
            }
            if (children.size() != 1) {
                String errorMessage = "Test folder should have exactly one child, but it has " + children.size() + "!";
                addResult(createResult(FAILURE, errorMessage));
            } else {
                failure = createResult(FAILURE, "Document does not have the new description! Id: " + children.get(0).getId());
                addResult(assertEquals(NEW_DESCRIPTION_VALUE, children.get(0).getDescription(), null, failure));
            }
        }
        // delete folders and documents
        for (Folder folder : folders.values()) {
            folder.deleteTree(true, null, true);
        }
    } finally {
        // delete the test folder
        deleteTestFolder();
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Folder(org.apache.chemistry.opencmis.client.api.Folder) Document(org.apache.chemistry.opencmis.client.api.Document) BulkUpdateObjectIdAndChangeToken(org.apache.chemistry.opencmis.commons.data.BulkUpdateObjectIdAndChangeToken) CmisTestResult(org.apache.chemistry.opencmis.tck.CmisTestResult) CmisObject(org.apache.chemistry.opencmis.client.api.CmisObject) CmisObject(org.apache.chemistry.opencmis.client.api.CmisObject)

Example 43 with CmisTestResult

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

the class AbstractSessionTest method createFolder.

/**
 * Creates a folder.
 */
protected Folder createFolder(Session session, Folder parent, String name, String objectTypeId) {
    if (parent == null) {
        throw new IllegalArgumentException("Parent is not set!");
    }
    if (name == null) {
        throw new IllegalArgumentException("Name is not set!");
    }
    if (objectTypeId == null) {
        throw new IllegalArgumentException("Object Type ID is not set!");
    }
    // check type
    ObjectType type;
    try {
        type = session.getTypeDefinition(objectTypeId);
    } catch (CmisObjectNotFoundException e) {
        addResult(createResult(UNEXPECTED_EXCEPTION, "Folder type '" + objectTypeId + "' is not available: " + e.getMessage(), e, true));
        return null;
    }
    if (Boolean.FALSE.equals(type.isCreatable())) {
        addResult(createResult(SKIPPED, "Folder type '" + objectTypeId + "' is not creatable!", true));
        return null;
    }
    // create
    Map<String, Object> properties = new HashMap<String, Object>();
    properties.put(PropertyIds.NAME, name);
    properties.put(PropertyIds.OBJECT_TYPE_ID, objectTypeId);
    Folder result = null;
    try {
        // create the folder
        result = parent.createFolder(properties, null, null, null, SELECT_ALL_NO_CACHE_OC);
    } catch (CmisBaseException e) {
        addResult(createResult(UNEXPECTED_EXCEPTION, "Folder could not be created! Exception: " + e.getMessage(), e, true));
        return null;
    }
    try {
        CmisTestResult f;
        // check folder name
        f = createResult(FAILURE, "Folder name does not match!", false);
        addResult(assertEquals(name, result.getName(), null, f));
        // check the new folder
        String[] propertiesToCheck = new String[result.getType().getPropertyDefinitions().size()];
        int i = 0;
        for (String propId : result.getType().getPropertyDefinitions().keySet()) {
            propertiesToCheck[i++] = propId;
        }
        addResult(checkObject(session, result, propertiesToCheck, "New folder object spec compliance"));
        // check object parents
        List<Folder> objectParents = result.getParents();
        f = createResult(FAILURE, "Newly created folder has no or more than one parent! ID: " + result.getId(), true);
        addResult(assertEquals(1, objectParents.size(), null, f));
        f = createResult(FAILURE, "First object parent of the newly created folder does not match parent! ID: " + result.getId(), true);
        assertShallowEquals(parent, objectParents.get(0), null, f);
        // check folder parent
        Folder folderParent = result.getFolderParent();
        f = createResult(FAILURE, "Newly created folder has no folder parent! ID: " + result.getId(), true);
        addResult(assertNotNull(folderParent, null, f));
        f = createResult(FAILURE, "Folder parent of the newly created folder does not match parent! ID: " + result.getId(), true);
        assertShallowEquals(parent, folderParent, null, f);
        // check children of parent
        boolean found = false;
        for (CmisObject child : parent.getChildren(SELECT_ALL_NO_CACHE_OC)) {
            if (child == null) {
                addResult(createResult(FAILURE, "Parent folder contains a null child!", true));
            } else {
                if (result.getId().equals(child.getId())) {
                    found = true;
                    f = createResult(FAILURE, "Folder and parent child don't match! ID: " + result.getId(), true);
                    assertShallowEquals(result, child, null, f);
                    break;
                }
            }
        }
        if (!found) {
            addResult(createResult(FAILURE, "Folder is not a child of the parent folder! ID: " + result.getId(), true));
        }
    } catch (CmisBaseException e) {
        addResult(createResult(UNEXPECTED_EXCEPTION, "Newly created folder is invalid! Exception: " + e.getMessage(), e, true));
    }
    return result;
}
Also used : HashMap(java.util.HashMap) Folder(org.apache.chemistry.opencmis.client.api.Folder) ObjectType(org.apache.chemistry.opencmis.client.api.ObjectType) CmisObjectNotFoundException(org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException) CmisBaseException(org.apache.chemistry.opencmis.commons.exceptions.CmisBaseException) 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) CmisObject(org.apache.chemistry.opencmis.client.api.CmisObject)

Example 44 with CmisTestResult

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

the class AbstractSessionTest method assertEquals.

protected CmisTestResult assertEquals(AllowableActions expected, AllowableActions 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 allowable actions are null, but actual allowable actions are not!");
        addResultChild(failure, f);
        return failure;
    }
    if (actual == null) {
        f = createResult(FAILURE, "Actual allowable actions are null, but expected allowable actions are not!");
        addResultChild(failure, f);
        return failure;
    }
    f = createResult(FAILURE, "Allowable action sets don't match!");
    addResult(results, assertEqualSet(expected.getAllowableActions(), actual.getAllowableActions(), null, f));
    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 45 with CmisTestResult

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

the class AbstractSessionTest method assertEquals.

protected CmisTestResult assertEquals(PropertyDefinition<?> expected, PropertyDefinition<?> 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 property defintion is null, but actual property defintion is not!");
        addResultChild(failure, f);
        return failure;
    }
    if (actual == null) {
        f = createResult(FAILURE, "Actual property defintion is null, but expected property defintion is not!");
        addResultChild(failure, f);
        return failure;
    }
    f = createResult(FAILURE, "Property IDs don't match!");
    addResult(results, assertEquals(expected.getId(), actual.getId(), null, f));
    f = createResult(FAILURE, "Local names don't match!");
    addResult(results, assertEquals(expected.getLocalName(), actual.getLocalName(), null, f));
    f = createResult(FAILURE, "Local namespaces don't match!");
    addResult(results, assertEquals(expected.getLocalNamespace(), actual.getLocalNamespace(), null, f));
    f = createResult(FAILURE, "Display names don't match!");
    addResult(results, assertEquals(expected.getDisplayName(), actual.getDisplayName(), null, f));
    f = createResult(FAILURE, "Query names don't match!");
    addResult(results, assertEquals(expected.getQueryName(), actual.getQueryName(), null, f));
    f = createResult(FAILURE, "Property types don't match!");
    addResult(results, assertEquals(expected.getPropertyType(), actual.getPropertyType(), null, f));
    f = createResult(FAILURE, "Cardinalities don't match!");
    addResult(results, assertEquals(expected.getCardinality(), actual.getCardinality(), null, f));
    f = createResult(FAILURE, "Descriptions don't match!");
    addResult(results, assertEquals(expected.getDescription(), actual.getDescription(), null, f));
    f = createResult(FAILURE, "Updatability flags don't match!");
    addResult(results, assertEquals(expected.getUpdatability(), actual.getUpdatability(), null, f));
    f = createResult(FAILURE, "Default values don't match!");
    addResult(results, assertEqualLists(expected.getDefaultValue(), actual.getDefaultValue(), null, f));
    f = createResult(FAILURE, "Inherited flags don't match!");
    addResult(results, assertEquals(expected.isInherited(), actual.isInherited(), null, f));
    f = createResult(FAILURE, "Required flags don't match!");
    addResult(results, assertEquals(expected.isRequired(), actual.isRequired(), null, f));
    f = createResult(FAILURE, "Queryable flags don't match!");
    addResult(results, assertEquals(expected.isQueryable(), actual.isQueryable(), null, f));
    f = createResult(FAILURE, "Orderable flags don't match!");
    addResult(results, assertEquals(expected.isOrderable(), actual.isOrderable(), null, f));
    f = createResult(FAILURE, "Open choice flags don't match!");
    addResult(results, assertEquals(expected.isOpenChoice(), actual.isOpenChoice(), null, f));
    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)

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