http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/91a388d0/juneau-rest-test/src/test/java/org/apache/juneau/rest/test/AcceptCharsetTest.java ---------------------------------------------------------------------- diff --git a/juneau-rest-test/src/test/java/org/apache/juneau/rest/test/AcceptCharsetTest.java b/juneau-rest-test/src/test/java/org/apache/juneau/rest/test/AcceptCharsetTest.java new file mode 100644 index 0000000..9cce642 --- /dev/null +++ b/juneau-rest-test/src/test/java/org/apache/juneau/rest/test/AcceptCharsetTest.java @@ -0,0 +1,123 @@ +// *************************************************************************************************************************** +// * 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.rest.test; + +import static javax.servlet.http.HttpServletResponse.*; +import static org.apache.juneau.rest.test.TestUtils.*; +import static org.junit.Assert.*; + +import java.io.*; + +import org.apache.juneau.internal.*; +import org.apache.juneau.rest.client.*; +import org.junit.*; + +public class AcceptCharsetTest { + + boolean debug = false; + + //==================================================================================================== + // Test that Q-values are being resolved correctly. + //==================================================================================================== + @Test + public void testQValues() throws Exception { + RestClient client = new TestRestClient().setHeader("Accept", "text/plain"); + + check1(client, "utf-8", "utf-8"); + check1(client, "iso-8859-1", "iso-8859-1"); + check1(client, "bad,utf-8", "utf-8"); + check1(client, "utf-8,bad", "utf-8"); + check1(client, "bad;q=0.9,utf-8;q=0.1", "utf-8"); + check1(client, "bad;q=0.1,utf-8;q=0.9", "utf-8"); + check1(client, "utf-8,iso-8859-1", "utf-8"); + check1(client, "iso-8859-1,utf-8", "utf-8"); + check1(client, "utf-8;q=0.9,iso-8859-1;q=0.1", "utf-8"); + check1(client, "utf-8;q=0.1,iso-8859-1;q=0.9", "iso-8859-1"); + check1(client, "*", "utf-8"); + check1(client, "bad,iso-8859-1;q=0.5,*;q=0.1", "iso-8859-1"); + check1(client, "bad,iso-8859-1;q=0.1,*;q=0.5", "utf-8"); + + client.closeQuietly(); + } + + private void check1(RestClient client, String requestCharset, String responseCharset) throws Exception { + RestCall r; + InputStream is; + String url = "/testAcceptCharset/testQValues"; + r = client.doGet(url).setHeader("Accept-Charset", requestCharset).connect(); + assertTrue(r.getResponse().getFirstHeader("Content-Type").getValue().toLowerCase().contains(responseCharset)); + is = r.getInputStream(); + assertEquals("foo", IOUtils.read(new InputStreamReader(is, responseCharset))); + } + + //==================================================================================================== + // Validate various Accept-Charset variations. + //==================================================================================================== + @Test + public void testCharsetOnResponse() throws Exception { + RestClient client = new TestRestClient().setAccept("text/plain").setContentType("text/plain"); + String url = "/testAcceptCharset/testCharsetOnResponse"; + String r; + + r = client.doPut(url, new StringReader("")).getResponseAsString(); + assertEquals("utf-8/utf-8", r.toLowerCase()); + + r = client.doPut(url, new StringReader("")).setHeader("Accept-Charset", "Shift_JIS").getResponseAsString(); + assertEquals("utf-8/shift_jis", r.toLowerCase()); + + try { + r = client.doPut(url+"?noTrace=true", new StringReader("")).setHeader("Accept-Charset", "BAD").getResponseAsString(); + fail("Exception expected"); + } catch (RestCallException e) { + checkErrorResponse(debug, e, SC_NOT_ACCEPTABLE, "No supported charsets in header 'Accept-Charset': 'BAD'"); + } + + r = client.doPut(url, new StringReader("")).setHeader("Accept-Charset", "UTF-8").getResponseAsString(); + assertEquals("utf-8/utf-8", r.toLowerCase()); + + r = client.doPut(url, new StringReader("")).setHeader("Accept-Charset", "bad,iso-8859-1").getResponseAsString(); + assertEquals("utf-8/iso-8859-1", r.toLowerCase()); + + r = client.doPut(url, new StringReader("")).setHeader("Accept-Charset", "bad;q=0.9,iso-8859-1;q=0.1").getResponseAsString(); + assertEquals("utf-8/iso-8859-1", r.toLowerCase()); + + r = client.doPut(url, new StringReader("")).setHeader("Accept-Charset", "bad;q=0.1,iso-8859-1;q=0.9").getResponseAsString(); + assertEquals("utf-8/iso-8859-1", r.toLowerCase()); + + client.setHeader("Accept-Charset", "utf-8"); + + r = client.doPut(url, new StringReader("")).setHeader("Content-Type", "text/plain").getResponseAsString(); + assertEquals("utf-8/utf-8", r.toLowerCase()); + + r = client.doPut(url, new StringReader("")).setHeader("Content-Type", "text/plain;charset=utf-8").getResponseAsString(); + assertEquals("utf-8/utf-8", r.toLowerCase()); + + r = client.doPut(url, new StringReader("")).setHeader("Content-Type", "text/plain;charset=UTF-8").getResponseAsString(); + assertEquals("utf-8/utf-8", r.toLowerCase()); + + r = client.doPut(url, new StringReader("")).setHeader("Content-Type", "text/plain;charset=iso-8859-1").getResponseAsString(); + assertEquals("iso-8859-1/utf-8", r.toLowerCase()); + + r = client.doPut(url, new StringReader("")).setHeader("Content-Type", "text/plain;charset=Shift_JIS").getResponseAsString(); + assertEquals("shift_jis/utf-8", r.toLowerCase()); + + try { + r = client.doPut(url + "?noTrace=true&Content-Type=text/plain;charset=BAD", new StringReader("")).getResponseAsString(); + fail("Exception expected"); + } catch (RestCallException e) { + checkErrorResponse(debug, e, SC_UNSUPPORTED_MEDIA_TYPE, "Unsupported charset in header 'Content-Type': 'text/plain;charset=BAD'"); + } + + client.closeQuietly(); + } +} \ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/91a388d0/juneau-rest-test/src/test/java/org/apache/juneau/rest/test/BeanContextPropertiesTest.java ---------------------------------------------------------------------- diff --git a/juneau-rest-test/src/test/java/org/apache/juneau/rest/test/BeanContextPropertiesTest.java b/juneau-rest-test/src/test/java/org/apache/juneau/rest/test/BeanContextPropertiesTest.java new file mode 100644 index 0000000..cab1f3d --- /dev/null +++ b/juneau-rest-test/src/test/java/org/apache/juneau/rest/test/BeanContextPropertiesTest.java @@ -0,0 +1,37 @@ +// *************************************************************************************************************************** +// * 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.rest.test; + +import static org.junit.Assert.*; + +import org.apache.juneau.json.*; +import org.apache.juneau.rest.client.*; +import org.junit.*; + +public class BeanContextPropertiesTest { + + boolean debug = false; + + //==================================================================================================== + // Validate that filters defined on class filter to underlying bean context. + //==================================================================================================== + @Test + public void testClassTransforms() throws Exception { + RestClient client = new TestRestClient(JsonSerializer.class, JsonParser.class); + String r; + r = client.doGet("/testBeanContext/testClassTransforms/2001-07-04T15:30:45Z?d2=2001-07-05T15:30:45Z").setHeader("X-D3", "2001-07-06T15:30:45Z").getResponseAsString(); + assertEquals("d1=2001-07-04T15:30:45Z,d2=2001-07-05T15:30:45Z,d3=2001-07-06T15:30:45Z", r); + + client.closeQuietly(); + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/91a388d0/juneau-rest-test/src/test/java/org/apache/juneau/rest/test/CallbackStringsTest.java ---------------------------------------------------------------------- diff --git a/juneau-rest-test/src/test/java/org/apache/juneau/rest/test/CallbackStringsTest.java b/juneau-rest-test/src/test/java/org/apache/juneau/rest/test/CallbackStringsTest.java new file mode 100644 index 0000000..0b73c13 --- /dev/null +++ b/juneau-rest-test/src/test/java/org/apache/juneau/rest/test/CallbackStringsTest.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.rest.test; + +import static org.junit.Assert.*; + +import org.apache.juneau.rest.client.*; +import org.junit.*; + +public class CallbackStringsTest { + + //==================================================================================================== + // Basic tests using @Body parameter + //==================================================================================================== + @Test + public void test() throws Exception { + RestClient c = new TestRestClient().setAccept("text/json+simple"); + String r; + + r = c.doCallback("GET /testCallback").getResponseAsString(); + assertEquals("{method:'GET',headers:{},content:''}", r); + + r = c.doCallback("GET /testCallback some sample content").getResponseAsString(); + assertEquals("{method:'GET',headers:{},content:'some sample content'}", r); + + r = c.doCallback("GET {Foo-X:123,Foo-Y:'abc'} /testCallback").getResponseAsString(); + assertEquals("{method:'GET',headers:{'Foo-X':'123','Foo-Y':'abc'},content:''}", r); + + r = c.doCallback("GET { Foo-X : 123, Foo-Y : 'abc' } /testCallback").getResponseAsString(); + assertEquals("{method:'GET',headers:{'Foo-X':'123','Foo-Y':'abc'},content:''}", r); + + r = c.doCallback("GET {Foo-X:123,Foo-Y:'abc'} /testCallback some sample content ").getResponseAsString(); + assertEquals("{method:'GET',headers:{'Foo-X':'123','Foo-Y':'abc'},content:'some sample content'}", r); + + r = c.doCallback("PUT {Foo-X:123,Foo-Y:'abc'} /testCallback some sample content ").getResponseAsString(); + assertEquals("{method:'PUT',headers:{'Foo-X':'123','Foo-Y':'abc'},content:'some sample content'}", r); + + c.closeQuietly(); + } +} http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/91a388d0/juneau-rest-test/src/test/java/org/apache/juneau/rest/test/CharsetEncodingsTest.java ---------------------------------------------------------------------- diff --git a/juneau-rest-test/src/test/java/org/apache/juneau/rest/test/CharsetEncodingsTest.java b/juneau-rest-test/src/test/java/org/apache/juneau/rest/test/CharsetEncodingsTest.java new file mode 100644 index 0000000..25197f8 --- /dev/null +++ b/juneau-rest-test/src/test/java/org/apache/juneau/rest/test/CharsetEncodingsTest.java @@ -0,0 +1,96 @@ +// *************************************************************************************************************************** +// * 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.rest.test; + +import static javax.servlet.http.HttpServletResponse.*; +import static org.apache.juneau.rest.test.TestUtils.*; +import static org.junit.Assert.*; + +import java.io.*; + +import org.apache.juneau.internal.*; +import org.apache.juneau.rest.client.*; +import org.junit.*; + + +public class CharsetEncodingsTest { + + private static boolean debug = false; + + /** + * Basic tests to ensure that the correct charsets are found and used + * under a variety of scenarios. + */ + @Test + public void test() throws Exception { + String url = "/testCharsetEncodings"; + RestClient client = new TestRestClient().setAccept("text/s").setContentType("text/p"); + InputStream is; + String r; + + r = client.doPut(url, new StringReader("foo")).getResponseAsString(); + if (debug) System.err.println(r); + assertEquals("utf-8/foo/utf-8", r); + + is = client.doPut(url, new StringReader("foo")).getInputStream(); + r = IOUtils.read(new InputStreamReader(is, "utf-8")); + if (debug) System.err.println(r); + assertEquals("utf-8/foo/utf-8", r); + + client.setHeader("Accept-Charset", "utf-8").setContentType("text/p;charset=utf-8"); + is = client.doPut(url, new StringReader("foo")).getInputStream(); + r = IOUtils.read(new InputStreamReader(is, "utf-8")); + if (debug) System.err.println(r); + assertEquals("utf-8/foo/utf-8", r); + + client.setHeader("Accept-Charset", "Shift_JIS").setContentType("text/p;charset=shift_jis"); + is = client.doPut(url, new StringReader("foo")).getInputStream(); + r = IOUtils.read(new InputStreamReader(is, "Shift_JIS")); + if (debug) System.err.println(r); + assertEquals("shift_jis/foo/shift_jis", r); + + try { + client.setHeader("Accept-Charset", "BAD").setContentType("text/p;charset=sjis"); + is = client.doPut(url + "?noTrace=true", new StringReader("foo")).getInputStream(); + r = IOUtils.read(new InputStreamReader(is, "sjis")); + if (debug) System.err.println(r); + fail("Exception expected"); + } catch (RestCallException e) { + checkErrorResponse(debug, e, SC_NOT_ACCEPTABLE, "No supported charsets in header 'Accept-Charset': 'BAD'"); + } + + client.setAccept("text/s").setHeader("Accept-Charset", "utf-8").setContentType("text/p"); + is = client.doPut(url+"?Content-Type=text/p", new StringReader("foo")).getInputStream(); + r = IOUtils.read(new InputStreamReader(is, "utf-8")); + if (debug) System.err.println(r); + assertEquals("utf-8/foo/utf-8", r); + + client.setAccept("text/s").setContentType("text/bad").setHeader("Accept-Charset", "utf-8"); + is = client.doPut(url+"?Content-Type=text/p;charset=utf-8", new StringReader("foo")).getInputStream(); + r = IOUtils.read(new InputStreamReader(is, "utf-8")); + if (debug) System.err.println(r); + assertEquals("utf-8/foo/utf-8", r); + + try { + client.setAccept("text/s").setContentType("text/p").setHeader("Accept-Charset", "utf-8"); + is = client.doPut(url+"?Content-Type=text/p;charset=BAD&noTrace=true", new StringReader("foo")).getInputStream(); + r = IOUtils.read(new InputStreamReader(is, "utf-8")); + if (debug) System.err.println(r); + assertEquals("utf-8/foo/utf-8", r); + fail("Exception expected"); + } catch (RestCallException e) { + checkErrorResponse(debug, e, SC_UNSUPPORTED_MEDIA_TYPE, "Unsupported charset in header 'Content-Type': 'text/p;charset=BAD'"); + } + client.closeQuietly(); + } +} http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/91a388d0/juneau-rest-test/src/test/java/org/apache/juneau/rest/test/ClientVersionTest.java ---------------------------------------------------------------------- diff --git a/juneau-rest-test/src/test/java/org/apache/juneau/rest/test/ClientVersionTest.java b/juneau-rest-test/src/test/java/org/apache/juneau/rest/test/ClientVersionTest.java new file mode 100644 index 0000000..c7ca711 --- /dev/null +++ b/juneau-rest-test/src/test/java/org/apache/juneau/rest/test/ClientVersionTest.java @@ -0,0 +1,90 @@ +// *************************************************************************************************************************** +// * 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.rest.test; + +import static org.junit.Assert.*; + +import org.apache.juneau.plaintext.*; +import org.apache.juneau.rest.client.*; +import org.junit.*; + +public class ClientVersionTest { + + private static String URL = "/testClientVersion"; + + //==================================================================================================== + // Basic tests - default X-Client-Version header. + //==================================================================================================== + @Test + public void testDefaultHeader() throws Exception { + RestClient c = new TestRestClient(PlainTextSerializer.class, PlainTextParser.class); + String url = URL + "/defaultHeader"; + + assertEquals("no-version", c.doGet(url).getResponseAsString()); + +// for (String s : "0, 0.0, 0.1, .1, .9, .99".split("\\s*,\\s*")) { +// c.setClientVersion(s); +// assertEquals(s, "[0.0,1.0)", c.doGet(url).getResponseAsString()); +// } + + for (String s : "1, 1.0, 1.0.0, 1.0.1".split("\\s*,\\s*")) { + c.setClientVersion(s); + assertEquals(s, "[1.0,1.0]", c.doGet(url).getResponseAsString()); + } + + for (String s : "1.1, 1.1.1, 1.2, 1.9.9".split("\\s*,\\s*")) { + c.setClientVersion(s); + assertEquals(s, "[1.1,2)", c.doGet(url).getResponseAsString()); + } + + for (String s : "2, 2.0, 2.1, 9, 9.9".split("\\s*,\\s*")) { + c.setClientVersion(s); + assertEquals(s, "2", c.doGet(url).getResponseAsString()); + } + + c.closeQuietly(); + } + + //==================================================================================================== + // Basic tests - Custom-Client-Version header. + //==================================================================================================== + @Test + public void testCustomHeader() throws Exception { + RestClient c = new TestRestClient(PlainTextSerializer.class, PlainTextParser.class); + String url = URL + "/customHeader"; + + assertEquals("no-version", c.doGet(url).getResponseAsString()); + + for (String s : "0, 0.0, 0.1, .1, .9, .99".split("\\s*,\\s*")) { + c.setHeader("Custom-Client-Version", s); + assertEquals("[0.0,1.0)", c.doGet(url).getResponseAsString()); + } + + for (String s : "1, 1.0, 1.0.0, 1.0.1".split("\\s*,\\s*")) { + c.setHeader("Custom-Client-Version", s); + assertEquals("[1.0,1.0]", c.doGet(url).getResponseAsString()); + } + + for (String s : "1.1, 1.1.1, 1.2, 1.9.9".split("\\s*,\\s*")) { + c.setHeader("Custom-Client-Version", s); + assertEquals("[1.1,2)", c.doGet(url).getResponseAsString()); + } + + for (String s : "2, 2.0, 2.1, 9, 9.9".split("\\s*,\\s*")) { + c.setHeader("Custom-Client-Version", s); + assertEquals("2", c.doGet(url).getResponseAsString()); + } + + c.closeQuietly(); + } +} http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/91a388d0/juneau-rest-test/src/test/java/org/apache/juneau/rest/test/ConfigTest.java ---------------------------------------------------------------------- diff --git a/juneau-rest-test/src/test/java/org/apache/juneau/rest/test/ConfigTest.java b/juneau-rest-test/src/test/java/org/apache/juneau/rest/test/ConfigTest.java new file mode 100644 index 0000000..be7ebaa --- /dev/null +++ b/juneau-rest-test/src/test/java/org/apache/juneau/rest/test/ConfigTest.java @@ -0,0 +1,59 @@ +// *************************************************************************************************************************** +// * 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.rest.test; + +import static org.apache.juneau.rest.test.TestUtils.*; +import static org.junit.Assert.*; + +import org.apache.juneau.ini.*; +import org.apache.juneau.json.*; +import org.apache.juneau.rest.*; +import org.apache.juneau.rest.client.*; +import org.junit.*; + +public class ConfigTest { + + private static String URL = "/testConfig"; + + //==================================================================================================== + // Basic tests + //==================================================================================================== + @Test + public void test() throws Exception { + RestClient c = new TestRestClient(JsonSerializer.class, JsonParser.class).setAccept("text/json+simple"); + + ConfigFile cf = c.doGet(URL).getResponse(ConfigFileImpl.class); + + assertObjectEquals("{int1:'1',int2:'1,2,3',int3:'$C{Test/int1, -1}',int4:'$C{Test/int3, -1}',int5:'$C{XXX, -1}',boolean1:'true',boolean2:'true,true',path:'$E{PATH}',testManifestEntry:'$MF{Test-Entry}'}", cf.get("Test")); + + assertEquals("'1'", c.doGet(URL + "/Test%2Fint1/" + getName(String.class)).getResponseAsString()); + assertEquals("['1']", c.doGet(URL + "/Test%2Fint1/" + getName(String[].class)).getResponseAsString()); + assertEquals("'1,2,3'", c.doGet(URL + "/Test%2Fint2/" + getName(String.class)).getResponseAsString()); + assertEquals("['1','2','3']", c.doGet(URL + "/Test%2Fint2/" + getName(String[].class)).getResponseAsString()); + assertEquals("[1,2,3]", c.doGet(URL + "/Test%2Fint2/" + getName(int[].class)).getResponseAsString()); + assertEquals("[1,2,3]", c.doGet(URL + "/Test%2Fint2/" + getName(Integer[].class)).getResponseAsString()); + assertEquals("[1]", c.doGet(URL + "/Test%2Fint3/" + getName(int[].class)).getResponseAsString()); + assertEquals("[1]", c.doGet(URL + "/Test%2Fint4/" + getName(int[].class)).getResponseAsString()); + assertEquals("[-1]", c.doGet(URL + "/Test%2Fint5/" + getName(int[].class)).getResponseAsString()); + assertEquals("true", c.doGet(URL + "/Test%2Fboolean1/" + getName(Boolean.class)).getResponseAsString()); + assertEquals("[true,true]", c.doGet(URL + "/Test%2Fboolean2/" + getName(Boolean[].class)).getResponseAsString()); + assertTrue(c.doGet(URL + "/Test%2Fpath/" + getName(String.class)).getResponseAsString().length() > 10); + assertEquals("'test-value'", c.doGet(URL + "/Test%2FtestManifestEntry/" + getName(String.class)).getResponseAsString()); + + c.closeQuietly(); + } + + private String getName(Class<?> c) { + return RestUtils.encode(c.getName()); + } +} http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/91a388d0/juneau-rest-test/src/test/java/org/apache/juneau/rest/test/Constants.java ---------------------------------------------------------------------- diff --git a/juneau-rest-test/src/test/java/org/apache/juneau/rest/test/Constants.java b/juneau-rest-test/src/test/java/org/apache/juneau/rest/test/Constants.java new file mode 100644 index 0000000..0f8a09d --- /dev/null +++ b/juneau-rest-test/src/test/java/org/apache/juneau/rest/test/Constants.java @@ -0,0 +1,53 @@ +// *************************************************************************************************************************** +// * 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.rest.test; + +import java.net.*; + + +public class Constants { + + private static String juneauSampleUrl = System.getProperty("JUNO_SAMPLE_URL", "http://localhost:10000"); + private static URI juneauSampleUri = (juneauSampleUrl == null ? null : URI.create(juneauSampleUrl)); + + /** + * Returns the value of the "JUNO_SAMPLE_URL" system property, or throws a {@link RuntimeException} + * if it's not set. + */ + public static String getJuneauSamplesUrl() { + if (juneauSampleUrl == null) + throw new RuntimeException("'JUNO_SAMPLE_URL' system property not set to URL of juneau.sample.war location."); + return juneauSampleUrl; + } + + public static URI getJuneauSamplesUri() { + if (juneauSampleUri == null) + throw new RuntimeException("'JUNO_SAMPLE_URL' system property not set to URL of juneau.sample.war location."); + return juneauSampleUri; + } + + private static String juneauServerTestUrl = System.getProperty("JUNO_SERVER_TEST_URL", "http://localhost:10001"); + private static URI juneauServerTestUri = (juneauServerTestUrl == null ? null : URI.create(juneauServerTestUrl)); + + public static String getServerTestUrl() { + if (juneauServerTestUrl == null) + throw new RuntimeException("'JUNO_SERVER_TEST_URL' system property not set to URL of juneau.sample.war location."); + return juneauServerTestUrl; + } + + public static URI getServerTestUri() { + if (juneauServerTestUri == null) + throw new RuntimeException("'JUNO_SERVER_TEST_URL' system property not set to URL of juneau.sample.war location."); + return juneauServerTestUri; + } +} http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/91a388d0/juneau-rest-test/src/test/java/org/apache/juneau/rest/test/ContentTest.java ---------------------------------------------------------------------- diff --git a/juneau-rest-test/src/test/java/org/apache/juneau/rest/test/ContentTest.java b/juneau-rest-test/src/test/java/org/apache/juneau/rest/test/ContentTest.java new file mode 100644 index 0000000..8a19e64 --- /dev/null +++ b/juneau-rest-test/src/test/java/org/apache/juneau/rest/test/ContentTest.java @@ -0,0 +1,706 @@ +// *************************************************************************************************************************** +// * 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.rest.test; + +import static org.junit.Assert.*; + +import java.io.*; +import java.net.*; + +import org.apache.juneau.json.*; +import org.apache.juneau.plaintext.*; +import org.apache.juneau.rest.client.*; +import org.apache.juneau.urlencoding.*; +import org.junit.*; + +public class ContentTest { + + private static String URL = "/testContent"; + + //==================================================================================================== + // Basic tests using @Body parameter + //==================================================================================================== + @Test + public void testUsingContentParam() throws Exception { + RestClient c = new TestRestClient().setAccept("text/json+simple"); + String r; + + // @RestMethod(name="POST", path="/boolean") + // public boolean testBool(@Body boolean b) { + // return b; + // } + r = c.doPost(URL + "/boolean?body=true", null).getResponseAsString(); + assertEquals("true", r); + r = c.doPost(URL + "/boolean?body=(true)", null).getResponseAsString(); + assertEquals("true", r); + r = c.doPost(URL + "/boolean?body=$b(true)", null).getResponseAsString(); + assertEquals("true", r); + r = c.doPost(URL + "/boolean?body=false", null).getResponseAsString(); + assertEquals("false", r); + r = c.doPost(URL + "/boolean?body=(false)", null).getResponseAsString(); + assertEquals("false", r); + r = c.doPost(URL + "/boolean?body=$b(false)", null).getResponseAsString(); + assertEquals("false", r); + try { + r = c.doPost(URL + "/boolean?body=%00&noTrace=true", null).getResponseAsString(); + fail("Exception expected!"); + } catch (RestCallException e) { + assertEquals(400, e.getResponseCode()); + } + try { + r = c.doPost(URL + "/boolean?body=bad&noTrace=true", null).getResponseAsString(); + fail("Exception expected!"); + } catch (RestCallException e) { + assertEquals(400, e.getResponseCode()); + } + + + // @RestMethod(name="POST", path="/Boolean") + // public Boolean testBoolean(@Body Boolean b) { + // return b; + // } + r = c.doPost(URL + "/Boolean?body=true", null).getResponseAsString(); + assertEquals("true", r); + r = c.doPost(URL + "/Boolean?body=(true)", null).getResponseAsString(); + assertEquals("true", r); + r = c.doPost(URL + "/Boolean?body=$b(true)", null).getResponseAsString(); + assertEquals("true", r); + r = c.doPost(URL + "/Boolean?body=false", null).getResponseAsString(); + assertEquals("false", r); + r = c.doPost(URL + "/Boolean?body=(false)", null).getResponseAsString(); + assertEquals("false", r); + r = c.doPost(URL + "/Boolean?body=$b(false)", null).getResponseAsString(); + assertEquals("false", r); + r = c.doPost(URL + "/Boolean?body=%00", null).getResponseAsString(); + assertEquals("null", r); + try { + r = c.doPost(URL + "/Boolean?body=bad&noTrace=true", null).getResponseAsString(); + fail("Exception expected!"); + } catch (RestCallException e) { + assertEquals(400, e.getResponseCode()); + } + + // @RestMethod(name="POST", path="/int") + // public int testInt(@Body int i) { + // return i; + // } + r = c.doPost(URL + "/int?body=-123", null).getResponseAsString(); + assertEquals("-123", r); + r = c.doPost(URL + "/int?body=(-123)", null).getResponseAsString(); + assertEquals("-123", r); + r = c.doPost(URL + "/int?body=$n(-123)", null).getResponseAsString(); + assertEquals("-123", r); + try { + r = c.doPost(URL + "/int?body=%00&noTrace=true", null).getResponseAsString(); + fail("Exception expected!"); + } catch (RestCallException e) { + assertEquals(400, e.getResponseCode()); + } + try { + r = c.doPost(URL + "/int?body=bad&noTrace=true", null).getResponseAsString(); + fail("Exception expected!"); + } catch (RestCallException e) { + assertEquals(400, e.getResponseCode()); + } + + // @RestMethod(name="POST", path="/Integer") + // public Integer testInteger(@Body Integer i) { + // return i; + // } + r = c.doPost(URL + "/Integer?body=-123", null).getResponseAsString(); + assertEquals("-123", r); + r = c.doPost(URL + "/Integer?body=(-123)", null).getResponseAsString(); + assertEquals("-123", r); + r = c.doPost(URL + "/Integer?body=$n(-123)", null).getResponseAsString(); + assertEquals("-123", r); + r = c.doPost(URL + "/Integer?body=%00", null).getResponseAsString(); + assertEquals("null", r); + try { + r = c.doPost(URL + "/Integer?body=bad&noTrace=true", null).getResponseAsString(); + fail("Exception expected!"); + } catch (RestCallException e) { + assertEquals(400, e.getResponseCode()); + } + + // @RestMethod(name="POST", path="/float") + // public float testFloat(@Body float f) { + // return f; + // } + r = c.doPost(URL + "/float?body=-1.23", null).getResponseAsString(); + assertEquals("-1.23", r); + r = c.doPost(URL + "/float?body=(-1.23)", null).getResponseAsString(); + assertEquals("-1.23", r); + r = c.doPost(URL + "/float?body=$n(-1.23)", null).getResponseAsString(); + assertEquals("-1.23", r); + try { + r = c.doPost(URL + "/float?body=%00&noTrace=true", null).getResponseAsString(); + fail("Exception expected!"); + } catch (RestCallException e) { + assertEquals(400, e.getResponseCode()); + } + try { + r = c.doPost(URL + "/float?body=bad&noTrace=true", null).getResponseAsString(); + fail("Exception expected!"); + } catch (RestCallException e) { + assertEquals(400, e.getResponseCode()); + } + + // @RestMethod(name="POST", path="/Float") + // public Float testFloat2(@Body Float f) { + // return f; + // } + r = c.doPost(URL + "/Float?body=-1.23", null).getResponseAsString(); + assertEquals("-1.23", r); + r = c.doPost(URL + "/Float?body=(-1.23)", null).getResponseAsString(); + assertEquals("-1.23", r); + r = c.doPost(URL + "/Float?body=$n(-1.23)", null).getResponseAsString(); + assertEquals("-1.23", r); + r = c.doPost(URL + "/Float?body=%00", null).getResponseAsString(); + assertEquals("null", r); + try { + r = c.doPost(URL + "/Float?body=bad&noTrace=true", null).getResponseAsString(); + fail("Exception expected!"); + } catch (RestCallException e) { + assertEquals(400, e.getResponseCode()); + } + + // @RestMethod(name="POST", path="/Map") + // public TreeMap<String,String> testMap(@Body TreeMap<String,String> m) { + // return m; + // } + r = c.doPost(URL + "/Map?body=(a=b,c=d)", null).getResponseAsString(); + assertEquals("{a:'b',c:'d'}", r); + r = c.doPost(URL + "/Map?body=%00", null).getResponseAsString(); + assertEquals("null", r); + try { + r = c.doPost(URL + "/Map?body=bad&noTrace=true", null).getResponseAsString(); + fail("Exception expected!"); + } catch (RestCallException e) { + assertEquals(400, e.getResponseCode()); + } + + // @RestMethod(name="POST", path="/B") + // public DTO2s.B testPojo1(@Body DTO2s.B b) { + // return b; + // } + DTOs.B b = DTOs.B.create(); + r = c.doPost(URL + "/B?body=" + UonSerializer.DEFAULT.serialize(b), null).getResponseAsString(); + assertEquals("{f01:['a','b'],f02:['c','d'],f03:[1,2],f04:[3,4],f05:[['e','f'],['g','h']],f06:[['i','j'],['k','l']],f07:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f08:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f09:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]],f10:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]],f11:['a','b'],f12:['c','d'],f13:[1,2],f14:[3,4],f15:[['e','f'],['g','h']],f16:[['i','j'],['k','l']],f17:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f18:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f19:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]],f20:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]]}", r); + r = c.doPost(URL + "/B?body=" + UonSerializer.DEFAULT_SIMPLE.serialize(b), null).getResponseAsString(); + assertEquals("{f01:['a','b'],f02:['c','d'],f03:[1,2],f04:[3,4],f05:[['e','f'],['g','h']],f06:[['i','j'],['k','l']],f07:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f08:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f09:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]],f10:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]],f11:['a','b'],f12:['c','d'],f13:[1,2],f14:[3,4],f15:[['e','f'],['g','h']],f16:[['i','j'],['k','l']],f17:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f18:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f19:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]],f20:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]]}", r); + + // @RestMethod(name="POST", path="/C") + // public DTO2s.C testPojo2(@Body DTO2s.C c) { + // return c; + // } + DTOs.C x = DTOs.C.create(); + r = c.doPost(URL + "/C?body=" + UonSerializer.DEFAULT.serialize(x), null).getResponseAsString(); + assertEquals("{f01:['a','b'],f02:['c','d'],f03:[1,2],f04:[3,4],f05:[['e','f'],['g','h']],f06:[['i','j'],['k','l']],f07:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f08:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f09:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]],f10:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]],f11:['a','b'],f12:['c','d'],f13:[1,2],f14:[3,4],f15:[['e','f'],['g','h']],f16:[['i','j'],['k','l']],f17:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f18:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f19:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]],f20:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]]}", r); + r = c.doPost(URL + "/C?body=" + UonSerializer.DEFAULT_SIMPLE.serialize(x), null).getResponseAsString(); + assertEquals("{f01:['a','b'],f02:['c','d'],f03:[1,2],f04:[3,4],f05:[['e','f'],['g','h']],f06:[['i','j'],['k','l']],f07:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f08:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f09:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]],f10:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]],f11:['a','b'],f12:['c','d'],f13:[1,2],f14:[3,4],f15:[['e','f'],['g','h']],f16:[['i','j'],['k','l']],f17:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f18:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f19:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]],f20:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]]}", r); + + c.closeQuietly(); + } + + //==================================================================================================== + // Basic tests using &Body parameter with &Accept=text/json + //==================================================================================================== + @Test + public void testUsingContentParamJsonHeader() throws Exception { + RestClient c = new TestRestClient().setAccept("text/json+simple").setHeader("Content-Type", "text/json"); + String r; + + // @RestMethod(name="POST", path="/boolean") + // public boolean testBool(@Body boolean b) { + // return b; + // } + r = c.doPost(URL + "/boolean?body=true", null).getResponseAsString(); + assertEquals("true", r); + r = c.doPost(URL + "/boolean?body=false", null).getResponseAsString(); + assertEquals("false", r); + try { + r = c.doPost(URL + "/boolean?body=null&noTrace=true", null).getResponseAsString(); + fail("Exception expected!"); + } catch (RestCallException e) { + assertEquals(400, e.getResponseCode()); + } + try { + r = c.doPost(URL + "/boolean?body=bad&noTrace=true", null).getResponseAsString(); + fail("Exception expected!"); + } catch (RestCallException e) { + assertEquals(400, e.getResponseCode()); + } + + + // @RestMethod(name="POST", path="/Boolean") + // public Boolean testBoolean(@Body Boolean b) { + // return b; + // } + r = c.doPost(URL + "/Boolean?body=true", null).getResponseAsString(); + assertEquals("true", r); + r = c.doPost(URL + "/Boolean?body=false", null).getResponseAsString(); + assertEquals("false", r); + r = c.doPost(URL + "/Boolean?body=null", null).getResponseAsString(); + assertEquals("null", r); + try { + r = c.doPost(URL + "/Boolean?body=bad&noTrace=true", null).getResponseAsString(); + fail("Exception expected!"); + } catch (RestCallException e) { + assertEquals(400, e.getResponseCode()); + } + + // @RestMethod(name="POST", path="/int") + // public int testInt(@Body int i) { + // return i; + // } + r = c.doPost(URL + "/int?body=-123", null).getResponseAsString(); + assertEquals("-123", r); + try { + r = c.doPost(URL + "/int?body=null&noTrace=true", null).getResponseAsString(); + fail("Exception expected!"); + } catch (RestCallException e) { + assertEquals(400, e.getResponseCode()); + } + try { + r = c.doPost(URL + "/int?body=bad&noTrace=true", null).getResponseAsString(); + fail("Exception expected!"); + } catch (RestCallException e) { + assertEquals(400, e.getResponseCode()); + } + + // @RestMethod(name="POST", path="/Integer") + // public Integer testInteger(@Body Integer i) { + // return i; + // } + r = c.doPost(URL + "/Integer?body=-123", null).getResponseAsString(); + assertEquals("-123", r); + r = c.doPost(URL + "/Integer?body=null", null).getResponseAsString(); + assertEquals("null", r); + try { + r = c.doPost(URL + "/Integer?body=bad&noTrace=true", null).getResponseAsString(); + fail("Exception expected!"); + } catch (RestCallException e) { + assertEquals(400, e.getResponseCode()); + } + + // @RestMethod(name="POST", path="/float") + // public float testFloat(@Body float f) { + // return f; + // } + r = c.doPost(URL + "/float?body=-1.23", null).getResponseAsString(); + assertEquals("-1.23", r); + try { + r = c.doPost(URL + "/float?body=null&noTrace=true", null).getResponseAsString(); + fail("Exception expected!"); + } catch (RestCallException e) { + assertEquals(400, e.getResponseCode()); + } + try { + r = c.doPost(URL + "/float?body=bad&noTrace=true", null).getResponseAsString(); + fail("Exception expected!"); + } catch (RestCallException e) { + assertEquals(400, e.getResponseCode()); + } + + // @RestMethod(name="POST", path="/Float") + // public Float testFloat2(@Body Float f) { + // return f; + // } + r = c.doPost(URL + "/Float?body=-1.23", null).getResponseAsString(); + assertEquals("-1.23", r); + r = c.doPost(URL + "/Float?body=null", null).getResponseAsString(); + assertEquals("null", r); + try { + r = c.doPost(URL + "/Float?body=bad&noTrace=true", null).getResponseAsString(); + fail("Exception expected!"); + } catch (RestCallException e) { + assertEquals(400, e.getResponseCode()); + } + + // @RestMethod(name="POST", path="/Map") + // public TreeMap<String,String> testMap(@Body TreeMap<String,String> m) { + // return m; + // } + r = c.doPost(URL + "/Map?body=" + encode("{a:'b',c:'d'}"), null).getResponseAsString(); + assertEquals("{a:'b',c:'d'}", r); + r = c.doPost(URL + "/Map?body=null", null).getResponseAsString(); + assertEquals("null", r); + try { + r = c.doPost(URL + "/Map?body=bad&noTrace=true", null).getResponseAsString(); + fail("Exception expected!"); + } catch (RestCallException e) { + assertEquals(400, e.getResponseCode()); + } + + // @RestMethod(name="POST", path="/B") + // public DTO2s.B testPojo1(@Body DTO2s.B b) { + // return b; + // } + DTOs.B b = DTOs.B.create(); + r = c.doPost(URL + "/B?body=" + encode(JsonSerializer.DEFAULT_LAX.serialize(b)), null).getResponseAsString(); + assertEquals("{f01:['a','b'],f02:['c','d'],f03:[1,2],f04:[3,4],f05:[['e','f'],['g','h']],f06:[['i','j'],['k','l']],f07:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f08:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f09:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]],f10:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]],f11:['a','b'],f12:['c','d'],f13:[1,2],f14:[3,4],f15:[['e','f'],['g','h']],f16:[['i','j'],['k','l']],f17:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f18:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f19:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]],f20:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]]}", r); + + // @RestMethod(name="POST", path="/C") + // public DTO2s.C testPojo2(@Body DTO2s.C c) { + // return c; + // } + DTOs.C x = DTOs.C.create(); + r = c.doPost(URL + "/C?body=" + encode(JsonSerializer.DEFAULT_LAX.serialize(x)), null).getResponseAsString(); + assertEquals("{f01:['a','b'],f02:['c','d'],f03:[1,2],f04:[3,4],f05:[['e','f'],['g','h']],f06:[['i','j'],['k','l']],f07:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f08:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f09:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]],f10:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]],f11:['a','b'],f12:['c','d'],f13:[1,2],f14:[3,4],f15:[['e','f'],['g','h']],f16:[['i','j'],['k','l']],f17:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f18:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f19:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]],f20:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]]}", r); + + c.closeQuietly(); + } + + //==================================================================================================== + // Basic tests using &Body parameter with &Accept=text/json + //==================================================================================================== + @Test + public void testUsingContentParamJsonParam() throws Exception { + RestClient c = new TestRestClient().setAccept("text/json+simple"); + String r; + + // @RestMethod(name="POST", path="/boolean") + // public boolean testBool(@Body boolean b) { + // return b; + // } + r = c.doPost(URL + "/boolean?body=true&Content-Type=text/json", null).getResponseAsString(); + assertEquals("true", r); + r = c.doPost(URL + "/boolean?body=false&Content-Type=text/json", null).getResponseAsString(); + assertEquals("false", r); + try { + r = c.doPost(URL + "/boolean?body=null&Content-Type=text/json&noTrace=true", null).getResponseAsString(); + fail("Exception expected!"); + } catch (RestCallException e) { + assertEquals(400, e.getResponseCode()); + } + try { + r = c.doPost(URL + "/boolean?body=bad&Content-Type=text/json&noTrace=true", null).getResponseAsString(); + fail("Exception expected!"); + } catch (RestCallException e) { + assertEquals(400, e.getResponseCode()); + } + + + // @RestMethod(name="POST", path="/Boolean") + // public Boolean testBoolean(@Body Boolean b) { + // return b; + // } + r = c.doPost(URL + "/Boolean?body=true&Content-Type=text/json", null).getResponseAsString(); + assertEquals("true", r); + r = c.doPost(URL + "/Boolean?body=false&Content-Type=text/json", null).getResponseAsString(); + assertEquals("false", r); + r = c.doPost(URL + "/Boolean?body=null&Content-Type=text/json", null).getResponseAsString(); + assertEquals("null", r); + try { + r = c.doPost(URL + "/Boolean?body=bad&Content-Type=text/json&noTrace=true", null).getResponseAsString(); + fail("Exception expected!"); + } catch (RestCallException e) { + assertEquals(400, e.getResponseCode()); + } + + // @RestMethod(name="POST", path="/int") + // public int testInt(@Body int i) { + // return i; + // } + r = c.doPost(URL + "/int?body=-123&Content-Type=text/json", null).getResponseAsString(); + assertEquals("-123", r); + try { + r = c.doPost(URL + "/int?body=null&Content-Type=text/json&noTrace=true", null).getResponseAsString(); + fail("Exception expected!"); + } catch (RestCallException e) { + assertEquals(400, e.getResponseCode()); + } + try { + r = c.doPost(URL + "/int?body=bad&Content-Type=text/json&noTrace=true", null).getResponseAsString(); + fail("Exception expected!"); + } catch (RestCallException e) { + assertEquals(400, e.getResponseCode()); + } + + // @RestMethod(name="POST", path="/Integer") + // public Integer testInteger(@Body Integer i) { + // return i; + // } + r = c.doPost(URL + "/Integer?body=-123&Content-Type=text/json", null).getResponseAsString(); + assertEquals("-123", r); + r = c.doPost(URL + "/Integer?body=null&Content-Type=text/json", null).getResponseAsString(); + assertEquals("null", r); + try { + r = c.doPost(URL + "/Integer?body=bad&Content-Type=text/json&noTrace=true", null).getResponseAsString(); + fail("Exception expected!"); + } catch (RestCallException e) { + assertEquals(400, e.getResponseCode()); + } + + // @RestMethod(name="POST", path="/float") + // public float testFloat(@Body float f) { + // return f; + // } + r = c.doPost(URL + "/float?body=-1.23&Content-Type=text/json", null).getResponseAsString(); + assertEquals("-1.23", r); + try { + r = c.doPost(URL + "/float?body=null&Content-Type=text/json&noTrace=true", null).getResponseAsString(); + fail("Exception expected!"); + } catch (RestCallException e) { + assertEquals(400, e.getResponseCode()); + } + try { + r = c.doPost(URL + "/float?body=bad&Content-Type=text/json&noTrace=true", null).getResponseAsString(); + fail("Exception expected!"); + } catch (RestCallException e) { + assertEquals(400, e.getResponseCode()); + } + + // @RestMethod(name="POST", path="/Float") + // public Float testFloat2(@Body Float f) { + // return f; + // } + r = c.doPost(URL + "/Float?body=-1.23&Content-Type=text/json", null).getResponseAsString(); + assertEquals("-1.23", r); + r = c.doPost(URL + "/Float?body=null&Content-Type=text/json", null).getResponseAsString(); + assertEquals("null", r); + try { + r = c.doPost(URL + "/Float?body=bad&Content-Type=text/json&noTrace=true", null).getResponseAsString(); + fail("Exception expected!"); + } catch (RestCallException e) { + assertEquals(400, e.getResponseCode()); + } + + // @RestMethod(name="POST", path="/Map") + // public TreeMap<String,String> testMap(@Body TreeMap<String,String> m) { + // return m; + // } + r = c.doPost(URL + "/Map?body=" + encode("{a:'b',c:'d'}") + "&Content-Type=text/json", null).getResponseAsString(); + assertEquals("{a:'b',c:'d'}", r); + r = c.doPost(URL + "/Map?body=null&Content-Type=text/json", null).getResponseAsString(); + assertEquals("null", r); + try { + r = c.doPost(URL + "/Map?body=bad&Content-Type=text/json&noTrace=true", null).getResponseAsString(); + fail("Exception expected!"); + } catch (RestCallException e) { + assertEquals(400, e.getResponseCode()); + } + + // @RestMethod(name="POST", path="/B") + // public DTO2s.B testPojo1(@Body DTO2s.B b) { + // return b; + // } + DTOs.B b = DTOs.B.create(); + r = c.doPost(URL + "/B?body=" + encode(JsonSerializer.DEFAULT_LAX.serialize(b)) + "&Content-Type=text/json", null).getResponseAsString(); + assertEquals("{f01:['a','b'],f02:['c','d'],f03:[1,2],f04:[3,4],f05:[['e','f'],['g','h']],f06:[['i','j'],['k','l']],f07:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f08:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f09:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]],f10:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]],f11:['a','b'],f12:['c','d'],f13:[1,2],f14:[3,4],f15:[['e','f'],['g','h']],f16:[['i','j'],['k','l']],f17:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f18:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f19:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]],f20:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]]}", r); + + // @RestMethod(name="POST", path="/C") + // public DTO2s.C testPojo2(@Body DTO2s.C c) { + // return c; + // } + DTOs.C x = DTOs.C.create(); + r = c.doPost(URL + "/C?body=" + encode(JsonSerializer.DEFAULT_LAX.serialize(x)) + "&Content-Type=text/json", null).getResponseAsString(); + assertEquals("{f01:['a','b'],f02:['c','d'],f03:[1,2],f04:[3,4],f05:[['e','f'],['g','h']],f06:[['i','j'],['k','l']],f07:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f08:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f09:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]],f10:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]],f11:['a','b'],f12:['c','d'],f13:[1,2],f14:[3,4],f15:[['e','f'],['g','h']],f16:[['i','j'],['k','l']],f17:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f18:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f19:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]],f20:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]]}", r); + + c.closeQuietly(); + } + + //==================================================================================================== + // Basic tests using HTTP body content + //==================================================================================================== + @Test + public void testUsingContent() throws Exception { + RestClient c = new TestRestClient().setAccept("text/json+simple").setHeader("Content-Type", "text/uon").setSerializer(PlainTextSerializer.class); + String r; + + // @RestMethod(name="POST", path="/boolean") + // public boolean testBool(@Body boolean b) { + // return b; + // } + r = c.doPost(URL + "/boolean", "true").getResponseAsString(); + assertEquals("true", r); + r = c.doPost(URL + "/boolean", "(true)").getResponseAsString(); + assertEquals("true", r); + r = c.doPost(URL + "/boolean", "$b(true)").getResponseAsString(); + assertEquals("true", r); + r = c.doPost(URL + "/boolean", "false").getResponseAsString(); + assertEquals("false", r); + r = c.doPost(URL + "/boolean", "(false)").getResponseAsString(); + assertEquals("false", r); + r = c.doPost(URL + "/boolean", "$b(false)").getResponseAsString(); + assertEquals("false", r); + try { + r = c.doPost(URL + "/boolean?noTrace=true", "%00").getResponseAsString(); + fail("Exception expected!"); + } catch (RestCallException e) { + assertEquals(400, e.getResponseCode()); + } + try { + r = c.doPost(URL + "/boolean?noTrace=true", "bad").getResponseAsString(); + fail("Exception expected!"); + } catch (RestCallException e) { + assertEquals(400, e.getResponseCode()); + } + + + // @RestMethod(name="POST", path="/Boolean") + // public Boolean testBoolean(@Body Boolean b) { + // return b; + // } + r = c.doPost(URL + "/Boolean", "true").getResponseAsString(); + assertEquals("true", r); + r = c.doPost(URL + "/Boolean", "(true)").getResponseAsString(); + assertEquals("true", r); + r = c.doPost(URL + "/Boolean", "$b(true)").getResponseAsString(); + assertEquals("true", r); + r = c.doPost(URL + "/Boolean", "false").getResponseAsString(); + assertEquals("false", r); + r = c.doPost(URL + "/Boolean", "(false)").getResponseAsString(); + assertEquals("false", r); + r = c.doPost(URL + "/Boolean", "$b(false)").getResponseAsString(); + assertEquals("false", r); + r = c.doPost(URL + "/Boolean", "\u0000").getResponseAsString(); + assertEquals("null", r); + try { + r = c.doPost(URL + "/Boolean?noTrace=true", "bad").getResponseAsString(); + fail("Exception expected!"); + } catch (RestCallException e) { + assertEquals(400, e.getResponseCode()); + } + + // @RestMethod(name="POST", path="/int") + // public int testInt(@Body int i) { + // return i; + // } + r = c.doPost(URL + "/int", "-123").getResponseAsString(); + assertEquals("-123", r); + r = c.doPost(URL + "/int", "(-123)").getResponseAsString(); + assertEquals("-123", r); + r = c.doPost(URL + "/int", "$n(-123)").getResponseAsString(); + assertEquals("-123", r); + try { + r = c.doPost(URL + "/int?noTrace=true", "%00").getResponseAsString(); + fail("Exception expected!"); + } catch (RestCallException e) { + assertEquals(400, e.getResponseCode()); + } + try { + r = c.doPost(URL + "/int?noTrace=true", "bad").getResponseAsString(); + fail("Exception expected!"); + } catch (RestCallException e) { + assertEquals(400, e.getResponseCode()); + } + + // @RestMethod(name="POST", path="/Integer") + // public Integer testInteger(@Body Integer i) { + // return i; + // } + r = c.doPost(URL + "/Integer", "-123").getResponseAsString(); + assertEquals("-123", r); + r = c.doPost(URL + "/Integer", "(-123)").getResponseAsString(); + assertEquals("-123", r); + r = c.doPost(URL + "/Integer", "$n(-123)").getResponseAsString(); + assertEquals("-123", r); + r = c.doPost(URL + "/Integer", "\u0000").getResponseAsString(); + assertEquals("null", r); + try { + r = c.doPost(URL + "/Integer?noTrace=true", "bad").getResponseAsString(); + fail("Exception expected!"); + } catch (RestCallException e) { + assertEquals(400, e.getResponseCode()); + } + + // @RestMethod(name="POST", path="/float") + // public float testFloat(@Body float f) { + // return f; + // } + r = c.doPost(URL + "/float", "-1.23").getResponseAsString(); + assertEquals("-1.23", r); + r = c.doPost(URL + "/float", "(-1.23)").getResponseAsString(); + assertEquals("-1.23", r); + r = c.doPost(URL + "/float", "$n(-1.23)").getResponseAsString(); + assertEquals("-1.23", r); + try { + r = c.doPost(URL + "/float?noTrace=true", "\u0000").getResponseAsString(); + fail("Exception expected!"); + } catch (RestCallException e) { + assertEquals(400, e.getResponseCode()); + } + try { + r = c.doPost(URL + "/float?noTrace=true", "bad").getResponseAsString(); + fail("Exception expected!"); + } catch (RestCallException e) { + assertEquals(400, e.getResponseCode()); + } + + // @RestMethod(name="POST", path="/Float") + // public Float testFloat2(@Body Float f) { + // return f; + // } + r = c.doPost(URL + "/Float", "-1.23").getResponseAsString(); + assertEquals("-1.23", r); + r = c.doPost(URL + "/Float", "(-1.23)").getResponseAsString(); + assertEquals("-1.23", r); + r = c.doPost(URL + "/Float", "$n(-1.23)").getResponseAsString(); + assertEquals("-1.23", r); + r = c.doPost(URL + "/Float", "\u0000").getResponseAsString(); + assertEquals("null", r); + try { + r = c.doPost(URL + "/Float?noTrace=true", "bad").getResponseAsString(); + fail("Exception expected!"); + } catch (RestCallException e) { + assertEquals(400, e.getResponseCode()); + } + + // @RestMethod(name="POST", path="/Map") + // public TreeMap<String,String> testMap(@Body TreeMap<String,String> m) { + // return m; + // } + r = c.doPost(URL + "/Map", "(a=b,c=d)").getResponseAsString(); + assertEquals("{a:'b',c:'d'}", r); + r = c.doPost(URL + "/Map", "\u0000").getResponseAsString(); + assertEquals("null", r); + try { + r = c.doPost(URL + "/Map?noTrace=true", "bad").getResponseAsString(); + fail("Exception expected!"); + } catch (RestCallException e) { + assertEquals(400, e.getResponseCode()); + } + + // @RestMethod(name="POST", path="/B") + // public DTO2s.B testPojo1(@Body DTO2s.B b) { + // return b; + // } + DTOs.B b = DTOs.B.create(); + r = c.doPost(URL + "/B", "" + UonSerializer.DEFAULT.serialize(b)).getResponseAsString(); + assertEquals("{f01:['a','b'],f02:['c','d'],f03:[1,2],f04:[3,4],f05:[['e','f'],['g','h']],f06:[['i','j'],['k','l']],f07:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f08:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f09:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]],f10:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]],f11:['a','b'],f12:['c','d'],f13:[1,2],f14:[3,4],f15:[['e','f'],['g','h']],f16:[['i','j'],['k','l']],f17:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f18:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f19:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]],f20:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]]}", r); + r = c.doPost(URL + "/B", "" + UonSerializer.DEFAULT_SIMPLE.serialize(b)).getResponseAsString(); + assertEquals("{f01:['a','b'],f02:['c','d'],f03:[1,2],f04:[3,4],f05:[['e','f'],['g','h']],f06:[['i','j'],['k','l']],f07:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f08:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f09:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]],f10:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]],f11:['a','b'],f12:['c','d'],f13:[1,2],f14:[3,4],f15:[['e','f'],['g','h']],f16:[['i','j'],['k','l']],f17:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f18:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f19:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]],f20:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]]}", r); + + // @RestMethod(name="POST", path="/C") + // public DTO2s.C testPojo2(@Body DTO2s.C c) { + // return c; + // } + DTOs.C x = DTOs.C.create(); + r = c.doPost(URL + "/C", "" + UonSerializer.DEFAULT.serialize(x)).getResponseAsString(); + assertEquals("{f01:['a','b'],f02:['c','d'],f03:[1,2],f04:[3,4],f05:[['e','f'],['g','h']],f06:[['i','j'],['k','l']],f07:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f08:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f09:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]],f10:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]],f11:['a','b'],f12:['c','d'],f13:[1,2],f14:[3,4],f15:[['e','f'],['g','h']],f16:[['i','j'],['k','l']],f17:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f18:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f19:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]],f20:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]]}", r); + r = c.doPost(URL + "/C", "" + UonSerializer.DEFAULT_SIMPLE.serialize(x)).getResponseAsString(); + assertEquals("{f01:['a','b'],f02:['c','d'],f03:[1,2],f04:[3,4],f05:[['e','f'],['g','h']],f06:[['i','j'],['k','l']],f07:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f08:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f09:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]],f10:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]],f11:['a','b'],f12:['c','d'],f13:[1,2],f14:[3,4],f15:[['e','f'],['g','h']],f16:[['i','j'],['k','l']],f17:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f18:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f19:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]],f20:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]]}", r); + + c.closeQuietly(); + } + + + private String encode(String s) { + try { + return URLEncoder.encode(s, "UTF-8"); + } catch (UnsupportedEncodingException e) { + throw new RuntimeException(e); + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/91a388d0/juneau-rest-test/src/test/java/org/apache/juneau/rest/test/DTOs.java ---------------------------------------------------------------------- diff --git a/juneau-rest-test/src/test/java/org/apache/juneau/rest/test/DTOs.java b/juneau-rest-test/src/test/java/org/apache/juneau/rest/test/DTOs.java new file mode 100644 index 0000000..3e3ea07 --- /dev/null +++ b/juneau-rest-test/src/test/java/org/apache/juneau/rest/test/DTOs.java @@ -0,0 +1,139 @@ +// *************************************************************************************************************************** +// * 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.rest.test; + +import java.util.*; + +import org.apache.juneau.annotation.*; +import org.apache.juneau.urlencoding.annotation.*; + +public class DTOs { + + @Bean(sort=true) + public static class A { + public String a; + public int b; + public boolean c; + + public static A create() { + A t = new A(); + t.a = "a"; + t.b = 1; + t.c = true; + return t; + } + + } + + @SuppressWarnings("serial") + @Bean(sort=true) + public static class B { + public String[] f01; + public List<String> f02; + public int[] f03; + public List<Integer> f04; + public String[][] f05; + public List<String[]> f06; + public A[] f07; + public List<A> f08; + public A[][] f09; + public List<List<A>> f10; + + private String[] f11; + private List<String> f12; + private int[] f13; + private List<Integer> f14; + private String[][] f15; + private List<String[]> f16; + private A[] f17; + private List<A> f18; + private A[][] f19; + private List<List<A>> f20; + + public String[] getF11() { return f11; } + public List<String> getF12() { return f12; } + public int[] getF13() { return f13; } + public List<Integer> getF14() { return f14; } + public String[][] getF15() { return f15; } + public List<String[]> getF16() { return f16; } + public A[] getF17() { return f17; } + public List<A> getF18() { return f18; } + public A[][] getF19() { return f19; } + public List<List<A>> getF20() { return f20; } + + public void setF11(String[] f11) { this.f11 = f11; } + public void setF12(List<String> f12) { this.f12 = f12; } + public void setF13(int[] f13) { this.f13 = f13; } + public void setF14(List<Integer> f14) { this.f14 = f14; } + public void setF15(String[][] f15) { this.f15 = f15; } + public void setF16(List<String[]> f16) { this.f16 = f16; } + public void setF17(A[] f17) { this.f17 = f17; } + public void setF18(List<A> f18) { this.f18 = f18; } + public void setF19(A[][] f19) { this.f19 = f19; } + public void setF20(List<List<A>> f20) { this.f20 = f20; } + + static B create() { + B t = new B(); + t.f01 = new String[]{"a","b"}; + t.f02 = new ArrayList<String>(){{add("c");add("d");}}; + t.f03 = new int[]{1,2}; + t.f04 = new ArrayList<Integer>(){{add(3);add(4);}}; + t.f05 = new String[][]{{"e","f"},{"g","h"}}; + t.f06 = new ArrayList<String[]>(){{add(new String[]{"i","j"});add(new String[]{"k","l"});}}; + t.f07 = new A[]{A.create(),A.create()}; + t.f08 = new ArrayList<A>(){{add(A.create());add(A.create());}}; + t.f09 = new A[][]{{A.create()},{A.create()}}; + t.f10 = new ArrayList<List<A>>(){{add(Arrays.asList(A.create()));add(Arrays.asList(A.create()));}}; + t.setF11(new String[]{"a","b"}); + t.setF12(new ArrayList<String>(){{add("c");add("d");}}); + t.setF13(new int[]{1,2}); + t.setF14(new ArrayList<Integer>(){{add(3);add(4);}}); + t.setF15(new String[][]{{"e","f"},{"g","h"}}); + t.setF16(new ArrayList<String[]>(){{add(new String[]{"i","j"});add(new String[]{"k","l"});}}); + t.setF17(new A[]{A.create(),A.create()}); + t.setF18(new ArrayList<A>(){{add(A.create());add(A.create());}}); + t.setF19(new A[][]{{A.create()},{A.create()}}); + t.setF20(new ArrayList<List<A>>(){{add(Arrays.asList(A.create()));add(Arrays.asList(A.create()));}}); + return t; + } + } + + @UrlEncoding(expandedParams=true) + public static class C extends B { + @SuppressWarnings("serial") + static C create() { + C t = new C(); + t.f01 = new String[]{"a","b"}; + t.f02 = new ArrayList<String>(){{add("c");add("d");}}; + t.f03 = new int[]{1,2}; + t.f04 = new ArrayList<Integer>(){{add(3);add(4);}}; + t.f05 = new String[][]{{"e","f"},{"g","h"}}; + t.f06 = new ArrayList<String[]>(){{add(new String[]{"i","j"});add(new String[]{"k","l"});}}; + t.f07 = new A[]{A.create(),A.create()}; + t.f08 = new ArrayList<A>(){{add(A.create());add(A.create());}}; + t.f09 = new A[][]{{A.create()},{A.create()}}; + t.f10 = new ArrayList<List<A>>(){{add(Arrays.asList(A.create()));add(Arrays.asList(A.create()));}}; + t.setF11(new String[]{"a","b"}); + t.setF12(new ArrayList<String>(){{add("c");add("d");}}); + t.setF13(new int[]{1,2}); + t.setF14(new ArrayList<Integer>(){{add(3);add(4);}}); + t.setF15(new String[][]{{"e","f"},{"g","h"}}); + t.setF16(new ArrayList<String[]>(){{add(new String[]{"i","j"});add(new String[]{"k","l"});}}); + t.setF17(new A[]{A.create(),A.create()}); + t.setF18(new ArrayList<A>(){{add(A.create());add(A.create());}}); + t.setF19(new A[][]{{A.create()},{A.create()}}); + t.setF20(new ArrayList<List<A>>(){{add(Arrays.asList(A.create()));add(Arrays.asList(A.create()));}}); + return t; + } + } +}
