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 2011/08/02 16:18:35 UTC
svn commit: r1153136 - in
/chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tck/src/main/java/org/apache/chemistry/opencmis/tck/impl:
AbstractCmisTest.java AbstractSessionTest.java
Author: fmui
Date: Tue Aug 2 14:18:34 2011
New Revision: 1153136
URL: http://svn.apache.org/viewvc?rev=1153136&view=rev
Log:
TCK: added object comparison
Modified:
chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tck/src/main/java/org/apache/chemistry/opencmis/tck/impl/AbstractCmisTest.java
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/AbstractCmisTest.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/AbstractCmisTest.java?rev=1153136&r1=1153135&r2=1153136&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tck/src/main/java/org/apache/chemistry/opencmis/tck/impl/AbstractCmisTest.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tck/src/main/java/org/apache/chemistry/opencmis/tck/impl/AbstractCmisTest.java Tue Aug 2 14:18:34 2011
@@ -18,7 +18,9 @@
*/
package org.apache.chemistry.opencmis.tck.impl;
+import java.text.SimpleDateFormat;
import java.util.ArrayList;
+import java.util.Calendar;
import java.util.Collection;
import java.util.List;
import java.util.Map;
@@ -144,6 +146,21 @@ public abstract class AbstractCmisTest i
return result;
}
+ // --- helpers ----
+
+ protected String formatValue(Object o) {
+ if (o == null) {
+ return "null";
+ }
+
+ if (o instanceof Calendar) {
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
+ return sdf.format(((Calendar) o).getTime());
+ }
+
+ return o.toString();
+ }
+
// --- asserts ----
protected boolean isEqual(Object expected, Object actual) {
@@ -235,8 +252,10 @@ public abstract class AbstractCmisTest i
return success;
}
- return addResultChild(failure,
- createResult(CmisTestResultStatus.INFO, "expected: " + expected + " / actual: " + actual));
+ return addResultChild(
+ failure,
+ createResult(CmisTestResultStatus.INFO, "expected: " + formatValue(expected) + " / actual: "
+ + formatValue(actual)));
}
protected CmisTestResult assertContains(Collection<?> collection, Object value, CmisTestResult success,
@@ -250,7 +269,7 @@ public abstract class AbstractCmisTest i
}
return addResultChild(failure,
- createResult(CmisTestResultStatus.INFO, "Collection does not contain '" + value + "'"));
+ createResult(CmisTestResultStatus.INFO, "Collection does not contain '" + formatValue(value) + "'"));
}
protected CmisTestResult assertEqualLists(List<?> expected, List<?> actual, CmisTestResult success,
@@ -278,8 +297,9 @@ public abstract class AbstractCmisTest i
if (!isEqual(expected.get(i), actual.get(i))) {
return addResultChild(
failure,
- createResult(CmisTestResultStatus.INFO, "expected list item[" + i + "]: " + expected.get(i)
- + " / actual list item[" + i + "]: " + actual.get(i)));
+ createResult(CmisTestResultStatus.INFO, "expected list item[" + i + "]: "
+ + formatValue(expected.get(i)) + " / actual list item[" + i + "]: "
+ + formatValue(actual.get(i))));
}
}
@@ -309,7 +329,8 @@ public abstract class AbstractCmisTest i
for (Object o : expected) {
if (!actual.contains(o)) {
- return addResultChild(failure, createResult(CmisTestResultStatus.INFO, "Item not in actual set: " + o));
+ return addResultChild(failure,
+ createResult(CmisTestResultStatus.INFO, "Item not in actual set: " + formatValue(o)));
}
}
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=1153136&r1=1153135&r2=1153136&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 Tue Aug 2 14:18:34 2011
@@ -1243,6 +1243,26 @@ public abstract class AbstractSessionTes
f = createResult(FAILURE, "Folder is not found in childs parents! Id: " + child.getId());
addResult(results, assertIsTrue(parents.size() > 0, null, f));
}
+
+ // get object by id and compare
+ CmisObject objectById = session.getObject(child.getId(), SELECT_ALL_NO_CACHE_OC);
+
+ f = createResult(FAILURE, "Child and object fetched by id don't match! Id: " + child.getId());
+ addResult(results, assertEquals(child, objectById, null, f));
+
+ // get object by path and compare
+ List<String> paths = ((FileableCmisObject) child).getPaths();
+
+ if (paths == null || paths.isEmpty()) {
+ addResult(results, createResult(FAILURE, "Child has no path! " + child.getId()));
+ } else {
+ for (String path : paths) {
+ CmisObject objectByPath = session.getObjectByPath(path);
+
+ f = createResult(FAILURE, "Child and object fetched by path don't match! Id: " + child.getId());
+ addResult(results, assertEquals(child, objectByPath, null, f));
+ }
+ }
}
f = createResult(FAILURE, "Child has no CAN_GET_OBJECT_PARENTS allowable action! Id: " + child.getId());
@@ -1835,6 +1855,110 @@ public abstract class AbstractSessionTes
}
}
+ protected CmisTestResult assertEquals(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;
+ }
+
+ 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));
+ }
+ }
+
+ // TODO: compare allowable actions
+ // TODO: compare ACLs
+ // TODO: compare renditions
+ // TODO: compare policies
+ // TODO: compare relationships
+
+ 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;
+ }
+ }
+
+ 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;
+ }
+ }
+
// --- helpers ---
protected void addResult(List<CmisTestResult> results, CmisTestResult result) {