chemistry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From f...@apache.org
Subject svn commit: r1152622 - /chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tck/src/main/java/org/apache/chemistry/opencmis/tck/impl/AbstractSessionTest.java
Date Sun, 31 Jul 2011 20:01:13 GMT
Author: fmui
Date: Sun Jul 31 20:01:12 2011
New Revision: 1152622

URL: http://svn.apache.org/viewvc?rev=1152622&view=rev
Log:
TCK: added content checks

Modified:
    chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tck/src/main/java/org/apache/chemistry/opencmis/tck/impl/AbstractSessionTest.java

Modified: chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tck/src/main/java/org/apache/chemistry/opencmis/tck/impl/AbstractSessionTest.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/impl/AbstractSessionTest.java?rev=1152622&r1=1152621&r2=1152622&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tck/src/main/java/org/apache/chemistry/opencmis/tck/impl/AbstractSessionTest.java
(original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tck/src/main/java/org/apache/chemistry/opencmis/tck/impl/AbstractSessionTest.java
Sun Jul 31 20:01:12 2011
@@ -25,6 +25,7 @@ import static org.apache.chemistry.openc
 import static org.apache.chemistry.opencmis.tck.CmisTestResultStatus.WARNING;
 
 import java.io.ByteArrayInputStream;
+import java.io.InputStream;
 import java.math.BigInteger;
 import java.util.ArrayList;
 import java.util.GregorianCalendar;
@@ -62,6 +63,7 @@ import org.apache.chemistry.opencmis.com
 import org.apache.chemistry.opencmis.commons.enums.BaseTypeId;
 import org.apache.chemistry.opencmis.commons.enums.BindingType;
 import org.apache.chemistry.opencmis.commons.enums.Cardinality;
+import org.apache.chemistry.opencmis.commons.enums.ContentStreamAllowed;
 import org.apache.chemistry.opencmis.commons.enums.IncludeRelationships;
 import org.apache.chemistry.opencmis.commons.enums.PropertyType;
 import org.apache.chemistry.opencmis.commons.enums.Updatability;
@@ -639,6 +641,9 @@ public abstract class AbstractSessionTes
 
             // check relationships
             checkRelationships(session, results, object);
+
+            // check document content
+            checkDocumentContent(session, results, object);
         }
 
         CmisTestResultImpl result = createResult(getWorst(results), message);
@@ -671,6 +676,95 @@ public abstract class AbstractSessionTes
         }
     }
 
+    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();
+
+        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!"));
+            }
+        }
+
+        ContentStream contentStream = doc.getContentStream();
+
+        if (contentStream == null) {
+            if (hasContentProperties) {
+                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!"));
+        }
+
+        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));
+        }
+        f = createResult(FAILURE, "Content MIME types don't match!");
+        addResult(results, assertEquals(doc.getContentStreamMimeType(), contentStream.getMimeType(),
null, f));
+
+        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();
+
+            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));
+        }
+    }
+
     protected CmisTestResult checkVersionHistory(Session session, CmisObject object, String[]
properties, String message) {
         List<CmisTestResult> results = new ArrayList<CmisTestResult>();
 



Mime
View raw message