jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ste...@apache.org
Subject svn commit: r1330400 - in /jackrabbit/oak/trunk/oak-it/mk/src/main/java/org/apache/jackrabbit/mk/test: AbstractMicroKernelIT.java MicroKernelIT.java
Date Wed, 25 Apr 2012 16:30:03 GMT
Author: stefan
Date: Wed Apr 25 16:30:02 2012
New Revision: 1330400

URL: http://svn.apache.org/viewvc?rev=1330400&view=rev
Log:
OAK-12: Implement a test suite for the MicroKernel (WIP)

Modified:
    jackrabbit/oak/trunk/oak-it/mk/src/main/java/org/apache/jackrabbit/mk/test/AbstractMicroKernelIT.java
    jackrabbit/oak/trunk/oak-it/mk/src/main/java/org/apache/jackrabbit/mk/test/MicroKernelIT.java

Modified: jackrabbit/oak/trunk/oak-it/mk/src/main/java/org/apache/jackrabbit/mk/test/AbstractMicroKernelIT.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-it/mk/src/main/java/org/apache/jackrabbit/mk/test/AbstractMicroKernelIT.java?rev=1330400&r1=1330399&r2=1330400&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-it/mk/src/main/java/org/apache/jackrabbit/mk/test/AbstractMicroKernelIT.java
(original)
+++ jackrabbit/oak/trunk/oak-it/mk/src/main/java/org/apache/jackrabbit/mk/test/AbstractMicroKernelIT.java
Wed Apr 25 16:30:02 2012
@@ -26,10 +26,12 @@ import org.json.simple.JSONObject;
 import org.json.simple.parser.JSONParser;
 import org.junit.After;
 import org.junit.Before;
+import org.junit.ComparisonFailure;
 import org.junit.runners.Parameterized.Parameters;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
 
 /**
  * Abstract base class for {@link MicroKernel} integration tests.
@@ -123,6 +125,7 @@ public abstract class AbstractMicroKerne
         fixture.tearDownCluster(mks);
     }
 
+    //--------------------------------< utility methods for parsing json data >
     /**
      * Returns a {@code JSONParser} instance for parsing JSON format data.
      * This method returns a cached instance.
@@ -140,7 +143,6 @@ public abstract class AbstractMicroKerne
         return parser;
     }
 
-    //--------------------------------< utility methods for parsing json data >
     /**
      * Parses the provided string into a {@code JSONObject}.
      *
@@ -176,4 +178,89 @@ public abstract class AbstractMicroKerne
             throw new AssertionError("not a valid JSON array: " + e.getMessage());
         }
     }
+
+    protected void assertPropertyValue(JSONObject obj, String relPath, Double expected)
+            throws AssertionError {
+        Object val = resolveValue(obj, relPath);
+        assertNotNull("not found: " + relPath, val);
+
+        assertEquals(expected, val);
+    }
+
+    protected void assertPropertyValue(JSONObject obj, String relPath, Long expected)
+            throws AssertionError {
+        Object val = resolveValue(obj, relPath);
+        assertNotNull("not found: " + relPath, val);
+
+        assertEquals(expected, val);
+    }
+
+    protected void assertPropertyValue(JSONObject obj, String relPath, Boolean expected)
+            throws AssertionError {
+        Object val = resolveValue(obj, relPath);
+        assertNotNull("not found: " + relPath, val);
+
+        assertEquals(expected, val);
+    }
+
+    protected void assertPropertyValue(JSONObject obj, String relPath, String expected)
+            throws AssertionError {
+        Object val = resolveValue(obj, relPath);
+        assertNotNull("not found: " + relPath, val);
+
+        assertEquals(expected, val);
+    }
+
+    protected void assertPropertyValue(JSONObject obj, String relPath, Object[] expected)
+            throws AssertionError {
+        JSONArray array = resolveArrayValue(obj, relPath);
+        assertNotNull("not found: " + relPath, array);
+
+        assertEquals(expected.length, array.size());
+
+        // JSON numeric types: Double, Long
+        // convert types as necessary for comparison using equals method
+        for (int i = 0; i < array.size(); i++) {
+            Object o1 = expected[i];
+            Object o2 = array.get(i);
+            if (o1 instanceof Number && o2 instanceof Number) {
+                if (o1 instanceof Integer) {
+                    o1 = new Long((Integer) o1);
+                } else if (o1 instanceof Short) {
+                    o1 = new Long((Short) o1);
+                } else if (o1 instanceof Float) {
+                    o1 = new Double((Float) o1);
+                }
+            }
+            assertEquals(o1, o2);
+        }
+    }
+
+    protected JSONObject resolveObjectValue(JSONObject obj, String relPath) {
+        Object val = resolveValue(obj, relPath);
+        if (val instanceof JSONObject) {
+            return (JSONObject) val;
+        }
+        throw new AssertionError("failed to resolve JSONObject value at " + relPath + ":
" + val);
+    }
+
+    protected JSONArray resolveArrayValue(JSONObject obj, String relPath) {
+        Object val = resolveValue(obj, relPath);
+        if (val instanceof JSONArray) {
+            return (JSONArray) val;
+        }
+        throw new AssertionError("failed to resolve JSONArray value at " + relPath + ": "
+ val);
+    }
+
+    protected Object resolveValue(JSONObject obj, String relPath) {
+        String names[] = relPath.split("/");
+        Object val = obj;
+        for (String name : names) {
+            if (! (val instanceof JSONObject)) {
+                throw new AssertionError("not found: " + relPath);
+            }
+            val = ((JSONObject) val).get(name);
+        }
+        return val;
+    }
 }

Modified: jackrabbit/oak/trunk/oak-it/mk/src/main/java/org/apache/jackrabbit/mk/test/MicroKernelIT.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-it/mk/src/main/java/org/apache/jackrabbit/mk/test/MicroKernelIT.java?rev=1330400&r1=1330399&r2=1330400&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-it/mk/src/main/java/org/apache/jackrabbit/mk/test/MicroKernelIT.java
(original)
+++ jackrabbit/oak/trunk/oak-it/mk/src/main/java/org/apache/jackrabbit/mk/test/MicroKernelIT.java
Wed Apr 25 16:30:02 2012
@@ -42,6 +42,7 @@ public class MicroKernelIT extends Abstr
                 "\"stringProp\":\"stringVal\"," +
                 "\"intProp\":42," +
                 "\"floatProp\":42.2," +
+                "\"booleanProp\": true," +
                 "\"multiIntProp\":[1,2,3]}", null, "");
     }
 
@@ -68,8 +69,13 @@ public class MicroKernelIT extends Abstr
     public void getNodes() {
         String head = mk.getHeadRevision();
 
-        JSONObject jsonObj = parseJSONObject(mk.getNodes("/test", head, 0, 0, -1, null));
-        assertTrue(jsonObj.containsKey("stringProp"));
+        // verify initial content
+        JSONObject obj = parseJSONObject(mk.getNodes("/", head, 1, 0, -1, null));
+        assertPropertyValue(obj, "test/stringProp", "stringVal");
+        assertPropertyValue(obj, "test/intProp", 42L);
+        assertPropertyValue(obj, "test/floatProp", 42.2);
+        assertPropertyValue(obj, "test/booleanProp", true);
+        assertPropertyValue(obj, "test/multiIntProp", new Object[]{1,2,3});
     }
 
     @Test
@@ -141,8 +147,8 @@ public class MicroKernelIT extends Abstr
         head = mk.commit("/",
                 "+\"fuu\" : {} \n" +
                         "^\"fuu/bar\" : 42", head, "");
-        String n = mk.getNodes("/fuu", head);
-        assertEquals("{\"bar\":42,\":childNodeCount\":0}", n);
+        JSONObject jsonObj = parseJSONObject(mk.getNodes("/fuu", head));
+        assertEquals(42l, jsonObj.get("bar"));
     }
 
     @Test



Mime
View raw message