Search in sources :

Example 46 with CmisTestResult

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

the class AbstractSessionTest method checkQueryName.

// --- type checks ---
protected CmisTestResult checkQueryName(String queryName, boolean isRequired, String message) {
    List<CmisTestResult> results = new ArrayList<CmisTestResult>();
    CmisTestResult f;
    if (queryName == null || queryName.length() == 0) {
        addResult(results, createResult(isRequired ? FAILURE : WARNING, "Query name is not set!"));
    } else {
        f = createResult(FAILURE, "Query name contains invalid character: ' '");
        addResult(results, assertIsTrue(queryName.indexOf(' ') < 0, null, f));
        f = createResult(FAILURE, "Query name contains invalid character: ','");
        addResult(results, assertIsTrue(queryName.indexOf(',') < 0, null, f));
        f = createResult(FAILURE, "Query name contains invalid character: '\"'");
        addResult(results, assertIsTrue(queryName.indexOf('"') < 0, null, f));
        f = createResult(FAILURE, "Query name contains invalid character: '''");
        addResult(results, assertIsTrue(queryName.indexOf('\'') < 0, null, f));
        f = createResult(FAILURE, "Query name contains invalid character: '\\'");
        addResult(results, assertIsTrue(queryName.indexOf('\\') < 0, null, f));
        f = createResult(FAILURE, "Query name contains invalid character: '.'");
        addResult(results, assertIsTrue(queryName.indexOf('.') < 0, null, f));
        f = createResult(FAILURE, "Query name contains invalid character: '('");
        addResult(results, assertIsTrue(queryName.indexOf('(') < 0, null, f));
        f = createResult(FAILURE, "Query name contains invalid character: ')'");
        addResult(results, assertIsTrue(queryName.indexOf(')') < 0, null, f));
        f = createResult(FAILURE, "Query name contains invalid character: '\\t'");
        addResult(results, assertIsTrue(queryName.indexOf('\t') < 0, null, f));
        f = createResult(FAILURE, "Query name contains invalid character: '\\n'");
        addResult(results, assertIsTrue(queryName.indexOf('\n') < 0, null, f));
        f = createResult(FAILURE, "Query name contains invalid character: '\\r'");
        addResult(results, assertIsTrue(queryName.indexOf('\r') < 0, 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 47 with CmisTestResult

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

the class AbstractSessionTest method assertEquals.

protected CmisTestResult assertEquals(ContentStream expected, ContentStream 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 stream is null, but actual stream is not!");
        addResultChild(failure, f);
        IOUtils.closeQuietly(actual);
        return failure;
    }
    if (actual == null) {
        f = createResult(FAILURE, "Actual object is null, but expected object is not!");
        addResultChild(failure, f);
        IOUtils.closeQuietly(expected);
        return failure;
    }
    f = createResult(WARNING, "Filenames don't match!");
    addResult(results, assertEquals(expected.getFileName(), actual.getFileName(), null, f));
    f = createResult(FAILURE, "MIME types don't match!");
    addResult(results, assertEquals(expected.getMimeType(), actual.getMimeType(), null, f));
    f = createResult(WARNING, "Lengths don't match!");
    addResult(results, assertEquals(expected.getBigLength(), actual.getBigLength(), null, f));
    boolean match = true;
    BufferedInputStream as = new BufferedInputStream(actual.getStream(), 64 * 1024);
    BufferedInputStream es = new BufferedInputStream(expected.getStream(), 64 * 1024);
    try {
        int ab = 0;
        int eb = 0;
        while (true) {
            if (ab > -1) {
                ab = as.read();
            }
            if (eb > -1) {
                eb = es.read();
            }
            if (ab == -1 && eb == -1) {
                break;
            }
            if (ab != eb) {
                match = false;
            }
        }
    } catch (Exception e) {
        f = createResult(UNEXPECTED_EXCEPTION, e.getMessage(), e, false);
        addResultChild(failure, f);
    }
    if (!match) {
        f = createResult(FAILURE, "Content streams don't match!");
        addResultChild(failure, f);
    }
    IOUtils.closeQuietly(as);
    IOUtils.closeQuietly(es);
    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 : BufferedInputStream(java.io.BufferedInputStream) CmisTestResult(org.apache.chemistry.opencmis.tck.CmisTestResult) ArrayList(java.util.ArrayList) CmisObjectNotFoundException(org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException) CmisBaseException(org.apache.chemistry.opencmis.commons.exceptions.CmisBaseException) CmisNotSupportedException(org.apache.chemistry.opencmis.commons.exceptions.CmisNotSupportedException) IOException(java.io.IOException) CmisInvalidArgumentException(org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException)

Example 48 with CmisTestResult

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

the class AbstractSessionTest method createPolicy.

/**
 * Creates a policy.
 */
protected Policy createPolicy(Session session, Folder parent, String name, String policyText, 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, "Policy type '" + objectTypeId + "' is not available: " + e.getMessage(), e, true));
        return null;
    }
    if (Boolean.FALSE.equals(type.isCreatable())) {
        addResult(createResult(SKIPPED, "Policy type '" + objectTypeId + "' is not creatable!", true));
        return null;
    }
    boolean isFilable = Boolean.TRUE.equals(type.isFileable());
    addResult(createResult(INFO, "Policy type '" + objectTypeId + "' is " + (isFilable ? "" : "not ") + "filable."));
    // create
    Map<String, Object> properties = new HashMap<String, Object>();
    properties.put(PropertyIds.NAME, name);
    properties.put(PropertyIds.OBJECT_TYPE_ID, objectTypeId);
    if (policyText != null) {
        properties.put(PropertyIds.POLICY_TEXT, policyText);
    }
    Policy result = null;
    try {
        // create the item
        if (isFilable) {
            result = parent.createPolicy(properties, null, null, null, SELECT_ALL_NO_CACHE_OC);
        } else {
            ObjectId policyId = session.createPolicy(properties, null, null, null, null);
            result = (Policy) session.getObject(policyId, SELECT_ALL_NO_CACHE_OC);
        }
    } catch (CmisBaseException e) {
        addResult(createResult(UNEXPECTED_EXCEPTION, "Policy could not be created! Exception: " + e.getMessage(), e, true));
        return null;
    }
    CmisTestResult f;
    try {
        // check item name
        f = createResult(FAILURE, "Policy name does not match!", false);
        addResult(assertEquals(name, result.getName(), null, f));
        addResult(checkObject(session, result, getAllProperties(result), "New policy object spec compliance"));
    } catch (CmisBaseException e) {
        addResult(createResult(UNEXPECTED_EXCEPTION, "Newly created policy is invalid! Exception: " + e.getMessage(), e, true));
    }
    // check parents
    List<Folder> parents = result.getParents(SELECT_ALL_NO_CACHE_OC);
    if (isFilable) {
        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!"));
        }
    } else {
        f = createResult(FAILURE, "Policy is not filable but has a parent!", false);
        addResult(assertIsTrue(parents.isEmpty(), null, f));
    }
    return result;
}
Also used : Policy(org.apache.chemistry.opencmis.client.api.Policy) HashMap(java.util.HashMap) ObjectId(org.apache.chemistry.opencmis.client.api.ObjectId) 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)

Example 49 with CmisTestResult

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

the class AbstractSessionTest method checkACL.

protected CmisTestResult checkACL(Session session, Acl acl, boolean checkExact, String message) {
    List<CmisTestResult> results = new ArrayList<CmisTestResult>();
    CmisTestResult f;
    f = createResult(FAILURE, "ACL is null!");
    addResult(results, assertNotNull(acl, null, f));
    if (acl != null) {
        f = createResult(FAILURE, "List of ACEs is null!");
        addResult(results, assertNotNull(acl.getAces(), null, f));
        if (acl.getAces() != null) {
            for (Ace ace : acl.getAces()) {
                f = createResult(FAILURE, "ACE with empty principal ID!");
                addResult(results, assertStringNotEmpty(ace.getPrincipalId(), null, f));
                f = createResult(FAILURE, "ACE with empty permission list!");
                addResult(results, assertListNotEmpty(ace.getPermissions(), null, f));
                if (ace.getPermissions() != null) {
                    for (String permission : ace.getPermissions()) {
                        f = createResult(FAILURE, "ACE with empty permission entry!");
                        addResult(results, assertStringNotEmpty(permission, null, f));
                    }
                }
            }
        }
        CmisTestResultStatus status = checkExact ? WARNING : INFO;
        f = createResult(status, "ACL is provided but the isExact flag is not set!");
        addResult(results, assertNotNull(acl.isExact(), null, f));
    }
    CmisTestResultImpl result = createResult(getWorst(results), message);
    result.getChildren().addAll(results);
    return result.getStatus().getLevel() <= OK.getLevel() ? null : result;
}
Also used : Ace(org.apache.chemistry.opencmis.commons.data.Ace) CmisTestResultStatus(org.apache.chemistry.opencmis.tck.CmisTestResultStatus) CmisTestResult(org.apache.chemistry.opencmis.tck.CmisTestResult) ArrayList(java.util.ArrayList)

Example 50 with CmisTestResult

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

the class AbstractSessionTest method checkProperty.

protected CmisTestResult checkProperty(Property<?> property, String message, PropertyCheckEnum propertyCheck) {
    List<CmisTestResult> results = new ArrayList<CmisTestResult>();
    CmisTestResult f;
    f = createResult(FAILURE, "Property is not included in response!");
    addResult(results, assertNotNull(property, null, f));
    if (property != null) {
        f = createResult(FAILURE, "Property ID is not set or empty!");
        addResult(results, assertStringNotEmpty(property.getId(), null, f));
        f = createResult(WARNING, "Display name is not set!");
        addResult(results, assertNotNull(property.getDisplayName(), null, f));
        f = createResult(WARNING, "Query name is not set!");
        addResult(results, assertNotNull(property.getQueryName(), null, f));
        f = createResult(WARNING, "Local name is not set!");
        addResult(results, assertNotNull(property.getLocalName(), null, f));
        if ((propertyCheck == PropertyCheckEnum.MUST_BE_SET) || (propertyCheck == PropertyCheckEnum.STRING_MUST_NOT_BE_EMPTY)) {
            f = createResult(FAILURE, "Property has no value!");
            addResult(results, assertListNotEmpty(property.getValues(), null, f));
        } else if (propertyCheck == PropertyCheckEnum.STRING_SHOULD_NOT_BE_EMPTY) {
            f = createResult(WARNING, "Property has no value!");
            addResult(results, assertListNotEmpty(property.getValues(), null, f));
        } else if (propertyCheck == PropertyCheckEnum.MUST_NOT_BE_SET) {
            f = createResult(FAILURE, "Property has a value!");
            addResult(results, assertIsTrue(property.getValues().isEmpty(), null, f));
        }
        boolean isString = ((property.getDefinition().getPropertyType() == PropertyType.STRING) || (property.getDefinition().getPropertyType() == PropertyType.ID) || (property.getDefinition().getPropertyType() == PropertyType.URI) || (property.getDefinition().getPropertyType() == PropertyType.HTML));
        for (Object value : property.getValues()) {
            if (value == null) {
                addResult(results, createResult(FAILURE, "Property values contain a null value!"));
                break;
            } else if (isString) {
                if (propertyCheck == PropertyCheckEnum.STRING_MUST_NOT_BE_EMPTY) {
                    f = createResult(FAILURE, "Property values contain an empty string!");
                    addResult(results, assertStringNotEmpty(value.toString(), null, f));
                } else if (propertyCheck == PropertyCheckEnum.STRING_SHOULD_NOT_BE_EMPTY) {
                    f = createResult(WARNING, "Property values contain an empty string!");
                    addResult(results, assertStringNotEmpty(value.toString(), null, f));
                }
            }
        }
        if (property.getDefinition().getCardinality() == Cardinality.SINGLE) {
            f = createResult(FAILURE, "Property cardinality is SINGLE but property has more than one value!");
            addResult(results, assertIsTrue(property.getValues().size() <= 1, null, f));
        }
        if (property.getDefinition().isRequired() == null) {
            addResult(results, createResult(FAILURE, "Property definition doesn't contain the required flag!"));
        } else {
            if (property.getDefinition().isRequired().booleanValue()) {
                f = createResult(FAILURE, "Property is required but has no value!");
                addResult(results, assertListNotEmpty(property.getValues(), 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) FileableCmisObject(org.apache.chemistry.opencmis.client.api.FileableCmisObject) CmisObject(org.apache.chemistry.opencmis.client.api.CmisObject)

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