Search in sources :

Example 1 with Item

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

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

the class CreateAndDeleteItemTest method run.

@Override
public void run(Session session) {
    if (session.getRepositoryInfo().getCmisVersion() == CmisVersion.CMIS_1_0) {
        addResult(createResult(SKIPPED, "Items are not supported by CMIS 1.0. Test skipped!"));
        return;
    }
    if (hasItems(session)) {
        CmisTestResult f;
        int numOfItems = 20;
        // create a test folder
        Folder testFolder = createTestFolder(session);
        try {
            Map<String, Item> items = new HashMap<String, Item>();
            // create items
            for (int i = 0; i < numOfItems; i++) {
                Item newItem = createItem(session, testFolder, "item" + i);
                items.put(newItem.getId(), newItem);
            }
            // check if all items are there
            ItemIterable<CmisObject> children = testFolder.getChildren(SELECT_ALL_NO_CACHE_OC);
            List<String> childrenIds = new ArrayList<String>();
            for (CmisObject child : children) {
                if (child != null) {
                    childrenIds.add(child.getId());
                    Item item = items.get(child.getId());
                    f = createResult(FAILURE, "Item and test folder child don't match! Id: " + child.getId());
                    addResult(assertShallowEquals(item, child, null, f));
                }
            }
            f = createResult(FAILURE, "Number of created items does not match the number of existing items!");
            addResult(assertEquals(numOfItems, childrenIds.size(), null, f));
            for (Item item : items.values()) {
                if (!childrenIds.contains(item.getId())) {
                    addResult(createResult(FAILURE, "Created item not found in test folder children! Id: " + item.getId()));
                }
            }
            // delete all item
            for (Item item : items.values()) {
                item.delete(true);
                f = createResult(FAILURE, "Item should not exist anymore but it is still there! Id: " + item.getId());
                addResult(assertIsFalse(exists(item), null, f));
            }
        } finally {
            // delete the test folder
            deleteTestFolder();
        }
        addResult(createInfoResult("Tested the creation and deletion of " + numOfItems + " items."));
    } else {
        addResult(createResult(SKIPPED, "Items not supported. Test skipped!"));
    }
}
Also used : Item(org.apache.chemistry.opencmis.client.api.Item) HashMap(java.util.HashMap) CmisTestResult(org.apache.chemistry.opencmis.tck.CmisTestResult) ArrayList(java.util.ArrayList) CmisObject(org.apache.chemistry.opencmis.client.api.CmisObject) Folder(org.apache.chemistry.opencmis.client.api.Folder)

Aggregations

HashMap (java.util.HashMap)2 CmisObject (org.apache.chemistry.opencmis.client.api.CmisObject)2 Folder (org.apache.chemistry.opencmis.client.api.Folder)2 Item (org.apache.chemistry.opencmis.client.api.Item)2 CmisTestResult (org.apache.chemistry.opencmis.tck.CmisTestResult)2 ArrayList (java.util.ArrayList)1 FileableCmisObject (org.apache.chemistry.opencmis.client.api.FileableCmisObject)1 ObjectType (org.apache.chemistry.opencmis.client.api.ObjectType)1 CmisBaseException (org.apache.chemistry.opencmis.commons.exceptions.CmisBaseException)1 CmisObjectNotFoundException (org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException)1