http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/91a388d0/juneau-server-test/src/test/java/org/apache/juneau/server/test/ContentTest.java ---------------------------------------------------------------------- diff --git a/juneau-server-test/src/test/java/org/apache/juneau/server/test/ContentTest.java b/juneau-server-test/src/test/java/org/apache/juneau/server/test/ContentTest.java deleted file mode 100755 index 041dc4f..0000000 --- a/juneau-server-test/src/test/java/org/apache/juneau/server/test/ContentTest.java +++ /dev/null @@ -1,706 +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.server.test; - -import static org.junit.Assert.*; - -import java.io.*; -import java.net.*; - -import org.apache.juneau.client.*; -import org.apache.juneau.json.*; -import org.apache.juneau.plaintext.*; -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-server-test/src/test/java/org/apache/juneau/server/test/DTOs.java ---------------------------------------------------------------------- diff --git a/juneau-server-test/src/test/java/org/apache/juneau/server/test/DTOs.java b/juneau-server-test/src/test/java/org/apache/juneau/server/test/DTOs.java deleted file mode 100755 index a6e1246..0000000 --- a/juneau-server-test/src/test/java/org/apache/juneau/server/test/DTOs.java +++ /dev/null @@ -1,139 +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.server.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; - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/91a388d0/juneau-server-test/src/test/java/org/apache/juneau/server/test/DefaultContentTypesTest.java ---------------------------------------------------------------------- diff --git a/juneau-server-test/src/test/java/org/apache/juneau/server/test/DefaultContentTypesTest.java b/juneau-server-test/src/test/java/org/apache/juneau/server/test/DefaultContentTypesTest.java deleted file mode 100755 index 28bb43c..0000000 --- a/juneau-server-test/src/test/java/org/apache/juneau/server/test/DefaultContentTypesTest.java +++ /dev/null @@ -1,497 +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.server.test; - -import static javax.servlet.http.HttpServletResponse.*; -import static org.apache.juneau.server.test.TestUtils.*; -import static org.junit.Assert.*; - -import org.apache.juneau.client.*; -import org.apache.juneau.json.*; -import org.junit.*; - - -public class DefaultContentTypesTest { - - private static String URL = "/testDefaultContentTypes"; - private static boolean debug = false; - - //==================================================================================================== - // Test that default Accept and Content-Type headers on servlet annotation are picked up. - //==================================================================================================== - @Test - public void testDefaultHeadersOnServletAnnotation() throws Exception { - RestClient client = new TestRestClient(JsonSerializer.DEFAULT, JsonParser.DEFAULT); - String r; - - String url = URL + "/testDefaultHeadersOnServletAnnotation"; - - client.setAccept("").setContentType(""); - r = client.doPut(url, "").getResponseAsString(); - assertEquals("s2/p2", r); - - client.setAccept("text/s1").setContentType(""); - r = client.doPut(url, "").getResponseAsString(); - assertEquals("s1/p2", r); - - client.setAccept("").setContentType("text/p1"); - r = client.doPut(url, "").getResponseAsString(); - assertEquals("s2/p1", r); - - client.setAccept("text/s1").setContentType("text/p1"); - r = client.doPut(url, "").getResponseAsString(); - assertEquals("s1/p1", r); - - client.setAccept("text/s2").setContentType(""); - r = client.doPut(url, "").getResponseAsString(); - assertEquals("s2/p2", r); - - client.setAccept("").setContentType("text/p2"); - r = client.doPut(url, "").getResponseAsString(); - assertEquals("s2/p2", r); - - client.setAccept("text/s2").setContentType("text/p2"); - r = client.doPut(url, "").getResponseAsString(); - assertEquals("s2/p2", r); - - try { - client.setAccept("text/s3").setContentType(""); - r = client.doPut(url+"?noTrace=true", "").getResponseAsString(); - fail("Exception expected"); - } catch (RestCallException e) { - checkErrorResponse(debug, e, SC_NOT_ACCEPTABLE, - "Unsupported media-type in request header 'Accept': 'text/s3'", - "Supported media-types: [text/s1, text/s2]" - ); - } - - try { - client.setAccept("").setContentType("text/p3"); - r = client.doPut(url+"?noTrace=true", "").getResponseAsString(); - fail("Exception expected"); - } catch (RestCallException e) { - checkErrorResponse(debug, e, SC_UNSUPPORTED_MEDIA_TYPE, - "Unsupported media-type in request header 'Content-Type': 'text/p3'", - "Supported media-types: [text/p1, text/p2]" - ); - } - - try { - client.setAccept("text/s3").setContentType("text/p3"); - r = client.doPut(url+"?noTrace=true", "").getResponseAsString(); - fail("Exception expected"); - } catch (RestCallException e) { - checkErrorResponse(debug, e, SC_UNSUPPORTED_MEDIA_TYPE, - "Unsupported media-type in request header 'Content-Type': 'text/p3'", - "Supported media-types: [text/p1, text/p2]" - ); - } - - client.closeQuietly(); - } - - //==================================================================================================== - // Test that default Accept and Content-Type headers on servlet annotation are picked up - // when @RestMethod.parsers/serializers annotations are used. - //==================================================================================================== - @Test - public void testRestMethodParsersSerializers() throws Exception { - RestClient client = new TestRestClient(JsonSerializer.DEFAULT, JsonParser.DEFAULT); - String r; - - String url = URL + "/testRestMethodParsersSerializers"; - - try { - client.setAccept("").setContentType(""); - r = client.doPut(url+"?noTrace=true", "").getResponseAsString(); - fail("Exception expected"); - } catch (RestCallException e) { - checkErrorResponse(debug, e, SC_UNSUPPORTED_MEDIA_TYPE, - "Unsupported media-type in request header 'Content-Type': 'text/p2'", - "Supported media-types: [text/p3]" - ); - } - - try { - client.setAccept("text/s1").setContentType(""); - r = client.doPut(url+"?noTrace=true", "").getResponseAsString(); - fail("Exception expected"); - } catch (RestCallException e) { - checkErrorResponse(debug, e, SC_UNSUPPORTED_MEDIA_TYPE, - "Unsupported media-type in request header 'Content-Type': 'text/p2'", - "Supported media-types: [text/p3]" - ); - } - - try { - client.setAccept("").setContentType("text/p1"); - r = client.doPut(url+"?noTrace=true", "").getResponseAsString(); - fail("Exception expected"); - } catch (RestCallException e) { - checkErrorResponse(debug, e, SC_UNSUPPORTED_MEDIA_TYPE, - "Unsupported media-type in request header 'Content-Type': 'text/p1'", - "Supported media-types: [text/p3]" - ); - } - - try { - client.setAccept("text/s1").setContentType("text/p1"); - r = client.doPut(url+"?noTrace=true", "").getResponseAsString(); - fail("Exception expected"); - } catch (RestCallException e) { - checkErrorResponse(debug, e, SC_UNSUPPORTED_MEDIA_TYPE, - "Unsupported media-type in request header 'Content-Type': 'text/p1'", - "Supported media-types: [text/p3]" - ); - } - - try { - client.setAccept("text/s2").setContentType(""); - r = client.doPut(url+"?noTrace=true", "").getResponseAsString(); - fail("Exception expected"); - } catch (RestCallException e) { - checkErrorResponse(debug, e, SC_UNSUPPORTED_MEDIA_TYPE, - "Unsupported media-type in request header 'Content-Type': 'text/p2'", - "Supported media-types: [text/p3]" - ); - } - - try { - client.setAccept("").setContentType("text/p2"); - r = client.doPut(url+"?noTrace=true", "").getResponseAsString(); - fail("Exception expected"); - } catch (RestCallException e) { - checkErrorResponse(debug, e, SC_UNSUPPORTED_MEDIA_TYPE, - "Unsupported media-type in request header 'Content-Type': 'text/p2'", - "Supported media-types: [text/p3]" - ); - } - - try { - client.setAccept("text/s2").setContentType("text/p2"); - r = client.doPut(url+"?noTrace=true", "").getResponseAsString(); - fail("Exception expected"); - } catch (RestCallException e) { - checkErrorResponse(debug, e, SC_UNSUPPORTED_MEDIA_TYPE, - "Unsupported media-type in request header 'Content-Type': 'text/p2'", - "Supported media-types: [text/p3]" - ); - } - - try { - client.setAccept("text/s3").setContentType(""); - r = client.doPut(url+"?noTrace=true", "").getResponseAsString(); - fail("Exception expected"); - } catch (RestCallException e) { - checkErrorResponse(debug, e, SC_UNSUPPORTED_MEDIA_TYPE, - "Unsupported media-type in request header 'Content-Type': 'text/p2'", - "Supported media-types: [text/p3]" - ); - } - - try { - client.setAccept("").setContentType("text/p3"); - r = client.doPut(url+"?noTrace=true", "").getResponseAsString(); - fail("Exception expected"); - } catch (RestCallException e) { - checkErrorResponse(debug, e, SC_NOT_ACCEPTABLE, - "Unsupported media-type in request header 'Accept': 'text/s2'", - "Supported media-types: [text/s3]" - ); - } - - client.setAccept("text/s3").setContentType("text/p3"); - r = client.doPut(url, "").getResponseAsString(); - assertEquals("s3/p3", r); - - client.closeQuietly(); - } - - //==================================================================================================== - // Test that default Accept and Content-Type headers on servlet annotation are picked up - // when @RestMethod.addParsers/addSerializers annotations are used. - //==================================================================================================== - @Test - public void testRestMethodAddParsersSerializers() throws Exception { - RestClient client = new TestRestClient(JsonSerializer.DEFAULT, JsonParser.DEFAULT); - String r; - - String url = URL + "/testRestMethodAddParsersSerializers"; - - client.setAccept("").setContentType(""); - r = client.doPut(url, "").getResponseAsString(); - assertEquals("s2/p2", r); - - client.setAccept("text/s1").setContentType(""); - r = client.doPut(url, "").getResponseAsString(); - assertEquals("s1/p2", r); - - client.setAccept("").setContentType("text/p1"); - r = client.doPut(url, "").getResponseAsString(); - assertEquals("s2/p1", r); - - client.setAccept("text/s1").setContentType("text/p1"); - r = client.doPut(url, "").getResponseAsString(); - assertEquals("s1/p1", r); - - client.setAccept("text/s2").setContentType(""); - r = client.doPut(url, "").getResponseAsString(); - assertEquals("s2/p2", r); - - client.setAccept("").setContentType("text/p2"); - r = client.doPut(url, "").getResponseAsString(); - assertEquals("s2/p2", r); - - client.setAccept("text/s2").setContentType("text/p2"); - r = client.doPut(url, "").getResponseAsString(); - assertEquals("s2/p2", r); - - client.setAccept("text/s3").setContentType(""); - r = client.doPut(url, "").getResponseAsString(); - assertEquals("s3/p2", r); - - client.setAccept("").setContentType("text/p3"); - r = client.doPut(url, "").getResponseAsString(); - assertEquals("s2/p3", r); - - client.setAccept("text/s3").setContentType("text/p3"); - r = client.doPut(url, "").getResponseAsString(); - assertEquals("s3/p3", r); - - try { - client.setAccept("").setContentType("text/p4"); - r = client.doPut(url+"?noTrace=true", "").getResponseAsString(); - fail("Exception expected"); - } catch (RestCallException e) { - // Note that parsers defined on method are listed before parsers defined on class. - checkErrorResponse(debug, e, SC_UNSUPPORTED_MEDIA_TYPE, - "Unsupported media-type in request header 'Content-Type': 'text/p4'", - "Supported media-types: [text/p3, text/p1, text/p2]" - ); - } - - try { - client.setAccept("text/s4").setContentType(""); - r = client.doPut(url+"?noTrace=true", "").getResponseAsString(); - fail("Exception expected"); - } catch (RestCallException e) { - // Note that serializers defined on method are listed before serializers defined on class. - checkErrorResponse(debug, e, SC_NOT_ACCEPTABLE, - "Unsupported media-type in request header 'Accept': 'text/s4'", - "Supported media-types: [text/s3, text/s1, text/s2]" - ); - } - - client.closeQuietly(); - } - - //==================================================================================================== - // Various Accept incantations. - //==================================================================================================== - @Test - public void testAccept() throws Exception { - RestClient client = new TestRestClient(JsonSerializer.DEFAULT, JsonParser.DEFAULT).setContentType("text/p1"); - String r; - - String url = URL + "/testAccept"; - - // "*/*" should match the first serializer, not the default serializer. - client.setAccept("*/*"); - r = client.doPut(url, "").getResponseAsString(); - assertEquals("s1/p1", r); - - // "text/*" should match the first serializer, not the default serializer. - client.setAccept("text/*"); - r = client.doPut(url, "").getResponseAsString(); - assertEquals("s1/p1", r); - - try { - client.setAccept("bad/*"); - r = client.doPut(url+"?noTrace=true", "").getResponseAsString(); - fail("Exception expected"); - } catch (RestCallException e) { - checkErrorResponse(debug, e, SC_NOT_ACCEPTABLE, - "Unsupported media-type in request header 'Accept': 'bad/*'", - "Supported media-types: [text/s1, text/s2]" - ); - } - - client.setAccept("bad/*,text/*"); - r = client.doPut(url, "").getResponseAsString(); - assertEquals("s1/p1", r); - - client.setAccept("text/*,bad/*"); - r = client.doPut(url, "").getResponseAsString(); - assertEquals("s1/p1", r); - - client.setAccept("text/s1;q=0.5,text/s2"); - r = client.doPut(url, "").getResponseAsString(); - assertEquals("s2/p1", r); - - client.setAccept("text/s1,text/s2;q=0.5"); - r = client.doPut(url, "").getResponseAsString(); - assertEquals("s1/p1", r); - - client.closeQuietly(); - } - - //==================================================================================================== - // Test that default Accept and Content-Type headers on method annotation are picked up - // when @RestMethod.parsers/serializers annotations are used. - //==================================================================================================== - @Test - public void testRestMethodParserSerializerAnnotations() throws Exception { - RestClient client = new TestRestClient(JsonSerializer.DEFAULT, JsonParser.DEFAULT); - String r; - - String url = URL + "/testRestMethodParserSerializerAnnotations"; - - client.setAccept("").setContentType(""); - r = client.doPut(url, "").getResponseAsString(); - assertEquals("s3/p3", r); - - try { - client.setAccept("text/s1").setContentType(""); - r = client.doPut(url+"?noTrace=true", "").getResponseAsString(); - fail("Exception expected"); - } catch (RestCallException e) { - checkErrorResponse(debug, e, SC_NOT_ACCEPTABLE, - "Unsupported media-type in request header 'Accept': 'text/s1'", - "Supported media-types: [text/s3]" - ); - } - - try { - client.setAccept("").setContentType("text/p1"); - r = client.doPut(url+"?noTrace=true", "").getResponseAsString(); - fail("Exception expected"); - } catch (RestCallException e) { - checkErrorResponse(debug, e, SC_UNSUPPORTED_MEDIA_TYPE, - "Unsupported media-type in request header 'Content-Type': 'text/p1'", - "Supported media-types: [text/p3]" - ); - } - - try { - client.setAccept("text/s1").setContentType("text/p1"); - r = client.doPut(url+"?noTrace=true", "").getResponseAsString(); - fail("Exception expected"); - } catch (RestCallException e) { - checkErrorResponse(debug, e, SC_UNSUPPORTED_MEDIA_TYPE, - "Unsupported media-type in request header 'Content-Type': 'text/p1'", - "Supported media-types: [text/p3]" - ); - } - - try { - client.setAccept("text/s2").setContentType(""); - r = client.doPut(url+"?noTrace=true", "").getResponseAsString(); - fail("Exception expected"); - } catch (RestCallException e) { - checkErrorResponse(debug, e, SC_NOT_ACCEPTABLE, - "Unsupported media-type in request header 'Accept': 'text/s2'", - "Supported media-types: [text/s3]" - ); - } - - try { - client.setAccept("").setContentType("text/p2"); - r = client.doPut(url+"?noTrace=true", "").getResponseAsString(); - fail("Exception expected"); - } catch (RestCallException e) { - checkErrorResponse(debug, e, SC_UNSUPPORTED_MEDIA_TYPE, - "Unsupported media-type in request header 'Content-Type': 'text/p2'", - "Supported media-types: [text/p3]" - ); - } - - try { - client.setAccept("text/s2").setContentType("text/p2"); - r = client.doPut(url+"?noTrace=true", "").getResponseAsString(); - fail("Exception expected"); - } catch (RestCallException e) { - checkErrorResponse(debug, e, SC_UNSUPPORTED_MEDIA_TYPE, - "Unsupported media-type in request header 'Content-Type': 'text/p2'", - "Supported media-types: [text/p3]" - ); - } - - client.setAccept("text/s3").setContentType(""); - r = client.doPut(url, "").getResponseAsString(); - assertEquals("s3/p3", r); - - client.setAccept("").setContentType("text/p3"); - r = client.doPut(url, "").getResponseAsString(); - assertEquals("s3/p3", r); - - client.setAccept("text/s3").setContentType("text/p3"); - r = client.doPut(url, "").getResponseAsString(); - assertEquals("s3/p3", r); - - client.closeQuietly(); - } - - //==================================================================================================== - // Test that default Accept and Content-Type headers on method annotation are picked up - // when @RestMethod.addParsers/addSerializers annotations are used. - //==================================================================================================== - @Test - public void testRestMethodAddParsersSerializersAnnotations() throws Exception { - RestClient client = new TestRestClient(JsonSerializer.DEFAULT, JsonParser.DEFAULT); - String r; - - String url = URL + "/testRestMethodAddParsersSerializersAnnotations"; - - client.setAccept("").setContentType(""); - r = client.doPut(url, "").getResponseAsString(); - assertEquals("s3/p3", r); - - client.setAccept("text/s1").setContentType(""); - r = client.doPut(url, "").getResponseAsString(); - assertEquals("s1/p3", r); - - client.setAccept("").setContentType("text/p1"); - r = client.doPut(url, "").getResponseAsString(); - assertEquals("s3/p1", r); - - client.setAccept("text/s1").setContentType("text/p1"); - r = client.doPut(url, "").getResponseAsString(); - assertEquals("s1/p1", r); - - client.setAccept("text/s2").setContentType(""); - r = client.doPut(url, "").getResponseAsString(); - assertEquals("s2/p3", r); - - client.setAccept("").setContentType("text/p2"); - r = client.doPut(url, "").getResponseAsString(); - assertEquals("s3/p2", r); - - client.setAccept("text/s2").setContentType("text/p2"); - r = client.doPut(url, "").getResponseAsString(); - assertEquals("s2/p2", r); - - client.setAccept("text/s3").setContentType(""); - r = client.doPut(url, "").getResponseAsString(); - assertEquals("s3/p3", r); - - client.setAccept("").setContentType("text/p3"); - r = client.doPut(url, "").getResponseAsString(); - assertEquals("s3/p3", r); - - client.setAccept("text/s3").setContentType("text/p3"); - r = client.doPut(url, "").getResponseAsString(); - assertEquals("s3/p3", r); - - client.closeQuietly(); - } -} http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/91a388d0/juneau-server-test/src/test/java/org/apache/juneau/server/test/ErrorConditionsTest.java ---------------------------------------------------------------------- diff --git a/juneau-server-test/src/test/java/org/apache/juneau/server/test/ErrorConditionsTest.java b/juneau-server-test/src/test/java/org/apache/juneau/server/test/ErrorConditionsTest.java deleted file mode 100755 index 5316ad4..0000000 --- a/juneau-server-test/src/test/java/org/apache/juneau/server/test/ErrorConditionsTest.java +++ /dev/null @@ -1,219 +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.server.test; - -import static javax.servlet.http.HttpServletResponse.*; -import static org.apache.juneau.server.test.TestUtils.*; -import static org.junit.Assert.*; - -import org.apache.juneau.*; -import org.apache.juneau.client.*; -import org.apache.juneau.json.*; -import org.junit.*; - - -public class ErrorConditionsTest { - - private static String URL = "/testErrorConditions"; - private static boolean debug = false; - private static RestClient client; - - @BeforeClass - public static void beforeClass() { - client = new TestRestClient(JsonSerializer.DEFAULT, JsonParser.DEFAULT); - } - - @AfterClass - public static void afterClass() { - client.closeQuietly(); - } - //==================================================================================================== - // Test non-existent properties - //==================================================================================================== - @Test - public void testNonExistentBeanProperties() throws Exception { - String url = URL + "/testNonExistentBeanProperties"; - - try { - client.doPut(url + "?noTrace=true", new ObjectMap("{f2:'foo'}")).getResponseAsString(); - fail("Exception expected"); - } catch (RestCallException e) { - checkErrorResponse(debug, e, SC_BAD_REQUEST, - "Could not convert request body content to class type 'org.apache.juneau.server.test.ErrorConditionsResource$Test1' using parser 'org.apache.juneau.json.JsonParser'", - "Unknown property 'f2' encountered while trying to parse into class 'org.apache.juneau.server.test.ErrorConditionsResource$Test1'"); - } - - try { - client.doPut(url + "?noTrace=true", new ObjectMap("{f1:'foo', f2:'foo'}")).getResponseAsString(); - fail("Exception expected"); - } catch (RestCallException e) { - checkErrorResponse(debug, e, SC_BAD_REQUEST, - "Could not convert request body content to class type 'org.apache.juneau.server.test.ErrorConditionsResource$Test1' using parser 'org.apache.juneau.json.JsonParser'", - "Unknown property 'f2' encountered while trying to parse into class 'org.apache.juneau.server.test.ErrorConditionsResource$Test1'"); - } - } - - //==================================================================================================== - // Test trying to set properties to wrong data type - //==================================================================================================== - @Test - public void testWrongDataType() throws Exception { - String url = URL + "/testWrongDataType"; - try { - client.doPut(url + "?noTrace=true", new ObjectMap("{f1:'foo'}")).getResponseAsString(); - fail("Exception expected"); - } catch (RestCallException e) { - checkErrorResponse(debug, e, SC_BAD_REQUEST, - "Invalid number"); - } - } - - //==================================================================================================== - // Test trying to parse into class with non-public no-arg constructor. - //==================================================================================================== - @Test - public void testParseIntoNonConstructableBean() throws Exception { - String url = URL + "/testParseIntoNonConstructableBean"; - try { - client.doPut(url + "?noTrace=true", new ObjectMap("{f1:1}")).getResponseAsString(); - fail("Exception expected"); - } catch (RestCallException e) { - checkErrorResponse(debug, e, SC_BAD_REQUEST, - "Class 'org.apache.juneau.server.test.ErrorConditionsResource$Test3a' could not be instantiated."); - } - } - - //==================================================================================================== - // Test trying to parse into non-static inner class - //==================================================================================================== - @Test - public void testParseIntoNonStaticInnerClass() throws Exception { - String url = URL + "/testParseIntoNonStaticInnerClass"; - try { - client.doPut(url + "?noTrace=true", new ObjectMap("{f1:1}")).getResponseAsString(); - fail("Exception expected"); - } catch (RestCallException e) { - checkErrorResponse(debug, e, SC_BAD_REQUEST, - "Class 'org.apache.juneau.server.test.ErrorConditionsResource$Test3b' could not be instantiated. Reason: 'No properties detected on bean class'"); - } - } - - //==================================================================================================== - // Test trying to parse into non-public inner class - //==================================================================================================== - @Test - public void testParseIntoNonPublicInnerClass() throws Exception { - String url = URL + "/testParseIntoNonPublicInnerClass"; - try { - client.doPut(url + "?noTrace=true", new ObjectMap("{f1:1}")).getResponseAsString(); - fail("Exception expected"); - } catch (RestCallException e) { - checkErrorResponse(debug, e, SC_BAD_REQUEST, - "Class 'org.apache.juneau.server.test.ErrorConditionsResource$Test3b1' could not be instantiated", - "Class is not public"); - } - } - - //==================================================================================================== - // Test exception thrown during bean construction. - //==================================================================================================== - @Test - public void testThrownConstructorException() throws Exception { - String url = URL + "/testThrownConstructorException"; - try { - client.doPut(url + "?noTrace=true", "'foo'").getResponseAsString(); - fail("Exception expected"); - } catch (RestCallException e) { - checkErrorResponse(debug, e, SC_BAD_REQUEST, - "Could not convert request body content to class type 'org.apache.juneau.server.test.ErrorConditionsResource$Test3c' using parser 'org.apache.juneau.json.JsonParser'.", - "Caused by (RuntimeException): Test error"); - } - } - - //==================================================================================================== - // Test trying to set parameters to invalid types. - //==================================================================================================== - @Test - public void testSetParameterToInvalidTypes() throws Exception { - String url = URL + "/testSetParameterToInvalidTypes"; - try { - client.doPut(url + "/1?noTrace=true&p1=foo", "").getResponseAsString(); - fail("Exception expected"); - } catch (RestCallException e) { - checkErrorResponse(debug, e, SC_BAD_REQUEST, - "Could not convert QUERY 'p1' to type 'int' on method 'org.apache.juneau.server.test.ErrorConditionsResource.testSetParameterToInvalidTypes'"); - } - - try { - client.doPut(url + "/foo?noTrace=true&p1=1", "").getResponseAsString(); - fail("Exception expected"); - } catch (RestCallException e) { - checkErrorResponse(debug, e, SC_BAD_REQUEST, - "Could not convert PATH 'a1' to type 'int' on method 'org.apache.juneau.server.test.ErrorConditionsResource.testSetParameterToInvalidTypes'"); - } - - try { - client.doPut(url + "/1?noTrace=true&p1=1", "").setHeader("h1", "foo").getResponseAsString(); - fail("Exception expected"); - } catch (RestCallException e) { - checkErrorResponse(debug, e, SC_BAD_REQUEST, - "Could not convert HEADER 'h1' to type 'int' on method 'org.apache.juneau.server.test.ErrorConditionsResource.testSetParameterToInvalidTypes'"); - } - } - - //==================================================================================================== - // Test SC_NOT_FOUND & SC_METHOD_NOT_ALLOWED - //==================================================================================================== - @Test - public void test404and405() throws Exception { - String url = URL + "/test404and405"; - try { - client.doGet(URL + "/testNonExistent?noTrace=true").getResponseAsString(); - fail("Exception expected"); - } catch (RestCallException e) { - checkErrorResponse(debug, e, SC_NOT_FOUND, - "Method 'GET' not found on resource with matching pattern on path '/testNonExistent'"); - } - - try { - client.doPut(url + "?noTrace=true", "").getResponseAsString(); - fail("Exception expected"); - } catch (RestCallException e) { - checkErrorResponse(debug, e, SC_NOT_FOUND, - "Method 'PUT' not found on resource with matching pattern on path '/test404and405'"); - } - - try { - client.doPost(url + "?noTrace=true", "").getResponseAsString(); - fail("Exception expected"); - } catch (RestCallException e) { - checkErrorResponse(debug, e, SC_METHOD_NOT_ALLOWED, - "Method 'POST' not found on resource."); - } - } - - //==================================================================================================== - // Test SC_PRECONDITION_FAILED - //==================================================================================================== - @Test - public void test412() throws Exception { - String url = URL + "/test412"; - try { - client.doGet(url + "?noTrace=true").getResponseAsString(); - fail("Exception expected"); - } catch (RestCallException e) { - checkErrorResponse(debug, e, SC_PRECONDITION_FAILED, - "Method 'GET' not found on resource on path '/test412' with matching matcher."); - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/91a388d0/juneau-server-test/src/test/java/org/apache/juneau/server/test/GroupsTest.java ---------------------------------------------------------------------- diff --git a/juneau-server-test/src/test/java/org/apache/juneau/server/test/GroupsTest.java b/juneau-server-test/src/test/java/org/apache/juneau/server/test/GroupsTest.java deleted file mode 100755 index 9fc58b3..0000000 --- a/juneau-server-test/src/test/java/org/apache/juneau/server/test/GroupsTest.java +++ /dev/null @@ -1,122 +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.server.test; - -import static javax.servlet.http.HttpServletResponse.*; -import static org.apache.juneau.server.test.TestUtils.*; -import static org.junit.Assert.*; - -import java.io.*; - -import org.apache.juneau.client.*; -import org.apache.juneau.json.*; -import org.junit.*; - - -public class GroupsTest { - - private static String URL = "/testGroups"; - private static boolean debug = false; - - //==================================================================================================== - // Serializer defined on class. - //==================================================================================================== - @Test - public void testSerializerDefinedOnClass() throws Exception { - RestClient client = new TestRestClient(JsonSerializer.DEFAULT, JsonParser.DEFAULT); - String url = URL + "/testSerializerDefinedOnClass"; - String r; - - try { - client.setContentType("text/p1"); - r = client.doGet(url+"?noTrace=true").getResponseAsString(); - fail("Exception expected"); - } catch (RestCallException e) { - checkErrorResponse(debug, e, SC_NOT_ACCEPTABLE, - "Unsupported media-type in request header 'Accept': 'application/json'", - "Supported media-types: [text/s1, text/s2]" - ); - } - - client.setAccept("text/s1").setContentType(""); - r = client.doGet(url).getResponseAsString(); - assertEquals("text/s,GET", r); - - client.setAccept("text/s2").setContentType(""); - r = client.doGet(url).getResponseAsString(); - assertEquals("text/s,GET", r); - - try { - client.setAccept("text/s3").setContentType(""); - r = client.doGet(url+"?noTrace=true").getResponseAsString(); - assertEquals("text/s,GET", r); - } catch (RestCallException e) { - checkErrorResponse(debug, e, SC_NOT_ACCEPTABLE, - "Unsupported media-type in request header 'Accept': 'text/s3'", - "Supported media-types: [text/s1, text/s2]" - ); - } - - try { - client.setAccept("text/json").setContentType("text/p1"); - r = client.doPut(url+"?noTrace=true", new StringReader("foo")).getResponseAsString(); - fail("Exception expected"); - } catch (RestCallException e) { - checkErrorResponse(debug, e, SC_NOT_ACCEPTABLE, - "Unsupported media-type in request header 'Accept': 'text/json'", - "Supported media-types: [text/s1, text/s2]" - ); - } - - try { - client.setAccept("text/s1").setContentType("text/json"); - r = client.doPut(url+"?noTrace=true", new StringReader("foo")).getResponseAsString(); - fail("Exception expected"); - } catch (RestCallException e) { - checkErrorResponse(debug, e, SC_UNSUPPORTED_MEDIA_TYPE, - "Unsupported media-type in request header 'Content-Type': 'text/json'", - "Supported media-types: [text/p1, text/p2]" - ); - } - - client.setContentType("text/p1").setAccept("text/s1"); - r = client.doPut(url, new StringReader("foo")).getResponseAsString(); - assertEquals("text/s,foo", r); - - client.setContentType("text/p2").setAccept("text/s2"); - r = client.doPut(url, new StringReader("foo")).getResponseAsString(); - assertEquals("text/s,foo", r); - - try { - client.setContentType("text/p1").setAccept("text/s3"); - r = client.doPut(url+"?noTrace=true", new StringReader("foo")).getResponseAsString(); - } catch (RestCallException e) { - checkErrorResponse(debug, e, SC_NOT_ACCEPTABLE, - "Unsupported media-type in request header 'Accept': 'text/s3'", - "Supported media-types: [text/s1, text/s2]" - ); - } - - try { - client.setContentType("text/p3").setAccept("text/s1"); - r = client.doPut(url+"?noTrace=true", new StringReader("foo")).getResponseAsString(); - } catch (RestCallException e) { - checkErrorResponse(debug, e, SC_UNSUPPORTED_MEDIA_TYPE, - "Unsupported media-type in request header 'Content-Type': 'text/p3'", - "Supported media-types: [text/p1, text/p2]" - ); - } - - client.closeQuietly(); - } -}
