jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1132604 - in /jackrabbit/sandbox/spi2microkernel/src: main/java/org/apache/jackrabbit/spi2microkernel/util/ test/java/org/apache/jackrabbit/spi2microkernel/ test/resources/ test/resources/org/ test/resources/org/apache/ test/resources/org/...
Date Mon, 06 Jun 2011 12:00:23 GMT
Author: mduerig
Date: Mon Jun  6 12:00:23 2011
New Revision: 1132604

URL: http://svn.apache.org/viewvc?rev=1132604&view=rev
Log:
spi2microkernel prototype (WIP)

Added:
    jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/JsonBuilder.java
    jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/JsonBuilderTest.java
    jackrabbit/sandbox/spi2microkernel/src/test/resources/
    jackrabbit/sandbox/spi2microkernel/src/test/resources/org/
    jackrabbit/sandbox/spi2microkernel/src/test/resources/org/apache/
    jackrabbit/sandbox/spi2microkernel/src/test/resources/org/apache/jackrabbit/
    jackrabbit/sandbox/spi2microkernel/src/test/resources/org/apache/jackrabbit/spi2microkernel/
    jackrabbit/sandbox/spi2microkernel/src/test/resources/org/apache/jackrabbit/spi2microkernel/test.json
Modified:
    jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/MicrokernelTests.java
    jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/Tests.java

Added: jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/JsonBuilder.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/JsonBuilder.java?rev=1132604&view=auto
==============================================================================
--- jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/JsonBuilder.java
(added)
+++ jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/JsonBuilder.java
Mon Jun  6 12:00:23 2011
@@ -0,0 +1,447 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.jackrabbit.spi2microkernel.util;
+
+import java.io.IOException;
+import java.io.Writer;
+
+/**
+ * Partially based on json-simple
+ * Limitation: arrays can only have primitive members (i.e. no arrays nor objects)
+ */
+public final class JsonBuilder {
+    private final Writer writer;
+
+    private JsonBuilder(Writer writer) {
+        this.writer = writer;
+    }
+
+    public static JsonObjectBuilder create(Writer writer) throws IOException {
+        return new JsonBuilder(writer).new JsonObjectBuilder(null);
+    }
+
+    public final class JsonObjectBuilder {
+        private final JsonObjectBuilder parent;
+
+        private boolean hasKeys;
+
+        public JsonObjectBuilder(JsonObjectBuilder parent) throws IOException {
+            this.parent = parent;
+            writer.write('{');
+        }
+        
+        public JsonObjectBuilder value(String key, String value) throws IOException {
+            write(key, encode(value));
+            return this;
+        }
+
+        public JsonObjectBuilder value(String key, int value) throws IOException {
+            write(key, encode(value));
+            return this;
+        }
+
+        public JsonObjectBuilder value(String key, long value) throws IOException {
+            write(key, encode(value));
+            return this;
+        }
+
+        public JsonObjectBuilder value(String key, float value) throws IOException {
+            write(key, encode(value));
+            return this;
+        }
+
+        public JsonObjectBuilder value(String key, double value) throws IOException {
+            write(key, encode(value));
+            return this;
+        }
+
+        public JsonObjectBuilder value(String key, Number value) throws IOException {
+            write(key, encode(value));
+            return this;
+        }
+
+        public JsonObjectBuilder value(String key, boolean value) throws IOException {
+            write(key, encode(value));
+            return this;
+        }
+
+        public JsonObjectBuilder nil(String key) throws IOException {
+            write(key, "null");
+            return this;
+        }
+
+        public JsonObjectBuilder array(String key, String[] value) throws IOException {
+            write(key, encode(value));
+            return this;
+        }
+
+        public JsonObjectBuilder array(String key, int[] value) throws IOException {
+            write(key, encode(value));
+            return this;
+        }
+
+        public JsonObjectBuilder array(String key, long[] value) throws IOException {
+            write(key, encode(value));
+            return this;
+        }
+
+        public JsonObjectBuilder array(String key, float[] value) throws IOException {
+            write(key, encode(value));
+            return this;
+        }
+
+        public JsonObjectBuilder array(String key, double[] value) throws IOException {
+            write(key, encode(value));
+            return this;
+        }
+
+        public JsonObjectBuilder array(String key, Number[] value) throws IOException {
+            write(key, encode(value));
+            return this;
+        }
+
+        public JsonObjectBuilder array(String key, boolean[] value) throws IOException {
+            write(key, encode(value));
+            return this;
+        }
+
+        public JsonArrayBuilder array(String key) throws IOException {
+            writeKey(key);
+            return new JsonArrayBuilder(this);
+        }
+
+        public JsonObjectBuilder object(String key) throws IOException {
+            writeKey(key);
+            return new JsonObjectBuilder(this);
+        }
+
+        public JsonObjectBuilder build() throws IOException {
+            writer.write('}');
+            return parent;
+        }
+
+        //------------------------------------------< private >---
+
+        private void optionalComma() throws IOException {
+            if (hasKeys) {
+                writer.write(',');
+            }
+            else {
+                hasKeys = true;
+            }
+        }
+
+        private void writeKey(String key) throws IOException {
+            optionalComma();
+            writer.write(quote(escape(key)));
+            writer.write(':');
+        }
+
+        private void write(String key, String value) throws IOException {
+            writeKey(key);
+            writer.write(value);
+        }
+
+    }
+
+    public final class JsonArrayBuilder {
+        private final JsonObjectBuilder parent;
+
+        private boolean hasValues;
+
+        public JsonArrayBuilder(JsonObjectBuilder parent) throws IOException {
+            writer.write('[');
+            this.parent = parent;
+        }
+
+        public JsonArrayBuilder value(String value) throws IOException {
+            optionalComma();
+            writer.write(encode(value));
+            return this;
+        }
+
+        public JsonArrayBuilder value(int value) throws IOException {
+            optionalComma();
+            writer.write(encode(value));
+            return this;
+        }
+
+        public JsonArrayBuilder value(long value) throws IOException {
+            optionalComma();
+            writer.write(encode(value));
+            return this;
+        }
+
+        public JsonArrayBuilder value(float value) throws IOException {
+            optionalComma();
+            writer.write(encode(value));
+            return this;
+        }
+
+        public JsonArrayBuilder value(double value) throws IOException {
+            optionalComma();
+            writer.write(encode(value));
+            return this;
+        }
+
+        public JsonArrayBuilder value(Number value) throws IOException {
+            optionalComma();
+            writer.write(encode(value));
+            return this;
+        }
+
+        public JsonArrayBuilder value(boolean value) throws IOException {
+            optionalComma();
+            writer.write(encode(value));
+            return this;
+        }
+
+        public JsonArrayBuilder nil() throws IOException {
+            optionalComma();
+            writer.write("null");
+            return this;
+        }
+
+        public JsonObjectBuilder build() throws IOException {
+            writer.write(']');
+            return parent;
+        }
+
+        //------------------------------------------< private >---
+
+        private void optionalComma() throws IOException {
+            if (hasValues) {
+                writer.write(',');
+            }
+            else {
+                hasValues = true;
+            }
+        }
+    }
+
+    //------------------------------------------< private >---
+
+    private static String quote(String string) {
+        return '"' + string + '"';
+    }
+
+    private static String encode(String value) {
+        return quote(escape(value)); 
+    }
+
+    private static String encode(int value) {
+        return Integer.toString(value);
+    }
+
+    private static String encode(long value) {
+        return Long.toString(value); 
+    }
+
+    private static String encode(float value) {
+        return Float.isInfinite(value) || Float.isNaN(value)
+            ? "null"
+            : Float.toString(value);
+    }
+
+    private static String encode(double value) {
+        return Double.isInfinite(value) || Double.isNaN(value)
+            ? "null"
+            : Double.toString(value);
+    }
+
+    private static String encode(Number value) {
+        return value.toString();
+    }
+
+    private static String encode(boolean value) {
+        return Boolean.toString(value); 
+    }
+
+    private static String encode(String[] values) {
+        if (values.length == 0) {
+            return "[]";
+        }
+
+        StringBuffer sb = new StringBuffer();
+        sb.append('[');
+        for (String value : values) {
+            sb.append(encode(value));
+            sb.append(',');
+        }
+        sb.deleteCharAt(sb.length() - 1);
+        sb.append(']');
+        return sb.toString();
+    }
+
+    private static String encode(int[] values) {
+        if (values.length == 0) {
+            return "[]";
+        }
+
+        StringBuffer sb = new StringBuffer();
+        sb.append('[');
+        for (int value : values) {
+            sb.append(encode(value));
+            sb.append(',');
+        }
+        sb.deleteCharAt(sb.length() - 1);
+        sb.append(']');
+        return sb.toString();
+    }
+
+    private static String encode(long[] values) {
+        if (values.length == 0) {
+            return "[]";
+        }
+
+        StringBuffer sb = new StringBuffer();
+        sb.append('[');
+        for (long value : values) {
+            sb.append(encode(value));
+            sb.append(',');
+        }
+        sb.deleteCharAt(sb.length() - 1);
+        sb.append(']');
+        return sb.toString();
+    }
+
+    private static String encode(float[] values) {
+        if (values.length == 0) {
+            return "[]";
+        }
+
+        StringBuffer sb = new StringBuffer();
+        sb.append('[');
+        for (float value : values) {
+            sb.append(encode(value));
+            sb.append(',');
+        }
+        sb.deleteCharAt(sb.length() - 1);
+        sb.append(']');
+        return sb.toString();
+    }
+
+    private static String encode(double[] values) {
+        if (values.length == 0) {
+            return "[]";
+        }
+
+        StringBuffer sb = new StringBuffer();
+        sb.append('[');
+        for (double value : values) {
+            sb.append(encode(value));
+            sb.append(',');
+        }
+        sb.deleteCharAt(sb.length() - 1);
+        sb.append(']');
+        return sb.toString();
+    }
+
+    private static String encode(Number[] values) {
+        if (values.length == 0) {
+            return "[]";
+        }
+
+        StringBuffer sb = new StringBuffer();
+        sb.append('[');
+        for (Number value : values) {
+            sb.append(encode(value));
+            sb.append(',');
+        }
+        sb.deleteCharAt(sb.length() - 1);
+        sb.append(']');
+        return sb.toString();
+    }
+
+    private static String encode(boolean[] values) {
+        if (values.length == 0) {
+            return "[]";
+        }
+
+        StringBuffer sb = new StringBuffer();
+        sb.append('[');
+        for (boolean value : values) {
+            sb.append(encode(value));
+            sb.append(',');
+        }
+        sb.deleteCharAt(sb.length() - 1);
+        sb.append(']');
+        return sb.toString();
+    }
+
+    /**
+     * Escape quotes, \, /, \r, \n, \b, \f, \t and other control characters (U+0000 through
U+001F).
+     */
+    private static String escape(String string) {
+        if(string == null) {
+            return null;
+        }
+
+        StringBuffer sb = new StringBuffer();
+		for(int i = 0; i < string.length(); i++) {
+			char ch = string.charAt(i);
+			switch(ch) {
+                case '"':
+                    sb.append("\\\"");
+                    break;
+                case '\\':
+                    sb.append("\\\\");
+                    break;
+                case '\b':
+                    sb.append("\\b");
+                    break;
+                case '\f':
+                    sb.append("\\f");
+                    break;
+                case '\n':
+                    sb.append("\\n");
+                    break;
+                case '\r':
+                    sb.append("\\r");
+                    break;
+                case '\t':
+                    sb.append("\\t");
+                    break;
+                case '/':
+                    sb.append("\\/");
+                    break;
+                default:
+                    //Reference: http://www.unicode.org/versions/Unicode5.1.0/
+                    if (ch >= '\u0000' && ch <= '\u001F' ||
+                        ch >= '\u007F' && ch <= '\u009F' ||
+                        ch >= '\u2000' && ch <= '\u20FF') {
+
+                        String ss = Integer.toHexString(ch);
+                        sb.append("\\u");
+                        for (int k = 0; k < 4 - ss.length(); k++) {
+                            sb.append('0');
+                        }
+                        sb.append(ss.toUpperCase());
+                    }
+                    else {
+                        sb.append(ch);
+                    }
+			}
+		}
+
+        return sb.toString();
+	}
+
+}

Added: jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/JsonBuilderTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/JsonBuilderTest.java?rev=1132604&view=auto
==============================================================================
--- jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/JsonBuilderTest.java
(added)
+++ jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/JsonBuilderTest.java
Mon Jun  6 12:00:23 2011
@@ -0,0 +1,201 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.jackrabbit.spi2microkernel;
+
+import junit.framework.Assert;
+import org.apache.jackrabbit.spi2microkernel.util.JsonBuilder;
+import org.apache.jackrabbit.spi2microkernel.util.JsonBuilder.JsonArrayBuilder;
+import org.apache.jackrabbit.spi2microkernel.util.JsonBuilder.JsonObjectBuilder;
+import org.apache.jackrabbit.spi2microkernel.util.JsonHandlerBase;
+import org.json.simple.parser.JSONParser;
+import org.json.simple.parser.ParseException;
+import org.junit.Test;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.io.StringReader;
+import java.io.StringWriter;
+import java.math.BigDecimal;
+
+import static junit.framework.Assert.assertEquals;
+
+public class JsonBuilderTest {
+
+    @Test 
+    public void jsonBuilderTest() throws IOException {
+
+        StringWriter sw = new StringWriter();
+        JsonBuilder.create(sw)
+                .value("foo", "bar")
+                .value("int", 3)
+                .value("float", 3f)
+                .object("obj")
+                    .value("boolean", true)
+                    .nil("nil")
+                    .array("arr")
+                        .value(1)
+                        .value(2.0f)
+                        .value(2.0d)
+                        .value("42")
+                    .build()
+                .build()
+                .array("string array", new String[]{"","1","foo"})
+                .array("int array", new int[]{1,2,3})
+                .array("long array", new long[]{1,2,3})
+                .array("float array", new float[]{1,2,3})
+                .array("double array", new double[]{1,2,3})
+                .array("boolean array", new boolean[]{true, false})
+                .array("number array", new BigDecimal[]{new BigDecimal(21), new BigDecimal(42)})
+                .value("some", "more")
+            .build();
+
+        String json = sw.toString();
+        assertEquals("{\"foo\":\"bar\",\"int\":3,\"float\":3.0,\"obj\":{\"boolean\":true,\"nil\":null,"
+
+                "\"arr\":[1,2.0,2.0,\"42\"]},\"string array\":[\"\",\"1\",\"foo\"],\"int
array\":[1,2,3]," +
+                "\"long array\":[1,2,3],\"float array\":[1.0,2.0,3.0],\"double array\":[1.0,2.0,3.0],"
+
+                "\"boolean array\":[true,false],\"number array\":[21,42],\"some\":\"more\"}",
json);
+    }
+
+    @Test
+    public void fixedPointTest() throws IOException, ParseException {
+        InputStream one = JsonBuilderTest.class.getResourceAsStream("test.json");
+        InputStreamReader isr = new InputStreamReader(one);
+
+        String s1 = fix(isr);
+        String s2 = fix(s1);
+
+        // fix == fix fix
+        assertEquals(s1, s2);
+    }
+
+    //------------------------------------------< private >---
+
+    private static String fix(Reader reader) throws IOException, ParseException {
+        StringWriter sw = new StringWriter();
+        new JSONParser().parse(reader, new JsonHandler(JsonBuilder.create(sw)));
+        return sw.toString();
+    }
+
+    private static String fix(String string) throws IOException, ParseException {
+        return fix(new StringReader(string));
+    }
+
+    private static class JsonHandler extends JsonHandlerBase {
+        private JsonObjectBuilder objectBuilder;
+        private JsonArrayBuilder arrayBuilder;
+        private String currentKey;
+
+        public JsonHandler(JsonObjectBuilder objectBuilder) {
+            this.objectBuilder = objectBuilder;
+        }
+
+        @Override
+        public boolean startObject() throws ParseException, IOException {
+            if (currentKey != null) {
+                objectBuilder = objectBuilder.object(currentKey);
+            }
+            return true;
+        }
+
+        @Override
+        public boolean endObject() throws ParseException, IOException {
+            objectBuilder = objectBuilder.build();
+            return true;
+        }
+
+        @Override
+        public boolean startObjectEntry(String key) throws ParseException, IOException {
+            currentKey = key;
+            return true;
+        }
+
+        @Override
+        public boolean startArray() throws ParseException, IOException {
+            arrayBuilder = objectBuilder.array(currentKey);
+            return true;
+        }
+
+        @Override
+        public boolean endArray() throws ParseException, IOException {
+            objectBuilder = arrayBuilder.build();
+            arrayBuilder = null;
+            return true;
+        }
+
+        @Override
+        public boolean primitive(Object value) throws ParseException, IOException {
+            if (arrayBuilder == null) {
+                if(value == null){
+                    objectBuilder.nil(currentKey);
+                }
+                else if(value instanceof String) {
+                    objectBuilder.value(currentKey, (String)value);
+                }
+                else if(value instanceof Integer) {
+                    objectBuilder.value(currentKey, ((Integer) value).intValue());
+                }
+                else if(value instanceof Long) {
+                    objectBuilder.value(currentKey, ((Long) value).longValue());
+                }
+                else if(value instanceof Double) {
+                    objectBuilder.value(currentKey, ((Double) value).doubleValue());
+                }
+                else if(value instanceof Float) {
+                    objectBuilder.value(currentKey, ((Float) value).floatValue());
+                }
+                else if(value instanceof Boolean) {
+                    objectBuilder.value(currentKey, (Boolean) value);
+                }
+                else {
+                    Assert.fail();
+                }
+            }
+            else {
+                if(value == null){
+                    arrayBuilder.nil();
+                }
+                else if(value instanceof String) {
+                    arrayBuilder.value((String) value);
+                }
+                else if(value instanceof Integer) {
+                    arrayBuilder.value(((Integer) value).intValue());
+                }
+                else if(value instanceof Long) {
+                    arrayBuilder.value(((Long) value).longValue());
+                }
+                else if(value instanceof Double) {
+                    arrayBuilder.value(((Double) value).doubleValue());
+                }
+                else if(value instanceof Float) {
+                    arrayBuilder.value(((Float) value).floatValue());
+                }
+                else if(value instanceof Boolean) {
+                    arrayBuilder.value((Boolean) value);
+                }
+                else {
+                    Assert.fail();
+                }
+            }
+            return true;
+        }
+    }
+}

Modified: jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/MicrokernelTests.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/MicrokernelTests.java?rev=1132604&r1=1132603&r2=1132604&view=diff
==============================================================================
--- jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/MicrokernelTests.java
(original)
+++ jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/MicrokernelTests.java
Mon Jun  6 12:00:23 2011
@@ -20,31 +20,43 @@
 package org.apache.jackrabbit.spi2microkernel;
 
 import org.apache.jackrabbit.mk.MicroKernelImpl;
+import org.apache.jackrabbit.mk.api.MicroKernel;
+import org.json.simple.JSONObject;
+import org.json.simple.parser.JSONParser;
+import org.json.simple.parser.ParseException;
 import org.junit.Before;
 import org.junit.Ignore;
 import org.junit.Test;
 
 import java.io.File;
+import java.lang.reflect.Array;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
 
 public class MicrokernelTests {
     private static final File REPO_HOME_DIR = new File("target/repository");
 
+    private MicroKernelImpl microkernel;
+
     @Before
     public void setup() {
-        MicroKernelImpl mk = new MicroKernelImpl(REPO_HOME_DIR.getAbsolutePath());
+        MicroKernel mk = getMicroKernel();
         String head = mk.getHeadRevision();
 
         if (!mk.nodeExists("/test", head)) {
-            mk.commit("/", "+test : {}", head);
+            mk.commit("/", "+test : {" +
+                "\"stringProp\":\"stringVal\"," +
+                "\"intProp\":42," +
+                "\"floatProp\":42.2," +
+                "\"multiIntProp\":[1,2,3]} ", head);
         }
     }
 
     @Ignore  // todo fix in microkernel
     @Test
     public void missingName() {
-        MicroKernelImpl mk = new MicroKernelImpl(REPO_HOME_DIR.getAbsolutePath());
+        MicroKernel mk = getMicroKernel();
         String head = mk.getHeadRevision();
 
         String s1 = mk.getNodes("/test", 0, head);
@@ -55,9 +67,69 @@ public class MicrokernelTests {
     @Ignore  // todo fix in microkernel
     @Test
     public void npe() {
-        MicroKernelImpl mk = new MicroKernelImpl(REPO_HOME_DIR.getAbsolutePath());
+        MicroKernel mk = getMicroKernel();
         String head = mk.getHeadRevision();
 
         mk.commit("/", "+foo/bar : {}", head);
     }
+
+    @Test
+    public void testStringProperty() throws ParseException {
+        MicroKernel mk = getMicroKernel();
+        String head = mk.getHeadRevision();
+
+        String json = mk.getNodes("/test", 2, head);
+        JSONObject result = (JSONObject) new JSONParser().parse(json);
+        Object stringProp = result.get("stringProp");
+        assertTrue(stringProp instanceof String);
+        assertEquals("stringVal", stringProp);
+    }
+
+    @Ignore  // todo fix in microkernel
+    @Test
+    public void testIntProperty() throws ParseException {
+        MicroKernel mk = getMicroKernel();
+        String head = mk.getHeadRevision();
+
+        String json = mk.getNodes("/test", 2, head);
+        JSONObject result = (JSONObject) new JSONParser().parse(json);
+        Object intProp = result.get("intProp");
+        assertTrue(intProp instanceof Long);
+        assertEquals(42, intProp);
+    }
+
+    @Ignore  // todo fix in microkernel
+    @Test
+    public void testFloatProperty() throws ParseException {
+        MicroKernel mk = getMicroKernel();
+        String head = mk.getHeadRevision();
+
+        String json = mk.getNodes("/test", 2, head);
+        JSONObject result = (JSONObject) new JSONParser().parse(json);
+        Object floatProp = result.get("floatProp");
+        assertTrue(floatProp instanceof Double);
+        assertEquals(42.2, floatProp);
+    }
+
+    @Ignore  // todo fix in microkernel
+    @Test
+    public void testMultiIntProperty() throws ParseException {
+        MicroKernel mk = getMicroKernel();
+        String head = mk.getHeadRevision();
+
+        String json = mk.getNodes("/test", 2, head);
+        JSONObject result = (JSONObject) new JSONParser().parse(json);
+        Object multiIntProp = result.get("multiIntProp");
+        assertTrue(multiIntProp instanceof Array);
+    }
+
+    //------------------------------------------< private >---
+
+    private MicroKernel getMicroKernel() {
+        if (microkernel == null) {
+            microkernel = new MicroKernelImpl(REPO_HOME_DIR.getAbsolutePath());
+        }
+        return microkernel; 
+    }
+
 }

Modified: jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/Tests.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/Tests.java?rev=1132604&r1=1132603&r2=1132604&view=diff
==============================================================================
--- jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/Tests.java
(original)
+++ jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/Tests.java
Mon Jun  6 12:00:23 2011
@@ -35,12 +35,12 @@ import javax.jcr.RepositoryFactory;
 import javax.jcr.Session;
 import javax.jcr.Value;
 import java.io.File;
-import java.util.Arrays;
 import java.util.Collections;
 import java.util.HashSet;
 import java.util.Iterator;
 import java.util.Set;
 
+import static java.util.Arrays.asList;
 import static org.junit.Assert.*;
 
 public class Tests {
@@ -99,11 +99,8 @@ public class Tests {
             add("system");
         }};
 
-        for (String wsp : workspaces) {
-            assertTrue(names.remove(wsp));
-        }
-
-        assertTrue(names.isEmpty());
+        assertTrue(asList(workspaces).containsAll(names));
+        assertTrue(names.containsAll(asList(workspaces)));
     }
 
     @Test
@@ -113,7 +110,7 @@ public class Tests {
         Session session2 = getRepository().login();
         try {
             String[] workspaces = session2.getWorkspace().getAccessibleWorkspaceNames();
-            assertTrue(Arrays.asList(workspaces).contains("new"));
+            assertTrue(asList(workspaces).contains("new"));
             Session session3 = getRepository().login("new");
             assertEquals("new", session3.getWorkspace().getName());
             session3.logout();
@@ -126,7 +123,7 @@ public class Tests {
         Session session4 = getRepository().login();
         try {
             String[] workspaces = session4.getWorkspace().getAccessibleWorkspaceNames();
-            assertFalse(Arrays.asList(workspaces).contains("new"));
+            assertFalse(asList(workspaces).contains("new"));
         }
         finally {
             session4.logout();
@@ -156,6 +153,18 @@ public class Tests {
         assertEquals("/foo", node.getPath());
     }
 
+    @Test
+    public void getNodeFromNode() throws RepositoryException {
+        Node root = getNode("/");
+        Node node = root.getNode("foo");
+        assertNotNull(node);
+        assertEquals("foo", node.getName());
+        assertEquals("/foo", node.getPath());
+
+        Node nodeAgain = getNode("/foo");
+        assertTrue(node.isSame(nodeAgain));
+    }
+
     @Test(expected = PathNotFoundException.class)
     public void getNonexNode() throws RepositoryException {
         getNode("/qoo");
@@ -163,7 +172,7 @@ public class Tests {
 
     @Test
     public void getProperty() throws RepositoryException {
-        Property property = getSession().getProperty("/foo/stringProp");
+        Property property = getProperty("/foo/stringProp");
         assertNotNull(property);
         assertEquals("stringProp", property.getName());
         assertEquals("/foo/stringProp", property.getPath());
@@ -186,6 +195,9 @@ public class Tests {
         assertNotNull(value);
         assertEquals(PropertyType.STRING, value.getType());
         assertEquals("stringVal", value.getString());
+
+        Property propertyAgain = getProperty("/foo/stringProp");
+        assertTrue(property.isSame(propertyAgain));
     }
 
     //------------------------------------------< private >---
@@ -213,4 +225,8 @@ public class Tests {
     private Node getNode(String path) throws RepositoryException {
         return getSession().getNode(path);
     }
+
+    private Property getProperty(String path) throws RepositoryException {
+        return getSession().getProperty(path);
+    }
 }

Added: jackrabbit/sandbox/spi2microkernel/src/test/resources/org/apache/jackrabbit/spi2microkernel/test.json
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/spi2microkernel/src/test/resources/org/apache/jackrabbit/spi2microkernel/test.json?rev=1132604&view=auto
==============================================================================
--- jackrabbit/sandbox/spi2microkernel/src/test/resources/org/apache/jackrabbit/spi2microkernel/test.json
(added)
+++ jackrabbit/sandbox/spi2microkernel/src/test/resources/org/apache/jackrabbit/spi2microkernel/test.json
Mon Jun  6 12:00:23 2011
@@ -0,0 +1,31 @@
+{
+    "a":"Aqq",
+    "b":"Bqq",
+    "arr":[1,2,3,0.2, true, null, "quc"],
+    "obj":{
+        "q":0.02,
+        "n":null,
+        "bool": {
+            "t":true,
+            "f":false
+        },
+        "":{"":{"":{"":{"":{"":{"":{"":{"":{"":{"":{"":{"":{}}}}}}}}}}}}},
+        "1":{
+	        "test-node" : {
+                "jcr:primaryType" : "sling:propertySetTestNodeType",
+                "string" : "Sling",
+                "strings" : ["Apache", "Sling"],
+                "long" : 42,
+                "longs" : [4, 8, 15, 16, 23, 42],
+                "boolean" : true,
+                "booleans" : [true, false],
+                "uri" : "http://www.google.com/",
+                "uris" : ["http://sling.apache.org/", "http://www.google.com/"],
+                "name" : "sling:test",
+                "names" : ["jcr:base", "sling:test"],
+                "path" : "/sling-test/initial-content-folder/folder-content-test",
+                "paths" : ["/sling-test/initial-content-folder/folder-content-test", "/apps"]
+	       }
+        }
+    }
+}
\ No newline at end of file



Mime
View raw message