Search in sources :

Example 1 with CmisTestResult

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

the class AbstractSessionTest method createItem.

/**
 * Creates a item.
 */
protected Item createItem(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, "Item type '" + objectTypeId + "' is not available: " + e.getMessage(), e, true));
        return null;
    }
    if (Boolean.FALSE.equals(type.isCreatable())) {
        addResult(createResult(SKIPPED, "Item 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);
    Item result = null;
    try {
        // create the item
        result = parent.createItem(properties, null, null, null, SELECT_ALL_NO_CACHE_OC);
    } catch (CmisBaseException e) {
        addResult(createResult(UNEXPECTED_EXCEPTION, "Item could not be created! Exception: " + e.getMessage(), e, true));
        return null;
    }
    try {
        CmisTestResult f;
        // check item name
        f = createResult(FAILURE, "Item name does not match!", false);
        addResult(assertEquals(name, result.getName(), null, f));
        addResult(checkObject(session, result, getAllProperties(result), "New item object spec compliance"));
    } catch (CmisBaseException e) {
        addResult(createResult(UNEXPECTED_EXCEPTION, "Newly created item is invalid! Exception: " + e.getMessage(), e, true));
    }
    // check parents
    List<Folder> parents = result.getParents(SELECT_ALL_NO_CACHE_OC);
    boolean found = false;
    for (Folder folder : parents) {
        if (parent.getId().equals(folder.getId())) {
            found = true;
            break;
        }
    }
    if (!found) {
        addResult(createResult(FAILURE, "The folder the item has been created in is not in the list of the item parents!"));
    }
    return result;
}
Also used : HashMap(java.util.HashMap) Folder(org.apache.chemistry.opencmis.client.api.Folder) ObjectType(org.apache.chemistry.opencmis.client.api.ObjectType) Item(org.apache.chemistry.opencmis.client.api.Item) 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)

Example 2 with CmisTestResult

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

the class AbstractSessionTest method assertEquals.

protected CmisTestResult assertEquals(Ace expected, Ace 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 ACE is null, but actual ACE is not!");
        addResultChild(failure, f);
        return failure;
    }
    if (actual == null) {
        f = createResult(FAILURE, "Actual ACE is null, but expected ACE is not!");
        addResultChild(failure, f);
        return failure;
    }
    f = createResult(FAILURE, "Principal IDs dont't match!");
    addResult(results, assertEquals(expected.getPrincipalId(), actual.getPrincipalId(), null, f));
    f = createResult(FAILURE, "Permissions dont't match!");
    addResult(results, assertEqualLists(expected.getPermissions(), actual.getPermissions(), 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 3 with CmisTestResult

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

the class AbstractSessionTest method deleteObject.

/**
 * Deletes an object and checks if it is deleted.
 */
protected void deleteObject(CmisObject object) {
    if (object != null) {
        if (object instanceof Folder) {
            try {
                ((Folder) object).deleteTree(true, null, true);
            } catch (CmisBaseException e) {
                addResult(createResult(UNEXPECTED_EXCEPTION, "Folder could not be deleted! Exception: " + e.getMessage(), e, true));
            }
        } else {
            try {
                object.delete(true);
            } catch (CmisBaseException e) {
                addResult(createResult(UNEXPECTED_EXCEPTION, "Object could not be deleted! Exception: " + e.getMessage(), e, true));
            }
        }
        CmisTestResult f = createResult(FAILURE, "Object should not exist anymore but it is still there! ID: " + object.getId(), true);
        addResult(assertIsFalse(exists(object), null, f));
    }
}
Also used : CmisBaseException(org.apache.chemistry.opencmis.commons.exceptions.CmisBaseException) CmisTestResult(org.apache.chemistry.opencmis.tck.CmisTestResult) Folder(org.apache.chemistry.opencmis.client.api.Folder)

Example 4 with CmisTestResult

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

the class AbstractSessionTest method assertEqualAceLists.

protected CmisTestResult assertEqualAceLists(List<Ace> expected, List<Ace> actual, CmisTestResult success, CmisTestResult failure) {
    List<CmisTestResult> results = new ArrayList<CmisTestResult>();
    CmisTestResult f;
    if (expected == null && actual == null) {
        return success;
    }
    if (expected == null) {
        return addResultChild(failure, createResult(CmisTestResultStatus.INFO, "Expected ACE list is null!"));
    }
    if (actual == null) {
        return addResultChild(failure, createResult(CmisTestResultStatus.INFO, "Actual ACE list is null!"));
    }
    if (expected.size() != actual.size()) {
        addResult(results, createResult(CmisTestResultStatus.INFO, "ACE list sizes don't match! expected: " + expected.size() + " / actual: " + actual.size()));
    } else {
        for (int i = 0; i < expected.size(); i++) {
            f = createResult(FAILURE, "ACEs at position " + i + "  dont't match!");
            addResult(results, assertEquals(expected.get(i), actual.get(i), 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 5 with CmisTestResult

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

the class AbstractSessionTest method assertEquals.

protected CmisTestResult assertEquals(Rendition expected, Rendition 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 rendition is null, but actual rendition is not!");
        addResultChild(failure, f);
        return failure;
    }
    if (actual == null) {
        f = createResult(FAILURE, "Actual rendition is null, but expected rendition is not!");
        addResultChild(failure, f);
        return failure;
    }
    f = createResult(FAILURE, "Stream IDs dont't match!");
    addResult(results, assertEquals(expected.getStreamId(), actual.getStreamId(), null, f));
    f = createResult(FAILURE, "Kinds dont't match!");
    addResult(results, assertEquals(expected.getKind(), actual.getKind(), null, f));
    f = createResult(FAILURE, "MIME types dont't match!");
    addResult(results, assertEquals(expected.getMimeType(), actual.getMimeType(), null, f));
    f = createResult(FAILURE, "Titles dont't match!");
    addResult(results, assertEquals(expected.getTitle(), actual.getTitle(), null, f));
    f = createResult(FAILURE, "Lengths dont't match!");
    addResult(results, assertEquals(expected.getLength(), actual.getLength(), null, f));
    f = createResult(FAILURE, "Heights dont't match!");
    addResult(results, assertEquals(expected.getBigHeight(), actual.getBigHeight(), null, f));
    f = createResult(FAILURE, "Widths dont't match!");
    addResult(results, assertEquals(expected.getBigWidth(), actual.getBigWidth(), null, f));
    f = createResult(FAILURE, "Rendition document IDs dont't match!");
    addResult(results, assertEquals(expected.getRenditionDocumentId(), actual.getRenditionDocumentId(), 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