You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ju...@apache.org on 2010/01/28 18:07:05 UTC

svn commit: r904159 - in /sling/trunk/bundles/extensions/groovy: ./ src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/sling/ src/main/java/org/apache/sling/commons/ src/main/java/org/apache/sling/common...

Author: justin
Date: Thu Jan 28 17:07:04 2010
New Revision: 904159

URL: http://svn.apache.org/viewvc?rev=904159&view=rev
Log:
creating dirs for SLING-1303

Added:
    sling/trunk/bundles/extensions/groovy/
    sling/trunk/bundles/extensions/groovy/pom.xml
    sling/trunk/bundles/extensions/groovy/src/
    sling/trunk/bundles/extensions/groovy/src/main/
    sling/trunk/bundles/extensions/groovy/src/main/java/
    sling/trunk/bundles/extensions/groovy/src/main/java/org/
    sling/trunk/bundles/extensions/groovy/src/main/java/org/apache/
    sling/trunk/bundles/extensions/groovy/src/main/java/org/apache/sling/
    sling/trunk/bundles/extensions/groovy/src/main/java/org/apache/sling/commons/
    sling/trunk/bundles/extensions/groovy/src/main/java/org/apache/sling/commons/json/
    sling/trunk/bundles/extensions/groovy/src/main/java/org/apache/sling/commons/json/groovy/
    sling/trunk/bundles/extensions/groovy/src/main/java/org/apache/sling/commons/json/groovy/dummy.txt
    sling/trunk/bundles/extensions/groovy/src/test/
    sling/trunk/bundles/extensions/groovy/src/test/java/
    sling/trunk/bundles/extensions/groovy/src/test/java/json/
    sling/trunk/bundles/extensions/groovy/src/test/java/json/JSONAssert.java

Added: sling/trunk/bundles/extensions/groovy/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/groovy/pom.xml?rev=904159&view=auto
==============================================================================
--- sling/trunk/bundles/extensions/groovy/pom.xml (added)
+++ sling/trunk/bundles/extensions/groovy/pom.xml Thu Jan 28 17:07:04 2010
@@ -0,0 +1,67 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!--
+  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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+    <modelVersion>4.0.0</modelVersion>
+    <parent>
+        <artifactId>sling</artifactId>
+        <groupId>org.apache.sling</groupId>
+        <version>8</version>
+    </parent>
+
+    <groupId>org.apache.sling</groupId>
+    <artifactId>org.apache.sling.extensions.groovy</artifactId>
+    <version>1.0.0-SNAPSHOT</version>
+    <packaging>bundle</packaging>
+
+    <name>Apache Sling Groovy Extensions</name>
+    <description>
+        Various extensions for Apache Sling to faciliate Groovy scripts.
+    </description>
+        
+    <scm>
+        <connection>scm:svn:http://svn.apache.org/repos/asf/sling/trunk/bundles/extensions/groovy</connection>
+        <developerConnection>scm:svn:https://svn.apache.org/repos/asf/sling/trunk/bundles/extensions/groovy</developerConnection>
+        <url>http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/groovy</url>
+    </scm>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.felix</groupId>
+                <artifactId>maven-bundle-plugin</artifactId>
+                <extensions>true</extensions>
+            </plugin>
+        </plugins>
+    </build>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.sling</groupId>
+            <artifactId>org.apache.sling.commons.json</artifactId>
+            <version>2.0.5-SNAPSHOT</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+        </dependency>
+    </dependencies>
+</project>
\ No newline at end of file

Added: sling/trunk/bundles/extensions/groovy/src/main/java/org/apache/sling/commons/json/groovy/dummy.txt
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/groovy/src/main/java/org/apache/sling/commons/json/groovy/dummy.txt?rev=904159&view=auto
==============================================================================
--- sling/trunk/bundles/extensions/groovy/src/main/java/org/apache/sling/commons/json/groovy/dummy.txt (added)
+++ sling/trunk/bundles/extensions/groovy/src/main/java/org/apache/sling/commons/json/groovy/dummy.txt Thu Jan 28 17:07:04 2010
@@ -0,0 +1 @@
+dummy

Added: sling/trunk/bundles/extensions/groovy/src/test/java/json/JSONAssert.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/groovy/src/test/java/json/JSONAssert.java?rev=904159&view=auto
==============================================================================
--- sling/trunk/bundles/extensions/groovy/src/test/java/json/JSONAssert.java (added)
+++ sling/trunk/bundles/extensions/groovy/src/test/java/json/JSONAssert.java Thu Jan 28 17:07:04 2010
@@ -0,0 +1,183 @@
+/*
+ * 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 json;
+
+import java.util.Iterator;
+
+import junit.framework.Assert;
+
+import org.apache.sling.commons.json.JSONArray;
+import org.apache.sling.commons.json.JSONException;
+import org.apache.sling.commons.json.JSONObject;
+
+/**
+ * Provides assertions on equality for JSON Arrays and Objects.
+ * 
+ * Based on code written by Andres Almiray <aa...@users.sourceforge.net> as
+ * part of the json-lib project - http://json-lib.sourceforge.net/
+ */
+public class JSONAssert extends Assert {
+	/**
+	 * Asserts that two JSONArrays are equal.
+	 */
+	public static void assertEquals(JSONArray expected, JSONArray actual)
+			throws JSONException {
+		assertEquals(null, expected, actual);
+	}
+
+	/**
+	 * Asserts that two JSONObjects are equal.
+	 */
+	public static void assertEquals(JSONObject expected, JSONObject actual)
+			throws JSONException {
+		assertEquals(null, expected, actual);
+	}
+
+	/**
+	 * Asserts that two JSONArrays are equal.
+	 */
+	public static void assertEquals(String message, JSONArray expected,
+			JSONArray actual) throws JSONException {
+		String header = message == null ? "" : message + ": ";
+		if (expected == null) {
+			fail(header + "expected array was null");
+		}
+		if (actual == null) {
+			fail(header + "actual array was null");
+		}
+		if (expected == actual || expected.equals(actual)) {
+			return;
+		}
+		if (actual.length() != expected.length()) {
+			fail(header + "arrays sizes differed, expected.length()="
+					+ expected.length() + " actual.length()=" + actual.length());
+		}
+
+		int max = expected.length();
+		for (int i = 0; i < max; i++) {
+			Object o1 = expected.get(i);
+			Object o2 = actual.get(i);
+
+			// handle nulls
+			if (JSONObject.NULL.equals(o1)) {
+				if (JSONObject.NULL.equals(o2)) {
+					continue;
+				} else {
+					fail(header + "arrays first differed at element [" + i
+							+ "];");
+				}
+			} else {
+				if (JSONObject.NULL.equals(o2)) {
+					fail(header + "arrays first differed at element [" + i
+							+ "];");
+				}
+			}
+
+			if (o1 instanceof JSONArray && o2 instanceof JSONArray) {
+				JSONArray e = (JSONArray) o1;
+				JSONArray a = (JSONArray) o2;
+				assertEquals(header + "arrays first differed at element " + i
+						+ ";", e, a);
+			} else if (o1 instanceof JSONObject && o2 instanceof JSONObject) {
+				assertEquals(header + "arrays first differed at element [" + i
+						+ "];", (JSONObject) o1, (JSONObject) o2);
+			} else if (o1 instanceof String) {
+				assertEquals(header + "arrays first differed at element [" + i
+						+ "];", (String) o1, String.valueOf(o2));
+			} else if (o2 instanceof String) {
+				assertEquals(header + "arrays first differed at element [" + i
+						+ "];", String.valueOf(o1), (String) o2);
+			} else {
+				assertEquals(header + "arrays first differed at element [" + i
+						+ "];", o1, o2);
+			}
+		}
+	}
+
+	/**
+	 * Asserts that two JSONObjects are equal.
+	 */
+	public static void assertEquals(String message, JSONObject expected,
+			JSONObject actual) throws JSONException {
+		String header = message == null ? "" : message + ": ";
+		if (expected == null) {
+			fail(header + "expected object was null");
+		}
+		if (actual == null) {
+			fail(header + "actual object was null");
+		}
+		if (expected == actual /* || expected.equals( actual ) */) {
+			return;
+		}
+
+		JSONArray expectedNames = expected.names();
+		JSONArray actualNames = actual.names();
+
+		if (expectedNames == null && actualNames == null) {
+			return;
+		}
+
+		if (expectedNames == null) {
+		    expectedNames = new JSONArray();
+		}
+		
+		if (actualNames == null) {
+		    actualNames = new JSONArray();
+		}
+
+		assertEquals(header
+				+ "names sizes differed, expected.names().length()="
+				+ expectedNames.length() + " actual.names().length()="
+				+ actualNames.length(), expectedNames.length(), actualNames
+				.length());
+		for (Iterator<String> keys = expected.keys(); keys.hasNext();) {
+			String key = (String) keys.next();
+			Object o1 = expected.opt(key);
+			Object o2 = actual.opt(key);
+
+			if (JSONObject.NULL.equals(o1)) {
+				if (JSONObject.NULL.equals(o2)) {
+					continue;
+				} else {
+					fail(header + "objects differed at key [" + key + "];");
+				}
+			} else {
+				if (JSONObject.NULL.equals(o2)) {
+					fail(header + "objects differed at key [" + key + "];");
+				}
+			}
+
+			if (o1 instanceof JSONObject && o2 instanceof JSONObject) {
+				assertEquals(header + "objects differed at key [" + key + "];",
+						(JSONObject) o1, (JSONObject) o2);
+			} else if (o1 instanceof JSONArray && o2 instanceof JSONArray) {
+				assertEquals(header + "objects differed at key [" + key + "];",
+						(JSONArray) o1, (JSONArray) o2);
+			} else if (o1 instanceof String) {
+				assertEquals(header + "objects differed at key [" + key + "];",
+						(String) o1, String.valueOf(o2));
+			} else if (o2 instanceof String) {
+				assertEquals(header + "objects differed at key [" + key + "];",
+						String.valueOf(o1), (String) o2);
+			} else {
+				assertEquals(header + "objects differed at key [" + key + "];",
+						o1, o2);
+			}
+		}
+	}
+
+}