jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1212018 [5/7] - in /jackrabbit/sandbox/jackrabbit-microkernel: ./ src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/jackrabbit/ src/main/java/org/apache/jackrabbit/configuration/ src/main/j...
Date Thu, 08 Dec 2011 18:18:45 GMT
Propchange: jackrabbit/sandbox/jackrabbit-microkernel/src/test/java/org/apache/jackrabbit/json/JsonParserTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/sandbox/jackrabbit-microkernel/src/test/java/org/apache/jackrabbit/json/JsonParserTest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Added: jackrabbit/sandbox/jackrabbit-microkernel/src/test/java/org/apache/jackrabbit/json/JsopParserTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-microkernel/src/test/java/org/apache/jackrabbit/json/JsopParserTest.java?rev=1212018&view=auto
==============================================================================
--- jackrabbit/sandbox/jackrabbit-microkernel/src/test/java/org/apache/jackrabbit/json/JsopParserTest.java
(added)
+++ jackrabbit/sandbox/jackrabbit-microkernel/src/test/java/org/apache/jackrabbit/json/JsopParserTest.java
Thu Dec  8 18:18:42 2011
@@ -0,0 +1,102 @@
+/*
+ * 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.json;
+
+import org.apache.jackrabbit.json.Token.Type;
+import org.junit.Test;
+
+import static junit.framework.Assert.assertEquals;
+
+public class JsopParserTest {
+
+    @Test
+    public void test() {
+        String jsop =
+            "+\"foo\":\"bar\"" +
+            "+ \"foo\" : \"bar\"" +
+            "+ \"foo\" : {\"key\" : [12, 34]}" +
+            "- \"foo\"" +
+            "^ \"foo\" : \"bar\"" +
+            "> \"foo\" : \"bar\"" +
+            "> \"foo\" : {\"moo\" : \"bar\"}" +
+            "+ \"foo\" : [12, 34]" +
+            "^ \"foo\" : [12, 34]";
+
+        new JsopParser(new JsopHandler(){
+            @Override
+            public void add(Token path, JsonTokenizer value) {
+                assertEquals("foo", path.text());
+                assertEquals(Type.BEGIN_OBJECT, value.read().type());
+                assertEquals("key", value.read().text());
+                assertEquals(Type.COLON, value.read().type());
+                assertEquals(Type.BEGIN_ARRAY, value.read().type());
+                assertEquals("12", value.read().text());
+                assertEquals(Type.COMMA, value.read().type());
+                assertEquals("34", value.read().text());
+                assertEquals(Type.END_ARRAY, value.read().type());
+                assertEquals(Type.END_OBJECT, value.read().type());
+            }
+
+            @Override
+            public void add(Token path, Token value) {
+                assertEquals("foo", path.text());
+                assertEquals("bar", value.text());
+            }
+
+            @Override
+            public void add(Token path, Token[] values) {
+                assertEquals(2, values.length);
+                assertEquals("12", values[0].text());
+                assertEquals("34", values[1].text());
+            }
+
+            @Override
+            public void remove(Token path) {
+                assertEquals("foo", path.text());
+            }
+
+            @Override
+            public void set(Token path, Token value) {
+                assertEquals("foo", path.text());
+                assertEquals("bar", value.text());
+            }
+
+            @Override
+            public void set(Token path, Token[] values) {
+                assertEquals(2, values.length);
+                assertEquals("12", values[0].text());
+                assertEquals("34", values[1].text());
+            }
+
+            @Override
+            public void reorder(Token path, Token position, Token target) {
+                assertEquals("foo", path.text());
+                assertEquals("moo", position.text());
+                assertEquals("bar", target.text());
+            }
+
+            @Override
+            public void move(Token path, Token target) {
+                assertEquals("foo", path.text());
+                assertEquals("bar", target.text());
+            }
+        }).parseJsop(new DefaultJsonTokenizer(jsop));
+    }
+}

Propchange: jackrabbit/sandbox/jackrabbit-microkernel/src/test/java/org/apache/jackrabbit/json/JsopParserTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/sandbox/jackrabbit-microkernel/src/test/java/org/apache/jackrabbit/json/JsopParserTest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Added: jackrabbit/sandbox/jackrabbit-microkernel/src/test/java/org/apache/jackrabbit/json/UnescapingJsonTokenizerTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-microkernel/src/test/java/org/apache/jackrabbit/json/UnescapingJsonTokenizerTest.java?rev=1212018&view=auto
==============================================================================
--- jackrabbit/sandbox/jackrabbit-microkernel/src/test/java/org/apache/jackrabbit/json/UnescapingJsonTokenizerTest.java
(added)
+++ jackrabbit/sandbox/jackrabbit-microkernel/src/test/java/org/apache/jackrabbit/json/UnescapingJsonTokenizerTest.java
Thu Dec  8 18:18:42 2011
@@ -0,0 +1,59 @@
+/*
+ * 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.json;
+
+import org.apache.jackrabbit.json.Token.Type;
+import org.junit.Test;
+
+import static junit.framework.Assert.assertEquals;
+
+public class UnescapingJsonTokenizerTest {
+
+    private static final Token[] TOKENS = new Token[] {
+        new Token(Type.STRING, "foobar", 0),
+        new Token(Type.STRING, "foo\\bar", 9),
+        new Token(Type.STRING, "foobar", 20),
+        new Token(Type.STRING, "foobar", 33),
+        new Token(Type.STRING, "foo\bbar", 48),
+        new Token(Type.STRING, "foo\tbar", 59),
+        new Token(Type.STRING, "foo\nbar", 70),
+        new Token(Type.STRING, "foo\fbar", 81),
+        new Token(Type.STRING, "foo\rbar", 92),
+        new Token(Type.STRING, "foo\"bar", 103),
+    };
+
+    private static final Token EOF_TOKEN = new Token(Type.EOF, "", 113);
+
+    @Test
+    public void test() {
+        JsonTokenizer tokenizer = new UnescapingJsonTokenizer("\"foobar\" \"foo\\\\bar\"
" +
+                "\"foo\\x62bar\" \"foo\\u0062bar\" \"foo\\bbar\" \"foo\\tbar\" \"foo\\nbar\"
" +
+                "\"foo\\fbar\" \"foo\\rbar\" \"foo\\\"bar\"");
+
+        for (Token token : TOKENS) {
+            Token t = tokenizer.read();
+            assertEquals(token, t);
+            assertEquals(token.pos(),  t.pos());
+        }
+        Token t = tokenizer.read();
+        assertEquals(EOF_TOKEN, t);
+        assertEquals(EOF_TOKEN.pos(), t.pos());
+    }
+}

Propchange: jackrabbit/sandbox/jackrabbit-microkernel/src/test/java/org/apache/jackrabbit/json/UnescapingJsonTokenizerTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/sandbox/jackrabbit-microkernel/src/test/java/org/apache/jackrabbit/json/UnescapingJsonTokenizerTest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Added: jackrabbit/sandbox/jackrabbit-microkernel/src/test/java/org/apache/jackrabbit/util/Loop.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-microkernel/src/test/java/org/apache/jackrabbit/util/Loop.java?rev=1212018&view=auto
==============================================================================
--- jackrabbit/sandbox/jackrabbit-microkernel/src/test/java/org/apache/jackrabbit/util/Loop.java
(added)
+++ jackrabbit/sandbox/jackrabbit-microkernel/src/test/java/org/apache/jackrabbit/util/Loop.java
Thu Dec  8 18:18:42 2011
@@ -0,0 +1,49 @@
+/*
+ * 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.util;
+
+/**
+ * This class loops up to 5 seconds for a test to succeed.
+ */
+public abstract class Loop {
+
+    public Loop() {
+        // loop at most 500 times with 10 milliseconds delay
+        for (int i = 0; i < 500; i++) {
+            try {
+                test();
+                return;
+            } catch (AssertionError e) {
+                // ignore
+            } catch (Exception e) {
+                // ignore
+            }
+            try {
+                Thread.sleep(10);
+            } catch (InterruptedException e) {
+                // ignore
+            }
+        }
+        test();
+    }
+
+    public abstract void test();
+
+}

Propchange: jackrabbit/sandbox/jackrabbit-microkernel/src/test/java/org/apache/jackrabbit/util/Loop.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/sandbox/jackrabbit-microkernel/src/test/java/org/apache/jackrabbit/util/Loop.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Added: jackrabbit/sandbox/jackrabbit-microkernel/src/test/java/org/apache/jackrabbit/util/NumberStream.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-microkernel/src/test/java/org/apache/jackrabbit/util/NumberStream.java?rev=1212018&view=auto
==============================================================================
--- jackrabbit/sandbox/jackrabbit-microkernel/src/test/java/org/apache/jackrabbit/util/NumberStream.java
(added)
+++ jackrabbit/sandbox/jackrabbit-microkernel/src/test/java/org/apache/jackrabbit/util/NumberStream.java
Thu Dec  8 18:18:42 2011
@@ -0,0 +1,40 @@
+/*
+ * 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.util;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+public class NumberStream extends InputStream {
+    private final int limit;
+    private int counter;
+
+    public NumberStream(int limit) {
+        this.limit = limit;
+    }
+
+    @Override
+    public int read() throws IOException {
+        return counter < limit
+            ? counter++ & 0xff
+            : -1;
+    }
+
+}

Propchange: jackrabbit/sandbox/jackrabbit-microkernel/src/test/java/org/apache/jackrabbit/util/NumberStream.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/sandbox/jackrabbit-microkernel/src/test/java/org/apache/jackrabbit/util/NumberStream.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Added: jackrabbit/sandbox/jackrabbit-microkernel/src/test/resources/test1.json
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-microkernel/src/test/resources/test1.json?rev=1212018&view=auto
==============================================================================
--- jackrabbit/sandbox/jackrabbit-microkernel/src/test/resources/test1.json (added)
+++ jackrabbit/sandbox/jackrabbit-microkernel/src/test/resources/test1.json Thu Dec  8 18:18:42
2011
@@ -0,0 +1 @@
+{"string":"va\"lue","empty":"","number":1.42,"null":null,"false":false,"true":true,"emptyArray":[],"nestedArray":[[],[[],[]]],"array":[1,2,3],"array2":["aa","bb","cc"],"emptyObject":{},"almostEmptyObject":{":size":12},"object":{":size":212,"string":"value","empty":"","number":1.42,"null":null,"false":false,"true":true,"emptyArray":[],"array1":[1,2,3,{}],"array2":[1,2,3,{"number":1.42,"array99":[1,2,3,{}]}],"emptyObject":{},"object":{}}}
\ No newline at end of file

Propchange: jackrabbit/sandbox/jackrabbit-microkernel/src/test/resources/test1.json
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message