Search in sources :

Example 6 with CmisTestResult

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

the class AbstractSessionTest method assertShallowEquals.

protected CmisTestResult assertShallowEquals(CmisObject expected, 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 object is null, but actual object is not!");
        addResultChild(failure, f);
        return failure;
    }
    if (actual == null) {
        f = createResult(FAILURE, "Actual object is null, but expected object is not!");
        addResultChild(failure, f);
        return failure;
    }
    f = createResult(FAILURE, "Ids don't match!");
    addResult(results, assertEquals(expected.getId(), actual.getId(), null, f));
    f = createResult(FAILURE, "Base types don't match!");
    addResult(results, assertEquals(expected.getBaseTypeId(), actual.getBaseTypeId(), null, f));
    f = createResult(FAILURE, "Types don't match!");
    addResult(results, assertEquals(expected.getType().getId(), actual.getType().getId(), 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 7 with CmisTestResult

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

the class AbstractSessionTest method checkDocumentContent.

private void checkDocumentContent(Session session, List<CmisTestResult> results, CmisObject object) {
    if (!(object instanceof Document)) {
        // only documents have content
        return;
    }
    CmisTestResult f;
    Document doc = (Document) object;
    DocumentTypeDefinition type = (DocumentTypeDefinition) doc.getType();
    // check ContentStreamAllowed flag
    boolean hasContentProperties = (doc.getContentStreamFileName() != null) || (doc.getContentStreamId() != null) || (doc.getContentStreamLength() > -1) || (doc.getContentStreamMimeType() != null);
    if (hasContentProperties) {
        if (type.getContentStreamAllowed() == ContentStreamAllowed.NOTALLOWED) {
            addResult(results, createResult(FAILURE, "Content properties have values but the document type doesn't allow content!"));
        }
    } else {
        if (type.getContentStreamAllowed() == ContentStreamAllowed.REQUIRED) {
            addResult(results, createResult(FAILURE, "Content properties are not set but the document type demands content!"));
        }
    }
    // get the content stream
    ContentStream contentStream = doc.getContentStream();
    if (contentStream == null) {
        if (hasContentProperties && doc.getContentStreamLength() > 0) {
            addResult(results, createResult(FAILURE, "Content properties have values but the document has no content!"));
        }
        if (type.getContentStreamAllowed() == ContentStreamAllowed.REQUIRED) {
            addResult(results, createResult(FAILURE, "The document type demands content but the document has no content!"));
        }
        return;
    }
    if (type.getContentStreamAllowed() == ContentStreamAllowed.NOTALLOWED) {
        addResult(results, createResult(FAILURE, "Document type doesn't allow content but document has content!"));
    }
    // file name check
    f = createResult(FAILURE, "Content file names don't match!");
    addResult(results, assertEquals(doc.getContentStreamFileName(), contentStream.getFileName(), null, f));
    if (doc.getContentStreamLength() > -1 && contentStream.getLength() > -1) {
        f = createResult(FAILURE, "Content lengths don't match!");
        addResult(results, assertEquals(doc.getContentStreamLength(), contentStream.getLength(), null, f));
    }
    // MIME type check
    String docMimeType = doc.getContentStreamMimeType();
    if (docMimeType != null) {
        int x = docMimeType.indexOf(';');
        if (x > -1) {
            docMimeType = docMimeType.substring(0, x);
        }
        docMimeType = docMimeType.trim();
    }
    String contentMimeType = contentStream.getMimeType();
    if (contentMimeType != null) {
        int x = contentMimeType.indexOf(';');
        if (x > -1) {
            contentMimeType = contentMimeType.substring(0, x);
        }
        contentMimeType = contentMimeType.trim();
    }
    f = createResult(FAILURE, "Content MIME types don't match!");
    addResult(results, assertEquals(docMimeType, contentMimeType, null, f));
    if (contentStream.getMimeType() != null) {
        if (contentMimeType.equals(docMimeType)) {
            f = createResult(WARNING, "Content MIME types don't match!");
            addResult(results, assertEquals(doc.getContentStreamMimeType(), contentStream.getMimeType(), null, f));
        }
        f = createResult(FAILURE, "Content MIME types is invalid: " + contentStream.getMimeType());
        addResult(results, assertIsTrue(contentStream.getMimeType().length() > 2 && contentStream.getMimeType().indexOf('/') > 0, null, f));
    }
    // check stream
    InputStream stream = contentStream.getStream();
    if (stream == null) {
        addResult(results, createResult(FAILURE, "Docuemnt has no content stream!"));
        return;
    }
    try {
        long bytes = 0;
        byte[] buffer = new byte[64 * 1024];
        int b = stream.read(buffer);
        while (b > -1) {
            bytes += b;
            b = stream.read(buffer);
        }
        stream.close();
        // check content length
        if (doc.getContentStreamLength() > -1) {
            f = createResult(FAILURE, "Content stream length property value doesn't match the actual content length!");
            addResult(results, assertEquals(doc.getContentStreamLength(), bytes, null, f));
        }
        if (contentStream.getLength() > -1) {
            f = createResult(FAILURE, "Content length value doesn't match the actual content length!");
            addResult(results, assertEquals(contentStream.getLength(), bytes, null, f));
        }
    } catch (Exception e) {
        addResult(results, createResult(FAILURE, "Reading content failed: " + e, e, false));
    } finally {
        IOUtils.closeQuietly(stream);
    }
}
Also used : DocumentTypeDefinition(org.apache.chemistry.opencmis.commons.definitions.DocumentTypeDefinition) ContentStream(org.apache.chemistry.opencmis.commons.data.ContentStream) BufferedInputStream(java.io.BufferedInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) CmisTestResult(org.apache.chemistry.opencmis.tck.CmisTestResult) Document(org.apache.chemistry.opencmis.client.api.Document) 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 8 with CmisTestResult

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

the class AbstractSessionTest method assertEquals.

protected CmisTestResult assertEquals(CmisObject expected, CmisObject actual, CmisTestResult success, CmisTestResult failure, boolean checkAcls, boolean checkPolicies) {
    List<CmisTestResult> results = new ArrayList<CmisTestResult>();
    CmisTestResult f;
    if ((expected == null) && (actual == null)) {
        return success;
    }
    if (expected == null) {
        f = createResult(FAILURE, "Expected object is null, but actual object is not!");
        addResultChild(failure, f);
        return failure;
    }
    if (actual == null) {
        f = createResult(FAILURE, "Actual object is null, but expected object is not!");
        addResultChild(failure, f);
        return failure;
    }
    if (expected.getProperties().size() != actual.getProperties().size()) {
        f = createResult(FAILURE, "Number of properties don't match");
        addResult(results, assertEquals(expected.getProperties().size(), actual.getProperties().size(), null, f));
    } else {
        for (Property<?> expectedProperty : expected.getProperties()) {
            Property<?> actualProperty = actual.getProperty(expectedProperty.getId());
            f = createResult(FAILURE, "Properties don't match! Property: " + expectedProperty.getId());
            addResult(results, assertEquals(expectedProperty, actualProperty, null, f));
        }
    }
    f = createResult(FAILURE, "Allowable actions don't match!");
    addResult(results, assertEquals(expected.getAllowableActions(), actual.getAllowableActions(), null, f));
    if (checkAcls) {
        f = createResult(FAILURE, "ACLs don't match!");
        addResult(results, assertEquals(expected.getAcl(), actual.getAcl(), null, f));
    }
    if (checkPolicies) {
        f = createResult(FAILURE, "Policies don't match!");
        addResult(results, assertEqualObjectList(expected.getPolicies(), actual.getPolicies(), null, f));
    }
    f = createResult(FAILURE, "Relationships don't match!");
    addResult(results, assertEqualObjectList(expected.getRelationships(), actual.getRelationships(), null, f));
    f = createResult(FAILURE, "Renditions don't match!");
    addResult(results, assertEqualRenditionLists(expected.getRenditions(), actual.getRenditions(), 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 9 with CmisTestResult

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

the class AbstractSessionTest method checkVersionHistory.

protected CmisTestResult checkVersionHistory(Session session, CmisObject object, String[] properties, String message) {
    List<CmisTestResult> results = new ArrayList<CmisTestResult>();
    CmisTestResult f;
    if (object.getBaseTypeId() != BaseTypeId.CMIS_DOCUMENT) {
        // skip non-document objects
        return null;
    }
    if (!Boolean.TRUE.equals(((DocumentTypeDefinition) object.getType()).isVersionable())) {
        // skip non-versionable types
        return null;
    }
    Document doc = (Document) object;
    // check version series ID
    String versionSeriesId = doc.getVersionSeriesId();
    f = createResult(FAILURE, "Versionable document has no version series ID property!");
    addResult(results, assertStringNotEmpty(versionSeriesId, null, f));
    if (versionSeriesId == null) {
        CmisTestResultImpl result = createResult(getWorst(results), message);
        result.getChildren().addAll(results);
        return result;
    }
    // get version history
    List<Document> versions = doc.getAllVersions(SELECT_ALL_NO_CACHE_OC);
    f = createResult(FAILURE, "Version history is null!");
    addResult(results, assertNotNull(versions, null, f));
    if (versions == null) {
        CmisTestResultImpl result = createResult(getWorst(results), message);
        result.getChildren().addAll(results);
        return result;
    }
    f = createResult(FAILURE, "Version history must have at least one version!");
    addResult(results, assertListNotEmpty(versions, null, f));
    if (!versions.isEmpty()) {
        // get latest version
        Document lastestVersion = doc.getObjectOfLatestVersion(false, SELECT_ALL_NO_CACHE_OC);
        addResult(results, checkObject(session, lastestVersion, properties, "Latest version check: " + lastestVersion.getId()));
        f = createResult(FAILURE, "Latest version is not flagged as latest version! ID: " + lastestVersion.getId());
        addResult(results, assertIsTrue(lastestVersion.isLatestVersion(), null, f));
        // get latest major version
        Document lastestMajorVersion = null;
        try {
            lastestMajorVersion = doc.getObjectOfLatestVersion(true, SELECT_ALL_NO_CACHE_OC);
            f = createResult(FAILURE, "getObjectOfLatestVersion returned an invalid object!");
            addResult(results, assertNotNull(lastestMajorVersion, null, f));
        } catch (CmisObjectNotFoundException e) {
        // no latest major version
        }
        if (lastestMajorVersion != null) {
            addResult(results, checkObject(session, lastestMajorVersion, properties, "Latest major version check: " + lastestMajorVersion.getId()));
            f = createResult(FAILURE, "Latest major version is not flagged as latest major version! ID: " + lastestMajorVersion.getId());
            addResult(results, assertIsTrue(lastestMajorVersion.isLatestMajorVersion(), null, f));
        }
        // iterate through the version history and test each version
        // document
        long creatationDate = Long.MAX_VALUE;
        int latestVersion = 0;
        int latestMajorVersion = 0;
        long latestModificationDate = Long.MAX_VALUE;
        int latestModifictaionIndex = Integer.MIN_VALUE;
        Set<String> versionLabels = new HashSet<String>();
        boolean found = false;
        boolean foundLastestVersion = false;
        boolean foundLastestMajorVersion = false;
        for (int i = 0; i < versions.size(); i++) {
            Document version = versions.get(i);
            f = createResult(FAILURE, "Version " + i + " is null!");
            addResult(results, assertNotNull(version, null, f));
            if (version == null) {
                continue;
            }
            addResult(results, checkObject(session, version, properties, "Version check: " + version.getId()));
            // check first entry
            if (i == 0) {
                if (version.isVersionSeriesCheckedOut()) {
                    f = createResult(WARNING, "Version series is checked-out and the PWC is not the latest version! ID: " + version.getId() + " (Note: The words of the CMIS specification define that the PWC is the latest version." + " But that is not the intention of the spec and will be changed in CMIS 1.1." + " Thus this a warning, not an error.)");
                    addResult(results, assertIsTrue(version.isLatestVersion(), null, f));
                } else {
                    f = createResult(FAILURE, "Version series is not checked-out and first version history entry is not the latest version! ID: " + version.getId());
                    addResult(results, assertIsTrue(version.isLatestVersion(), null, f));
                }
            }
            // check version ID
            f = createResult(FAILURE, "Version series id does not match! ID: " + version.getId());
            addResult(results, assertEquals(versionSeriesId, version.getVersionSeriesId(), null, f));
            // check creation date
            if (creatationDate == version.getCreationDate().getTimeInMillis()) {
                addResult(results, createResult(WARNING, "Two or more versions have the same creation date!"));
            } else {
                f = createResult(FAILURE, "Version history order incorrect! Must be sorted bei creation date!");
                addResult(results, assertIsTrue(version.getCreationDate().getTimeInMillis() <= creatationDate, null, f));
            }
            // count latest versions and latest major versions
            if (version.isLatestVersion()) {
                latestVersion++;
            }
            if (version.isLatestMajorVersion()) {
                latestMajorVersion++;
            }
            // find latest modification date
            if (latestModificationDate == version.getLastModificationDate().getTimeInMillis()) {
                addResult(results, createResult(WARNING, "Two or more versions have the same last modification date!"));
            } else if (latestModificationDate < version.getLastModificationDate().getTimeInMillis()) {
                latestModificationDate = version.getLastModificationDate().getTimeInMillis();
                latestModifictaionIndex = i;
            }
            // check for version label duplicates
            String versionLabel = version.getVersionLabel();
            f = createResult(WARNING, "More than one version have this version label: " + versionLabel);
            addResult(results, assertIsFalse(versionLabels.contains(versionLabel), null, f));
            versionLabels.add(versionLabel);
            // check PWC
            if (version.getId().equals(version.getVersionSeriesCheckedOutId())) {
                f = createResult(FAILURE, "PWC must not be flagged as latest major version! ID: " + version.getId());
                addResult(results, assertIsFalse(version.isLatestMajorVersion(), null, f));
            }
            // check checked out
            if (Boolean.TRUE.equals(doc.isVersionSeriesCheckedOut())) {
                f = createResult(WARNING, "Version series is marked as checked out but cmis:versionSeriesCheckedOutId is not set! ID: " + version.getId());
                addResult(results, assertStringNotEmpty(doc.getVersionSeriesCheckedOutId(), null, f));
                f = createResult(WARNING, "Version series is marked as checked out but cmis:versionSeriesCheckedOutBy is not set! ID: " + version.getId());
                addResult(results, assertStringNotEmpty(doc.getVersionSeriesCheckedOutBy(), null, f));
            } else if (Boolean.FALSE.equals(doc.isVersionSeriesCheckedOut())) {
                f = createResult(FAILURE, "Version series is not marked as checked out but cmis:versionSeriesCheckedOutId is set! ID: " + version.getId());
                addResult(results, assertNull(doc.getVersionSeriesCheckedOutId(), null, f));
                f = createResult(FAILURE, "Version series is not marked as checked out but cmis:versionSeriesCheckedOutIdBy is set! ID: " + version.getId());
                addResult(results, assertNull(doc.getVersionSeriesCheckedOutBy(), null, f));
            }
            // found origin object?
            if (version.getId().equals(object.getId())) {
                found = true;
            }
            // found latest version?
            if (version.getId().equals(lastestVersion.getId())) {
                foundLastestVersion = true;
            }
            // found latest major version?
            if (lastestMajorVersion != null && version.getId().equals(lastestMajorVersion.getId())) {
                foundLastestMajorVersion = true;
            }
        }
        // check latest versions
        f = createResult(FAILURE, "Version series ID has " + latestVersion + " latest versions! There must be only one!");
        addResult(results, assertEquals(1, latestVersion, null, f));
        if (!foundLastestVersion) {
            addResult(results, createResult(FAILURE, "Latest version not found in version history!"));
        }
        // check latest major versions
        if (lastestMajorVersion == null) {
            f = createResult(FAILURE, "Version series ID has " + latestMajorVersion + " latest major version(s) but getObjectOfLatestVersion() didn't return a major version!");
            addResult(results, assertEquals(0, latestMajorVersion, null, f));
        } else {
            f = createResult(FAILURE, "Version series ID has " + latestMajorVersion + " latest major versions but there should be exactly one!");
            addResult(results, assertEquals(1, latestMajorVersion, null, f));
            if (!foundLastestMajorVersion) {
                addResult(results, createResult(FAILURE, "Latest major version not found in version history!"));
            }
        }
        // check latest version
        if (latestModifictaionIndex >= 0) {
            f = createResult(FAILURE, "Version with the latest modification date is not flagged as latest version! ID: " + versions.get(latestModifictaionIndex));
            addResult(results, assertIsTrue(versions.get(latestModifictaionIndex).isLatestVersion(), null, f));
        }
        // check if the origin object was found
        if (!found) {
            addResult(results, createResult(FAILURE, "Document not found in its version history!"));
        }
    }
    CmisTestResultImpl result = createResult(getWorst(results), message);
    result.getChildren().addAll(results);
    return result.getStatus().getLevel() <= OK.getLevel() ? null : result;
}
Also used : DocumentTypeDefinition(org.apache.chemistry.opencmis.commons.definitions.DocumentTypeDefinition) ArrayList(java.util.ArrayList) Document(org.apache.chemistry.opencmis.client.api.Document) CmisObjectNotFoundException(org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException) CmisTestResult(org.apache.chemistry.opencmis.tck.CmisTestResult) HashSet(java.util.HashSet)

Example 10 with CmisTestResult

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

the class AbstractSessionTest method assertEquals.

protected CmisTestResult assertEquals(Property<?> expected, Property<?> 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 is null, but actual property is not!");
        addResultChild(failure, f);
        return failure;
    }
    if (actual == null) {
        f = createResult(FAILURE, "Actual property is null, but expected property is not!");
        addResultChild(failure, f);
        return failure;
    }
    f = createResult(FAILURE, "Property definitions don't match!");
    addResult(results, assertEquals(expected.getDefinition(), actual.getDefinition(), null, f));
    f = createResult(FAILURE, "Property values don't match!");
    addResult(results, assertEqualLists(expected.getValues(), actual.getValues(), 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