Search in sources :

Example 1 with Rendition

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

the class AbstractSessionTest method checkRenditions.

protected CmisTestResult checkRenditions(Session session, CmisObject object, String message) {
    List<CmisTestResult> results = new ArrayList<CmisTestResult>();
    CmisTestResult f;
    if (object.getRenditions() != null) {
        for (Rendition rend : object.getRenditions()) {
            f = createResult(FAILURE, "A rendition in the list of renditions is null!");
            addResult(results, assertNotNull(rend, null, f));
            if (rend != null) {
                f = createResult(FAILURE, "A rendition has an empty stream ID!");
                addResult(results, assertStringNotEmpty(rend.getStreamId(), null, f));
                f = createResult(FAILURE, "A rendition has an empty kind! Stream ID: " + rend.getStreamId());
                addResult(results, assertStringNotEmpty(rend.getKind(), null, f));
                f = createResult(FAILURE, "A rendition has an empty MIME type! Stream ID: " + rend.getStreamId());
                addResult(results, assertStringNotEmpty(rend.getMimeType(), null, f));
                if ("cmis:thumbnail".equals(rend.getKind())) {
                    f = createResult(WARNING, "A rendition is of kind 'cmis:thumbnail' but the height is not set or has an invalid value! Stream ID: " + rend.getStreamId());
                    addResult(results, assertIsTrue(rend.getHeight() > 0, null, f));
                    f = createResult(WARNING, "A rendition is of kind 'cmis:thumbnail' but the width is not set or has an invalid value! Stream ID: " + rend.getStreamId());
                    addResult(results, assertIsTrue(rend.getWidth() > 0, null, f));
                }
                // check the content
                ContentStream contentStream = rend.getContentStream();
                f = createResult(FAILURE, "A rendition has no content stream! Stream ID: " + rend.getStreamId());
                addResult(results, assertNotNull(contentStream, null, f));
                if (contentStream != null) {
                    InputStream stream = contentStream.getStream();
                    f = createResult(FAILURE, "A rendition has no stream! Stream ID: " + rend.getStreamId());
                    addResult(results, assertNotNull(stream, null, f));
                    if (stream != null) {
                        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 (rend.getLength() > -1) {
                                f = createResult(FAILURE, "Rendition content stream length value doesn't match the actual content length!");
                                addResult(results, assertEquals(rend.getLength(), bytes, null, f));
                            }
                        } catch (Exception e) {
                            addResult(results, createResult(FAILURE, "Reading content failed: " + e, e, false));
                        } finally {
                            IOUtils.closeQuietly(stream);
                        }
                    }
                }
            }
        }
    }
    CmisTestResultImpl result = createResult(getWorst(results), message);
    result.getChildren().addAll(results);
    return result.getStatus().getLevel() <= OK.getLevel() ? null : result;
}
Also used : ContentStream(org.apache.chemistry.opencmis.commons.data.ContentStream) Rendition(org.apache.chemistry.opencmis.client.api.Rendition) BufferedInputStream(java.io.BufferedInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) 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)

Aggregations

BufferedInputStream (java.io.BufferedInputStream)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 Rendition (org.apache.chemistry.opencmis.client.api.Rendition)1 ContentStream (org.apache.chemistry.opencmis.commons.data.ContentStream)1 CmisBaseException (org.apache.chemistry.opencmis.commons.exceptions.CmisBaseException)1 CmisInvalidArgumentException (org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException)1 CmisNotSupportedException (org.apache.chemistry.opencmis.commons.exceptions.CmisNotSupportedException)1 CmisObjectNotFoundException (org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException)1 CmisTestResult (org.apache.chemistry.opencmis.tck.CmisTestResult)1