From 28f92c6fc62f3bc0637ac77681aabcc8c0b5e42c Mon Sep 17 00:00:00 2001 From: lresende Date: Thu, 11 Sep 2008 04:12:24 +0000 Subject: Renaming branch git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@694107 13f79535-47bb-0310-9956-ffa450edef68 --- .../databinding/json/JSONTransformerTestCase.java | 128 ---------------- .../databinding/json/JavaBean2JSONTestCase.java | 170 --------------------- .../tuscany/sca/databinding/json/MyBean.java | 158 ------------------- .../tuscany/sca/databinding/json/MyInterface.java | 29 ---- .../sca/databinding/json/MyInterfaceImpl.java | 67 -------- .../tuscany/sca/databinding/json/POJOTestCase.java | 87 ----------- 6 files changed, 639 deletions(-) delete mode 100644 branches/trunk-20080910/modules/databinding-json/src/test/java/org/apache/tuscany/sca/databinding/json/JSONTransformerTestCase.java delete mode 100644 branches/trunk-20080910/modules/databinding-json/src/test/java/org/apache/tuscany/sca/databinding/json/JavaBean2JSONTestCase.java delete mode 100644 branches/trunk-20080910/modules/databinding-json/src/test/java/org/apache/tuscany/sca/databinding/json/MyBean.java delete mode 100644 branches/trunk-20080910/modules/databinding-json/src/test/java/org/apache/tuscany/sca/databinding/json/MyInterface.java delete mode 100644 branches/trunk-20080910/modules/databinding-json/src/test/java/org/apache/tuscany/sca/databinding/json/MyInterfaceImpl.java delete mode 100644 branches/trunk-20080910/modules/databinding-json/src/test/java/org/apache/tuscany/sca/databinding/json/POJOTestCase.java (limited to 'branches/trunk-20080910/modules/databinding-json/src/test/java/org') diff --git a/branches/trunk-20080910/modules/databinding-json/src/test/java/org/apache/tuscany/sca/databinding/json/JSONTransformerTestCase.java b/branches/trunk-20080910/modules/databinding-json/src/test/java/org/apache/tuscany/sca/databinding/json/JSONTransformerTestCase.java deleted file mode 100644 index 3c7f151ed7..0000000000 --- a/branches/trunk-20080910/modules/databinding-json/src/test/java/org/apache/tuscany/sca/databinding/json/JSONTransformerTestCase.java +++ /dev/null @@ -1,128 +0,0 @@ -/* - * 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.tuscany.sca.databinding.json; - -import java.io.StringReader; -import java.io.StringWriter; - -import javax.xml.namespace.QName; -import javax.xml.stream.XMLInputFactory; -import javax.xml.stream.XMLOutputFactory; -import javax.xml.stream.XMLStreamReader; -import javax.xml.stream.XMLStreamWriter; - -import junit.framework.Assert; -import junit.framework.TestCase; - -import org.apache.axiom.om.OMElement; -import org.apache.tuscany.sca.databinding.TransformationContext; -import org.apache.tuscany.sca.databinding.impl.TransformationContextImpl; -import org.apache.tuscany.sca.databinding.json.axiom.JSON2OMElement; -import org.apache.tuscany.sca.databinding.xml.XMLStreamSerializer; -import org.apache.tuscany.sca.interfacedef.DataType; -import org.apache.tuscany.sca.interfacedef.impl.DataTypeImpl; -import org.apache.tuscany.sca.interfacedef.util.XMLType; -import org.json.JSONObject; - -public class JSONTransformerTestCase extends TestCase { - private static final String IPO_XML = "" + "" - + " " - + " Helen Zoe" - + " 47 Eden Street" - + " Cambridge" - + " CB1 1JR" - + " " - + " " - + " Robert Smith" - + " 8 Oak Avenue" - + " Old Town" - + " PA" - + " 95819" - + " " - + " " - + " " - + " Lapis necklace" - + " 1" - + " 99.95" - + " Want this for the holidays" - + " 1999-12-05" - + " " - + " " - + ""; - - private static final String JSON_STR = "{\"xsl:root\":{\"@xmlns\":{\"xsl\":\"http://foo.com\"},\"data\":{\"$\":\"my json string\"}}}"; - - public void testXML2JSON() throws Exception { - XMLStreamReader reader = XMLInputFactory.newInstance().createXMLStreamReader(new StringReader(IPO_XML)); - XMLStreamReader2JSON t1 = new XMLStreamReader2JSON(); - JSONObject json = (JSONObject) t1.transform(reader, null); - Assert.assertNotNull(json); - - // Cannot round-trip as we hit a bug in Jettison: http://jira.codehaus.org/browse/JETTISON-37 - /* - JSON2XMLStreamReader t2 = new JSON2XMLStreamReader(); - XMLStreamReader reader2 = t2.transform(json, null); - StringWriter sw = new StringWriter(); - XMLStreamWriter streamWriter = XMLOutputFactory.newInstance().createXMLStreamWriter(sw); - new XMLStreamSerializer().serialize(reader2, streamWriter); - streamWriter.flush(); - System.out.println(sw.toString()); - */ - - } - - public void testJSON2XML() throws Exception { - JSON2XMLStreamReader t2 = new JSON2XMLStreamReader(); - XMLStreamReader reader2 = t2.transform(new JSONObject(JSON_STR), null); - StringWriter sw = new StringWriter(); - XMLStreamWriter streamWriter = XMLOutputFactory.newInstance().createXMLStreamWriter(sw); - new XMLStreamSerializer().serialize(reader2, streamWriter); - streamWriter.flush(); - Assert.assertTrue(sw.toString() - .contains("my json string")); - } - - public void testJSON2OMElement() throws Exception { - JSON2OMElement t1 = new JSON2OMElement(); - TransformationContext context = new TransformationContextImpl(); - DataType dt = new DataTypeImpl(Object.class, new XMLType(new QName("http://foo.com", "root"), null)); - context.setTargetDataType(dt); - OMElement element = t1.transform(new JSONObject(JSON_STR), context); - StringWriter writer = new StringWriter(); - element.serialize(writer); - // System.out.println(writer.toString()); - } - - public void testString2JSON() throws Exception { - String json = "{\"name\":\"John\",\"age\":25}"; - String2JSON t1 = new String2JSON(); - JSONObject jsonObject = (JSONObject) t1.transform(json, null); - assertEquals(jsonObject.getString("name"), "John"); - assertEquals(jsonObject.getInt("age"), 25); - JSON2String t2 = new JSON2String(); - String str = t2.transform(jsonObject, null); - assertTrue(str.contains("\"name\":\"John\"")); - assertTrue(str.contains("\"age\":25")); - } -} diff --git a/branches/trunk-20080910/modules/databinding-json/src/test/java/org/apache/tuscany/sca/databinding/json/JavaBean2JSONTestCase.java b/branches/trunk-20080910/modules/databinding-json/src/test/java/org/apache/tuscany/sca/databinding/json/JavaBean2JSONTestCase.java deleted file mode 100644 index 3b36f5be74..0000000000 --- a/branches/trunk-20080910/modules/databinding-json/src/test/java/org/apache/tuscany/sca/databinding/json/JavaBean2JSONTestCase.java +++ /dev/null @@ -1,170 +0,0 @@ -/* - * 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.tuscany.sca.databinding.json; - -import java.util.ArrayList; -import java.util.List; - -import junit.framework.Assert; - -import org.apache.tuscany.sca.databinding.TransformationContext; -import org.apache.tuscany.sca.databinding.impl.TransformationContextImpl; -import org.apache.tuscany.sca.interfacedef.impl.DataTypeImpl; -import org.json.JSONObject; -import org.junit.Test; - -/** - * @version $Rev$ $Date$ - */ -public class JavaBean2JSONTestCase { - - public static class MyBean { - private String name; - private int age; - private boolean vip; - private String friends[]; - private List books; - private YourBean you; - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public int getAge() { - return age; - } - - public void setAge(int age) { - this.age = age; - } - - public boolean isVip() { - return vip; - } - - public void setVip(boolean vip) { - this.vip = vip; - } - - public String[] getFriends() { - return friends; - } - - public void setFriends(String[] friends) { - this.friends = friends; - } - - public List getBooks() { - return books; - } - - public void setBooks(List books) { - this.books = books; - } - - public YourBean getYou() { - return you; - } - - public void setYou(YourBean you) { - this.you = you; - } - - } - - public static class YourBean { - private int id; - private String name; - - public int getId() { - return id; - } - - public void setId(int id) { - this.id = id; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - } - - @Test - public void testBean2JSON() throws Exception { - MyBean me = new MyBean(); - me.setAge(30); - me.setBooks(new ArrayList()); - me.setFriends(new String[] {"John", "Mike"}); - me.setVip(true); - me.setName("Me"); - YourBean you = new YourBean(); - you.setId(123); - you.setName(null); - me.setYou(you); - JavaBean2JSON t1 = new JavaBean2JSON(); - Object result = t1.transform(me, null); - System.out.println(result); - JSON2JavaBean t2 = new JSON2JavaBean(); - TransformationContext context = new TransformationContextImpl(); - context.setTargetDataType(new DataTypeImpl(MyBean.class, null)); - Object v = t2.transform(new JSONObject(result.toString()), context); - Assert.assertTrue(v instanceof MyBean); - // String json = - // "{\"age\":30,\"books\":[],\"friends\":[\"John\",\"Mike\"],\"name\":\"Me\",\"vip\":true,\"you\":{\"id\":123,\"name\":null}}"; - // Assert.assertEquals(json, result.toString()); - } - - @Test - public void testString2JSON() throws Exception { - JavaBean2JSONObject t1 = new JavaBean2JSONObject(); - Object result = t1.transform("ABC", null); - System.out.println(result); - JSON2JavaBean t2 = new JSON2JavaBean(); - TransformationContext context = new TransformationContextImpl(); - context.setTargetDataType(new DataTypeImpl(String.class, null)); - Object v = t2.transform(result, context); - Assert.assertTrue(v instanceof String); - Assert.assertEquals("ABC", v); - } - - @Test - public void testStringArray2JSON() throws Exception { - JavaBean2JSON t1 = new JavaBean2JSON(); - Object result = t1.transform(new String[] {"ABC", "DF"}, null); - System.out.println(result); - JSON2JavaBean t2 = new JSON2JavaBean(); - TransformationContext context = new TransformationContextImpl(); - context.setTargetDataType(new DataTypeImpl(String[].class, null)); - Object v = t2.transform(result, context); - Assert.assertTrue(v instanceof String[]); - String[] strs = (String[])v; - Assert.assertEquals("ABC", strs[0]); - Assert.assertEquals("DF", strs[1]); - } - -} diff --git a/branches/trunk-20080910/modules/databinding-json/src/test/java/org/apache/tuscany/sca/databinding/json/MyBean.java b/branches/trunk-20080910/modules/databinding-json/src/test/java/org/apache/tuscany/sca/databinding/json/MyBean.java deleted file mode 100644 index 60b293c1d4..0000000000 --- a/branches/trunk-20080910/modules/databinding-json/src/test/java/org/apache/tuscany/sca/databinding/json/MyBean.java +++ /dev/null @@ -1,158 +0,0 @@ -/* - * 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.tuscany.sca.databinding.json; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -public class MyBean { - private int age; - private String name; - private float[] rates = new float[] {1.0f, 2.0f}; - private List notes = new ArrayList(); - private Map map = new HashMap(); - private Object service; - private Object otherService; - private boolean good; - - public int getAge() { - return age; - } - - public void setAge(int age) { - this.age = age; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public List getNotes() { - return notes; - } - - public void setNotes(List notes) { - this.notes = notes; - } - - public float[] getRates() { - return rates; - } - - public void setRates(float[] rates) { - this.rates = rates; - } - - public Map getMap() { - return map; - } - - public void setMap(Map map) { - this.map = map; - } - - public Object getService() { - return service; - } - - public void setService(Object service) { - this.service = service; - } - - public Object getOtherService() { - return otherService; - } - - public void setOtherService(Object otherService) { - this.otherService = otherService; - } - - public boolean isGood() { - return good; - } - - public void setGood(boolean good) { - this.good = good; - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + age; - result = prime * result + (good ? 1231 : 1237); - result = prime * result + ((map == null) ? 0 : map.hashCode()); - result = prime * result + ((name == null) ? 0 : name.hashCode()); - result = prime * result + ((notes == null) ? 0 : notes.hashCode()); - result = prime * result + ((otherService == null) ? 0 : otherService.hashCode()); - result = prime * result + Arrays.hashCode(rates); - result = prime * result + ((service == null) ? 0 : service.hashCode()); - return result; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - final MyBean other = (MyBean)obj; - if (age != other.age) - return false; - if (good != other.good) - return false; - if (map == null) { - if (other.map != null) - return false; - } else if (!map.equals(other.map)) - return false; - if (name == null) { - if (other.name != null) - return false; - } else if (!name.equals(other.name)) - return false; - if (notes == null) { - if (other.notes != null) - return false; - } else if (!notes.equals(other.notes)) - return false; - if (otherService == null) { - if (other.otherService != null) - return false; - } else if (!otherService.equals(other.otherService)) - return false; - if (!Arrays.equals(rates, other.rates)) - return false; - if (service == null) { - if (other.service != null) - return false; - } else if (!service.equals(other.service)) - return false; - return true; - } -} diff --git a/branches/trunk-20080910/modules/databinding-json/src/test/java/org/apache/tuscany/sca/databinding/json/MyInterface.java b/branches/trunk-20080910/modules/databinding-json/src/test/java/org/apache/tuscany/sca/databinding/json/MyInterface.java deleted file mode 100644 index d32e0763c7..0000000000 --- a/branches/trunk-20080910/modules/databinding-json/src/test/java/org/apache/tuscany/sca/databinding/json/MyInterface.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * 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.tuscany.sca.databinding.json; - -/** - * @version $Rev$ $Date$ - */ -public interface MyInterface { - void setId(String id); - - String getId(); -} diff --git a/branches/trunk-20080910/modules/databinding-json/src/test/java/org/apache/tuscany/sca/databinding/json/MyInterfaceImpl.java b/branches/trunk-20080910/modules/databinding-json/src/test/java/org/apache/tuscany/sca/databinding/json/MyInterfaceImpl.java deleted file mode 100644 index 3a2b95a4e2..0000000000 --- a/branches/trunk-20080910/modules/databinding-json/src/test/java/org/apache/tuscany/sca/databinding/json/MyInterfaceImpl.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * 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.tuscany.sca.databinding.json; - -/** - * @version $Rev$ $Date$ - */ -public class MyInterfaceImpl implements MyInterface { - private String id; - - /** - * @see org.apache.tuscany.databinding.jaxb.MyInterface#getId() - */ - public String getId() { - return id; - } - - /** - * @see org.apache.tuscany.databinding.jaxb.MyInterface#setId(java.lang.String) - */ - public void setId(String id) { - this.id = id; - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((id == null) ? 0 : id.hashCode()); - return result; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - final MyInterfaceImpl other = (MyInterfaceImpl)obj; - if (id == null) { - if (other.id != null) - return false; - } else if (!id.equals(other.id)) - return false; - return true; - } - -} diff --git a/branches/trunk-20080910/modules/databinding-json/src/test/java/org/apache/tuscany/sca/databinding/json/POJOTestCase.java b/branches/trunk-20080910/modules/databinding-json/src/test/java/org/apache/tuscany/sca/databinding/json/POJOTestCase.java deleted file mode 100644 index 84995baadf..0000000000 --- a/branches/trunk-20080910/modules/databinding-json/src/test/java/org/apache/tuscany/sca/databinding/json/POJOTestCase.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * 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.tuscany.sca.databinding.json; - -import java.lang.reflect.Array; - -import junit.framework.TestCase; - -import org.apache.tuscany.sca.databinding.TransformationContext; -import org.apache.tuscany.sca.databinding.impl.TransformationContextImpl; -import org.apache.tuscany.sca.interfacedef.impl.DataTypeImpl; - -public class POJOTestCase extends TestCase { - public void testPOJO() throws Exception { - MyBean bean = new MyBean(); - bean.setName("Test"); - bean.setAge(20); - bean.getNotes().add("1"); - bean.getNotes().add("2"); - bean.getMap().put("1", 1); - MyInterface service = new MyInterfaceImpl(); - service.setId("ID001"); - bean.setService(service); - bean.setOtherService(service); - - roundTrip(bean); - } - - private void roundTrip(T bean) { - JavaBean2JSON t1 = new JavaBean2JSON(); - - Object json = t1.transform(bean, null); - System.out.println(json); - JSON2JavaBean t2 = new JSON2JavaBean(); - - TransformationContext context = new TransformationContextImpl(); - context.setTargetDataType(new DataTypeImpl(bean == null ? Object.class : bean.getClass(), null)); - Object newBean = t2.transform(json, context); - - if (newBean != null && newBean.getClass().isArray()) { - int len = Array.getLength(newBean); - assertEquals(Array.getLength(bean), len); - for (int i = 0; i < len; i++) { - assertEquals(Array.get(bean, i), Array.get(newBean, i)); - } - return; - } - assertEquals(bean, newBean); - } - - public void testString() throws Exception { - roundTrip("ABC"); - } - - public void testNull() throws Exception { - roundTrip(null); - } - - public void testArray() throws Exception { - roundTrip(new String[] {"123", "ABC"}); - } - - public void testByteArray() throws Exception { - roundTrip("ABC".getBytes()); - } - - public void testPrimitive() throws Exception { - roundTrip(123); - } - -} -- cgit v1.2.3