You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pivot.apache.org by gb...@apache.org on 2010/06/08 16:33:24 UTC
svn commit: r952662 - in
/pivot/branches/1.5.x/core/test/org/apache/pivot/json/test: BindTest.java
SampleBean.java
Author: gbrown
Date: Tue Jun 8 14:33:24 2010
New Revision: 952662
URL: http://svn.apache.org/viewvc?rev=952662&view=rev
Log:
Add JSON/bean binding unit tests.
Added:
pivot/branches/1.5.x/core/test/org/apache/pivot/json/test/BindTest.java
pivot/branches/1.5.x/core/test/org/apache/pivot/json/test/SampleBean.java
Added: pivot/branches/1.5.x/core/test/org/apache/pivot/json/test/BindTest.java
URL: http://svn.apache.org/viewvc/pivot/branches/1.5.x/core/test/org/apache/pivot/json/test/BindTest.java?rev=952662&view=auto
==============================================================================
--- pivot/branches/1.5.x/core/test/org/apache/pivot/json/test/BindTest.java (added)
+++ pivot/branches/1.5.x/core/test/org/apache/pivot/json/test/BindTest.java Tue Jun 8 14:33:24 2010
@@ -0,0 +1,43 @@
+/*
+ * 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.pivot.json.test;
+
+import static org.junit.Assert.assertEquals;
+
+import java.io.IOException;
+
+import org.apache.pivot.json.JSON;
+import org.apache.pivot.json.JSONSerializer;
+import org.apache.pivot.serialization.SerializationException;
+import org.junit.Test;
+
+public class BindTest {
+ @Test
+ public void testBind() throws IOException, SerializationException {
+ JSONSerializer jsonSerializer = new JSONSerializer();
+ Object sampleObject = jsonSerializer.readObject(getClass().getResourceAsStream("sample.json"));
+ SampleBean sampleBean = JSON.bind(sampleObject, SampleBean.class);
+
+ assertEquals(sampleBean.getA(), JSON.get(sampleObject, "a"));
+ assertEquals(sampleBean.getB(), JSON.get(sampleObject, "b"));
+ assertEquals(sampleBean.getC(), JSON.get(sampleObject, "c"));
+ assertEquals(sampleBean.getD(), JSON.get(sampleObject, "d"));
+ assertEquals(sampleBean.getE(), JSON.get(sampleObject, "e"));
+ assertEquals(sampleBean.getI().getA(), JSON.get(sampleObject, "i.a"));
+ assertEquals(sampleBean.getJ()[0], JSON.get(sampleObject, "j[0]"));
+ }
+}
Added: pivot/branches/1.5.x/core/test/org/apache/pivot/json/test/SampleBean.java
URL: http://svn.apache.org/viewvc/pivot/branches/1.5.x/core/test/org/apache/pivot/json/test/SampleBean.java?rev=952662&view=auto
==============================================================================
--- pivot/branches/1.5.x/core/test/org/apache/pivot/json/test/SampleBean.java (added)
+++ pivot/branches/1.5.x/core/test/org/apache/pivot/json/test/SampleBean.java Tue Jun 8 14:33:24 2010
@@ -0,0 +1,86 @@
+/*
+ * 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.pivot.json.test;
+
+import org.apache.pivot.collections.ArrayList;
+import org.apache.pivot.collections.HashMap;
+
+public class SampleBean {
+ private int a = 0;
+ private String b = null;
+ private boolean c = false;
+ private ArrayList<String> d = null;
+ private HashMap<String, Integer> e = null;
+ private SampleBean i = null;
+ private int[] j = null;
+
+ public int getA() {
+ return a;
+ }
+
+ public void setA(int a) {
+ this.a = a;
+ }
+
+ public String getB() {
+ return b;
+ }
+
+ public void setB(String b) {
+ this.b = b;
+ }
+
+ public boolean getC() {
+ return c;
+ }
+
+ public void setC(boolean c) {
+ this.c = c;
+ }
+
+ public ArrayList<String> getD() {
+ return d;
+ }
+
+ public void setD(ArrayList<String> d) {
+ this.d = d;
+ }
+
+ public HashMap<String, Integer> getE() {
+ return e;
+ }
+
+ public void setE(HashMap<String, Integer> e) {
+ this.e = e;
+ }
+
+ public SampleBean getI() {
+ return i;
+ }
+
+ public void setI(SampleBean i) {
+ this.i = i;
+ }
+
+ public int[] getJ() {
+ return j;
+ }
+
+ public void setJ(int[] j) {
+ this.j = j;
+ }
+}