You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@johnzon.apache.org by st...@apache.org on 2016/11/22 21:06:37 UTC

[2/6] johnzon git commit: Update geronimo-json-spec from 1.0 to 1.1, add JsonPointer encode and decode methods

Update geronimo-json-spec from 1.0 to 1.1, add JsonPointer encode and decode methods


Project: http://git-wip-us.apache.org/repos/asf/johnzon/repo
Commit: http://git-wip-us.apache.org/repos/asf/johnzon/commit/d8a56d05
Tree: http://git-wip-us.apache.org/repos/asf/johnzon/tree/d8a56d05
Diff: http://git-wip-us.apache.org/repos/asf/johnzon/diff/d8a56d05

Branch: refs/heads/JSONP-1.1
Commit: d8a56d05cd1d22c85ecad781cdbef4f01f77697c
Parents: 28748ff
Author: Mark Struberg <st...@apache.org>
Authored: Tue Nov 22 21:26:02 2016 +0100
Committer: Mark Struberg <st...@apache.org>
Committed: Tue Nov 22 21:26:02 2016 +0100

----------------------------------------------------------------------
 .../apache/johnzon/core/JsonPointerUtil.java    | 24 +++--
 .../johnzon/core/JsonPointerUtilTest.java       | 97 +++++++++++++++++++-
 johnzon-distribution/pom.xml                    |  3 +-
 3 files changed, 113 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/johnzon/blob/d8a56d05/johnzon-core/src/main/java/org/apache/johnzon/core/JsonPointerUtil.java
----------------------------------------------------------------------
diff --git a/johnzon-core/src/main/java/org/apache/johnzon/core/JsonPointerUtil.java b/johnzon-core/src/main/java/org/apache/johnzon/core/JsonPointerUtil.java
index 276fb42..91bc9c2 100644
--- a/johnzon-core/src/main/java/org/apache/johnzon/core/JsonPointerUtil.java
+++ b/johnzon-core/src/main/java/org/apache/johnzon/core/JsonPointerUtil.java
@@ -20,18 +20,30 @@ package org.apache.johnzon.core;
 
 public class JsonPointerUtil {
 
+    private JsonPointerUtil() {
+
+    }
+
     /**
-     *
-     * @param s
-     * @return
+     * Transforms "~" to "~0" and then "/" to "~1"
      */
     public static String encode(String s) {
-        return null;
+        if (s == null || s.length() == 0) {
+            return s;
+        }
+
+        return s.replace("~", "~0").replace("/", "~1");
     }
 
+    /**
+     * Transforms "~1" to "/" and then "~0" to "~",
+     */
     public static String decode(String s) {
-        return null;
-    }
+        if (s == null || s.length() == 0) {
+            return s;
+        }
 
+        return s.replace("~1", "/").replace("~0", "~");
+    }
 
 }

http://git-wip-us.apache.org/repos/asf/johnzon/blob/d8a56d05/johnzon-core/src/test/java/org/apache/johnzon/core/JsonPointerUtilTest.java
----------------------------------------------------------------------
diff --git a/johnzon-core/src/test/java/org/apache/johnzon/core/JsonPointerUtilTest.java b/johnzon-core/src/test/java/org/apache/johnzon/core/JsonPointerUtilTest.java
index 226d742..73b0e01 100644
--- a/johnzon-core/src/test/java/org/apache/johnzon/core/JsonPointerUtilTest.java
+++ b/johnzon-core/src/test/java/org/apache/johnzon/core/JsonPointerUtilTest.java
@@ -1,7 +1,98 @@
+/*
+ * 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.johnzon.core;
 
-/**
- * @author Armin Hasler (02eex458)
- */
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+
+import org.junit.Test;
+
 public class JsonPointerUtilTest {
+
+    @Test
+    public void testEncodeNull() {
+        assertNull(JsonPointerUtil.encode(null));
+    }
+
+    @Test
+    public void testEncodeEmptyString() {
+        String encodedString = JsonPointerUtil.encode("");
+        assertEquals("", encodedString);
+    }
+
+    @Test
+    public void testEncodeNoTransformation() {
+        String encodedString = JsonPointerUtil.encode("TestString");
+        assertEquals("TestString", encodedString);
+    }
+
+    @Test
+    public void testEncodeFirstTransformation() {
+        String encodedString = JsonPointerUtil.encode("~");
+        assertEquals("~0", encodedString);
+    }
+
+    @Test
+    public void testEncodeSecondTransformation() {
+        String encodedString = JsonPointerUtil.encode("/");
+        assertEquals("~1", encodedString);
+    }
+
+    @Test
+    public void testEncodeWholeTransformation() {
+        String decodedString = JsonPointerUtil.encode("~/");
+        assertEquals("~0~1", decodedString);
+    }
+
+    @Test
+    public void testDecodeNull() {
+        assertNull(JsonPointerUtil.decode(null));
+    }
+
+    @Test
+    public void testDecodeEmptyString() {
+        String decodedString = JsonPointerUtil.decode("");
+        assertEquals("", decodedString);
+    }
+
+    @Test
+    public void testDecodeNoTransformation() {
+        String decodedString = JsonPointerUtil.decode("TestString");
+        assertEquals("TestString", decodedString);
+    }
+
+    @Test
+    public void testDecodeFirstTransformation() {
+        String decodedString = JsonPointerUtil.decode("~1");
+        assertEquals("/", decodedString);
+    }
+
+    @Test
+    public void testDecodeSecondTransformation() {
+        String decodedString = JsonPointerUtil.decode("~0");
+        assertEquals("~", decodedString);
+    }
+
+    @Test
+    public void testDecodeWholeTransformation() {
+        String decodedString = JsonPointerUtil.decode("~01");
+        assertEquals("~1", decodedString);
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/johnzon/blob/d8a56d05/johnzon-distribution/pom.xml
----------------------------------------------------------------------
diff --git a/johnzon-distribution/pom.xml b/johnzon-distribution/pom.xml
index c0e6e26..f6f468e 100644
--- a/johnzon-distribution/pom.xml
+++ b/johnzon-distribution/pom.xml
@@ -21,7 +21,7 @@
   <parent>
     <artifactId>johnzon</artifactId>
     <groupId>org.apache.johnzon</groupId>
-    <version>0.9.6-SNAPSHOT</version>
+    <version>0.9.4-SNAPSHOT</version>
   </parent>
   <modelVersion>4.0.0</modelVersion>
 
@@ -49,7 +49,6 @@
       <scope>compile</scope>
       <classifier>javadoc</classifier>
     </dependency>
-
     <dependency>
       <groupId>org.apache.johnzon</groupId>
       <artifactId>johnzon-core</artifactId>