Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 93D04200B61 for ; Tue, 9 Aug 2016 19:16:04 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 924D7160A6B; Tue, 9 Aug 2016 17:16:04 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 5FCBF160AB0 for ; Tue, 9 Aug 2016 19:16:02 +0200 (CEST) Received: (qmail 77083 invoked by uid 500); 9 Aug 2016 17:16:01 -0000 Mailing-List: contact commits-help@juneau.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@juneau.incubator.apache.org Delivered-To: mailing list commits@juneau.incubator.apache.org Received: (qmail 76899 invoked by uid 99); 9 Aug 2016 17:16:01 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd4-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 09 Aug 2016 17:16:01 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd4-us-west.apache.org (ASF Mail Server at spamd4-us-west.apache.org) with ESMTP id B8B28C0719 for ; Tue, 9 Aug 2016 17:16:00 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd4-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -4.646 X-Spam-Level: X-Spam-Status: No, score=-4.646 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, KAM_LAZY_DOMAIN_SECURITY=1, RCVD_IN_DNSWL_HI=-5, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, RP_MATCHES_RCVD=-1.426] autolearn=disabled Received: from mx2-lw-us.apache.org ([10.40.0.8]) by localhost (spamd4-us-west.apache.org [10.40.0.11]) (amavisd-new, port 10024) with ESMTP id 0rlT4emC8XAJ for ; Tue, 9 Aug 2016 17:15:45 +0000 (UTC) Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx2-lw-us.apache.org (ASF Mail Server at mx2-lw-us.apache.org) with SMTP id EED1E61260 for ; Tue, 9 Aug 2016 17:15:24 +0000 (UTC) Received: (qmail 73382 invoked by uid 99); 9 Aug 2016 17:15:23 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 09 Aug 2016 17:15:23 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 69508EEE35; Tue, 9 Aug 2016 17:15:23 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: jamesbognar@apache.org To: commits@juneau.incubator.apache.org Date: Tue, 09 Aug 2016 17:15:43 -0000 Message-Id: <1d0e7bf8d2314127a200f694b5f52225@git.apache.org> In-Reply-To: <1be5a402644d443398e98626469dfa57@git.apache.org> References: <1be5a402644d443398e98626469dfa57@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [22/44] incubator-juneau git commit: Rename CT_* testcases. archived-at: Tue, 09 Aug 2016 17:16:04 -0000 http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/df0f8689/org.apache.juneau/src/test/java/org/apache/juneau/a/rttests/RoundTripPrimitivesBeansTest.java ---------------------------------------------------------------------- diff --git a/org.apache.juneau/src/test/java/org/apache/juneau/a/rttests/RoundTripPrimitivesBeansTest.java b/org.apache.juneau/src/test/java/org/apache/juneau/a/rttests/RoundTripPrimitivesBeansTest.java new file mode 100755 index 0000000..c028554 --- /dev/null +++ b/org.apache.juneau/src/test/java/org/apache/juneau/a/rttests/RoundTripPrimitivesBeansTest.java @@ -0,0 +1,367 @@ +/*************************************************************************************************************************** + * 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.juneau.a.rttests; + +import static org.junit.Assert.*; + +import java.util.*; + +import org.apache.juneau.parser.*; +import org.apache.juneau.serializer.*; +import org.junit.*; + +/** + * Tests designed to serialize and parse objects to make sure we end up + * with the same objects for all serializers and parsers. + */ +@SuppressWarnings({"unchecked","serial"}) +public class RoundTripPrimitivesBeansTest extends RoundTripTest { + + public RoundTripPrimitivesBeansTest(String label, Serializer s, Parser p, int flags) throws Exception { + super(label, s, p, flags); + } + + //==================================================================================================== + // testPrimitivesBean + //==================================================================================================== + @Test + public void testPrimitivesBean() throws Exception { + PrimitivesBean t = new PrimitivesBean().init(); + t = roundTrip(t, PrimitivesBean.class); + + // primitives + assertEquals(true, t.pBoolean); + assertEquals(1, t.pByte); + assertEquals('a', t.pChar); + assertEquals(2, t.pShort); + assertEquals(3, t.pInt); + assertEquals(4l, t.pLong); + assertEquals(5f, t.pFloat, 0.1f); + assertEquals(6d, t.pDouble, 0.1f); + + // uninitialized primitives + assertEquals(false, t.puBoolean); + assertEquals(0, t.puByte); + assertEquals((char)0, t.puChar); + assertEquals(0, t.puShort); + assertEquals(0, t.puInt); + assertEquals(0l, t.puLong); + assertEquals(0f, t.puFloat, 0.1f); + assertEquals(0d, t.puDouble, 0.1f); + + // primitive arrays + assertEquals(false, t.paBoolean[1][0]); + assertEquals(2, t.paByte[1][0]); + assertEquals('b', t.paChar[1][0]); + assertEquals(2, t.paShort[1][0]); + assertEquals(2, t.paInt[1][0]); + assertEquals(2l, t.paLong[1][0]); + assertEquals(2f, t.paFloat[1][0], 0.1f); + assertEquals(2d, t.paDouble[1][0], 0.1f); + assertNull(t.paBoolean[2]); + assertNull(t.paByte[2]); + assertNull(t.paChar[2]); + assertNull(t.paShort[2]); + assertNull(t.paInt[2]); + assertNull(t.paLong[2]); + assertNull(t.paFloat[2]); + assertNull(t.paDouble[2]); + + // uninitialized primitive arrays + assertNull(t.pauBoolean); + assertNull(t.pauByte); + assertNull(t.pauChar); + assertNull(t.pauShort); + assertNull(t.pauInt); + assertNull(t.pauLong); + assertNull(t.pauFloat); + assertNull(t.pauDouble); + + // anonymous list of primitive arrays + assertEquals(true, t.palBoolean.get(0)[0]); + assertEquals(1, t.palByte.get(0)[0]); + assertEquals('a', t.palChar.get(0)[0]); + assertEquals(1, t.palShort.get(0)[0]); + assertEquals(1, t.palInt.get(0)[0]); + assertEquals(1l, t.palLong.get(0)[0]); + assertEquals(1f, t.palFloat.get(0)[0], 0.1f); + assertEquals(1d, t.palDouble.get(0)[0], 0.1f); + assertNull(t.palBoolean.get(1)); + assertNull(t.palByte.get(1)); + assertNull(t.palChar.get(1)); + assertNull(t.palShort.get(1)); + assertNull(t.palInt.get(1)); + assertNull(t.palLong.get(1)); + assertNull(t.palFloat.get(1)); + assertNull(t.palDouble.get(1)); + + // regular list of primitive arrays + assertEquals(true, t.plBoolean.get(0)[0]); + assertEquals(1, t.plByte.get(0)[0]); + assertEquals('a', t.plChar.get(0)[0]); + assertEquals(1, t.plShort.get(0)[0]); + assertEquals(1, t.plInt.get(0)[0]); + assertEquals(1l, t.plLong.get(0)[0]); + assertEquals(1f, t.plFloat.get(0)[0], 0.1f); + assertEquals(1d, t.plDouble.get(0)[0], 0.1f); + assertNull(t.plBoolean.get(1)); + assertNull(t.plByte.get(1)); + assertNull(t.plChar.get(1)); + assertNull(t.plShort.get(1)); + assertNull(t.plInt.get(1)); + assertNull(t.plLong.get(1)); + assertNull(t.plFloat.get(1)); + assertNull(t.plDouble.get(1)); + } + + public static class PrimitivesBean { + + // primitives + public boolean pBoolean; + public byte pByte; + public char pChar; + public short pShort; + public int pInt; + public long pLong; + public float pFloat; + public double pDouble; + + // uninitialized primitives + public boolean puBoolean; + public byte puByte; + public char puChar; + public short puShort; + public int puInt; + public long puLong; + public float puFloat; + public double puDouble; + + // primitive arrays + public boolean[][] paBoolean; + public byte[][] paByte; + public char[][] paChar; + public short[][] paShort; + public int[][] paInt; + public long[][] paLong; + public float[][] paFloat; + public double[][] paDouble; + + // uninitialized primitive arrays + public boolean[][] pauBoolean; + public byte[][] pauByte; + public char[][] pauChar; + public short[][] pauShort; + public int[][] pauInt; + public long[][] pauLong; + public float[][] pauFloat; + public double[][] pauDouble; + + // Regular lists of primitives + public List plBoolean; + public List plByte; + public List plChar; + public List plShort; + public List plInt; + public List plLong; + public List plFloat; + public List plDouble; + + // Anonymous list of primitives + public List palBoolean; + public List palByte; + public List palChar; + public List palShort; + public List palInt; + public List palLong; + public List palFloat; + public List palDouble; + + public PrimitivesBean init() { + // primitives + pBoolean = true; + pByte = 1; + pChar = 'a'; + pShort = 2; + pInt = 3; + pLong = 4l; + pFloat = 5f; + pDouble = 6d; + + // primitive arrays + paBoolean = new boolean[][]{{true},{false},null}; + paByte = new byte[][]{{1},{2},null}; + paChar = new char[][]{{'a'},{'b'},null}; + paShort = new short[][]{{1},{2},null}; + paInt = new int[][]{{1},{2},null}; + paLong = new long[][]{{1},{2},null}; + paFloat = new float[][]{{1},{2},null}; + paDouble = new double[][]{{1},{2},null}; + + // Regular lists of primitives + plBoolean = new ArrayList() {{ + add(new boolean[]{true}); add(null); + }}; + plByte = new ArrayList() {{ + add(new byte[]{1}); add(null); + }}; + plChar = new ArrayList() {{ + add(new char[]{'a'}); add(null); + }}; + plShort = new ArrayList() {{ + add(new short[]{1}); add(null); + }}; + plInt = new ArrayList() {{ + add(new int[]{1}); add(null); + }}; + plLong = new ArrayList() {{ + add(new long[]{1}); add(null); + }}; + plFloat = new ArrayList() {{ + add(new float[]{1}); add(null); + }}; + plDouble = new ArrayList() {{ + add(new double[]{1}); add(null); + }}; + + // Anonymous list of primitives + palBoolean = new ArrayList(); + palBoolean.add(new boolean[]{true}); + palBoolean.add(null); + palByte = new ArrayList(); + palByte.add(new byte[]{1}); + palByte.add(null); + palChar = new ArrayList(); + palChar.add(new char[]{'a'}); + palChar.add(null); + palShort = new ArrayList(); + palShort.add(new short[]{1}); + palShort.add(null); + palInt = new ArrayList(); + palInt.add(new int[]{1}); + palInt.add(null); + palLong = new ArrayList(); + palLong.add(new long[]{1}); + palLong.add(null); + palFloat = new ArrayList(); + palFloat.add(new float[]{1}); + palFloat.add(null); + palDouble = new ArrayList(); + palDouble.add(new double[]{1}); + palDouble.add(null); + return this; + } + } + + //==================================================================================================== + // List of PrimitivesBean + //==================================================================================================== + @Test + public void testPrimitivesBeanList() throws Exception { + List t = new ArrayList() {{ + add(new PrimitivesBean().init()); + add(null); + add(new PrimitivesBean().init()); + }}; + if (p == null) + return; + t = roundTrip(t, p.getBeanContext().getCollectionClassMeta(List.class, PrimitivesBean.class)); + + PrimitivesBean t2 = t.get(2); + + // primitives + assertEquals(true, t2.pBoolean); + assertEquals(1, t2.pByte); + assertEquals('a', t2.pChar); + assertEquals(2, t2.pShort); + assertEquals(3, t2.pInt); + assertEquals(4l, t2.pLong); + assertEquals(5f, t2.pFloat, 0.1f); + assertEquals(6d, t2.pDouble, 0.1f); + + // uninitialized primitives + assertEquals(false, t2.puBoolean); + assertEquals(0, t2.puByte); + assertEquals((char)0, t2.puChar); + assertEquals(0, t2.puShort); + assertEquals(0, t2.puInt); + assertEquals(0l, t2.puLong); + assertEquals(0f, t2.puFloat, 0.1f); + assertEquals(0d, t2.puDouble, 0.1f); + + // primitive arrays + assertEquals(false, t2.paBoolean[1][0]); + assertEquals(2, t2.paByte[1][0]); + assertEquals('b', t2.paChar[1][0]); + assertEquals(2, t2.paShort[1][0]); + assertEquals(2, t2.paInt[1][0]); + assertEquals(2l, t2.paLong[1][0]); + assertEquals(2f, t2.paFloat[1][0], 0.1f); + assertEquals(2d, t2.paDouble[1][0], 0.1f); + assertNull(t2.paBoolean[2]); + assertNull(t2.paByte[2]); + assertNull(t2.paChar[2]); + assertNull(t2.paShort[2]); + assertNull(t2.paInt[2]); + assertNull(t2.paLong[2]); + assertNull(t2.paFloat[2]); + assertNull(t2.paDouble[2]); + + // uninitialized primitive arrays + assertNull(t2.pauBoolean); + assertNull(t2.pauByte); + assertNull(t2.pauChar); + assertNull(t2.pauShort); + assertNull(t2.pauInt); + assertNull(t2.pauLong); + assertNull(t2.pauFloat); + assertNull(t2.pauDouble); + + // anonymous list of primitive arrays + assertEquals(true, t2.palBoolean.get(0)[0]); + assertEquals(1, t2.palByte.get(0)[0]); + assertEquals('a', t2.palChar.get(0)[0]); + assertEquals(1, t2.palShort.get(0)[0]); + assertEquals(1, t2.palInt.get(0)[0]); + assertEquals(1l, t2.palLong.get(0)[0]); + assertEquals(1f, t2.palFloat.get(0)[0], 0.1f); + assertEquals(1d, t2.palDouble.get(0)[0], 0.1f); + assertNull(t2.palBoolean.get(1)); + assertNull(t2.palByte.get(1)); + assertNull(t2.palChar.get(1)); + assertNull(t2.palShort.get(1)); + assertNull(t2.palInt.get(1)); + assertNull(t2.palLong.get(1)); + assertNull(t2.palFloat.get(1)); + assertNull(t2.palDouble.get(1)); + + // regular list of primitive arrays + assertEquals(true, t2.plBoolean.get(0)[0]); + assertEquals(1, t2.plByte.get(0)[0]); + assertEquals('a', t2.plChar.get(0)[0]); + assertEquals(1, t2.plShort.get(0)[0]); + assertEquals(1, t2.plInt.get(0)[0]); + assertEquals(1l, t2.plLong.get(0)[0]); + assertEquals(1f, t2.plFloat.get(0)[0], 0.1f); + assertEquals(1d, t2.plDouble.get(0)[0], 0.1f); + assertNull(t2.plBoolean.get(1)); + assertNull(t2.plByte.get(1)); + assertNull(t2.plChar.get(1)); + assertNull(t2.plShort.get(1)); + assertNull(t2.plInt.get(1)); + assertNull(t2.plLong.get(1)); + assertNull(t2.plFloat.get(1)); + assertNull(t2.plDouble.get(1)); + + assertNull(t.get(1)); + } +} http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/df0f8689/org.apache.juneau/src/test/java/org/apache/juneau/a/rttests/RoundTripReadOnlyBeansTest.java ---------------------------------------------------------------------- diff --git a/org.apache.juneau/src/test/java/org/apache/juneau/a/rttests/RoundTripReadOnlyBeansTest.java b/org.apache.juneau/src/test/java/org/apache/juneau/a/rttests/RoundTripReadOnlyBeansTest.java new file mode 100755 index 0000000..bf6214c --- /dev/null +++ b/org.apache.juneau/src/test/java/org/apache/juneau/a/rttests/RoundTripReadOnlyBeansTest.java @@ -0,0 +1,100 @@ +/*************************************************************************************************************************** + * 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.juneau.a.rttests; + +import static org.junit.Assert.*; + +import org.apache.juneau.annotation.*; +import org.apache.juneau.parser.*; +import org.apache.juneau.serializer.*; +import org.junit.*; + +/** + * Tests designed to serialize and parse objects to make sure we end up + * with the same objects for all serializers and parsers. + */ +public class RoundTripReadOnlyBeansTest extends RoundTripTest { + + public RoundTripReadOnlyBeansTest(String label, Serializer s, Parser p, int flags) throws Exception { + super(label, s, p, flags); + } + + //==================================================================================================== + // test + //==================================================================================================== + @Test + public void test() throws Exception { + B t1 = new B(1, "a"), t2 = new B(2, "b"); + A t3 = new A(t1, t2); + + t3 = roundTrip(t3, A.class); + assertEquals(1, t3.getF1().getF1()); + assertEquals("a", t3.getF1().getF2()); + assertEquals(2, t3.getF2().getF1()); + assertEquals("b", t3.getF2().getF2()); + } + + public static class A { + private B f1; + private final B f2; + + @BeanConstructor(properties={"f2"}) + public A(B f2) { + this.f2 = f2; + } + + public A(B f1, B f2) { + this.f1 = f1; + this.f2 = f2; + } + + public B getF1() { + return f1; + } + + public void setF1(B f1) { + this.f1 = f1; + } + + public B getF2() { + return f2; + } + } + + public static class B { + private int f1; + private final String f2; + + @BeanConstructor(properties={"f2"}) + public B(String sField) { + this.f2 = sField; + } + + public B(int iField, String sField) { + this.f1 = iField; + this.f2 = sField; + } + + public int getF1() { + return f1; + } + + public void setF1(int f1) { + this.f1 = f1; + } + + public String getF2() { + return f2; + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/df0f8689/org.apache.juneau/src/test/java/org/apache/juneau/a/rttests/RoundTripSimpleObjectsTest.java ---------------------------------------------------------------------- diff --git a/org.apache.juneau/src/test/java/org/apache/juneau/a/rttests/RoundTripSimpleObjectsTest.java b/org.apache.juneau/src/test/java/org/apache/juneau/a/rttests/RoundTripSimpleObjectsTest.java new file mode 100755 index 0000000..91b7d81 --- /dev/null +++ b/org.apache.juneau/src/test/java/org/apache/juneau/a/rttests/RoundTripSimpleObjectsTest.java @@ -0,0 +1,750 @@ +/*************************************************************************************************************************** + * 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.juneau.a.rttests; + +import static org.junit.Assert.*; + +import java.util.*; + +import org.apache.juneau.*; +import org.apache.juneau.parser.*; +import org.apache.juneau.serializer.*; +import org.junit.*; + +/** + * Tests designed to serialize and parse objects to make sure we end up + * with the same objects for all serializers and parsers. + */ +@SuppressWarnings({ "unchecked", "rawtypes" }) +public class RoundTripSimpleObjectsTest extends RoundTripTest { + + public RoundTripSimpleObjectsTest(String label, Serializer s, Parser p, int flags) throws Exception { + super(label, s, p, flags); + } + + //==================================================================================================== + // testNull + //==================================================================================================== + @Test + public void testNull() throws Exception { + String t = null; + t = roundTrip(t); + assertNull(t); + } + + //==================================================================================================== + // testString + //==================================================================================================== + @Test + public void testString() throws Exception { + String t = "foobar"; + t = roundTrip(t); + assertEquals("foobar", t); + t = ""; + t = roundTrip(t); + assertEquals("", t); + } + + //==================================================================================================== + // testStringArray + //==================================================================================================== + @Test + public void testStringArray() throws Exception { + String[] t = {"foo", null, "null", ""}; + t = roundTrip(t, String[].class); + assertEquals("foo", t[0]); + assertNull(t[1]); + assertEquals("null", t[2]); + assertEquals("", t[3]); + } + + //==================================================================================================== + // testString2dArray + //==================================================================================================== + @Test + public void testString2dArray() throws Exception { + String[][] t = {{"foo", null, "null", ""},null}; + t = roundTrip(t, String[][].class); + assertEquals("foo", t[0][0]); + assertNull(t[0][1]); + assertEquals("null", t[0][2]); + assertEquals("", t[0][3]); + assertNull(t[1]); + } + + //==================================================================================================== + // testInt + //==================================================================================================== + @Test + public void testInt() throws Exception { + int t = 123; + t = roundTrip(t); + assertEquals(123, t); + } + + //==================================================================================================== + // testIntArray + //==================================================================================================== + @Test + public void testIntArray() throws Exception { + int[] t = roundTrip(new int[]{1,2,3}, int[].class); + assertEquals(1, t[0]); + assertEquals(2, t[1]); + assertEquals(3, t[2]); + } + + //==================================================================================================== + // testInt2dArray + //==================================================================================================== + @Test + public void testInt2dArray() throws Exception { + int[][] t = {{1,2,3},null}; + t = roundTrip(t, int[][].class); + assertEquals(1, t[0][0]); + assertEquals(2, t[0][1]); + assertEquals(3, t[0][2]); + assertNull(t[1]); + } + + //==================================================================================================== + // testInt3dArray + //==================================================================================================== + @Test + public void testInt3dArray() throws Exception { + int[][][] t = {{{1,2,3},{4,5,6},null},null}; + t = roundTrip(t, int[][][].class); + assertEquals(1, t[0][0][0]); + assertEquals(2, t[0][0][1]); + assertEquals(3, t[0][0][2]); + assertEquals(4, t[0][1][0]); + assertEquals(5, t[0][1][1]); + assertEquals(6, t[0][1][2]); + assertNull(t[0][2]); + assertNull(t[1]); + } + + //==================================================================================================== + // testBoolean + //==================================================================================================== + @Test + public void testBoolean() throws Exception { + boolean t = true; + t = roundTrip(t); + assertTrue(t); + t = false; + t = roundTrip(t); + assertFalse(t); + } + + //==================================================================================================== + // testBooleanArray + //==================================================================================================== + @Test + public void testBooleanArray() throws Exception { + boolean[] t = {true,false}; + t = roundTrip(t, boolean[].class); + assertTrue(t[0]); + assertFalse(t[1]); + } + + //==================================================================================================== + // testBoolean2dArray + //==================================================================================================== + @Test + public void testBoolean2dArray() throws Exception { + boolean[][] t = {{true,false},null}; + t = roundTrip(t, boolean[][].class); + assertTrue(t[0][0]); + assertFalse(t[0][1]); + assertNull(t[1]); + } + + //==================================================================================================== + // testChar + //==================================================================================================== + @Test + public void testChar() throws Exception { + char t = 'a'; + t = roundTrip(t, char.class); + assertEquals('a', t); + } + + //==================================================================================================== + // testCharArray + //==================================================================================================== + @Test + public void testCharArray() throws Exception { + char[] t = {'a',0}; + t = roundTrip(t, char[].class); + assertEquals('a', t[0]); + assertEquals(0, t[1]); + } + + //==================================================================================================== + // testChar2dArray + //==================================================================================================== + @Test + public void testChar2dArray() throws Exception { + char[][] t = {{'a',0},null}; + t = roundTrip(t, char[][].class); + assertEquals('a', t[0][0]); + assertEquals(0, t[0][1]); + assertNull(t[1]); + } + + //==================================================================================================== + // testFloat + //==================================================================================================== + @Test + public void testFloat() throws Exception { + float t = 1f; + t = roundTrip(t, float.class); + assertEquals(1f, t, 0.1f); + } + + //==================================================================================================== + // testFloatArray + //==================================================================================================== + @Test + public void testFloatArray() throws Exception { + float[] t = {1f}; + t = roundTrip(t, float[].class); + assertEquals(1f, t[0], 0.1f); + } + + //==================================================================================================== + // testFloat2dArray + //==================================================================================================== + @Test + public void testFloat2dArray() throws Exception { + float[][] t = {{1f},null}; + t = roundTrip(t, float[][].class); + assertEquals(1f, t[0][0], 0.1f); + assertNull(t[1]); + } + + //==================================================================================================== + // testDouble + //==================================================================================================== + @Test + public void testDouble() throws Exception { + double t = 1d; + t = roundTrip(t, double.class); + assertEquals(1d, t, 0.1f); + } + + //==================================================================================================== + // testDoubleArray + //==================================================================================================== + @Test + public void testDoubleArray() throws Exception { + double[] t = {1d}; + t = roundTrip(t, double[].class); + assertEquals(1d, t[0], 0.1f); + } + + //==================================================================================================== + // testDouble2dArray + //==================================================================================================== + @Test + public void testDouble2dArray() throws Exception { + double[][] t = {{1d},null}; + t = roundTrip(t, double[][].class); + assertEquals(1d, t[0][0], 0.1f); + assertNull(t[1]); + } + + //==================================================================================================== + // testLong + //==================================================================================================== + @Test + public void testLong() throws Exception { + long t = 1l; + t = roundTrip(t, long.class); + assertEquals(1l, t); + } + + //==================================================================================================== + // testLongArray + //==================================================================================================== + @Test + public void testLongArray() throws Exception { + long[] t = {1l}; + t = roundTrip(t, long[].class); + assertEquals(1l, t[0]); + } + + //==================================================================================================== + // testLong2dArray + //==================================================================================================== + @Test + public void testLong2dArray() throws Exception { + long[][] t = {{1l},null}; + t = roundTrip(t, long[][].class); + assertEquals(1l, t[0][0]); + assertNull(t[1]); + } + + //==================================================================================================== + // testShort + //==================================================================================================== + @Test + public void testShort() throws Exception { + short t = (short)1; + t = roundTrip(t, short.class); + assertEquals(1l, t); + } + + //==================================================================================================== + // testShortArray + //==================================================================================================== + @Test + public void testShortArray() throws Exception { + short[] t = {(short)1}; + t = roundTrip(t, short[].class); + assertEquals(1l, t[0]); + } + + //==================================================================================================== + // testShort2dArray + //==================================================================================================== + @Test + public void testShort2dArray() throws Exception { + short[][] t = {{(short)1},null}; + t = roundTrip(t, short[][].class); + assertEquals((short)1, t[0][0]); + assertNull(t[1]); + } + + //==================================================================================================== + // testInteger + //==================================================================================================== + @Test + public void testInteger() throws Exception { + Integer t = 123; + t = roundTrip(t, Integer.class); + assertEquals(new Integer(123), t); + } + + //==================================================================================================== + // testIntegerArray + //==================================================================================================== + @Test + public void testIntegerArray() throws Exception { + Integer[] t = {123, null}; + t = roundTrip(t, Integer[].class); + assertEquals(new Integer(123), t[0]); + assertNull(t[1]); + } + + //==================================================================================================== + // testInteger2dArray + //==================================================================================================== + @Test + public void testInteger2dArray() throws Exception { + Integer[][] t = {{123,null},null}; + t = roundTrip(t, Integer[][].class); + assertEquals(new Integer(123), t[0][0]); + assertNull(t[0][1]); + assertNull(t[1]); + } + + //==================================================================================================== + // testInteger3dArray + //==================================================================================================== + @Test + public void testInteger3dArray() throws Exception { + Integer[][][] t = {{{123,null},null},null}; + t = roundTrip(t, Integer[][][].class); + assertEquals(new Integer(123), t[0][0][0]); + assertNull(t[0][0][1]); + assertNull(t[0][1]); + assertNull(t[1]); + } + + //==================================================================================================== + // testBooleanObject + //==================================================================================================== + @Test + public void testBooleanObject() throws Exception { + Boolean t = Boolean.TRUE; + t = roundTrip(t, Boolean.class); + assertTrue(t); + t = Boolean.FALSE; + t = roundTrip(t, Boolean.class); + assertFalse(t); + } + + //==================================================================================================== + // testBooleanObjectArray + //==================================================================================================== + @Test + public void testBooleanObjectArray() throws Exception { + Boolean[] t = {true,false,null}; + t = roundTrip(t, Boolean[].class); + assertTrue(t[0]); + assertFalse(t[1]); + assertNull(t[2]); + } + + //==================================================================================================== + // testBooleanObject2dArray + //==================================================================================================== + @Test + public void testBooleanObject2dArray() throws Exception { + Boolean[][] t = {{true,false,null},null}; + t = roundTrip(t, Boolean[][].class); + assertTrue(t[0][0]); + assertFalse(t[0][1]); + assertNull(t[0][2]); + assertNull(t[1]); + } + + //==================================================================================================== + // testCharacter + //==================================================================================================== + @Test + public void testCharacter() throws Exception { + Character t = 'a'; + t = roundTrip(t, Character.class); + assertEquals(new Character('a'), t); + } + + //==================================================================================================== + // testCharacterArray + //==================================================================================================== + @Test + public void testCharacterArray() throws Exception { + Character[] t = {'a',null}; + t = roundTrip(t, Character[].class); + assertEquals(new Character('a'), t[0]); + assertNull(t[1]); + } + + //==================================================================================================== + // testCharacter2dArray + //==================================================================================================== + @Test + public void testCharacter2dArray() throws Exception { + Character[][] t = {{'a',null},null}; + t = roundTrip(t, Character[][].class); + assertEquals(new Character('a'), t[0][0]); + assertNull(t[0][1]); + assertNull(t[1]); + } + + //==================================================================================================== + // testFloatObject + //==================================================================================================== + @Test + public void testFloatObject() throws Exception { + Float t = 1f; + t = roundTrip(t, Float.class); + assertEquals(new Float(1f), t); + } + + //==================================================================================================== + // testFloatObjectArray + //==================================================================================================== + @Test + public void testFloatObjectArray() throws Exception { + Float[] t = {1f, null}; + t = roundTrip(t, Float[].class); + assertEquals(new Float(1f), t[0]); + assertNull(t[1]); + } + + //==================================================================================================== + // testFloatObject2dArray + //==================================================================================================== + @Test + public void testFloatObject2dArray() throws Exception { + Float[][] t = {{1f,null},null}; + t = roundTrip(t, Float[][].class); + assertEquals(new Float(1f), t[0][0]); + assertNull(t[0][1]); + assertNull(t[1]); + } + + //==================================================================================================== + // testDoubleObject + //==================================================================================================== + @Test + public void testDoubleObject() throws Exception { + Double t = 1d; + t = roundTrip(t, Double.class); + assertEquals(new Double(1d), t); + } + + //==================================================================================================== + // testDoubleObjectArray + //==================================================================================================== + @Test + public void testDoubleObjectArray() throws Exception { + Double[] t = {1d,null}; + t = roundTrip(t, Double[].class); + assertEquals(new Double(1d), t[0]); + assertNull(t[1]); + } + + //==================================================================================================== + // testDoubleObject2dArray + //==================================================================================================== + @Test + public void testDoubleObject2dArray() throws Exception { + Double[][] t = {{1d,null},null}; + t = roundTrip(t, Double[][].class); + assertEquals(new Double(1d), t[0][0]); + assertNull(t[0][1]); + assertNull(t[1]); + } + + //==================================================================================================== + // testLongObject + //==================================================================================================== + @Test + public void testLongObject() throws Exception { + Long t = 1l; + t = roundTrip(t, Long.class); + assertEquals(new Long(1l), t); + } + + //==================================================================================================== + // testLongObjectArray + //==================================================================================================== + @Test + public void testLongObjectArray() throws Exception { + Long[] t = {1l, null}; + t = roundTrip(t, Long[].class); + assertEquals(new Long(1l), t[0]); + assertNull(t[1]); + } + + //==================================================================================================== + // testLongObject2dArray + //==================================================================================================== + @Test + public void testLongObject2dArray() throws Exception { + Long[][] t = {{1l,null},null}; + t = roundTrip(t, Long[][].class); + assertEquals(new Long(1l), t[0][0]); + assertNull(t[0][1]); + assertNull(t[1]); + } + + //==================================================================================================== + // testShortObject + //==================================================================================================== + @Test + public void testShortObject() throws Exception { + Short t = (short)1; + t = roundTrip(t, Short.class); + assertEquals(new Short((short)1), t); + } + + //==================================================================================================== + // testShortObjectArray + //==================================================================================================== + @Test + public void testShortObjectArray() throws Exception { + Short[] t = {(short)1,null}; + t = roundTrip(t, Short[].class); + assertEquals(new Short((short)1), t[0]); + assertNull(t[1]); + } + + //==================================================================================================== + // testShortObject2dArray + //==================================================================================================== + @Test + public void testShortObject2dArray() throws Exception { + Short[][] t = {{(short)1,null},null}; + t = roundTrip(t, Short[][].class); + assertEquals(new Short((short)1), t[0][0]); + assertNull(t[0][1]); + assertNull(t[1]); + } + + //==================================================================================================== + // testObjectMap + //==================================================================================================== + @Test + public void testObjectMap() throws Exception { + ObjectMap t = new ObjectMap("{a:'b',c:123,d:false,e:null,f:[123,'abc',true,false,null]}"); + t = roundTrip(t); + assertEquals("b", t.get("a")); + assertEquals(123, t.get("c")); + assertEquals(false, t.get("d")); + assertNull(t.get("e")); + List l = (List)t.get("f"); + assertEquals(123, l.get(0)); + assertEquals("abc", l.get(1)); + assertEquals(true, l.get(2)); + assertEquals(false, l.get(3)); + assertNull(l.get(4)); + } + + //==================================================================================================== + // testObjectList + //==================================================================================================== + @Test + public void testObjectList() throws Exception { + ObjectList t = new ObjectList("['abc',123,true,false,null,{a:'b'}]"); + t = roundTrip(t); + assertEquals("abc", t.get(0)); + assertEquals(123, t.get(1)); + assertEquals(true, t.get(2)); + assertEquals(false, t.get(3)); + assertNull(t.get(4)); + Map m = (Map)t.get(5); + assertEquals("b", m.get("a")); + } + + //==================================================================================================== + // testTreeMap + //==================================================================================================== + @Test + public void testTreeMap() throws Exception { + TreeMap t = new TreeMap(); + t.put("a", 1); + t.put("b", 2); + t.put("c", 3); + t = roundTrip(t, TreeMap.class); + assertEquals(1, t.get("a")); + assertEquals(2, t.get("b")); + assertEquals(3, t.get("c")); + + t = new TreeMap(); + t.put("a", true); + t.put("b", false); + t.put("c", null); + t.put("d", "foo"); + t.put("null", "baz"); + t.put("a\"a", "a\"a"); + t.put("b'b", "b'b"); + t.put("\"cc\"", "\"cc\""); + t.put("'dd'", "'dd'"); + t = roundTrip(t, TreeMap.class); + assertEquals(true, t.get("a")); + assertEquals(false, t.get("b")); + assertNull(t.get("c")); + assertEquals("foo", t.get("d")); + assertEquals("baz", t.get("null")); + assertEquals("a\"a", t.get("a\"a")); + assertEquals("b'b", t.get("b'b")); + assertEquals("\"cc\"", t.get("\"cc\"")); + assertEquals("'dd'", t.get("'dd'")); + } + + //==================================================================================================== + // testLinkedHashMap + //==================================================================================================== + @Test + public void testLinkedHashMap() throws Exception { + LinkedHashMap t = new LinkedHashMap(); + t.put("a", true); + t.put("b", false); + t.put("c", null); + t.put("d", "foo"); + t.put(null, "bar"); + t.put("null", "null"); + t.put("true", "true"); + t.put("false", "false"); + t.put("a\"a", "a\"a"); + t.put("b'b", "b'b"); + t.put("\"cc\"", "\"cc\""); + t.put("'dd'", "'dd'"); + t.put("", ""); + t.put("", ""); + t.put("", ""); + t.put("<>", "<>"); + t.put("{}", "{}"); + t.put("[]", "[]"); + t.put("&", "&"); + t.put("?", "?"); + t.put("/", "/"); + t.put("\b", "\b"); + t.put("\\b", "\\b"); + t.put("\n", "\n"); + t.put("\\n", "\\n"); + t.put("\t", "\t"); + t.put("\\t", "\\t"); + t.put("\f", "\f"); + t.put("\\f", "\\f"); + t.put("\\", "\\"); + t.put("\\\\", "\\\\"); + t.put("\u2345", "\u2345"); + t.put("\\u2345", "\\u2345"); + t.put("\\\u2345", "\\\u2345"); + t.put("<>{}[]&?/\b\n\t\f\\\\\u2345", "<>{}[]&?/\b\n\t\f\\\\\u2345"); + t = roundTrip(t, LinkedHashMap.class); + assertEquals(true, t.get("a")); + assertEquals(false, t.get("b")); + assertNull(t.get("c")); + assertEquals("foo", t.get("d")); + assertEquals("bar", t.get(null)); + assertEquals("null", t.get("null")); + assertEquals("true", t.get("true")); + assertEquals("false", t.get("false")); + assertEquals("a\"a", t.get("a\"a")); + assertEquals("b'b", t.get("b'b")); + assertEquals("\"cc\"", t.get("\"cc\"")); + assertEquals("'dd'", t.get("'dd'")); + assertEquals("", t.get("")); + assertEquals("", t.get("")); + assertEquals("", t.get("")); + assertEquals("<>", t.get("<>")); + assertEquals("{}", t.get("{}")); + assertEquals("[]", t.get("[]")); + assertEquals("&", t.get("&")); + assertEquals("?", t.get("?")); + assertEquals("/", t.get("/")); + assertEquals("\b", t.get("\b")); + assertEquals("\\b", t.get("\\b")); + assertEquals("\n", t.get("\n")); + assertEquals("\\n", t.get("\\n")); + assertEquals("\t", t.get("\t")); + assertEquals("\\t", t.get("\\t")); + assertEquals("\f", t.get("\f")); + assertEquals("\\f", t.get("\\f")); + assertEquals("\\", t.get("\\")); + assertEquals("\\\\", t.get("\\\\")); + assertEquals("\u2345", t.get("\u2345")); + assertEquals("\\u2345", t.get("\\u2345")); + assertEquals("\\\u2345", t.get("\\\u2345")); + assertEquals("<>{}[]&?/\b\n\t\f\\\\\u2345", t.get("<>{}[]&?/\b\n\t\f\\\\\u2345")); + } + + //==================================================================================================== + // testVector + //==================================================================================================== + @Test + public void testVector() throws Exception { + Vector t = new Vector(); + t.add(1); + t.add(2); + t.add(3); + t = roundTripCollection(t, Vector.class, Integer.class); + } + + //==================================================================================================== + // testNull + //==================================================================================================== + @Test + public void testExtendedUnicode() throws Exception { + // Test 4-byte UTF-8 character + String t = "𤭢𤭢"; + t = roundTrip(t); + assertEquals("𤭢𤭢", t); + } +} http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/df0f8689/org.apache.juneau/src/test/java/org/apache/juneau/a/rttests/RoundTripToObjectMapsTest.java ---------------------------------------------------------------------- diff --git a/org.apache.juneau/src/test/java/org/apache/juneau/a/rttests/RoundTripToObjectMapsTest.java b/org.apache.juneau/src/test/java/org/apache/juneau/a/rttests/RoundTripToObjectMapsTest.java new file mode 100755 index 0000000..9c7a276 --- /dev/null +++ b/org.apache.juneau/src/test/java/org/apache/juneau/a/rttests/RoundTripToObjectMapsTest.java @@ -0,0 +1,78 @@ +/*************************************************************************************************************************** + * 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.juneau.a.rttests; + +import static org.junit.Assert.*; + +import java.util.*; + +import org.apache.juneau.*; +import org.apache.juneau.parser.*; +import org.apache.juneau.serializer.*; +import org.junit.*; + + + +/** + * Tests designed to serialize and parse objects to make sure we end up + * with the same objects for all serializers and parsers. + */ +public class RoundTripToObjectMapsTest extends RoundTripTest { + + public RoundTripToObjectMapsTest(String label, Serializer s, Parser p, int flags) throws Exception { + super(label, s, p, flags); + } + + //==================================================================================================== + // Class with X(ObjectMap) constructor and toObjectMap() method. + //==================================================================================================== + @SuppressWarnings({ "serial", "unchecked" }) + @Test + public void test() throws Exception { + A a = new A(new ObjectMap("{f1:'a',f2:2}")); + a = roundTrip(a, A.class); + assertEquals("a", a.f1); + assertEquals(2, a.f2); + + A[] aa = new A[]{a}; + aa = roundTrip(aa, A[].class); + assertEquals(1, aa.length); + assertEquals("a", aa[0].f1); + assertEquals(2, aa[0].f2); + + List a2 = new ArrayList(){{add(new A(new ObjectMap("{f1:'a',f2:2}")));}}; + a2 = roundTrip(a2, BeanContext.DEFAULT.getCollectionClassMeta(List.class, A.class)); + assertEquals(1, a2.size()); + assertEquals("a", a2.get(0).f1); + assertEquals(2, a2.get(0).f2); + + Map a3 = new LinkedHashMap(){{put("a", new A(new ObjectMap("{f1:'a',f2:2}")));}}; + a3 = roundTrip(a3, BeanContext.DEFAULT.getMapClassMeta(Map.class, String.class, A.class)); + assertEquals(1, a3.size()); + assertEquals("a", a3.get("a").f1); + assertEquals(2, a3.get("a").f2); + } + + public static class A { + private String f1; + private int f2; + public A(ObjectMap m) { + this.f1 = m.getString("f1"); + this.f2 = m.getInt("f2"); + } + public ObjectMap toObjectMap() { + return new ObjectMap().append("f1",f1).append("f2",f2); + } + } + +} http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/df0f8689/org.apache.juneau/src/test/java/org/apache/juneau/a/rttests/RoundTripTransformBeansTest.java ---------------------------------------------------------------------- diff --git a/org.apache.juneau/src/test/java/org/apache/juneau/a/rttests/RoundTripTransformBeansTest.java b/org.apache.juneau/src/test/java/org/apache/juneau/a/rttests/RoundTripTransformBeansTest.java new file mode 100755 index 0000000..0e882eb --- /dev/null +++ b/org.apache.juneau/src/test/java/org/apache/juneau/a/rttests/RoundTripTransformBeansTest.java @@ -0,0 +1,382 @@ +/*************************************************************************************************************************** + * 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.juneau.a.rttests; + +import static org.junit.Assert.*; + +import java.io.*; +import java.util.*; + +import javax.xml.datatype.*; + +import org.apache.juneau.*; +import org.apache.juneau.annotation.*; +import org.apache.juneau.annotation.Transform; +import org.apache.juneau.json.*; +import org.apache.juneau.parser.*; +import org.apache.juneau.serializer.*; +import org.apache.juneau.transform.*; +import org.apache.juneau.transforms.*; +import org.junit.*; + +/** + * Tests designed to serialize and parse objects to make sure we end up + * with the same objects for all serializers and parsers. + */ +@SuppressWarnings({"unchecked","rawtypes","hiding","serial"}) +public class RoundTripTransformBeansTest extends RoundTripTest { + + public RoundTripTransformBeansTest(String label, Serializer s, Parser p, int flags) throws Exception { + super(label, s, p, flags); + } + + //==================================================================================================== + // testTransformBeans1 + //==================================================================================================== + @Test + public void testTransformBeans1() throws Exception { + Class[] f = { + ByteArrayBase64Transform.class, + CalendarTransform.ISO8601DTZ.class, + DateTransform.ISO8601DTZ.class + }; + s.addTransforms(f); + if (p != null) + p.addTransforms(f); + A t = new A().init(); + t = roundTrip(t, A.class); + + // ByteArrayBase64Transform + assertEquals(3, t.fByte[3]); + assertNull(t.fnByte); + assertEquals(5, t.faByte[2][1]); + assertEquals(6, t.flByte.get(1)[2]); + assertNull(t.flByte.get(2)); + assertEquals(6, t.fmByte.get("bar")[2]); + assertNull(t.fmByte.get("baz")); + + // CalendarTransform + t.fCalendar.setTimeZone(TimeZone.getTimeZone("GMT")); + assertEquals(2001, t.fCalendar.get(Calendar.YEAR)); + assertEquals(01, t.fCalendar.get(Calendar.MONTH)); + assertEquals(02, t.fCalendar.get(Calendar.DATE)); + assertEquals(03, t.fCalendar.get(Calendar.HOUR)); + assertEquals(04, t.fCalendar.get(Calendar.MINUTE)); + assertEquals(05, t.fCalendar.get(Calendar.SECOND)); + + t.faCalendar[0].setTimeZone(TimeZone.getTimeZone("GMT")); + assertEquals(2001, t.faCalendar[0].get(Calendar.YEAR)); + assertEquals(01, t.faCalendar[0].get(Calendar.MONTH)); + assertEquals(02, t.faCalendar[0].get(Calendar.DATE)); + assertEquals(03, t.faCalendar[0].get(Calendar.HOUR)); + assertEquals(04, t.faCalendar[0].get(Calendar.MINUTE)); + assertEquals(05, t.faCalendar[0].get(Calendar.SECOND)); + assertNull(t.fnCalendar); + assertNull(t.fn2Calendar); + + // DateTransform + assertEquals(1000, t.fDate.getTime()); + assertNull(t.fnDate); + assertEquals(3000, t.faDate[2].getTime()); + assertEquals(4000, t.flDate.get(0).getTime()); + assertNull(t.flDate.get(1)); + assertEquals(5000, t.fmDate.get("foo").getTime()); + assertNull(t.fmDate.get("bar")); + } + + public static class A { + + // Test ByteArrayBase64Transform + public byte[] fByte; + public byte[] fnByte; + public byte[][] faByte; + public List flByte; + public Map fmByte; + + public GregorianCalendar fCalendar; + public GregorianCalendar fnCalendar; + public Calendar fn2Calendar; + public GregorianCalendar[] faCalendar; + + public Date fDate; + public Date fnDate; + public Date[] faDate; + public List flDate; + public Map fmDate; + + public A init() { + fByte = new byte[]{0,1,2,3}; + fnByte = null; + faByte = new byte[][]{{0,1},{2,3},{4,5}}; + flByte = new ArrayList() {{ + add(new byte[]{1,2,3}); + add(new byte[]{4,5,6}); + add(null); + }}; + fmByte = new LinkedHashMap() {{ + put("foo", new byte[]{1,2,3}); + put("bar", new byte[]{4,5,6}); + put("baz", null); + }}; + + fCalendar = new GregorianCalendar() {{ + set(2001, 01, 02, 03, 04, 05); + setTimeZone(TimeZone.getTimeZone("GMT")); + }}; + fnCalendar = null; + fn2Calendar = null; + faCalendar = new GregorianCalendar[]{ + new GregorianCalendar() {{ + set(2001, 01, 02, 03, 04, 05); + setTimeZone(TimeZone.getTimeZone("GMT")); + }} + }; + + fDate = new Date(1000); + fnDate = null; + faDate = new Date[]{ + new Date(1000), new Date(2000), new Date(3000) + }; + flDate = new ArrayList() {{ + add(new Date(4000)); + add(null); + }}; + fmDate = new LinkedHashMap() {{ + put("foo", new Date(5000)); + put("bar", null); + }}; + return this; + } + } + + + //==================================================================================================== + // testTransformBeans2 + //==================================================================================================== + @Test + public void testTransformBeans2() throws Exception { + Class[] f = { + ByteArrayBase64Transform.class, + CalendarTransform.Medium.class, + DateTransform.RFC2822DT.class, + }; + s.addTransforms(f); + if (p != null) + p.addTransforms(f); + A t = new A().init(); + t = roundTrip(t, A.class); + + // ByteArrayBase64Transform + assertEquals(3, t.fByte[3]); + assertNull(t.fnByte); + assertEquals(5, t.faByte[2][1]); + assertEquals(6, t.flByte.get(1)[2]); + assertNull(t.flByte.get(2)); + assertEquals(6, t.fmByte.get("bar")[2]); + assertNull(t.fmByte.get("baz")); + + // CalendarTransform + t.fCalendar.setTimeZone(TimeZone.getTimeZone("GMT")); + assertEquals(2001, t.fCalendar.get(Calendar.YEAR)); + assertEquals(01, t.fCalendar.get(Calendar.MONTH)); + // Note: We lose precision on the following because of the transform type. + //assertEquals(02, b.fCalendar.get(Calendar.DATE)); + //assertEquals(03, b.fCalendar.get(Calendar.HOUR)); + //assertEquals(04, b.fCalendar.get(Calendar.MINUTE)); + //assertEquals(05, b.fCalendar.get(Calendar.SECOND)); + + t.faCalendar[0].setTimeZone(TimeZone.getTimeZone("GMT")); + assertEquals(2001, t.faCalendar[0].get(Calendar.YEAR)); + assertEquals(01, t.faCalendar[0].get(Calendar.MONTH)); + // Note: We lose precision on the following because of the transform type. + //assertEquals(02, b.faCalendar[0].get(Calendar.DATE)); + //assertEquals(03, b.faCalendar[0].get(Calendar.HOUR)); + //assertEquals(04, b.faCalendar[0].get(Calendar.MINUTE)); + //assertEquals(05, b.faCalendar[0].get(Calendar.SECOND)); + assertNull(t.fnCalendar); + assertNull(t.fn2Calendar); + + // DateTransform + assertEquals(1000, t.fDate.getTime()); + assertNull(t.fnDate); + assertEquals(3000, t.faDate[2].getTime()); + assertEquals(4000, t.flDate.get(0).getTime()); + assertNull(t.flDate.get(1)); + assertEquals(5000, t.fmDate.get("foo").getTime()); + assertNull(t.fmDate.get("bar")); + } + + //==================================================================================================== + // testTransform - Bean.transform annotation + //==================================================================================================== + @Test + public void testTransform() throws Exception { + B t = new B(); + t.f1 = "bar"; + t = roundTrip(t, B.class); + + assertEquals("bar", t.f1); + } + + @Transform(BTransform.class) + public static class B { + public String f1; + } + + public static class BTransform extends PojoTransform { + @Override /* PojoTransform */ + public String transform(B o) throws SerializeException { + return o.f1; + } + @Override /* PojoTransform */ + public B normalize(String f, ClassMeta hint) throws ParseException { + B b1 = new B(); + b1.f1 = f; + return b1; + } + } + + //==================================================================================================== + // testXMLGregorianCalendar - Test XMLGregorianCalendarTransform class. + //==================================================================================================== + @Test + public void testXMLGregorianCalendar() throws Exception { + + if (isValidationOnly()) + return; + + GregorianCalendar gc = new GregorianCalendar(); + XMLGregorianCalendar c = DatatypeFactory.newInstance().newXMLGregorianCalendar(gc); + + Serializer s = getSerializer().clone().addTransforms(XMLGregorianCalendarTransform.class); + Parser p = getParser().clone().addTransforms(XMLGregorianCalendarTransform.class); + + Object r = s.serialize(c); + XMLGregorianCalendar c2 = p.parse(r, XMLGregorianCalendar.class); + assertEquals(c, c2); + } + + //==================================================================================================== + // testSubTypeWithGenerics + //==================================================================================================== + @Test + public void testSubTypeWithGenerics() throws Exception { + JsonSerializer s = JsonSerializer.DEFAULT; + + C1 c1 = C3.create(); + String r = s.serialize(c1); + assertEquals("{\"type\":\"C3\",\"f1\":{\"f2\":\"f2\",\"f3\":3}}", r); + } + + + @Bean( + subTypeProperty="type", + subTypes={ + @BeanSubType(id="C3", type=C3.class) + } + ) + public static interface C1 extends Serializable { + void setF1(T f1); + T getF1(); + } + + public abstract static class C2 implements C1 { + protected T f1; + + @Override /* C1 */ + public void setF1(T f1) { + this.f1 = f1; + } + + @Override /* C1 */ + public T getF1() { + return f1; + } + } + + public static class C3 extends C2 { + + public static C3 create() { + C3 c3 = new C3(); + CDTO cdto = new CDTO(); + cdto.f2 = "f2"; + cdto.f3 = 3; + c3.f1 = cdto; + return c3; + } + + @Override /* C1 */ + public void setF1(T f1) { + this.f1 = f1; + } + + @Override /* C1 */ + public T getF1() { + return f1; + } + } + + public static class CDTO { + public String f2; + public int f3; + } + + + //==================================================================================================== + // Surrogate transforms + //==================================================================================================== + @Test + public void testSurrogateTransform() throws Exception { + addTransforms(D2.class); + + JsonSerializer s = new JsonSerializer.Simple().addTransforms(D2.class); + JsonParser p = new JsonParser().addTransforms(D2.class); + Object r; + D1 d1 = D1.create(); + + r = s.serialize(d1); + assertEquals("{f2:'f1'}", r); + + d1 = p.parse(r, D1.class); + assertEquals("f1", d1.f1); + + r = getSerializer().serialize(d1); + assertTrue(TestUtils.toString(r).contains("f2")); + + d1 = roundTrip(d1, D1.class); + } + + public static class D1 { + public String f1; + + public static D1 create() { + D1 d1 = new D1(); + d1.f1 = "f1"; + return d1; + } + } + + public static class D2 { + public String f2; + public D2(D1 d1) { + f2 = d1.f1; + } + public D2() { + } + public static D1 valueOf(D2 d2) { + D1 d1 = new D1(); + d1.f1 = d2.f2; + return d1; + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/df0f8689/org.apache.juneau/src/test/java/org/apache/juneau/a/rttests/RoundTripTrimStringsTest.java ---------------------------------------------------------------------- diff --git a/org.apache.juneau/src/test/java/org/apache/juneau/a/rttests/RoundTripTrimStringsTest.java b/org.apache.juneau/src/test/java/org/apache/juneau/a/rttests/RoundTripTrimStringsTest.java new file mode 100755 index 0000000..83b9e67 --- /dev/null +++ b/org.apache.juneau/src/test/java/org/apache/juneau/a/rttests/RoundTripTrimStringsTest.java @@ -0,0 +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.juneau.a.rttests; + +import static org.apache.juneau.TestUtils.*; + +import org.apache.juneau.*; +import org.apache.juneau.parser.*; +import org.apache.juneau.serializer.*; +import org.junit.*; + + +/** + * Tests for the {@link SerializerContext#SERIALIZER_trimStrings} and {@link ParserContext#PARSER_trimStrings}. + */ +public class RoundTripTrimStringsTest extends RoundTripTest { + + public RoundTripTrimStringsTest(String label, Serializer s, Parser p, int flags) throws Exception { + super(label, s, p, flags); + } + + //==================================================================================================== + // test + //==================================================================================================== + @SuppressWarnings("hiding") + @Test + public void test() throws Exception { + if (isValidationOnly()) + return; + Serializer s = getSerializer(); + Parser p = getParser(); + Object in, a, e; + + Serializer s2 = s.clone().setProperty(SerializerContext.SERIALIZER_trimStrings, true); + Parser p2 = p.clone().setProperty(ParserContext.PARSER_trimStrings, true); + + in = " foo bar "; + e = "foo bar"; + a = p.parse(s2.serialize(in), String.class); + assertEqualObjects(e, a); + a = p2.parse(s.serialize(in), String.class); + assertEqualObjects(e, a); + + in = new ObjectMap("{' foo ': ' bar '}"); + e = new ObjectMap("{foo:'bar'}"); + a = p.parse(s2.serialize(in), ObjectMap.class); + assertEqualObjects(e, a); + a = p2.parse(s.serialize(in), ObjectMap.class); + assertEqualObjects(e, a); + + in = new ObjectList("[' foo ', {' foo ': ' bar '}]"); + e = new ObjectList("['foo',{foo:'bar'}]"); + a = p.parse(s2.serialize(in), ObjectList.class); + assertEqualObjects(e, a); + a = p2.parse(s.serialize(in), ObjectList.class); + assertEqualObjects(e, a); + + in = new A().init1(); + e = new A().init2(); + a = p.parse(s2.serialize(in), A.class); + assertEqualObjects(e, a); + a = p2.parse(s.serialize(in), A.class); + assertEqualObjects(e, a); + } + + public static class A { + public String f1; + public String[] f2; + public ObjectList f3; + public ObjectMap f4; + + public A init1() throws Exception { + f1 = " f1 "; + f2 = new String[]{" f2a ", " f2b "}; + f3 = new ObjectList("[' f3a ',' f3b ']"); + f4 = new ObjectMap("{' foo ':' bar '}"); + return this; + } + + public A init2() throws Exception { + f1 = "f1"; + f2 = new String[]{"f2a", "f2b"}; + f3 = new ObjectList("['f3a','f3b']"); + f4 = new ObjectMap("{'foo':'bar'}"); + return this; + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/df0f8689/org.apache.juneau/src/test/java/org/apache/juneau/csv/CT_Csv.java ---------------------------------------------------------------------- diff --git a/org.apache.juneau/src/test/java/org/apache/juneau/csv/CT_Csv.java b/org.apache.juneau/src/test/java/org/apache/juneau/csv/CT_Csv.java deleted file mode 100755 index 5ef83ee..0000000 --- a/org.apache.juneau/src/test/java/org/apache/juneau/csv/CT_Csv.java +++ /dev/null @@ -1,50 +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.juneau.csv; - -import static org.junit.Assert.*; - -import java.util.*; - -import org.apache.juneau.serializer.*; -import org.junit.*; - -public class CT_Csv { - - //==================================================================================================== - // testBasic - //==================================================================================================== - @Test - public void testBasic() throws Exception { - List l = new LinkedList(); - l.add(new A("b1",1)); - l.add(new A("b2",2)); - - WriterSerializer s = new CsvSerializer(); - String r; - - r = s.serialize(l); - - assertEquals("b,c\nb1,1\nb2,2\n", r); - } - - public static class A { - public String b; - public int c; - - public A(String b, int c) { - this.b = b; - this.c = c; - } - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/df0f8689/org.apache.juneau/src/test/java/org/apache/juneau/csv/CsvTest.java ---------------------------------------------------------------------- diff --git a/org.apache.juneau/src/test/java/org/apache/juneau/csv/CsvTest.java b/org.apache.juneau/src/test/java/org/apache/juneau/csv/CsvTest.java new file mode 100755 index 0000000..09453df --- /dev/null +++ b/org.apache.juneau/src/test/java/org/apache/juneau/csv/CsvTest.java @@ -0,0 +1,50 @@ +/*************************************************************************************************************************** + * 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.juneau.csv; + +import static org.junit.Assert.*; + +import java.util.*; + +import org.apache.juneau.serializer.*; +import org.junit.*; + +public class CsvTest { + + //==================================================================================================== + // testBasic + //==================================================================================================== + @Test + public void testBasic() throws Exception { + List l = new LinkedList(); + l.add(new A("b1",1)); + l.add(new A("b2",2)); + + WriterSerializer s = new CsvSerializer(); + String r; + + r = s.serialize(l); + + assertEquals("b,c\nb1,1\nb2,2\n", r); + } + + public static class A { + public String b; + public int c; + + public A(String b, int c) { + this.b = b; + this.c = c; + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/df0f8689/org.apache.juneau/src/test/java/org/apache/juneau/dto/atom/AtomTest.java ---------------------------------------------------------------------- diff --git a/org.apache.juneau/src/test/java/org/apache/juneau/dto/atom/AtomTest.java b/org.apache.juneau/src/test/java/org/apache/juneau/dto/atom/AtomTest.java new file mode 100755 index 0000000..5e78d27 --- /dev/null +++ b/org.apache.juneau/src/test/java/org/apache/juneau/dto/atom/AtomTest.java @@ -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.juneau.dto.atom; + +import static javax.xml.bind.DatatypeConverter.*; +import static org.apache.juneau.BeanContext.*; +import static org.apache.juneau.TestUtils.*; +import static org.apache.juneau.xml.XmlSerializerContext.*; +import static org.junit.Assert.*; + +import java.net.*; + +import org.apache.juneau.xml.*; +import org.junit.*; + + +public class AtomTest { + + @Test + public void testBasic() throws Exception { + XmlSerializer s; + XmlParser p = XmlParser.DEFAULT; + String expected, r; + Feed f2; + + Feed f = new Feed() + .setTitle(new Text("text", "dive into mark")) + .setSubTitle(new Text("html", "A lot of effort went into making this effortless")) + .setUpdated(parseDateTime("2005-07-31T12:29:29Z")) + .setId(new Id("tag:example.org,2003:3")) + .addLinks( + new Link("alternate", "text/html", "http://example.org/").setHreflang("en"), + new Link("self", "application/atom+xml", "http://example.org/feed.atom") + ) + .setRights(new Text("Copyright (c) 2003, Mark Pilgrim")) + .setGenerator(new Generator("Example Toolkit").setUri(new URI("http://www.example.com/")).setVersion("1.0")) + .addEntries( + new Entry() + .setTitle(new Text("Atom draft-07 snapshot")) + .addLinks( + new Link("alternate", "text/html", "http://example.org/2005/04/02/atom"), + new Link("enclosure", "audio/mpeg", "http://example.org/audio/ph34r_my_podcast.mp3").setLength(1337) + ) + .setId(new Id("tag:example.org,2003:3.2397")) + .setUpdated(parseDateTime("2005-07-31T12:29:29Z")) + .setPublished(parseDateTime("2003-12-13T08:29:29-04:00")) + .addAuthors(new Person("Mark Pilgrim").setUri(new URI("http://example.org/")).setEmail("f8dy@example.com")) + .addContributors( + new Person("Sam Ruby"), + new Person("Joe Gregorio") + ) + .setContent( + new Content() + .setLang("en") + .setBase(new URI("http://diveintomark.org/")) + .setType("xhtml") + .setText("

[Update: The Atom draft is finished.]

") + ) + ) + ; + + //-------------------------------------------------------------------------------- + // Test without namespaces + //-------------------------------------------------------------------------------- + s = new XmlSerializer.SqReadable().setProperty(XML_enableNamespaces, false).setProperty(BEAN_sortProperties, true); + expected = readFile(getClass().getResource("/dto/atom/test1.xml").getPath()); + r = s.serialize(f); + assertEquals(expected, r); + f2 = p.parse(r, Feed.class); + assertEqualObjects(f, f2); + + //-------------------------------------------------------------------------------- + // Test with namespaces + //-------------------------------------------------------------------------------- + s = new XmlSerializer.SqReadable().setProperty(BEAN_sortProperties, true); + expected = readFile(getClass().getResource("/dto/atom/test2.xml").getPath()); + r = s.serialize(f); + assertEquals(expected, r); + f2 = p.parse(r, Feed.class); + assertEqualObjects(f, f2); + + //-------------------------------------------------------------------------------- + // Test with namespaces but with atom as the default namespace + //-------------------------------------------------------------------------------- + s = new XmlSerializer.SqReadable().setProperty(XML_defaultNamespaceUri, "atom").setProperty(BEAN_sortProperties, true); + expected = readFile(getClass().getResource("/dto/atom/test3.xml").getPath()); + r = s.serialize(f); + assertEquals(expected, r); + f2 = p.parse(r, Feed.class); + assertEqualObjects(f, f2); + } +} http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/df0f8689/org.apache.juneau/src/test/java/org/apache/juneau/dto/atom/CT_Atom.java ---------------------------------------------------------------------- diff --git a/org.apache.juneau/src/test/java/org/apache/juneau/dto/atom/CT_Atom.java b/org.apache.juneau/src/test/java/org/apache/juneau/dto/atom/CT_Atom.java deleted file mode 100755 index 09dc6f6..0000000 --- a/org.apache.juneau/src/test/java/org/apache/juneau/dto/atom/CT_Atom.java +++ /dev/null @@ -1,102 +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.juneau.dto.atom; - -import static javax.xml.bind.DatatypeConverter.*; -import static org.apache.juneau.BeanContext.*; -import static org.apache.juneau.TestUtils.*; -import static org.apache.juneau.xml.XmlSerializerContext.*; -import static org.junit.Assert.*; - -import java.net.*; - -import org.apache.juneau.xml.*; -import org.junit.*; - - -public class CT_Atom { - - @Test - public void testBasic() throws Exception { - XmlSerializer s; - XmlParser p = XmlParser.DEFAULT; - String expected, r; - Feed f2; - - Feed f = new Feed() - .setTitle(new Text("text", "dive into mark")) - .setSubTitle(new Text("html", "A lot of effort went into making this effortless")) - .setUpdated(parseDateTime("2005-07-31T12:29:29Z")) - .setId(new Id("tag:example.org,2003:3")) - .addLinks( - new Link("alternate", "text/html", "http://example.org/").setHreflang("en"), - new Link("self", "application/atom+xml", "http://example.org/feed.atom") - ) - .setRights(new Text("Copyright (c) 2003, Mark Pilgrim")) - .setGenerator(new Generator("Example Toolkit").setUri(new URI("http://www.example.com/")).setVersion("1.0")) - .addEntries( - new Entry() - .setTitle(new Text("Atom draft-07 snapshot")) - .addLinks( - new Link("alternate", "text/html", "http://example.org/2005/04/02/atom"), - new Link("enclosure", "audio/mpeg", "http://example.org/audio/ph34r_my_podcast.mp3").setLength(1337) - ) - .setId(new Id("tag:example.org,2003:3.2397")) - .setUpdated(parseDateTime("2005-07-31T12:29:29Z")) - .setPublished(parseDateTime("2003-12-13T08:29:29-04:00")) - .addAuthors(new Person("Mark Pilgrim").setUri(new URI("http://example.org/")).setEmail("f8dy@example.com")) - .addContributors( - new Person("Sam Ruby"), - new Person("Joe Gregorio") - ) - .setContent( - new Content() - .setLang("en") - .setBase(new URI("http://diveintomark.org/")) - .setType("xhtml") - .setText("

[Update: The Atom draft is finished.]

") - ) - ) - ; - - //-------------------------------------------------------------------------------- - // Test without namespaces - //-------------------------------------------------------------------------------- - s = new XmlSerializer.SqReadable().setProperty(XML_enableNamespaces, false).setProperty(BEAN_sortProperties, true); - expected = readFile(getClass().getResource("/dto/atom/test1.xml").getPath()); - r = s.serialize(f); - assertEquals(expected, r); - f2 = p.parse(r, Feed.class); - assertEqualObjects(f, f2); - - //-------------------------------------------------------------------------------- - // Test with namespaces - //-------------------------------------------------------------------------------- - s = new XmlSerializer.SqReadable().setProperty(BEAN_sortProperties, true); - expected = readFile(getClass().getResource("/dto/atom/test2.xml").getPath()); - r = s.serialize(f); - assertEquals(expected, r); - f2 = p.parse(r, Feed.class); - assertEqualObjects(f, f2); - - //-------------------------------------------------------------------------------- - // Test with namespaces but with atom as the default namespace - //-------------------------------------------------------------------------------- - s = new XmlSerializer.SqReadable().setProperty(XML_defaultNamespaceUri, "atom").setProperty(BEAN_sortProperties, true); - expected = readFile(getClass().getResource("/dto/atom/test3.xml").getPath()); - r = s.serialize(f); - assertEquals(expected, r); - f2 = p.parse(r, Feed.class); - assertEqualObjects(f, f2); - } -} http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/df0f8689/org.apache.juneau/src/test/java/org/apache/juneau/dto/cognos/CT_CognosXml.java ---------------------------------------------------------------------- diff --git a/org.apache.juneau/src/test/java/org/apache/juneau/dto/cognos/CT_CognosXml.java b/org.apache.juneau/src/test/java/org/apache/juneau/dto/cognos/CT_CognosXml.java deleted file mode 100755 index 9613ed5..0000000 --- a/org.apache.juneau/src/test/java/org/apache/juneau/dto/cognos/CT_CognosXml.java +++ /dev/null @@ -1,106 +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.juneau.dto.cognos; - -import static org.apache.juneau.TestUtils.*; -import static org.apache.juneau.serializer.SerializerContext.*; -import static org.apache.juneau.xml.XmlSerializerContext.*; -import static org.junit.Assert.*; - -import java.util.*; - -import org.apache.juneau.*; -import org.apache.juneau.xml.*; -import org.junit.*; - -public class CT_CognosXml { - - //==================================================================================================== - // test - //==================================================================================================== - @Test - public void test() throws Exception { - String expected = "" - + "\n" - + " \n" - + " \n" - + " \n" - + " \n" - + " \n" - + " \n" - + " \n" - + " \n" - + " \n" - + " \n" - + " Apr 26, 2002\n" - + " 0.21006642\n" - + " JA1\n" - + " F\n" - + " B\n" - + " 1\n" - + " \n" - + " \n" - + " Apr 27, 2002\n" - + " 0.1111111\n" - + " BBB\n" - + " G\n" - + " B\n" - + " 2\n" - + " \n" - + " \n" - + "\n"; - - List rows = new LinkedList(); - rows.add(new ObjectMap("{asOfDate:'Apr 26, 2002',rateOfReturn:0.210066429,famAcctIndex:'JA1',rowID:'F',brM:'B',productLineCode:1}")); - rows.add(new Item("Apr 27, 2002", 0.1111111, "BBB", "G", "B", 2)); - - Column[] c = { - new Column("asOfDate", "xs:string", 12), - new Column("rateOfReturn", "xs:double"), - new Column("famAcctIndex", "xs:string", 3), - new Column("rowID", "xs:string", 1), - new Column("brM", "xs:string", 1), - new Column("productLineCode", "xs:int") - }; - - XmlSerializer s = new XmlSerializer().setProperty(SERIALIZER_useIndentation, true).setProperty(SERIALIZER_quoteChar, '\'').setProperty(XML_defaultNamespaceUri, "cognos"); - - DataSet ds = new DataSet(c, rows, BeanContext.DEFAULT); - - String out = s.serialize(ds); - - assertEquals(expected, out); - - // Make sure we can parse it back into a POJO. - DataSet ds2 = XmlParser.DEFAULT.parse(out, DataSet.class); - assertEqualObjects(ds, ds2); - } - - public static class Item { - public String asOfDate; - public double rateOfReturn; - public String famAcctIndex; - public String rowID; - public String brM; - public int productLineCode; - - public Item(String asOfDate, double rateOfReturn, String famAcctIndex, String rowID, String brM, int productLineCode) { - this.asOfDate = asOfDate; - this.rateOfReturn = rateOfReturn; - this.famAcctIndex = famAcctIndex; - this.rowID = rowID; - this.brM = brM; - this.productLineCode = productLineCode; - } - } -} \ No newline at end of file