http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/ab15d45b/juneau-core-test/src/test/java/org/apache/juneau/html/CommonTest.java ---------------------------------------------------------------------- diff --git a/juneau-core-test/src/test/java/org/apache/juneau/html/CommonTest.java b/juneau-core-test/src/test/java/org/apache/juneau/html/CommonTest.java deleted file mode 100755 index e83900e..0000000 --- a/juneau-core-test/src/test/java/org/apache/juneau/html/CommonTest.java +++ /dev/null @@ -1,459 +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.html; - -import static org.apache.juneau.TestUtils.*; -import static org.junit.Assert.*; - -import java.net.*; -import java.net.URI; -import java.util.*; - -import org.apache.juneau.*; -import org.apache.juneau.annotation.*; -import org.apache.juneau.serializer.*; -import org.apache.juneau.utils.*; -import org.junit.*; - -@SuppressWarnings({"serial","javadoc"}) -public class CommonTest { - - //==================================================================================================== - // Trim nulls from beans - //==================================================================================================== - @Test - public void testTrimNullsFromBeans() throws Exception { - HtmlSerializerBuilder s = new HtmlSerializerBuilder().sq().addKeyValueTableHeaders(true); - HtmlParser p = HtmlParser.DEFAULT; - A t1 = A.create(), t2; - - s.trimNullProperties(false); - String r = s.build().serialize(t1); - assertEquals("<table><tr><th>key</th><th>value</th></tr><tr><td>s1</td><td><null/></td></tr><tr><td>s2</td><td>s2</td></tr></table>", r); - t2 = p.parse(r, A.class); - assertEqualObjects(t1, t2); - - s.trimNullProperties(true); - r = s.build().serialize(t1); - assertEquals("<table><tr><th>key</th><th>value</th></tr><tr><td>s2</td><td>s2</td></tr></table>", r); - t2 = p.parse(r, A.class); - assertEqualObjects(t1, t2); - } - - public static class A { - public String s1, s2; - - public static A create() { - A t = new A(); - t.s2 = "s2"; - return t; - } - } - - //==================================================================================================== - // Trim empty maps - //==================================================================================================== - @Test - public void testTrimEmptyMaps() throws Exception { - HtmlSerializerBuilder s = new HtmlSerializerBuilder().sq().addKeyValueTableHeaders(true); - HtmlParser p = HtmlParser.DEFAULT; - B t1 = B.create(), t2; - String r; - - s.trimEmptyMaps(false); - r = s.build().serialize(t1); - assertEquals("<table><tr><th>key</th><th>value</th></tr><tr><td>f1</td><td><table><tr><th>key</th><th>value</th></tr></table></td></tr><tr><td>f2</td><td><table><tr><th>key</th><th>value</th></tr><tr><td>f2a</td><td><null/></td></tr><tr><td>f2b</td><td><table><tr><th>key</th><th>value</th></tr><tr><td>s2</td><td>s2</td></tr></table></td></tr></table></td></tr></table>", r); - t2 = p.parse(r, B.class); - assertEqualObjects(t1, t2); - - s.trimEmptyMaps(true); - r = s.build().serialize(t1); - assertEquals("<table><tr><th>key</th><th>value</th></tr><tr><td>f2</td><td><table><tr><th>key</th><th>value</th></tr><tr><td>f2a</td><td><null/></td></tr><tr><td>f2b</td><td><table><tr><th>key</th><th>value</th></tr><tr><td>s2</td><td>s2</td></tr></table></td></tr></table></td></tr></table>", r); - t2 = p.parse(r, B.class); - assertNull(t2.f1); - } - - public static class B { - public TreeMap<String,A> f1, f2; - - public static B create() { - B t = new B(); - t.f1 = new TreeMap<String,A>(); - t.f2 = new TreeMap<String,A>(){{put("f2a",null);put("f2b",A.create());}}; - return t; - } - } - - //==================================================================================================== - // Trim empty lists - //==================================================================================================== - @Test - public void testTrimEmptyLists() throws Exception { - HtmlSerializerBuilder s = new HtmlSerializerBuilder().sq().addKeyValueTableHeaders(true); - HtmlParser p = HtmlParser.DEFAULT; - C t1 = C.create(), t2; - String r; - - s.trimEmptyCollections(false); - r = s.build().serialize(t1); - assertEquals("<table><tr><th>key</th><th>value</th></tr><tr><td>f1</td><td><ul></ul></td></tr><tr><td>f2</td><td><table _type='array'><tr><th>s2</th></tr><tr><null/></tr><tr><td>s2</td></tr></table></td></tr></table>", r); - t2 = p.parse(r, C.class); - assertEqualObjects(t1, t2); - - s.trimEmptyCollections(true); - r = s.build().serialize(t1); - assertEquals("<table><tr><th>key</th><th>value</th></tr><tr><td>f2</td><td><table _type='array'><tr><th>s2</th></tr><tr><null/></tr><tr><td>s2</td></tr></table></td></tr></table>", r); - t2 = p.parse(r, C.class); - assertNull(t2.f1); - } - - public static class C { - public List<A> f1, f2; - - public static C create() { - C t = new C(); - t.f1 = new AList<A>(); - t.f2 = new AList<A>().append(null).append(A.create()); - return t; - } - } - - //==================================================================================================== - // Trim empty arrays - //==================================================================================================== - @Test - public void testTrimEmptyArrays() throws Exception { - HtmlSerializerBuilder s = new HtmlSerializerBuilder().sq().addKeyValueTableHeaders(true); - HtmlParser p = HtmlParser.DEFAULT; - D t1 = D.create(), t2; - String r; - - s.trimEmptyCollections(false); - r = s.build().serialize(t1); - assertEquals( - "<table>" - +"<tr><th>key</th><th>value</th></tr>" - +"<tr>" - +"<td>f1</td>" - +"<td><ul></ul></td>" - +"</tr>" - +"<tr>" - +"<td>f2</td>" - +"<td>" - +"<table _type='array'>" - +"<tr><th>s2</th></tr>" - +"<tr><null/></tr>" - +"<tr><td>s2</td></tr>" - +"</table>" - +"</td>" - +"</tr>" - +"</table>", - r); - t2 = p.parse(r, D.class); - assertEqualObjects(t1, t2); - - s.trimEmptyCollections(true); - r = s.build().serialize(t1); - assertEquals( - "<table>" - +"<tr><th>key</th><th>value</th></tr>" - +"<tr>" - +"<td>f2</td>" - +"<td>" - +"<table _type='array'>" - +"<tr><th>s2</th></tr>" - +"<tr><null/></tr>" - +"<tr><td>s2</td></tr>" - +"</table>" - +"</td>" - +"</tr>" - +"</table>", - r); - t2 = p.parse(r, D.class); - assertNull(t2.f1); - } - - public static class D { - public A[] f1, f2; - - public static D create() { - D t = new D(); - t.f1 = new A[]{}; - t.f2 = new A[]{null, A.create()}; - return t; - } - } - - //==================================================================================================== - // @BeanProperty.properties annotation. - //==================================================================================================== - @Test - public void testBeanPropertyProperties() throws Exception { - HtmlSerializer s = new HtmlSerializerBuilder().sq().addKeyValueTableHeaders(true).build(); - E1 t = new E1(); - String r; - - r = s.serialize(t); - assertEquals( - "<table>" - +"<tr>" - +"<th>key</th>" - +"<th>value</th>" - +"</tr>" - +"<tr>" - +"<td>x1</td>" - +"<td>" - +"<table>" - +"<tr><th>key</th><th>value</th></tr>" - +"<tr><td>f1</td><td>1</td></tr>" - +"</table>" - +"</td>" - +"</tr>" - +"<tr>" - +"<td>x2</td>" - +"<td>" - +"<table>" - +"<tr><th>key</th><th>value</th></tr>" - +"<tr><td>f1</td><td>3</td></tr>" - +"</table>" - +"</td>" - +"</tr>" - +"<tr>" - +"<td>x3</td>" - +"<td>" - +"<table _type='array'>" - +"<tr><th>f1</th></tr>" - +"<tr><td>1</td></tr>" - +"</table>" - +"</td>" - +"</tr>" - +"<tr>" - +"<td>x4</td>" - +"<td>" - +"<table _type='array'>" - +"<tr><th>f1</th></tr>" - +"<tr><td>1</td></tr>" - +"</table>" - +"</td>" - +"</tr>" - +"<tr>" - +"<td>x5</td>" - +"<td>" - +"<table _type='array'>" - +"<tr><th>f1</th></tr>" - +"<tr><td><number>5</number></td></tr>" - +"</table>" - +"</td>" - +"</tr>" - +"<tr>" - +"<td>x6</td>" - +"<td>" - +"<table _type='array'>" - +"<tr><th>f1</th></tr>" - +"<tr><td><number>7</number></td></tr>" - +"</table>" - +"</td>" - +"</tr>" - +"</table>", - r); - r = s.getSchemaSerializer().serialize(new E1()); - assertTrue(r.indexOf("f2") == -1); - } - - public static class E1 { - @BeanProperty(properties="f1") public E2 x1 = new E2(); - @BeanProperty(properties="f1") public Map<String,Integer> x2 = new AMap<String,Integer>().append("f1",3).append("f2",4); - @BeanProperty(properties="f1") public E2[] x3 = {new E2()}; - @BeanProperty(properties="f1") public List<E2> x4 = new AList<E2>().append(new E2()); - @BeanProperty(properties="f1") public ObjectMap[] x5 = {new ObjectMap().append("f1",5).append("f2",6)}; - @BeanProperty(properties="f1") public List<ObjectMap> x6 = new AList<ObjectMap>().append(new ObjectMap().append("f1",7).append("f2",8)); - } - - public static class E2 { - public int f1 = 1; - public int f2 = 2; - } - - //==================================================================================================== - // @BeanProperty.properties annotation on list of beans. - //==================================================================================================== - @Test - public void testBeanPropertyPropertiesOnListOfBeans() throws Exception { - HtmlSerializer s = HtmlSerializer.DEFAULT_SQ; - List<F> l = new LinkedList<F>(); - F t = new F(); - t.x1.add(new F()); - l.add(t); - String html = s.serialize(l); - assertEquals( - "<table _type='array'>" - +"<tr><th>x1</th><th>x2</th></tr>" - +"<tr>" - +"<td>" - +"<table _type='array'>" - +"<tr><th>x2</th></tr>" - +"<tr><td>2</td></tr>" - +"</table>" - +"</td>" - +"<td>2</td>" - +"</tr>" - +"</table>", html); - } - - public static class F { - @BeanProperty(properties="x2") public List<F> x1 = new LinkedList<F>(); - public int x2 = 2; - } - - //==================================================================================================== - // Test that URLs and URIs are serialized and parsed correctly. - //==================================================================================================== - @Test - public void testURIAttr() throws Exception { - HtmlSerializer s = HtmlSerializer.DEFAULT_SQ; - HtmlParser p = HtmlParser.DEFAULT; - - G t = new G(); - t.uri = new URI("http://uri"); - t.f1 = new URI("http://f1"); - t.f2 = new URL("http://f2"); - - String html = s.serialize(t); - t = p.parse(html, G.class); - assertEquals("http://uri", t.uri.toString()); - assertEquals("http://f1", t.f1.toString()); - assertEquals("http://f2", t.f2.toString()); - } - - public static class G { - public URI uri; - public URI f1; - public URL f2; - } - - - //==================================================================================================== - // Recursion - //==================================================================================================== - @Test - public void testRecursion() throws Exception { - HtmlSerializerBuilder s = new HtmlSerializerBuilder().sq().addKeyValueTableHeaders(true); - - R1 r1 = new R1(); - R2 r2 = new R2(); - R3 r3 = new R3(); - r1.r2 = r2; - r2.r3 = r3; - r3.r1 = r1; - - // No recursion detection - try { - s.build().serialize(r1); - fail("Exception expected!"); - } catch (Exception e) { - String msg = e.getLocalizedMessage(); - assertTrue(msg.contains("It's recommended you use the SerializerContext.SERIALIZER_detectRecursions setting to help locate the loop.")); - } - - // Recursion detection, no ignore - s.detectRecursions(true); - try { - s.build().serialize(r1); - fail("Exception expected!"); - } catch (Exception e) { - String msg = e.getLocalizedMessage(); - assertTrue(msg.contains("[0]<noname>:org.apache.juneau.html.CommonTest$R1")); - assertTrue(msg.contains("->[1]r2:org.apache.juneau.html.CommonTest$R2")); - assertTrue(msg.contains("->[2]r3:org.apache.juneau.html.CommonTest$R3")); - assertTrue(msg.contains("->[3]r1:org.apache.juneau.html.CommonTest$R1")); - } - - s.ignoreRecursions(true); - assertEquals( - "<table><tr><th>key</th><th>value</th></tr><tr><td>name</td><td>foo</td></tr><tr><td>r2</td><td><table><tr><th>key</th><th>value</th></tr><tr><td>name</td><td>bar</td></tr><tr><td>r3</td><td><table><tr><th>key</th><th>value</th></tr><tr><td>name</td><td>baz</td></tr></table></td></tr></table></td></tr></table>", - s.build().serialize(r1) - ); - - // Make sure this doesn't blow up. - s.build().getSchemaSerializer().serialize(r1); - } - - public static class R1 { - public String name = "foo"; - public R2 r2; - } - public static class R2 { - public String name = "bar"; - public R3 r3; - } - public static class R3 { - public String name = "baz"; - public R1 r1; - } - - //==================================================================================================== - // Basic bean - //==================================================================================================== - @Test - public void testBasicBean() throws Exception { - WriterSerializer s = new HtmlSerializerBuilder().sq().trimNullProperties(false).sortProperties(true).addKeyValueTableHeaders(true).build(); - - J a = new J(); - a.setF1("J"); - a.setF2(100); - a.setF3(true); - assertEquals( - "<table>" - +"<tr><th>key</th><th>value</th></tr>" - +"<tr><td>f1</td><td>J</td></tr>" - +"<tr><td>f2</td><td>100</td></tr>" - +"<tr><td>f3</td><td>true</td></tr>" - +"</table>", - s.serialize(a)); - } - - public static class J { - private String f1 = null; - private int f2 = -1; - private boolean f3 = false; - - public String getF1() { - return this.f1; - } - - public void setF1(String f1) { - this.f1 = f1; - } - - public int getF2() { - return this.f2; - } - - public void setF2(int f2) { - this.f2 = f2; - } - - public boolean isF3() { - return this.f3; - } - - public void setF3(boolean f3) { - this.f3 = f3; - } - - @Override /* Object */ - public String toString() { - return ("J(f1: " + this.getF1() + ", f2: " + this.getF2() + ")"); - } - } -}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/ab15d45b/juneau-core-test/src/test/java/org/apache/juneau/html/HtmlTest.java ---------------------------------------------------------------------- diff --git a/juneau-core-test/src/test/java/org/apache/juneau/html/HtmlTest.java b/juneau-core-test/src/test/java/org/apache/juneau/html/HtmlTest.java deleted file mode 100755 index 9d76201..0000000 --- a/juneau-core-test/src/test/java/org/apache/juneau/html/HtmlTest.java +++ /dev/null @@ -1,287 +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.html; - -import static org.apache.juneau.html.HtmlSerializerContext.*; -import static org.junit.Assert.*; - -import java.util.*; - -import org.apache.juneau.*; -import org.apache.juneau.html.annotation.*; -import org.apache.juneau.testbeans.*; -import org.junit.*; - -@SuppressWarnings({"javadoc","unchecked","rawtypes","serial"}) -public class HtmlTest { - - //==================================================================================================== - // Verifies that lists of maps/beans are converted to tables correctly. - //==================================================================================================== - @Test - public void testTables1() throws Exception { - HtmlSerializer s = HtmlSerializer.DEFAULT_SQ; - Object[] t; - String html; - - t = new Object[] {new A1(), new A1()}; - html = s.serialize(t); - assertEquals("<table _type='array'><tr><th>f1</th></tr><tr><td>f1</td></tr><tr><td>f1</td></tr></table>", html); - - } - - public static class A1 { - public String f1 = "f1"; - } - - //==================================================================================================== - // Test URI_ANCHOR_SET options - //==================================================================================================== - @Test - public void testAnchorTextOptions() throws Exception { - HtmlSerializerBuilder s = new HtmlSerializerBuilder().sq().addKeyValueTableHeaders(true).uriResolution(UriResolution.NONE); - TestURI t = new TestURI(); - String r; - String expected = null; - - s.uriAnchorText(TO_STRING); - r = strip(s.build().serialize(t)); - expected = "" - +"\n[f0]=<a href='f0/x0'>f0/x0</a>" - +"\n[f1]=<a href='f1/x1'>f1/x1</a>" - +"\n[f2]=<a href='/f2/x2'>/f2/x2</a>" - +"\n[f3]=<a href='http://www.apache.org/f3/x3'>http://www.apache.org/f3/x3</a>" - +"\n[f4]=<a href='f4/x4'>f4/x4</a>" - +"\n[f5]=<a href='/f5/x5'>/f5/x5</a>" - +"\n[f6]=<a href='http://www.apache.org/f6/x6'>http://www.apache.org/f6/x6</a>" - +"\n[f7]=<a href='http://www.apache.org/f7/x7'>http://www.apache.org/f7/x7</a>" - +"\n[f8]=<a href='f8/x8'>f8/x8</a>" - +"\n[f9]=<a href='f9/x9'>f9/x9</a>" - +"\n[fa]=<a href='http://www.apache.org/fa/xa#MY_LABEL'>http://www.apache.org/fa/xa#MY_LABEL</a>" - +"\n[fb]=<a href='http://www.apache.org/fb/xb?label=MY_LABEL&foo=bar'>MY_LABEL</a>" - +"\n[fc]=<a href='http://www.apache.org/fc/xc?foo=bar&label=MY_LABEL'>MY_LABEL</a>" - +"\n[fd]=<a href='http://www.apache.org/fd/xd?label2=MY_LABEL&foo=bar'>http://www.apache.org/fd/xd?label2=MY_LABEL&foo=bar</a>" - +"\n[fe]=<a href='http://www.apache.org/fe/xe?foo=bar&label2=MY_LABEL'>http://www.apache.org/fe/xe?foo=bar&label2=MY_LABEL</a>"; - assertEquals(expected, r); - - s.uriAnchorText(URI); - r = strip(s.build().serialize(t)); - expected = "" - +"\n[f0]=<a href='f0/x0'>f0/x0</a>" - +"\n[f1]=<a href='f1/x1'>f1/x1</a>" - +"\n[f2]=<a href='/f2/x2'>/f2/x2</a>" - +"\n[f3]=<a href='http://www.apache.org/f3/x3'>http://www.apache.org/f3/x3</a>" - +"\n[f4]=<a href='f4/x4'>f4/x4</a>" - +"\n[f5]=<a href='/f5/x5'>/f5/x5</a>" - +"\n[f6]=<a href='http://www.apache.org/f6/x6'>http://www.apache.org/f6/x6</a>" - +"\n[f7]=<a href='http://www.apache.org/f7/x7'>http://www.apache.org/f7/x7</a>" - +"\n[f8]=<a href='f8/x8'>f8/x8</a>" - +"\n[f9]=<a href='f9/x9'>f9/x9</a>" - +"\n[fa]=<a href='http://www.apache.org/fa/xa#MY_LABEL'>http://www.apache.org/fa/xa#MY_LABEL</a>" - +"\n[fb]=<a href='http://www.apache.org/fb/xb?label=MY_LABEL&foo=bar'>MY_LABEL</a>" - +"\n[fc]=<a href='http://www.apache.org/fc/xc?foo=bar&label=MY_LABEL'>MY_LABEL</a>" - +"\n[fd]=<a href='http://www.apache.org/fd/xd?label2=MY_LABEL&foo=bar'>http://www.apache.org/fd/xd?label2=MY_LABEL&foo=bar</a>" - +"\n[fe]=<a href='http://www.apache.org/fe/xe?foo=bar&label2=MY_LABEL'>http://www.apache.org/fe/xe?foo=bar&label2=MY_LABEL</a>"; - assertEquals(expected, r); - - s.uriAnchorText(LAST_TOKEN); - r = strip(s.build().serialize(t)); - expected = "" - +"\n[f0]=<a href='f0/x0'>x0</a>" - +"\n[f1]=<a href='f1/x1'>x1</a>" - +"\n[f2]=<a href='/f2/x2'>x2</a>" - +"\n[f3]=<a href='http://www.apache.org/f3/x3'>x3</a>" - +"\n[f4]=<a href='f4/x4'>x4</a>" - +"\n[f5]=<a href='/f5/x5'>x5</a>" - +"\n[f6]=<a href='http://www.apache.org/f6/x6'>x6</a>" - +"\n[f7]=<a href='http://www.apache.org/f7/x7'>x7</a>" - +"\n[f8]=<a href='f8/x8'>x8</a>" - +"\n[f9]=<a href='f9/x9'>x9</a>" - +"\n[fa]=<a href='http://www.apache.org/fa/xa#MY_LABEL'>xa</a>" - +"\n[fb]=<a href='http://www.apache.org/fb/xb?label=MY_LABEL&foo=bar'>MY_LABEL</a>" - +"\n[fc]=<a href='http://www.apache.org/fc/xc?foo=bar&label=MY_LABEL'>MY_LABEL</a>" - +"\n[fd]=<a href='http://www.apache.org/fd/xd?label2=MY_LABEL&foo=bar'>xd</a>" - +"\n[fe]=<a href='http://www.apache.org/fe/xe?foo=bar&label2=MY_LABEL'>xe</a>"; - assertEquals(expected, r); - - s.uriAnchorText(URI_ANCHOR); - r = strip(s.build().serialize(t)); - expected = "" - +"\n[f0]=<a href='f0/x0'>f0/x0</a>" - +"\n[f1]=<a href='f1/x1'>f1/x1</a>" - +"\n[f2]=<a href='/f2/x2'>/f2/x2</a>" - +"\n[f3]=<a href='http://www.apache.org/f3/x3'>http://www.apache.org/f3/x3</a>" - +"\n[f4]=<a href='f4/x4'>f4/x4</a>" - +"\n[f5]=<a href='/f5/x5'>/f5/x5</a>" - +"\n[f6]=<a href='http://www.apache.org/f6/x6'>http://www.apache.org/f6/x6</a>" - +"\n[f7]=<a href='http://www.apache.org/f7/x7'>http://www.apache.org/f7/x7</a>" - +"\n[f8]=<a href='f8/x8'>f8/x8</a>" - +"\n[f9]=<a href='f9/x9'>f9/x9</a>" - +"\n[fa]=<a href='http://www.apache.org/fa/xa#MY_LABEL'>MY_LABEL</a>" - +"\n[fb]=<a href='http://www.apache.org/fb/xb?label=MY_LABEL&foo=bar'>MY_LABEL</a>" - +"\n[fc]=<a href='http://www.apache.org/fc/xc?foo=bar&label=MY_LABEL'>MY_LABEL</a>" - +"\n[fd]=<a href='http://www.apache.org/fd/xd?label2=MY_LABEL&foo=bar'>http://www.apache.org/fd/xd?label2=MY_LABEL&foo=bar</a>" - +"\n[fe]=<a href='http://www.apache.org/fe/xe?foo=bar&label2=MY_LABEL'>http://www.apache.org/fe/xe?foo=bar&label2=MY_LABEL</a>"; - assertEquals(expected, r); - - s.labelParameter("label2"); - r = strip(s.build().serialize(t)); - expected = "" - +"\n[f0]=<a href='f0/x0'>f0/x0</a>" - +"\n[f1]=<a href='f1/x1'>f1/x1</a>" - +"\n[f2]=<a href='/f2/x2'>/f2/x2</a>" - +"\n[f3]=<a href='http://www.apache.org/f3/x3'>http://www.apache.org/f3/x3</a>" - +"\n[f4]=<a href='f4/x4'>f4/x4</a>" - +"\n[f5]=<a href='/f5/x5'>/f5/x5</a>" - +"\n[f6]=<a href='http://www.apache.org/f6/x6'>http://www.apache.org/f6/x6</a>" - +"\n[f7]=<a href='http://www.apache.org/f7/x7'>http://www.apache.org/f7/x7</a>" - +"\n[f8]=<a href='f8/x8'>f8/x8</a>" - +"\n[f9]=<a href='f9/x9'>f9/x9</a>" - +"\n[fa]=<a href='http://www.apache.org/fa/xa#MY_LABEL'>MY_LABEL</a>" - +"\n[fb]=<a href='http://www.apache.org/fb/xb?label=MY_LABEL&foo=bar'>http://www.apache.org/fb/xb?label=MY_LABEL&foo=bar</a>" - +"\n[fc]=<a href='http://www.apache.org/fc/xc?foo=bar&label=MY_LABEL'>http://www.apache.org/fc/xc?foo=bar&label=MY_LABEL</a>" - +"\n[fd]=<a href='http://www.apache.org/fd/xd?label2=MY_LABEL&foo=bar'>MY_LABEL</a>" - +"\n[fe]=<a href='http://www.apache.org/fe/xe?foo=bar&label2=MY_LABEL'>MY_LABEL</a>"; - assertEquals(expected, r); - - s.detectLinksInStrings(false); - r = strip(s.build().serialize(t)); - expected = "" - +"\n[f0]=<a href='f0/x0'>f0/x0</a>" - +"\n[f1]=<a href='f1/x1'>f1/x1</a>" - +"\n[f2]=<a href='/f2/x2'>/f2/x2</a>" - +"\n[f3]=<a href='http://www.apache.org/f3/x3'>http://www.apache.org/f3/x3</a>" - +"\n[f4]=<a href='f4/x4'>f4/x4</a>" - +"\n[f5]=<a href='/f5/x5'>/f5/x5</a>" - +"\n[f6]=<a href='http://www.apache.org/f6/x6'>http://www.apache.org/f6/x6</a>" - +"\n[f7]=<a href='http://www.apache.org/f7/x7'>http://www.apache.org/f7/x7</a>" - +"\n[f8]=<a href='f8/x8'>f8/x8</a>" - +"\n[f9]=<a href='f9/x9'>f9/x9</a>" - +"\n[fa]=http://www.apache.org/fa/xa#MY_LABEL" - +"\n[fb]=http://www.apache.org/fb/xb?label=MY_LABEL&foo=bar" - +"\n[fc]=http://www.apache.org/fc/xc?foo=bar&label=MY_LABEL" - +"\n[fd]=http://www.apache.org/fd/xd?label2=MY_LABEL&foo=bar" - +"\n[fe]=http://www.apache.org/fe/xe?foo=bar&label2=MY_LABEL"; - assertEquals(expected, r); - - s.detectLinksInStrings(true); - s.lookForLabelParameters(false); - r = strip(s.build().serialize(t)); - expected = "" - +"\n[f0]=<a href='f0/x0'>f0/x0</a>" - +"\n[f1]=<a href='f1/x1'>f1/x1</a>" - +"\n[f2]=<a href='/f2/x2'>/f2/x2</a>" - +"\n[f3]=<a href='http://www.apache.org/f3/x3'>http://www.apache.org/f3/x3</a>" - +"\n[f4]=<a href='f4/x4'>f4/x4</a>" - +"\n[f5]=<a href='/f5/x5'>/f5/x5</a>" - +"\n[f6]=<a href='http://www.apache.org/f6/x6'>http://www.apache.org/f6/x6</a>" - +"\n[f7]=<a href='http://www.apache.org/f7/x7'>http://www.apache.org/f7/x7</a>" - +"\n[f8]=<a href='f8/x8'>f8/x8</a>" - +"\n[f9]=<a href='f9/x9'>f9/x9</a>" - +"\n[fa]=<a href='http://www.apache.org/fa/xa#MY_LABEL'>MY_LABEL</a>" - +"\n[fb]=<a href='http://www.apache.org/fb/xb?label=MY_LABEL&foo=bar'>http://www.apache.org/fb/xb?label=MY_LABEL&foo=bar</a>" - +"\n[fc]=<a href='http://www.apache.org/fc/xc?foo=bar&label=MY_LABEL'>http://www.apache.org/fc/xc?foo=bar&label=MY_LABEL</a>" - +"\n[fd]=<a href='http://www.apache.org/fd/xd?label2=MY_LABEL&foo=bar'>http://www.apache.org/fd/xd?label2=MY_LABEL&foo=bar</a>" - +"\n[fe]=<a href='http://www.apache.org/fe/xe?foo=bar&label2=MY_LABEL'>http://www.apache.org/fe/xe?foo=bar&label2=MY_LABEL</a>"; - assertEquals(expected, r); - } - - private String strip(String html) { - return html - .replace("<table><tr><th>key</th><th>value</th></tr>", "") - .replace("</table>", "") - .replace("<tr><td>", "\n[") - .replace("</td><td>", "]=") - .replace("</td></tr>", ""); - } - - //==================================================================================================== - // Test @Html.asPlainText annotation on classes and fields - //==================================================================================================== - @Test - public void testHtmlAnnotationAsPlainText() throws Exception { - HtmlSerializer s = new HtmlSerializerBuilder().sq().addKeyValueTableHeaders(true).build(); - Object o = null; - String r; - - o = new B1(); - r = s.serialize(o); - assertEquals("<test>", r); - - o = new B2(); - r = s.serialize(o); - assertEquals("<table><tr><th>key</th><th>value</th></tr><tr><td>f1</td><td><f1></td></tr></table>", r); - } - - @Html(asPlainText=true) - public static class B1 { - public String f1 = "<f1>"; - @Override /* Object */ - public String toString() { - return "<test>"; - } - } - - public static class B2 { - @Html(asPlainText=true) - public String f1 = "<f1>"; - } - - //==================================================================================================== - // Test @Html.asXml annotation on classes and fields - //==================================================================================================== - @Test - public void testHtmlAnnotationAsXml() throws Exception { - HtmlSerializer s = new HtmlSerializerBuilder().sq().addKeyValueTableHeaders(true).build(); - Object o = null; - String r; - - o = new C1(); - r = s.serialize(o); - assertEquals("<object><f1><f1></f1></object>", r); - - o = new C2(); - r = s.serialize(o); - assertEquals("<table><tr><th>key</th><th>value</th></tr><tr><td>f1</td><td><f1></td></tr></table>", r); - } - - @Html(asXml=true) - public static class C1 { - public String f1 = "<f1>"; - } - - public static class C2 { - @Html(asXml=true) - public String f1 = "<f1>"; - } - - //==================================================================================================== - // Test @Html.noTableHeaders - //==================================================================================================== - @Test - public void testNoTableHeaders() throws Exception { - HtmlSerializer s = HtmlSerializer.DEFAULT_SQ; - Object o = null; - String r; - - Map m = new MyMap(); - m.put("foo", "bar"); - o = new ObjectList().append(m); - r = s.serialize(o); - assertEquals("<ul><li><table><tr><td>foo</td><td>bar</td></tr></table></li></ul>", r); - } - - @Html(noTables=true, noTableHeaders=true) - public static class MyMap extends LinkedHashMap<String,String> {} - -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/ab15d45b/juneau-core-test/src/test/java/org/apache/juneau/https/AcceptExtensionsTest.java ---------------------------------------------------------------------- diff --git a/juneau-core-test/src/test/java/org/apache/juneau/https/AcceptExtensionsTest.java b/juneau-core-test/src/test/java/org/apache/juneau/https/AcceptExtensionsTest.java deleted file mode 100644 index c2759d4..0000000 --- a/juneau-core-test/src/test/java/org/apache/juneau/https/AcceptExtensionsTest.java +++ /dev/null @@ -1,118 +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.https; - -import static org.apache.juneau.TestUtils.*; -import static org.junit.Assert.*; - -import org.apache.juneau.http.*; -import org.junit.*; - -/** - * Verifies that the Accept class handles parameters and extensions correctly. - */ -public class AcceptExtensionsTest { - - //-------------------------------------------------------------------------------- - // Verifies that media type parameters are distinguished from media range extensions. - //-------------------------------------------------------------------------------- - @Test - public void testExtensions() throws Exception { - Accept accept; - MediaTypeRange mr; - - accept = Accept.forString("text/json"); - mr = accept.asRanges().get(0); - assertTextEquals("text/json", mr); - assertTextEquals("text/json", mr.getMediaType()); - assertObjectEquals("{}", mr.getMediaType().getParameters()); - assertTextEquals("1.0", mr.getQValue()); - assertObjectEquals("{}", mr.getExtensions()); - - accept = Accept.forString("foo,bar"); - mr = accept.asRanges().get(0); - assertTextEquals("foo", mr); - assertTextEquals("foo", mr.getMediaType()); - assertObjectEquals("{}", mr.getMediaType().getParameters()); - assertTextEquals("1.0", mr.getQValue()); - assertObjectEquals("{}", mr.getExtensions()); - - accept = Accept.forString(" foo , bar "); - mr = accept.asRanges().get(0); - assertTextEquals("foo", mr); - assertTextEquals("foo", mr.getMediaType()); - assertObjectEquals("{}", mr.getMediaType().getParameters()); - assertTextEquals("1.0", mr.getQValue()); - assertObjectEquals("{}", mr.getExtensions()); - - accept = Accept.forString("text/json;a=1;q=0.9;b=2"); - mr = accept.asRanges().get(0); - assertTextEquals("text/json;a=1;q=0.9;b=2", mr); - assertTextEquals("text/json;a=1", mr.getMediaType()); - assertObjectEquals("{a:['1']}", mr.getMediaType().getParameters()); - assertTextEquals("0.9", mr.getQValue()); - assertObjectEquals("{b:['2']}", mr.getExtensions()); - - accept = Accept.forString("text/json;a=1;a=2;q=0.9;b=3;b=4"); - mr = accept.asRanges().get(0); - assertTextEquals("text/json;a=1;a=2;q=0.9;b=3;b=4", mr); - assertTextEquals("text/json;a=1;a=2", mr.getMediaType()); - assertObjectEquals("{a:['1','2']}", mr.getMediaType().getParameters()); - assertTextEquals("0.9", mr.getQValue()); - assertObjectEquals("{b:['3','4']}", mr.getExtensions()); - - accept = Accept.forString("text/json;a=1"); - mr = accept.asRanges().get(0); - assertTextEquals("text/json;a=1", mr); - assertTextEquals("text/json;a=1", mr.getMediaType()); - assertObjectEquals("{a:['1']}", mr.getMediaType().getParameters()); - assertTextEquals("1.0", mr.getQValue()); - assertObjectEquals("{}", mr.getExtensions()); - - accept = Accept.forString("text/json;a=1;"); - mr = accept.asRanges().get(0); - assertTextEquals("text/json;a=1", mr); - assertTextEquals("text/json;a=1", mr.getMediaType()); - assertObjectEquals("{a:['1']}", mr.getMediaType().getParameters()); - assertTextEquals("1.0", mr.getQValue()); - assertObjectEquals("{}", mr.getExtensions()); - - accept = Accept.forString("text/json;q=0.9"); - mr = accept.asRanges().get(0); - assertTextEquals("text/json;q=0.9", mr); - assertTextEquals("text/json", mr.getMediaType()); - assertObjectEquals("{}", mr.getMediaType().getParameters()); - assertTextEquals("0.9", mr.getQValue()); - assertObjectEquals("{}", mr.getExtensions()); - - accept = Accept.forString("text/json;q=0.9;"); - mr = accept.asRanges().get(0); - assertTextEquals("text/json;q=0.9", mr); - assertTextEquals("text/json", mr.getMediaType()); - assertObjectEquals("{}", mr.getMediaType().getParameters()); - assertTextEquals("0.9", mr.getQValue()); - assertObjectEquals("{}", mr.getExtensions()); - } - - //-------------------------------------------------------------------------------- - // Tests the Accept.hasSubtypePart() method. - //-------------------------------------------------------------------------------- - @Test - public void testHasSubtypePart() { - Accept accept = Accept.forString("text/json+x,text/foo+y;q=0.0"); - assertTrue(accept.hasSubtypePart("json")); - assertTrue(accept.hasSubtypePart("x")); - assertFalse(accept.hasSubtypePart("foo")); - assertFalse(accept.hasSubtypePart("y")); - } -} http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/ab15d45b/juneau-core-test/src/test/java/org/apache/juneau/https/AcceptTest.java ---------------------------------------------------------------------- diff --git a/juneau-core-test/src/test/java/org/apache/juneau/https/AcceptTest.java b/juneau-core-test/src/test/java/org/apache/juneau/https/AcceptTest.java deleted file mode 100644 index 6f44506..0000000 --- a/juneau-core-test/src/test/java/org/apache/juneau/https/AcceptTest.java +++ /dev/null @@ -1,127 +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.https; - -import java.util.*; - -import org.apache.juneau.*; -import org.apache.juneau.http.*; -import org.apache.juneau.json.*; -import org.junit.*; -import org.junit.runner.*; -import org.junit.runners.*; - -/** - * Verifies that the Accept class handles matching correctly. - */ -@RunWith(Parameterized.class) -public class AcceptTest { - @Parameterized.Parameters - public static Collection<Object[]> getParameters() { - return Arrays.asList(new Object[][] { - - // label, accept-header, media-types, expected-index - - // Simple matches - { "SimpleMatch-1", "text/json", "['text/json']", 0 }, - { "SimpleMatch-2", "text/json", "['text/json','text/foo']", 0 }, - { "SimpleMatch-3", "text/json", "['text/foo','text/json']", 1 }, - - // Simple no-matches - { "SimpleNoMatch-1", "text/jsonx", "['text/json']", -1 }, - { "SimpleNoMatch-2", "text/jso", "['text/json']", -1 }, - { "SimpleNoMatch-3", "text/json", "['application/json']", -1 }, - { "SimpleNoMatch-4", "text/json", "[]", -1 }, - - // Meta-character matches - { "MetaMatch-1", "text/*", "['text/a','text/b+c','text/b+d+e']", 2 }, - { "MetaMatch-2", "text/b+*", "['text/a','text/b+c','text/b+d+e']", 2 }, - { "MetaMatch-3", "text/c+*", "['text/a','text/b+c','text/b+d+e']", 1 }, - { "MetaMatch-4", "text/b+d+e", "['text/a','text/b+c','text/b+d']", 2 }, - { "MetaMatch-5", "text/b+*", "['text/a','text/b+c','text/b+d']", 1 }, - { "MetaMatch-6", "text/d+e+*", "['text/a','text/b+c','text/b+d+e']", 2 }, - - { "MetaMatch-7", "*/a", "['text/a','application/a']", 0 }, - { "MetaMatch-8", "*/*", "['text/a','text/b+c']", 1 }, - { "MetaMatch-9", "*/*", "['text/b+c','text/a']", 0 }, - - // Reverse meta-character matches - { "RevMetaMatch-1", "text/a", "['text/*']", 0 }, - { "RevMetaMatch-3", "text/a", "['*/a']", 0 }, - { "RevMetaMatch-3", "text/a", "['*/*']", 0 }, - - // Meta-character mixture matches - { "MixedMetaMatch-1", "text/*", "['text/*','text/a','text/a+b','text/b+c','text/d+*']", 0 }, - { "MixedMetaMatch-2", "*/a", "['text/*','text/a','text/a+b','text/b+c','text/d+*']", 1 }, - { "MixedMetaMatch-3", "*/*", "['text/*','text/a','text/a+b','text/b+c','text/d+*']", 0 }, - { "MixedMetaMatch-4", "text/a+*", "['text/*','text/a','text/a+b','text/b+c','text/d+*']", 2 }, - { "MixedMetaMatch-5", "text/c+*", "['text/*','text/a','text/a+b','text/b+c','text/d+*']", 3 }, - { "MixedMetaMatch-6", "text/d+*", "['text/*','text/a','text/a+b','text/b+c','text/d+*']", 4 }, - - // Fuzzy matches - { "Fuzzy-1", "text/1+2", "['text/1+2']", 0 }, - // Order of subtype parts shouldn't matter. - { "Fuzzy-2", "text/2+1", "['text/1+2']", 0 }, - // Should match if Accept has 'extra' subtypes. - // For example, "Accept: text/json+activity" should match against the "text/json" serializer. - { "Fuzzy-3", "text/1+2", "['text/1']", 0 }, - // Shouldn't match because the accept media type must be at least a subset of the real media type - // For example, "Accept: text/json" should not match against the "text/json+lax" serializer. - { "Fuzzy-4", "text/1", "['text/1+2']", -1 }, - { "Fuzzy-5", "text/1+2", "['text/1','text/1+3']", 0 }, - // "text/1+2" should be a better match than just "text/1" - { "Fuzzy-6", "text/1+2", "['text/1','text/1+2','text/1+2+3']", 1 }, - // Same as last, but mix up the order a bit. - { "Fuzzy-7", "text/1+2", "['text/1+2+3','text/1','text/1+2']", 2 }, - // Same as last, but mix up the order of the subtypes as well. - { "Fuzzy-8", "text/1+2", "['text/3+2+1','text/1','text/2+1']", 2 }, - { "Fuzzy-9", "text/1+2+3+4", "['text/1+2','text/1+2+3']", 1 }, - { "Fuzzy-10", "text/1+2+3+4", "['text/1+2+3','text/1+2']", 0 }, - { "Fuzzy-11", "text/4+2+3+1", "['text/1+2+3','text/1+2']", 0 }, - { "Fuzzy-12", "text/4+2+3+1", "['text/1+2','text/1+2+3']", 1 }, - - // Q metrics - { "Q-1", "text/A;q=0.9,text/B;q=0.1", "['text/A','text/B']", 0 }, - { "Q-2", "text/A;q=0.9,text/B;q=0.1", "['text/B','text/A']", 1 }, - { "Q-3", "text/A+1;q=0.9,text/B;q=0.1", "['text/A','text/B']", 0 }, - { "Q-4", "text/A;q=0.9,text/B+1;q=0.1", "['text/A','text/B+1']", 0 }, - { "Q-5", "text/A;q=0.9,text/A+1;q=0.1", "['text/A+1','text/A']", 1 }, - - // Test q=0 - { "Q0-1", "text/A;q=0,text/B;q=0.1", "['text/A','text/B']", 1 }, - { "Q0-2", "text/A;q=0,text/B;q=0.1", "['text/A','text/A+1']", -1 }, - - // Test media types with parameters - { "Parms-1", "text/A", "['text/A;foo=bar','text/B']", 0 }, - { "Parms-2", "text/A;foo=bar", "['text/A','text/B']", 0 }, - }); - } - - private String label, accept, mediaTypes; - private int expected; - - public AcceptTest(String label, String accept, String mediaTypes, int expected) { - this.label = label; - this.accept = accept; - this.mediaTypes = mediaTypes; - this.expected = expected; - } - - @Test - public void test() throws Exception { - Accept accept = Accept.forString(this.accept); - MediaType[] mt = JsonParser.DEFAULT.parse(mediaTypes, MediaType[].class); - int r = accept.findMatch(mt); - TestUtils.assertEquals(expected, r, "{0} failed", label); - } -} http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/ab15d45b/juneau-core-test/src/test/java/org/apache/juneau/https/MediaRangeTest.java ---------------------------------------------------------------------- diff --git a/juneau-core-test/src/test/java/org/apache/juneau/https/MediaRangeTest.java b/juneau-core-test/src/test/java/org/apache/juneau/https/MediaRangeTest.java deleted file mode 100644 index 8ba7acb..0000000 --- a/juneau-core-test/src/test/java/org/apache/juneau/https/MediaRangeTest.java +++ /dev/null @@ -1,66 +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.https; - -import static org.junit.Assert.*; - -import java.util.*; - -import org.apache.juneau.http.*; -import org.apache.juneau.json.*; -import org.junit.*; -import org.junit.runner.*; -import org.junit.runners.*; - -/** - * Verifies that the MediaRange and MediaType classes parse and sort Accept headers correctly. - */ -@RunWith(Parameterized.class) -public class MediaRangeTest { - @Parameterized.Parameters - public static Collection<Object[]> getParameters() { - return Arrays.asList(new Object[][] { - { "0", "text/json", "['text/json']" }, - { "1", "text/json,text/*", "['text/json','text/*']" }, - { "2", "text/*,text/json", "['text/json','text/*']" }, - { "3", "text/*,text/*", "['text/*']" }, - { "4", "*/text,text/*", "['text/*','*/text']" }, - { "5", "text/*,*/text", "['text/*','*/text']" }, - { "6", "a;q=0.9,b;q=0.1", "['a;q=0.9','b;q=0.1']" }, - { "7", "b;q=0.9,a;q=0.1", "['b;q=0.9','a;q=0.1']" }, - { "8", "a,b;q=0.9,c;q=0.1,d;q=0", "['a','b;q=0.9','c;q=0.1','d;q=0.0']" }, - { "9", "d;q=0,c;q=0.1,b;q=0.9,a", "['a','b;q=0.9','c;q=0.1','d;q=0.0']" }, - { "10", "a;q=1,b;q=0.9,c;q=0.1,d;q=0", "['a','b;q=0.9','c;q=0.1','d;q=0.0']" }, - { "11", "d;q=0,c;q=0.1,b;q=0.9,a;q=1", "['a','b;q=0.9','c;q=0.1','d;q=0.0']" }, - { "12", "a;q=0,b;q=0.1,c;q=0.9,d;q=1", "['d','c;q=0.9','b;q=0.1','a;q=0.0']" }, - { "13", "*", "['*']" }, - { "14", "", "['*/*']" }, - { "15", null, "['*/*']" }, - { "16", "foo/bar/baz", "['foo/bar/baz']" }, - }); - } - - private String label, mediaRange, expected; - - public MediaRangeTest(String label, String mediaRange, String expected) { - this.label = label; - this.mediaRange = mediaRange; - this.expected = expected; - } - - @Test - public void test() { - MediaTypeRange[] r = MediaTypeRange.parse(mediaRange); - assertEquals(label + " failed", expected, JsonSerializer.DEFAULT_LAX.toString(r)); - } -} http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/ab15d45b/juneau-core-test/src/test/java/org/apache/juneau/ini/ConfigFileBuilderTest.java ---------------------------------------------------------------------- diff --git a/juneau-core-test/src/test/java/org/apache/juneau/ini/ConfigFileBuilderTest.java b/juneau-core-test/src/test/java/org/apache/juneau/ini/ConfigFileBuilderTest.java deleted file mode 100755 index f780f64..0000000 --- a/juneau-core-test/src/test/java/org/apache/juneau/ini/ConfigFileBuilderTest.java +++ /dev/null @@ -1,198 +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.ini; - -import static org.apache.juneau.TestUtils.*; -import static org.junit.Assert.*; -import static org.apache.juneau.internal.FileUtils.*; -import static org.apache.juneau.internal.StringUtils.*; -import static org.apache.juneau.internal.IOUtils.*; - -import java.io.*; - -import org.apache.juneau.svl.*; -import org.junit.*; - -@SuppressWarnings("javadoc") -public class ConfigFileBuilderTest { - - private static File tempDir; - private static String[] TEMP_DIR; - - @BeforeClass - public static void setup() { - tempDir = new File(System.getProperty("java.io.tmpdir"), generateUUID(12)); - mkdirs(tempDir, true); - TEMP_DIR = new String[]{tempDir.getAbsolutePath()}; - } - - @AfterClass - public static void teardown() { - delete(tempDir); - } - - /** - * - * @throws Exception - */ - @Test - public void testGet() throws Exception { - File f; - ConfigFileBuilder b1 = new ConfigFileBuilder().paths(TEMP_DIR).createIfNotExists(); - - ConfigFile cf = b1.build("TestGet.cfg"); - cf.put("Test/A", "a"); - - f = new File(tempDir, "TestGet.cfg"); - assertTrue(f.exists()); - - cf.save(); - assertTextEquals("[Test]|A = a|", read(f)); - - cf = b1.build("TestGet.cfg"); - assertObjectEquals("{'default':{},Test:{A:'a'}}", cf); - - String NL = System.getProperty("line.separator"); - cf = b1.build(new StringReader(("[Test]"+NL+"A = a"+NL))); - assertObjectEquals("{'default':{},Test:{A:'a'}}", cf); - - b1.charset(UTF8); - cf = b1.build("TestGet.cfg"); - assertObjectEquals("{'default':{},Test:{A:'a'}}", cf); - } - - /** - * Retrieving config file should fail if the file doesn't exist and createIfNotExist == false. - */ - @Test - public void testFailOnNonExistentFiles() throws Exception { - ConfigFileBuilder b = new ConfigFileBuilder().paths(new String[]{tempDir.getAbsolutePath()}); - try { b.build("TestGet2.cfg"); fail(); } catch (FileNotFoundException e) {} - try { b.build(tempDir.getAbsolutePath() + "TestGet2.cfg"); fail(); } catch (FileNotFoundException e) {} - - b = new ConfigFileBuilder().paths().createIfNotExists(); - try { b.build("TestGet.cfg"); fail(); } catch (FileNotFoundException e) {} - } - - - //==================================================================================================== - // loadIfModified() - //==================================================================================================== - @Test - public void testLoadIfModified() throws Exception { - ConfigFileBuilder b = new ConfigFileBuilder().paths(TEMP_DIR).createIfNotExists(); - File f; - ConfigFile cf = b.build("TestGet.cfg"); - cf.put("Test/A", "a"); - - f = new File(tempDir, "TestGet.cfg"); - String NL = System.getProperty("line.separator"); - write(f, new StringReader("[Test]"+NL+"A = b"+NL)); - modifyTimestamp(f); - - cf.loadIfModified(); - assertEquals("b", cf.getString("Test/A")); - cf.loadIfModified(); - assertEquals("b", cf.getString("Test/A")); - - // Config file with no backing file. - cf = b.build(); - cf.put("Test/B", "b"); - cf.loadIfModified(); - cf.loadIfModified(); - assertEquals("b", cf.getString("Test/B")); - } - - //==================================================================================================== - // read only - //==================================================================================================== - @Test - public void testReadOnly() throws Exception { - ConfigFileBuilder cm = new ConfigFileBuilder().paths(TEMP_DIR).createIfNotExists().readOnly(); - ConfigFile cf = cm.build("TestGet.cfg"); - - // All these should fail. - try { cf.loadIfModified(); fail(); } catch (UnsupportedOperationException e) {} - try { cf.load(); fail(); } catch (UnsupportedOperationException e) {} - try { cf.load(new StringReader("")); fail(); } catch (UnsupportedOperationException e) {} - try { cf.put("A","b"); fail(); } catch (UnsupportedOperationException e) {} - try { cf.put("A","b",true); fail(); } catch (UnsupportedOperationException e) {} - try { cf.put("A","b"); fail(); } catch (UnsupportedOperationException e) {} - try { cf.put("A","b",true); fail(); } catch (UnsupportedOperationException e) {} - try { cf.removeString("A"); fail(); } catch (UnsupportedOperationException e) {} - try { cf.addLines("A","b=c"); fail(); } catch (UnsupportedOperationException e) {} - try { cf.addHeaderComments("A", "b=c"); fail(); } catch (UnsupportedOperationException e) {} - try { cf.clearHeaderComments("A"); fail(); } catch (UnsupportedOperationException e) {} - try { cf.addSection("A"); fail(); } catch (UnsupportedOperationException e) {} - try { cf.setSection("A",null); fail(); } catch (UnsupportedOperationException e) {} - try { cf.removeSection("A"); fail(); } catch (UnsupportedOperationException e) {} - try { cf.save(); fail(); } catch (UnsupportedOperationException e) {} - try { cf.merge(cf); fail(); } catch (UnsupportedOperationException e) {} - try { cf.addListener(new ConfigFileListener(){}); fail(); } catch (UnsupportedOperationException e) {} - - // All these should succeed. - cf.getObject("A", String.class); - cf.getObject("A", "a", String.class); - cf.getString("A"); - cf.getString("A","a"); - cf.getObject("A", String.class); - cf.getObject("A", "a", String.class); - cf.getObject("A", String[].class); - cf.getStringArray("A"); - cf.getStringArray("A", null); - cf.getInt("A"); - cf.getInt("A", 0); - cf.getBoolean("A"); - cf.getBoolean("A", true); - cf.containsNonEmptyValue("A"); - cf.getSectionMap("A"); - cf.serializeTo(new StringWriter()); - cf.serializeTo(new StringWriter(), ConfigFileFormat.INI); - cf.getResolving(VarResolver.DEFAULT); - cf.toWritable(); - } - - //==================================================================================================== - // main(String[] args) - //==================================================================================================== - @Test - public void testMain() throws Exception { - System.setProperty("exit.2", "0"); - ConfigFileBuilder cm = new ConfigFileBuilder().paths(TEMP_DIR).createIfNotExists(); - - ConfigFile cf = cm.build("Test.cfg") - .addLines(null, "# c1", "\t# c2", " c3 ", " ", "x1=1", "x2=true", "x3=null") - .addLines("s1", "#c4", "k1=1", "#c5 foo=bar", "k2 = true", "k3 = \tnull"); - cf.save(); - - File configFile = new File(tempDir, "Test.cfg"); - File envFile = new File(tempDir, "Test.bat"); - - ConfigFileBuilder.main(new String[]{"createBatchEnvFile", "-configFile", configFile.getAbsolutePath(), "-envFile", envFile.getAbsolutePath()}); - String expected = "rem c1|rem c2|rem c3||set x1 = 1|set x2 = true|set x3 = null|rem c4|set s1_k1 = 1|rem c5 foo=bar|set s1_k2 = true|set s1_k3 = null|"; - String actual = read(envFile); - assertTextEquals(expected, actual); - - ConfigFileBuilder.main(new String[]{"createShellEnvFile", "-configFile", configFile.getAbsolutePath(), "-envFile", envFile.getAbsolutePath()}); - expected = "# c1|# c2|# c3||export x1=\"1\"|export x2=\"true\"|export x3=\"null\"|# c4|export s1_k1=\"1\"|# c5 foo=bar|export s1_k2=\"true\"|export s1_k3=\"null\"|"; - actual = read(envFile); - assertTextEquals(expected, actual); - - ConfigFileBuilder.main(new String[]{"setVals", "-configFile", configFile.getAbsolutePath(), "-vals", "x1=2", "s1/k1=2", "s2/k1=3"}); - modifyTimestamp(configFile); - cf.loadIfModified(); - assertObjectEquals("{'default':{x1:'2',x2:'true',x3:'null'},s1:{k1:'2',k2:'true',k3:'null'},s2:{k1:'3'}}", cf); - - ConfigFileBuilder.main(new String[]{}); - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/ab15d45b/juneau-core-test/src/test/java/org/apache/juneau/ini/ConfigFileInterfaceTest.java ---------------------------------------------------------------------- diff --git a/juneau-core-test/src/test/java/org/apache/juneau/ini/ConfigFileInterfaceTest.java b/juneau-core-test/src/test/java/org/apache/juneau/ini/ConfigFileInterfaceTest.java deleted file mode 100644 index 6aea780..0000000 --- a/juneau-core-test/src/test/java/org/apache/juneau/ini/ConfigFileInterfaceTest.java +++ /dev/null @@ -1,601 +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.ini; - -import static org.junit.Assert.*; -import static org.apache.juneau.TestUtils.*; - -import java.util.*; - -import org.apache.juneau.test.pojos.*; -import org.apache.juneau.utils.*; -import org.junit.*; - -@SuppressWarnings("javadoc") -public class ConfigFileInterfaceTest { - - ConfigFile cf; - ConfigInterface proxy; - - public ConfigFileInterfaceTest() throws Exception { - ConfigFileBuilder configFileBuilder = new ConfigFileBuilder(); - cf = configFileBuilder.build(); - proxy = cf.getSectionAsInterface("A", ConfigInterface.class); - } - - - //==================================================================================================== - // getSectionAsInterface(String,Class) - //==================================================================================================== - - @Test - public void testString() throws Exception { - proxy.setString("foo"); - assertEquals("foo", proxy.getString()); - assertEquals("foo", cf.get("A", "string")); - } - - @Test - public void testInt() throws Exception { - proxy.setInt(1); - assertEquals(1, proxy.getInt()); - assertEquals("1", cf.get("A", "int")); - } - - @Test - public void testInteger() throws Exception { - proxy.setInteger(2); - assertEquals(2, proxy.getInteger().intValue()); - assertEquals("2", cf.get("A", "integer")); - assertType(Integer.class, proxy.getInteger()); - } - - @Test - public void testBoolean() throws Exception { - proxy.setBoolean(true); - assertEquals(true, proxy.isBoolean()); - assertEquals("true", cf.get("A", "boolean")); - } - - @Test - public void testBooleanObject() throws Exception { - proxy.setBooleanObject(true); - assertEquals(true, proxy.getBooleanObject().booleanValue()); - assertEquals("true", cf.get("A", "booleanObject")); - assertType(Boolean.class, proxy.getBooleanObject()); - } - - @Test - public void testFloat() throws Exception { - proxy.setFloat(1f); - assertTrue(1f == proxy.getFloat()); - assertEquals("1.0", cf.get("A", "float")); - } - - @Test - public void testFloatObject() throws Exception { - proxy.setFloatObject(1f); - assertTrue(1f == proxy.getFloatObject().floatValue()); - assertEquals("1.0", cf.get("A", "floatObject")); - assertType(Float.class, proxy.getFloatObject()); - } - - @Test - public void testInt3dArray() throws Exception { - proxy.setInt3dArray(new int[][][]{{{1,2},null},null}); - assertEquals("[[[1,2],null],null]", cf.get("A", "int3dArray")); - assertObjectEquals("[[[1,2],null],null]", proxy.getInt3dArray()); - assertType(int[][][].class, proxy.getInt3dArray()); - } - - @Test - public void testInteger3dArray() throws Exception { - proxy.setInteger3dArray(new Integer[][][]{{{1,null},null},null}); - assertObjectEquals("[[[1,null],null],null]", proxy.getInteger3dArray()); - assertEquals("[[[1,null],null],null]", cf.get("A", "integer3dArray")); - assertType(Integer.class, proxy.getInteger3dArray()[0][0][0]); - } - - @Test - public void testString3dArray() throws Exception { - proxy.setString3dArray(new String[][][]{{{"foo",null},null},null}); - assertObjectEquals("[[['foo',null],null],null]", proxy.getString3dArray()); - assertEquals("[[['foo',null],null],null]", cf.get("A", "string3dArray")); - } - - @Test - public void testIntegerList() throws Exception { - proxy.setIntegerList(new AList<Integer>().append(1).append(null)); - assertObjectEquals("[1,null]", proxy.getIntegerList()); - assertEquals("[1,null]", cf.get("A", "integerList")); - assertType(Integer.class, proxy.getIntegerList().get(0)); - } - - @Test - public void testInteger3dList() throws Exception { - proxy.setInteger3dList( - new AList<List<List<Integer>>>() - .append( - new AList<List<Integer>>() - .append(new AList<Integer>().append(1).append(null)) - .append(null) - ) - .append(null) - ); - assertObjectEquals("[[[1,null],null],null]", proxy.getInteger3dList()); - assertEquals("[[[1,null],null],null]", cf.get("A", "integer3dList")); - assertType(Integer.class, proxy.getInteger3dList().get(0).get(0).get(0)); - } - - @Test - public void testInteger1d3dList() throws Exception { - proxy.setInteger1d3dList(new AList<Integer[][][]>().append(new Integer[][][]{{{1,null},null},null}).append(null)); - assertObjectEquals("[[[[1,null],null],null],null]", proxy.getInteger1d3dList()); - assertEquals("[[[[1,null],null],null],null]", cf.get("A", "integer1d3dList")); - assertType(Integer.class, proxy.getInteger1d3dList().get(0)[0][0][0]); - } - - @Test - public void testInt1d3dList() throws Exception { - proxy.setInt1d3dList(new AList<int[][][]>().append(new int[][][]{{{1,2},null},null}).append(null)); - assertObjectEquals("[[[[1,2],null],null],null]", proxy.getInt1d3dList()); - assertEquals("[[[[1,2],null],null],null]", cf.get("A", "int1d3dList")); - assertType(int[][][].class, proxy.getInt1d3dList().get(0)); - } - - @Test - public void testStringList() throws Exception { - proxy.setStringList(Arrays.asList("foo","bar",null)); - assertObjectEquals("['foo','bar',null]", proxy.getStringList()); - assertEquals("['foo','bar',null]", cf.get("A", "stringList")); - } - - // Beans - - @Test - public void testBean() throws Exception { - proxy.setBean(new ABean().init()); - assertObjectEquals("{a:1,b:'foo'}", proxy.getBean()); - assertEquals("{a:1,b:'foo'}", cf.get("A", "bean")); - assertType(ABean.class, proxy.getBean()); - } - - @Test - public void testBean3dArray() throws Exception { - proxy.setBean3dArray(new ABean[][][]{{{new ABean().init(),null},null},null}); - assertObjectEquals("[[[{a:1,b:'foo'},null],null],null]", proxy.getBean3dArray()); - assertEquals("[[[{a:1,b:'foo'},null],null],null]", cf.get("A", "bean3dArray")); - assertType(ABean.class, proxy.getBean3dArray()[0][0][0]); - } - - @Test - public void testBeanList() throws Exception { - proxy.setBeanList(Arrays.asList(new ABean().init())); - assertObjectEquals("[{a:1,b:'foo'}]", proxy.getBeanList()); - assertEquals("[{a:1,b:'foo'}]", cf.get("A", "beanList")); - assertType(ABean.class, proxy.getBeanList().get(0)); - } - - @Test - public void testBean1d3dList() throws Exception { - proxy.setBean1d3dList(new AList<ABean[][][]>().append(new ABean[][][]{{{new ABean().init(),null},null},null}).append(null)); - assertObjectEquals("[[[[{a:1,b:'foo'},null],null],null],null]", proxy.getBean1d3dList()); - assertEquals("[[[[{a:1,b:'foo'},null],null],null],null]", cf.get("A", "bean1d3dList")); - assertType(ABean.class, proxy.getBean1d3dList().get(0)[0][0][0]); - } - - @Test - public void testBeanMap() throws Exception { - proxy.setBeanMap(new AMap<String,ABean>().append("foo",new ABean().init())); - assertObjectEquals("{foo:{a:1,b:'foo'}}", proxy.getBeanMap()); - assertEquals("{foo:{a:1,b:'foo'}}", cf.get("A", "beanMap")); - assertType(ABean.class, proxy.getBeanMap().get("foo")); - } - - @Test - public void testBeanListMap() throws Exception { - proxy.setBeanListMap(new AMap<String,List<ABean>>().append("foo",Arrays.asList(new ABean().init()))); - assertObjectEquals("{foo:[{a:1,b:'foo'}]}", proxy.getBeanListMap()); - assertEquals("{foo:[{a:1,b:'foo'}]}", cf.get("A", "beanListMap")); - assertType(ABean.class, proxy.getBeanListMap().get("foo").get(0)); - } - - @Test - public void testBean1d3dListMap() throws Exception { - proxy.setBean1d3dListMap(new AMap<String,List<ABean[][][]>>().append("foo",new AList<ABean[][][]>().append(new ABean[][][]{{{new ABean().init(),null},null},null}).append(null))); - assertObjectEquals("{foo:[[[[{a:1,b:'foo'},null],null],null],null]}", proxy.getBean1d3dListMap()); - assertEquals("{foo:[[[[{a:1,b:'foo'},null],null],null],null]}", cf.get("A", "bean1d3dListMap")); - assertType(ABean.class, proxy.getBean1d3dListMap().get("foo").get(0)[0][0][0]); - } - - @Test - public void testBeanListMapIntegerKeys() throws Exception { - proxy.setBeanListMapIntegerKeys(new AMap<Integer,List<ABean>>().append(1,Arrays.asList(new ABean().init()))); - assertObjectEquals("{'1':[{a:1,b:'foo'}]}", proxy.getBeanListMapIntegerKeys()); - assertEquals("{'1':[{a:1,b:'foo'}]}", cf.get("A", "beanListMapIntegerKeys")); - assertType(ABean.class, proxy.getBeanListMapIntegerKeys().get(1).get(0)); - } - - // Typed beans - - @Test - public void testTypedBean() throws Exception { - proxy.setTypedBean(new TypedBeanImpl().init()); - assertObjectEquals("{_type:'TypedBeanImpl',a:1,b:'foo'}", proxy.getTypedBean()); - assertEquals("{_type:'TypedBeanImpl',a:1,b:'foo'}", cf.get("A", "typedBean")); - assertType(TypedBeanImpl.class, proxy.getTypedBean()); - } - - @Test - public void testTypedBean3dArray() throws Exception { - proxy.setTypedBean3dArray(new TypedBean[][][]{{{new TypedBeanImpl().init(),null},null},null}); - assertObjectEquals("[[[{_type:'TypedBeanImpl',a:1,b:'foo'},null],null],null]", proxy.getTypedBean3dArray()); - assertEquals("[[[{_type:'TypedBeanImpl',a:1,b:'foo'},null],null],null]", cf.get("A", "typedBean3dArray")); - assertType(TypedBeanImpl.class, proxy.getTypedBean3dArray()[0][0][0]); - } - - @Test - public void testTypedBeanList() throws Exception { - proxy.setTypedBeanList(Arrays.asList((TypedBean)new TypedBeanImpl().init())); - assertObjectEquals("[{_type:'TypedBeanImpl',a:1,b:'foo'}]", proxy.getTypedBeanList()); - assertEquals("[{_type:'TypedBeanImpl',a:1,b:'foo'}]", cf.get("A", "typedBeanList")); - assertType(TypedBeanImpl.class, proxy.getTypedBeanList().get(0)); - } - - @Test - public void testTypedBean1d3dList() throws Exception { - proxy.setTypedBean1d3dList(new AList<TypedBean[][][]>().append(new TypedBean[][][]{{{new TypedBeanImpl().init(),null},null},null}).append(null)); - assertObjectEquals("[[[[{_type:'TypedBeanImpl',a:1,b:'foo'},null],null],null],null]", proxy.getTypedBean1d3dList()); - assertEquals("[[[[{_type:'TypedBeanImpl',a:1,b:'foo'},null],null],null],null]", cf.get("A", "typedBean1d3dList")); - assertType(TypedBeanImpl.class, proxy.getTypedBean1d3dList().get(0)[0][0][0]); - } - - @Test - public void testTypedBeanMap() throws Exception { - proxy.setTypedBeanMap(new AMap<String,TypedBean>().append("foo",new TypedBeanImpl().init())); - assertObjectEquals("{foo:{_type:'TypedBeanImpl',a:1,b:'foo'}}", proxy.getTypedBeanMap()); - assertEquals("{foo:{_type:'TypedBeanImpl',a:1,b:'foo'}}", cf.get("A", "typedBeanMap")); - assertType(TypedBeanImpl.class, proxy.getTypedBeanMap().get("foo")); - } - - @Test - public void testTypedBeanListMap() throws Exception { - proxy.setTypedBeanListMap(new AMap<String,List<TypedBean>>().append("foo",Arrays.asList((TypedBean)new TypedBeanImpl().init()))); - assertObjectEquals("{foo:[{_type:'TypedBeanImpl',a:1,b:'foo'}]}", proxy.getTypedBeanListMap()); - assertEquals("{foo:[{_type:'TypedBeanImpl',a:1,b:'foo'}]}", cf.get("A", "typedBeanListMap")); - assertType(TypedBeanImpl.class, proxy.getTypedBeanListMap().get("foo").get(0)); - } - - @Test - public void testTypedBean1d3dListMap() throws Exception { - proxy.setTypedBean1d3dListMap(new AMap<String,List<TypedBean[][][]>>().append("foo",new AList<TypedBean[][][]>().append(new TypedBean[][][]{{{new TypedBeanImpl().init(),null},null},null}).append(null))); - assertObjectEquals("{foo:[[[[{_type:'TypedBeanImpl',a:1,b:'foo'},null],null],null],null]}", proxy.getTypedBean1d3dListMap()); - assertEquals("{foo:[[[[{_type:'TypedBeanImpl',a:1,b:'foo'},null],null],null],null]}", cf.get("A", "typedBean1d3dListMap")); - assertType(TypedBeanImpl.class, proxy.getTypedBean1d3dListMap().get("foo").get(0)[0][0][0]); - } - - @Test - public void testTypedBeanListMapIntegerKeys() throws Exception { - proxy.setTypedBeanListMapIntegerKeys(new AMap<Integer,List<TypedBean>>().append(1,Arrays.asList((TypedBean)new TypedBeanImpl().init()))); - assertObjectEquals("{'1':[{_type:'TypedBeanImpl',a:1,b:'foo'}]}", proxy.getTypedBeanListMapIntegerKeys()); - assertEquals("{'1':[{_type:'TypedBeanImpl',a:1,b:'foo'}]}", cf.get("A", "typedBeanListMapIntegerKeys")); - assertType(TypedBeanImpl.class, proxy.getTypedBeanListMapIntegerKeys().get(1).get(0)); - } - - // Swapped POJOs - - @Test - public void testSwappedPojo() throws Exception { - proxy.setSwappedPojo(new SwappedPojo()); - assertObjectEquals("'swap-~!@#$%^&*()_+`-={}[]|:;\"<,>.?/'", proxy.getSwappedPojo()); - assertEquals("swap-~!@#$%^&*()_+`-={}[]|:;\"<,>.?/", cf.get("A", "swappedPojo")); - assertType(SwappedPojo.class, proxy.getSwappedPojo()); - } - - @Test - public void testSwappedPojo3dArray() throws Exception { - proxy.setSwappedPojo3dArray(new SwappedPojo[][][]{{{new SwappedPojo(),null},null},null}); - assertObjectEquals("[[['swap-~!@#$%^&*()_+`-={}[]|:;\"<,>.?/',null],null],null]", proxy.getSwappedPojo3dArray()); - assertEquals("[[['swap-~!@#$%^&*()_+`-={}[]|:;\"<,>.?/',null],null],null]", cf.get("A", "swappedPojo3dArray")); - assertType(SwappedPojo.class, proxy.getSwappedPojo3dArray()[0][0][0]); - } - - @Test - public void testSwappedPojoMap() throws Exception { - proxy.setSwappedPojoMap(new AMap<SwappedPojo,SwappedPojo>().append(new SwappedPojo(), new SwappedPojo())); - assertObjectEquals("{'swap-~!@#$%^&*()_+`-={}[]|:;\"<,>.?/':'swap-~!@#$%^&*()_+`-={}[]|:;\"<,>.?/'}", proxy.getSwappedPojoMap()); - assertEquals("{'swap-~!@#$%^&*()_+`-={}[]|:;\"<,>.?/':'swap-~!@#$%^&*()_+`-={}[]|:;\"<,>.?/'}", cf.get("A", "swappedPojoMap")); - assertType(SwappedPojo.class, proxy.getSwappedPojoMap().keySet().iterator().next()); - assertType(SwappedPojo.class, proxy.getSwappedPojoMap().values().iterator().next()); - } - - @Test - public void testSwappedPojo3dMap() throws Exception { - proxy.setSwappedPojo3dMap(new AMap<SwappedPojo,SwappedPojo[][][]>().append(new SwappedPojo(), new SwappedPojo[][][]{{{new SwappedPojo(),null},null},null})); - assertObjectEquals("{'swap-~!@#$%^&*()_+`-={}[]|:;\"<,>.?/':[[['swap-~!@#$%^&*()_+`-={}[]|:;\"<,>.?/',null],null],null]}", proxy.getSwappedPojo3dMap()); - assertEquals("{'swap-~!@#$%^&*()_+`-={}[]|:;\"<,>.?/':[[['swap-~!@#$%^&*()_+`-={}[]|:;\"<,>.?/',null],null],null]}", cf.get("A", "swappedPojo3dMap")); - assertType(SwappedPojo.class, proxy.getSwappedPojo3dMap().keySet().iterator().next()); - assertType(SwappedPojo.class, proxy.getSwappedPojo3dMap().values().iterator().next()[0][0][0]); - } - - // Implicit swapped POJOs - - @Test - public void testImplicitSwappedPojo() throws Exception { - proxy.setImplicitSwappedPojo(new ImplicitSwappedPojo()); - assertObjectEquals("'swap-~!@#$%^&*()_+`-={}[]|:;\"<,>.?/'", proxy.getImplicitSwappedPojo()); - assertEquals("swap-~!@#$%^&*()_+`-={}[]|:;\"<,>.?/", cf.get("A", "implicitSwappedPojo")); - assertType(ImplicitSwappedPojo.class, proxy.getImplicitSwappedPojo()); - } - - @Test - public void testImplicitSwappedPojo3dArray() throws Exception { - proxy.setImplicitSwappedPojo3dArray(new ImplicitSwappedPojo[][][]{{{new ImplicitSwappedPojo(),null},null},null}); - assertObjectEquals("[[['swap-~!@#$%^&*()_+`-={}[]|:;\"<,>.?/',null],null],null]", proxy.getImplicitSwappedPojo3dArray()); - assertEquals("[[['swap-~!@#$%^&*()_+`-={}[]|:;\"<,>.?/',null],null],null]", cf.get("A", "implicitSwappedPojo3dArray")); - assertType(ImplicitSwappedPojo.class, proxy.getImplicitSwappedPojo3dArray()[0][0][0]); - } - - @Test - public void testImplicitSwappedPojoMap() throws Exception { - proxy.setImplicitSwappedPojoMap(new AMap<ImplicitSwappedPojo,ImplicitSwappedPojo>().append(new ImplicitSwappedPojo(), new ImplicitSwappedPojo())); - assertObjectEquals("{'swap-~!@#$%^&*()_+`-={}[]|:;\"<,>.?/':'swap-~!@#$%^&*()_+`-={}[]|:;\"<,>.?/'}", proxy.getImplicitSwappedPojoMap()); - assertEquals("{'swap-~!@#$%^&*()_+`-={}[]|:;\"<,>.?/':'swap-~!@#$%^&*()_+`-={}[]|:;\"<,>.?/'}", cf.get("A", "implicitSwappedPojoMap")); - assertType(ImplicitSwappedPojo.class, proxy.getImplicitSwappedPojoMap().keySet().iterator().next()); - assertType(ImplicitSwappedPojo.class, proxy.getImplicitSwappedPojoMap().values().iterator().next()); - } - - @Test - public void testImplicitSwappedPojo3dMap() throws Exception { - proxy.setImplicitSwappedPojo3dMap(new AMap<ImplicitSwappedPojo,ImplicitSwappedPojo[][][]>().append(new ImplicitSwappedPojo(), new ImplicitSwappedPojo[][][]{{{new ImplicitSwappedPojo(),null},null},null})); - assertObjectEquals("{'swap-~!@#$%^&*()_+`-={}[]|:;\"<,>.?/':[[['swap-~!@#$%^&*()_+`-={}[]|:;\"<,>.?/',null],null],null]}", proxy.getImplicitSwappedPojo3dMap()); - assertEquals("{'swap-~!@#$%^&*()_+`-={}[]|:;\"<,>.?/':[[['swap-~!@#$%^&*()_+`-={}[]|:;\"<,>.?/',null],null],null]}", cf.get("A", "implicitSwappedPojo3dMap")); - assertType(ImplicitSwappedPojo.class, proxy.getImplicitSwappedPojo3dMap().keySet().iterator().next()); - assertType(ImplicitSwappedPojo.class, proxy.getImplicitSwappedPojo3dMap().values().iterator().next()[0][0][0]); - } - - // Enums - - @Test - public void testEnum() throws Exception { - proxy.setEnum(TestEnum.TWO); - assertObjectEquals("'TWO'", proxy.getEnum()); - assertEquals("TWO", cf.get("A", "enum")); - assertType(TestEnum.class, proxy.getEnum()); - } - - @Test - public void testEnum3d() throws Exception { - proxy.setEnum3d(new TestEnum[][][]{{{TestEnum.TWO,null},null},null}); - assertObjectEquals("[[['TWO',null],null],null]", proxy.getEnum3d()); - assertEquals("[[['TWO',null],null],null]", cf.get("A", "enum3d")); - assertType(TestEnum.class, proxy.getEnum3d()[0][0][0]); - } - - @Test - public void testEnumList() throws Exception { - proxy.setEnumList(new AList<TestEnum>().append(TestEnum.TWO).append(null)); - assertObjectEquals("['TWO',null]", proxy.getEnumList()); - assertEquals("['TWO',null]", cf.get("A", "enumList")); - assertType(TestEnum.class, proxy.getEnumList().get(0)); - } - - @Test - public void testEnum3dList() throws Exception { - proxy.setEnum3dList( - new AList<List<List<TestEnum>>>() - .append( - new AList<List<TestEnum>>() - .append( - new AList<TestEnum>().append(TestEnum.TWO).append(null) - ) - .append(null) - .append(null) - ) - ); - assertObjectEquals("[[['TWO',null],null,null]]", proxy.getEnum3dList()); - assertEquals("[[['TWO',null],null,null]]", cf.get("A", "enum3dList")); - assertType(TestEnum.class, proxy.getEnum3dList().get(0).get(0).get(0)); - } - - @Test - public void testEnum1d3dList() throws Exception { - proxy.setEnum1d3dList(new AList<TestEnum[][][]>().append(new TestEnum[][][]{{{TestEnum.TWO,null},null},null}).append(null)); - assertObjectEquals("[[[['TWO',null],null],null],null]", proxy.getEnum1d3dList()); - assertEquals("[[[['TWO',null],null],null],null]", cf.get("A", "enum1d3dList")); - assertType(TestEnum.class, proxy.getEnum1d3dList().get(0)[0][0][0]); - } - - @Test - public void testEnumMap() throws Exception { - proxy.setEnumMap(new AMap<TestEnum,TestEnum>().append(TestEnum.ONE,TestEnum.TWO)); - assertObjectEquals("{ONE:'TWO'}", proxy.getEnumMap()); - assertEquals("{ONE:'TWO'}", cf.get("A", "enumMap")); - assertType(TestEnum.class, proxy.getEnumMap().keySet().iterator().next()); - assertType(TestEnum.class, proxy.getEnumMap().values().iterator().next()); - } - - @Test - public void testEnum3dArrayMap() throws Exception { - proxy.setEnum3dArrayMap(new AMap<TestEnum,TestEnum[][][]>().append(TestEnum.ONE, new TestEnum[][][]{{{TestEnum.TWO,null},null},null})); - assertObjectEquals("{ONE:[[['TWO',null],null],null]}", proxy.getEnum3dArrayMap()); - assertEquals("{ONE:[[['TWO',null],null],null]}", cf.get("A", "enum3dArrayMap")); - assertType(TestEnum.class, proxy.getEnum3dArrayMap().keySet().iterator().next()); - assertType(TestEnum.class, proxy.getEnum3dArrayMap().values().iterator().next()[0][0][0]); - } - - @Test - public void testEnum1d3dListMap() throws Exception { - proxy.setEnum1d3dListMap(new AMap<TestEnum,List<TestEnum[][][]>>().append(TestEnum.ONE, new AList<TestEnum[][][]>().append(new TestEnum[][][]{{{TestEnum.TWO,null},null},null}).append(null))); - assertObjectEquals("{ONE:[[[['TWO',null],null],null],null]}", proxy.getEnum1d3dListMap()); - assertEquals("{ONE:[[[['TWO',null],null],null],null]}", cf.get("A", "enum1d3dListMap")); - assertType(TestEnum.class, proxy.getEnum1d3dListMap().keySet().iterator().next()); - assertType(TestEnum.class, proxy.getEnum1d3dListMap().values().iterator().next().get(0)[0][0][0]); - } - - public static interface ConfigInterface { - - // Various primitives - - public String getString(); - public void setString(String x); - - public int getInt(); - public void setInt(int x); - - public Integer getInteger(); - public void setInteger(Integer x); - - public boolean isBoolean(); - public void setBoolean(boolean x); - - public Boolean getBooleanObject(); - public void setBooleanObject(Boolean x); - - public float getFloat(); - public void setFloat(float x); - - public Float getFloatObject(); - public void setFloatObject(Float x); - - public int[][][] getInt3dArray(); - public void setInt3dArray(int[][][] x); - - public Integer[][][] getInteger3dArray(); - public void setInteger3dArray(Integer[][][] x); - - public String[][][] getString3dArray(); - public void setString3dArray(String[][][] x); - - public List<Integer> getIntegerList(); - public void setIntegerList(List<Integer> x); - - public List<List<List<Integer>>> getInteger3dList(); - public void setInteger3dList(List<List<List<Integer>>> x); - - public List<Integer[][][]> getInteger1d3dList(); - public void setInteger1d3dList(List<Integer[][][]> x); - - public List<int[][][]> getInt1d3dList(); - public void setInt1d3dList(List<int[][][]> x); - - public List<String> getStringList(); - public void setStringList(List<String> x); - - // Beans - - public ABean getBean(); - public void setBean(ABean x); - - public ABean[][][] getBean3dArray(); - public void setBean3dArray(ABean[][][] x); - - public List<ABean> getBeanList(); - public void setBeanList(List<ABean> x); - - public List<ABean[][][]> getBean1d3dList(); - public void setBean1d3dList(List<ABean[][][]> x); - - public Map<String,ABean> getBeanMap(); - public void setBeanMap(Map<String,ABean> x); - - public Map<String,List<ABean>> getBeanListMap(); - public void setBeanListMap(Map<String,List<ABean>> x); - - public Map<String,List<ABean[][][]>> getBean1d3dListMap(); - public void setBean1d3dListMap(Map<String,List<ABean[][][]>> x); - - public Map<Integer,List<ABean>> getBeanListMapIntegerKeys(); - public void setBeanListMapIntegerKeys(Map<Integer,List<ABean>> x); - - // Typed beans - - public TypedBean getTypedBean(); - public void setTypedBean(TypedBean x); - - public TypedBean[][][] getTypedBean3dArray(); - public void setTypedBean3dArray(TypedBean[][][] x); - - public List<TypedBean> getTypedBeanList(); - public void setTypedBeanList(List<TypedBean> x); - - public List<TypedBean[][][]> getTypedBean1d3dList(); - public void setTypedBean1d3dList(List<TypedBean[][][]> x); - - public Map<String,TypedBean> getTypedBeanMap(); - public void setTypedBeanMap(Map<String,TypedBean> x); - - public Map<String,List<TypedBean>> getTypedBeanListMap(); - public void setTypedBeanListMap(Map<String,List<TypedBean>> x); - - public Map<String,List<TypedBean[][][]>> getTypedBean1d3dListMap(); - public void setTypedBean1d3dListMap(Map<String,List<TypedBean[][][]>> x); - - public Map<Integer,List<TypedBean>> getTypedBeanListMapIntegerKeys(); - public void setTypedBeanListMapIntegerKeys(Map<Integer,List<TypedBean>> x); - - // Swapped POJOs - - public SwappedPojo getSwappedPojo(); - public void setSwappedPojo(SwappedPojo x); - - public SwappedPojo[][][] getSwappedPojo3dArray(); - public void setSwappedPojo3dArray(SwappedPojo[][][] x); - - public Map<SwappedPojo,SwappedPojo> getSwappedPojoMap(); - public void setSwappedPojoMap(Map<SwappedPojo,SwappedPojo> x); - - public Map<SwappedPojo,SwappedPojo[][][]> getSwappedPojo3dMap(); - public void setSwappedPojo3dMap(Map<SwappedPojo,SwappedPojo[][][]> x); - - // Implicit swapped POJOs - - public ImplicitSwappedPojo getImplicitSwappedPojo(); - public void setImplicitSwappedPojo(ImplicitSwappedPojo x); - - public ImplicitSwappedPojo[][][] getImplicitSwappedPojo3dArray(); - public void setImplicitSwappedPojo3dArray(ImplicitSwappedPojo[][][] x); - - public Map<ImplicitSwappedPojo,ImplicitSwappedPojo> getImplicitSwappedPojoMap(); - public void setImplicitSwappedPojoMap(Map<ImplicitSwappedPojo,ImplicitSwappedPojo> x); - - public Map<ImplicitSwappedPojo,ImplicitSwappedPojo[][][]> getImplicitSwappedPojo3dMap(); - public void setImplicitSwappedPojo3dMap(Map<ImplicitSwappedPojo,ImplicitSwappedPojo[][][]> x); - - // Enums - - public TestEnum getEnum(); - public void setEnum(TestEnum x); - - public TestEnum[][][] getEnum3d(); - public void setEnum3d(TestEnum[][][] x); - - public List<TestEnum> getEnumList(); - public void setEnumList(List<TestEnum> x); - - public List<List<List<TestEnum>>> getEnum3dList(); - public void setEnum3dList(List<List<List<TestEnum>>> x); - - public List<TestEnum[][][]> getEnum1d3dList(); - public void setEnum1d3dList(List<TestEnum[][][]> x); - - public Map<TestEnum,TestEnum> getEnumMap(); - public void setEnumMap(Map<TestEnum,TestEnum> x); - - public Map<TestEnum,TestEnum[][][]> getEnum3dArrayMap(); - public void setEnum3dArrayMap(Map<TestEnum,TestEnum[][][]> x); - - public Map<TestEnum,List<TestEnum[][][]>> getEnum1d3dListMap(); - public void setEnum1d3dListMap(Map<TestEnum,List<TestEnum[][][]>> x); - } -} \ No newline at end of file
