You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@chemistry.apache.org by fm...@apache.org on 2017/01/04 16:34:02 UTC

svn commit: r1777334 - in /chemistry/opencmis/trunk: chemistry-opencmis-client/chemistry-opencmis-client-api/src/main/java/org/apache/chemistry/opencmis/client/api/ chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemi...

Author: fmui
Date: Wed Jan  4 16:34:02 2017
New Revision: 1777334

URL: http://svn.apache.org/viewvc?rev=1777334&view=rev
Log:
added more convenient methods to work with content streams

Modified:
    chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-api/src/main/java/org/apache/chemistry/opencmis/client/api/Session.java
    chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/SessionImpl.java
    chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/util/ContentStreamUtils.java
    chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/util/FileUtils.java
    chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/util/OperationContextUtils.java
    chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/util/TypeUtils.java
    chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/test/java/org/apache/chemistry/opencmis/client/runtime/OperationContextTest.java
    chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tck/src/main/java/org/apache/chemistry/opencmis/tck/tests/crud/CreateAndDeleteDocumentTest.java

Modified: chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-api/src/main/java/org/apache/chemistry/opencmis/client/api/Session.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-api/src/main/java/org/apache/chemistry/opencmis/client/api/Session.java?rev=1777334&r1=1777333&r2=1777334&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-api/src/main/java/org/apache/chemistry/opencmis/client/api/Session.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-api/src/main/java/org/apache/chemistry/opencmis/client/api/Session.java Wed Jan  4 16:34:02 2017
@@ -1194,7 +1194,7 @@ public interface Session extends Seriali
      * @param docId
      *            the ID of the document
      * @param streamId
-     *            the stream ID
+     *            the stream ID or {@code null} for the main stream
      * @param offset
      *            the offset of the stream or {@code null} to read the stream
      *            from the beginning
@@ -1210,6 +1210,40 @@ public interface Session extends Seriali
     ContentStream getContentStream(ObjectId docId, String streamId, BigInteger offset, BigInteger length);
 
     /**
+     * Retrieves the main content stream of a document.
+     * 
+     * @param path
+     *            the path of the document
+     * 
+     * @return the content stream or {@code null} if the document has no content
+     *         stream
+     * 
+     * @cmis 1.0
+     */
+    ContentStream getContentStreamByPath(String path);
+
+    /**
+     * Retrieves the content stream of a document.
+     * 
+     * @param path
+     *            the path of the document
+     * @param streamId
+     *            the stream ID or {@code null} for the main stream
+     * @param offset
+     *            the offset of the stream or {@code null} to read the stream
+     *            from the beginning
+     * @param length
+     *            the maximum length of the stream or {@code null} to read to
+     *            the end of the stream
+     * 
+     * @return the content stream or {@code null} if the document has no content
+     *         stream
+     * 
+     * @cmis 1.0
+     */
+    ContentStream getContentStreamByPath(String path, String streamId, BigInteger offset, BigInteger length);
+
+    /**
      * Fetches the ACL of an object from the repository.
      * 
      * @param objectId

Modified: chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/SessionImpl.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/SessionImpl.java?rev=1777334&r1=1777333&r2=1777334&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/SessionImpl.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/SessionImpl.java Wed Jan  4 16:34:02 2017
@@ -1488,6 +1488,49 @@ public class SessionImpl implements Sess
         } catch (CmisConstraintException e) {
             // no content stream
             return null;
+        } catch (CmisObjectNotFoundException onfe) {
+            removeObjectFromCache(docId.getId());
+            throw onfe;
+        }
+
+        return contentStream;
+    }
+
+    @Override
+    public ContentStream getContentStreamByPath(String path) {
+        return getContentStreamByPath(path, null, null, null);
+    }
+
+    @Override
+    public ContentStream getContentStreamByPath(String path, String streamId, BigInteger offset, BigInteger length) {
+        checkPath(path);
+
+        // check the cache
+        String docId = cache.getObjectIdByPath(path);
+
+        // not in cache -> get the object
+        if (docId == null) {
+            ObjectData objectData = getBinding().getObjectService().getObjectByPath(getRepositoryId(), path,
+                    "cmis:objectId,cmis:baseTypeId", false, IncludeRelationships.NONE, "cmis:none", false, false, null);
+            docId = objectData.getId();
+
+            // don't check if the object is a document
+            // the path could belong to a folder or an item and the stream ID
+            // could point to a rendition
+        }
+
+        // get the stream
+        ContentStream contentStream = null;
+        try {
+            contentStream = getBinding().getObjectService().getContentStream(getRepositoryId(), docId, streamId,
+                    offset, length, null);
+        } catch (CmisConstraintException ce) {
+            // no content stream
+            return null;
+        } catch (CmisObjectNotFoundException onfe) {
+            removeObjectFromCache(docId);
+            cache.remove(docId);
+            throw onfe;
         }
 
         return contentStream;

Modified: chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/util/ContentStreamUtils.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/util/ContentStreamUtils.java?rev=1777334&r1=1777333&r2=1777334&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/util/ContentStreamUtils.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/util/ContentStreamUtils.java Wed Jan  4 16:34:02 2017
@@ -19,14 +19,16 @@
 package org.apache.chemistry.opencmis.client.util;
 
 import java.io.BufferedInputStream;
+import java.io.BufferedOutputStream;
 import java.io.ByteArrayInputStream;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
+import java.io.OutputStream;
 import java.math.BigInteger;
-
 import org.apache.chemistry.opencmis.commons.data.ContentStream;
 import org.apache.chemistry.opencmis.commons.data.MutableContentStream;
 import org.apache.chemistry.opencmis.commons.impl.IOUtils;
@@ -44,10 +46,9 @@ public final class ContentStreamUtils {
     }
 
     // --- generic ---
-
     /**
      * Creates a content stream object for an InputStream.
-     * 
+     *
      * @param filename
      *            name of the content stream
      * @param length
@@ -56,7 +57,7 @@ public final class ContentStreamUtils {
      *            content MIME type
      * @param stream
      *            the InputStream
-     * 
+     *
      * @return a {@link MutableContentStream} object
      */
     public static MutableContentStream createContentStream(String filename, long length, String mimetype,
@@ -66,7 +67,7 @@ public final class ContentStreamUtils {
 
     /**
      * Creates a content stream object for an InputStream.
-     * 
+     *
      * @param filename
      *            name of the content stream
      * @param length
@@ -75,7 +76,7 @@ public final class ContentStreamUtils {
      *            content MIME type
      * @param stream
      *            the InputStream
-     * 
+     *
      * @return a {@link MutableContentStream} object
      */
     public static MutableContentStream createContentStream(String filename, BigInteger length, String mimetype,
@@ -84,17 +85,16 @@ public final class ContentStreamUtils {
     }
 
     // --- byte arrays ---
-
     /**
      * Creates a content stream object from a byte array.
-     * 
+     *
      * The MIME type is set to "application/octet-stream".
-     * 
+     *
      * @param filename
      *            name of the content stream
      * @param contentBytes
      *            content bytes
-     * 
+     *
      * @return a {@link MutableContentStream} object
      */
     public static MutableContentStream createByteArrayContentStream(String filename, byte[] contentBytes) {
@@ -103,16 +103,16 @@ public final class ContentStreamUtils {
 
     /**
      * Creates a content stream object from a byte array.
-     * 
+     *
      * @param filename
      *            name of the content stream
      * @param contentBytes
      *            the content bytes
      * @param mimetype
      *            content MIME type
-     * 
+     *
      * @return a {@link MutableContentStream} object
-     * 
+     *
      */
     public static MutableContentStream createByteArrayContentStream(String filename, byte[] contentBytes,
             String mimetype) {
@@ -125,7 +125,7 @@ public final class ContentStreamUtils {
 
     /**
      * Creates a content stream object from a byte array.
-     * 
+     *
      * @param filename
      *            name of the content stream
      * @param contentBytes
@@ -136,9 +136,9 @@ public final class ContentStreamUtils {
      *            the maximum number of bytes to read from the content bytes
      * @param mimetype
      *            content MIME type
-     * 
+     *
      * @return a {@link MutableContentStream} object
-     * 
+     *
      */
     public static MutableContentStream createByteArrayContentStream(String filename, byte[] contentBytes, int offset,
             int length, String mimetype) {
@@ -157,17 +157,16 @@ public final class ContentStreamUtils {
     }
 
     // --- strings ---
-
     /**
      * Creates a content stream object from a string.
-     * 
+     *
      * The MIME type is set to "text/plain".
-     * 
+     *
      * @param filename
      *            name of the content stream
      * @param content
      *            the content string
-     * 
+     *
      * @return a {@link MutableContentStream} object
      */
     public static MutableContentStream createTextContentStream(String filename, String content) {
@@ -176,14 +175,14 @@ public final class ContentStreamUtils {
 
     /**
      * Creates a content stream object from a string.
-     * 
+     *
      * @param filename
      *            name of the content stream
      * @param content
      *            the content string
      * @param mimetype
      *            content MIME type
-     * 
+     *
      * @return a {@link MutableContentStream} object
      */
     public static MutableContentStream createTextContentStream(String filename, String content, String mimetype) {
@@ -192,15 +191,14 @@ public final class ContentStreamUtils {
     }
 
     // --- files ---
-
     /**
      * Creates a content stream object from file.
-     * 
+     *
      * The MIME type is guessed from the file name and the content.
-     * 
+     *
      * @param file
      *            the file
-     * 
+     *
      * @return a {@link MutableContentStream} object
      */
     public static MutableContentStream createFileContentStream(File file) throws FileNotFoundException {
@@ -209,14 +207,14 @@ public final class ContentStreamUtils {
 
     /**
      * Creates a content stream object from file.
-     * 
+     *
      * The MIME type is guessed from the file name and the content.
-     * 
+     *
      * @param filename
      *            name of the content stream
      * @param file
      *            the file
-     * 
+     *
      * @return a {@link MutableContentStream} object
      */
     public static MutableContentStream createFileContentStream(String filename, File file) throws FileNotFoundException {
@@ -225,12 +223,12 @@ public final class ContentStreamUtils {
 
     /**
      * Creates a content stream object from file.
-     * 
+     *
      * @param file
      *            the file
      * @param mimetype
      *            content MIME type
-     * 
+     *
      * @return a {@link MutableContentStream} object
      */
     public static MutableContentStream createFileContentStream(File file, String mimetype) throws FileNotFoundException {
@@ -239,14 +237,14 @@ public final class ContentStreamUtils {
 
     /**
      * Creates a content stream object from file.
-     * 
+     *
      * @param filename
      *            name of the content stream
      * @param file
      *            the file
      * @param mimetype
      *            content MIME type
-     * 
+     *
      * @return a {@link MutableContentStream} object
      */
     public static MutableContentStream createFileContentStream(String filename, File file, String mimetype)
@@ -255,8 +253,64 @@ public final class ContentStreamUtils {
                 new FileInputStream(file))));
     }
 
-    // --- helpers ---
+    // --- write ---
+
+    /**
+     * Writes a content stream to an output stream.
+     * 
+     * If the content stream is {@code null} or the stream itself is
+     * {@code null}, nothing is written to the output stream. The content stream
+     * is closed at the end. The output stream remains open.
+     * 
+     * @param contentStream
+     *            the content stream, may be {@code null}
+     * @param outputStream
+     *            the output stream, not {@code null}
+     */
+    public static void writeContentStreamToOutputStream(ContentStream contentStream, OutputStream outputStream)
+            throws IOException {
+        if (outputStream == null) {
+            throw new IllegalArgumentException("Output stream is null!");
+        }
+
+        if (contentStream == null || contentStream.getStream() == null) {
+            return;
+        }
+
+        try {
+            IOUtils.copy(contentStream.getStream(), outputStream);
+        } finally {
+            IOUtils.closeQuietly(contentStream);
+        }
+    }
+
+    /**
+     * Writes a content stream to a file.
+     * 
+     * If the content stream is {@code null} or the stream itself is
+     * {@code null}, the file is empty. The content stream and the file are
+     * closed at the end.
+     * 
+     * @param contentStream
+     *            the content stream, may be {@code null}
+     * @param file
+     *            the file, not {@code null}
+     */
+    public static void writeContentStreamToFile(ContentStream contentStream, File file) throws IOException {
+        if (file == null) {
+            throw new IllegalArgumentException("File is null!");
+        }
 
+        OutputStream fileStream = new BufferedOutputStream(new FileOutputStream(file));
+        try {
+            writeContentStreamToOutputStream(contentStream, fileStream);
+            fileStream.flush();
+        } finally {
+            IOUtils.closeQuietly(fileStream);
+        }
+    }
+
+    // --- helpers ---
     private static String checkFilename(String filename) {
         if (filename == null || filename.length() == 0) {
             return "content";
@@ -279,7 +333,6 @@ public final class ContentStreamUtils {
     }
 
     // --- classes ---
-
     /**
      * InputStream that gets closed when the end of the stream is reached or the
      * underlying stream throws an exception.

Modified: chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/util/FileUtils.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/util/FileUtils.java?rev=1777334&r1=1777333&r2=1777334&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/util/FileUtils.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/util/FileUtils.java Wed Jan  4 16:34:02 2017
@@ -20,7 +20,6 @@ package org.apache.chemistry.opencmis.cl
 
 import java.io.File;
 import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.PrintStream;
 import java.util.HashMap;
@@ -255,18 +254,7 @@ public final class FileUtils {
             return;
         }
 
-        FileOutputStream out = new FileOutputStream(destinationPath);
-
-        ContentStream stream = null;
-        try {
-            stream = doc.getContentStream();
-            if (stream != null) {
-                IOUtils.copy(stream.getStream(), out, 64 * 1024);
-            }
-        } finally {
-            IOUtils.closeQuietly(out);
-            IOUtils.closeQuietly(stream);
-        }
+        ContentStreamUtils.writeContentStreamToFile(doc.getContentStream(), new File(destinationPath));
     }
 
     /**

Modified: chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/util/OperationContextUtils.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/util/OperationContextUtils.java?rev=1777334&r1=1777333&r2=1777334&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/util/OperationContextUtils.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/util/OperationContextUtils.java Wed Jan  4 16:34:02 2017
@@ -18,6 +18,7 @@
  */
 package org.apache.chemistry.opencmis.client.util;
 
+import java.util.Collection;
 import java.util.Collections;
 import java.util.HashSet;
 import java.util.Set;
@@ -33,6 +34,8 @@ import org.apache.chemistry.opencmis.com
  */
 public final class OperationContextUtils {
 
+    private static final char[] INVALID_QUERY_NAME_CHARS = " \t\n\r\f\"',\\.()".toCharArray();
+
     public static final String PROPERTIES_STAR = "*";
     public static final String RENDITION_NONE = "cmis:none";
 
@@ -54,13 +57,16 @@ public final class OperationContextUtils
     }
 
     /**
-     * Creates a new OperationContext object with the given parameters. Caching
-     * is enabled.
+     * Creates a new OperationContext object with the given parameters.
      */
     public static OperationContext createOperationContext(Set<String> filter, boolean includeAcls,
             boolean includeAllowableActions, boolean includePolicies, IncludeRelationships includeRelationships,
             Set<String> renditionFilter, boolean includePathSegments, String orderBy, boolean cacheEnabled,
             int maxItemsPerPage) {
+        if (!checkQueryNames(filter)) {
+            throw new IllegalArgumentException("Invalid filter: " + filter);
+        }
+
         return new OperationContextImpl(filter, includeAcls, includeAllowableActions, includePolicies,
                 includeRelationships, renditionFilter, includePathSegments, orderBy, cacheEnabled, maxItemsPerPage);
     }
@@ -77,14 +83,17 @@ public final class OperationContextUtils
      * Creates a new OperationContext object that only selects the bare minimum
      * plus the provided properties. Caching is enabled.
      */
-    public static OperationContext createMinimumOperationContext(String... property) {
+    public static OperationContext createMinimumOperationContext(String... propertyQueryNames) {
         Set<String> filter = new HashSet<String>();
         filter.add(PropertyIds.OBJECT_ID);
         filter.add(PropertyIds.OBJECT_TYPE_ID);
         filter.add(PropertyIds.BASE_TYPE_ID);
 
-        if (property != null) {
-            for (String prop : property) {
+        if (propertyQueryNames != null) {
+            for (String prop : propertyQueryNames) {
+                if (!checkQueryName(prop)) {
+                    throw new IllegalArgumentException("Not a valid property query name: " + prop);
+                }
                 filter.add(prop);
             }
         }
@@ -253,4 +262,53 @@ public final class OperationContextUtils
             }
         };
     }
+
+    // --- helpers ---
+
+    /**
+     * Checks if a property query name is valid.
+     * 
+     * @param queryName
+     *            the query name
+     * @return {@code true} if the query name is valid, {@code false} otherwise
+     */
+    private static boolean checkQueryName(String queryName) {
+        if (queryName == null || queryName.length() == 0) {
+            return false;
+        }
+
+        int n = queryName.length();
+        for (int i = 0; i < n; i++) {
+            char c = queryName.charAt(i);
+            for (char ic : INVALID_QUERY_NAME_CHARS) {
+                if (c == ic) {
+                    return false;
+                }
+            }
+        }
+
+        return true;
+    }
+
+    /**
+     * Checks if a set of property query name is valid.
+     * 
+     * @param queryNames
+     *            the query names
+     * @return {@code true} if all query names are valid, {@code false}
+     *         otherwise
+     */
+    private static boolean checkQueryNames(Collection<String> queryNames) {
+        if (queryNames == null || queryNames.isEmpty()) {
+            return true;
+        }
+
+        for (String qn : queryNames) {
+            if (!checkQueryName(qn)) {
+                return false;
+            }
+        }
+
+        return true;
+    }
 }

Modified: chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/util/TypeUtils.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/util/TypeUtils.java?rev=1777334&r1=1777333&r2=1777334&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/util/TypeUtils.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/util/TypeUtils.java Wed Jan  4 16:34:02 2017
@@ -26,6 +26,7 @@ import java.io.OutputStream;
 import java.io.OutputStreamWriter;
 import java.io.Writer;
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.List;
 import java.util.Map;
 
@@ -151,7 +152,14 @@ public final class TypeUtils {
         return JSONConverter.convertTypeDefinition((Map<String, Object>) json);
     }
 
-    private static boolean checkQueryName(String queryName) {
+    /**
+     * Checks if a property query name is valid.
+     * 
+     * @param queryName
+     *            the query name
+     * @return {@code true} if the query name is valid, {@code false} otherwise
+     */
+    public static boolean checkQueryName(String queryName) {
         return queryName != null && queryName.length() > 0 && queryName.indexOf(' ') < 0 && queryName.indexOf('\t') < 0
                 && queryName.indexOf('\n') < 0 && queryName.indexOf('\r') < 0 && queryName.indexOf('\f') < 0
                 && queryName.indexOf(',') < 0 && queryName.indexOf('"') < 0 && queryName.indexOf('\'') < 0

Modified: chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/test/java/org/apache/chemistry/opencmis/client/runtime/OperationContextTest.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/test/java/org/apache/chemistry/opencmis/client/runtime/OperationContextTest.java?rev=1777334&r1=1777333&r2=1777334&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/test/java/org/apache/chemistry/opencmis/client/runtime/OperationContextTest.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/test/java/org/apache/chemistry/opencmis/client/runtime/OperationContextTest.java Wed Jan  4 16:34:02 2017
@@ -105,5 +105,11 @@ public class OperationContextTest {
         assertTrue(oc3.isIncludeAcls());
         assertTrue(oc3.isIncludePolicies());
         assertFalse(oc3.isIncludePathSegments());
+
+        try {
+            OperationContext oc4 = OperationContextUtils.createMinimumOperationContext("test(prop");
+        } catch (IllegalArgumentException iae) {
+            // expected: query name contains an invalid character
+        }
     }
 }

Modified: chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tck/src/main/java/org/apache/chemistry/opencmis/tck/tests/crud/CreateAndDeleteDocumentTest.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tck/src/main/java/org/apache/chemistry/opencmis/tck/tests/crud/CreateAndDeleteDocumentTest.java?rev=1777334&r1=1777333&r2=1777334&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tck/src/main/java/org/apache/chemistry/opencmis/tck/tests/crud/CreateAndDeleteDocumentTest.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tck/src/main/java/org/apache/chemistry/opencmis/tck/tests/crud/CreateAndDeleteDocumentTest.java Wed Jan  4 16:34:02 2017
@@ -18,6 +18,7 @@
  */
 package org.apache.chemistry.opencmis.tck.tests.crud;
 
+import java.io.IOException;
 import static org.apache.chemistry.opencmis.tck.CmisTestResultStatus.FAILURE;
 import static org.apache.chemistry.opencmis.tck.CmisTestResultStatus.INFO;
 import static org.apache.chemistry.opencmis.tck.CmisTestResultStatus.WARNING;
@@ -216,11 +217,39 @@ public class CreateAndDeleteDocumentTest
                 if (contentStream == null || contentStream.getStream() == null) {
                     addResult(createResult(FAILURE, "Document has no content! Id: " + document.getId()));
                     continue;
-                } else {
-                    IOUtils.closeQuietly(contentStream);
                 }
 
-                // TODO: content checks
+                try {
+                    // first stream from document
+                    String contentStr = getStringFromContentStream(contentStream);
+
+                    f = createResult(FAILURE, "Unexpected document content! Id: " + document.getId());
+                    addResult(assertEquals(CONTENT, contentStr, null, f));
+
+                    // second stream from session
+                    String contentStr2 = getStringFromContentStream(session.getContentStream(document));
+
+                    f = createResult(FAILURE, "Unexpected document content! Id: " + document.getId());
+                    addResult(assertEquals(CONTENT, contentStr2, null, f));
+
+                    // third stream by path
+                    List<String> paths = document.getPaths();
+
+                    f = createResult(FAILURE,
+                            "The document must have at least one path because it was created in a folder! Id: "
+                                    + document.getId());
+                    addResult(assertIsTrue(paths != null && paths.size() > 0, null, f));
+
+                    String contentStr3 = getStringFromContentStream(session.getContentStreamByPath(paths.get(0)));
+
+                    f = createResult(FAILURE, "Unexpected document content! Id: " + document.getId());
+                    addResult(assertEquals(CONTENT, contentStr3, null, f));
+                } catch (IOException ioe) {
+                    addResult(createResult(FAILURE, "Could not read content of document! Id: " + document.getId(), ioe,
+                            false));
+                } finally {
+                    IOUtils.closeQuietly(contentStream);
+                }
             }
 
             // delete all documents