You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@juneau.apache.org by ja...@apache.org on 2017/09/08 23:21:18 UTC
svn commit: r21538 [16/27] - in /release/incubator/juneau:
juneau-microservice-server/ juneau-microservice-server/.settings/
juneau-microservice-server/src/ juneau-microservice-server/src/main/
juneau-microservice-server/src/main/java/ juneau-microserv...
Added: release/incubator/juneau/juneau-microservice-test/src/test/java/org/apache/juneau/rest/test/NlsTest.java
==============================================================================
--- release/incubator/juneau/juneau-microservice-test/src/test/java/org/apache/juneau/rest/test/NlsTest.java (added)
+++ release/incubator/juneau/juneau-microservice-test/src/test/java/org/apache/juneau/rest/test/NlsTest.java Fri Sep 8 23:21:12 2017
@@ -0,0 +1,97 @@
+// ***************************************************************************************************************************
+// * 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 org.apache.juneau.dto.swagger.*;
+import org.apache.juneau.rest.client.*;
+import org.junit.*;
+
+public class NlsTest extends RestTestcase {
+
+ private static String URL = "/testNls";
+ private RestClient client = TestMicroservice.DEFAULT_CLIENT;
+
+ // ====================================================================================================
+ // test1 - Pull labels from annotations only.
+ // ====================================================================================================
+ @Test
+ public void test1() throws Exception {
+
+ Swagger s = client.doOptions(URL + "/test1").getResponse(Swagger.class);
+ assertObjectEquals("{title:'Test1.a',description:'Test1.b'}", s.getInfo());
+ assertObjectEquals("[{'in':'body',description:'Test1.f'},{'in':'header',name:'D',type:'string',description:'Test1.g'},{'in':'header',name:'D2',type:'string',description:'Test1.j'},{'in':'header',name:'g'},{'in':'path',name:'a',type:'string',description:'Test1.d',required:true},{'in':'path',name:'a2',type:'string',description:'Test1.h',required:true},{'in':'path',name:'e',required:true},{'in':'query',name:'b',type:'string',description:'Test1.e'},{'in':'query',name:'b2',type:'string',description:'Test1.i'},{'in':'query',name:'f'}]", s.getPaths().get("/{a}").get("post").getParameters());
+ assertObjectEquals("{'200':{description:'OK'},'201':{description:'Test1.l',headers:{bar:{description:'Test1.m',type:'string'}}}}", s.getPaths().get("/{a}").get("post").getResponses());
+ }
+
+ // ====================================================================================================
+ // test2 - Pull labels from resource bundles only - simple keys.
+ // ====================================================================================================
+ @Test
+ public void test2() throws Exception {
+
+ Swagger s = client.doOptions(URL + "/test2").getResponse(Swagger.class);
+ assertObjectEquals("{title:'Test2.a',description:'Test2.b'}", s.getInfo());
+ assertObjectEquals("[{'in':'body',description:'Test2.f'},{'in':'header',name:'D',description:'Test2.g'},{'in':'header',name:'D2',description:'Test2.j'},{'in':'header',name:'g'},{'in':'path',name:'a',description:'Test2.d',required:true},{'in':'path',name:'a2',description:'Test2.h',required:true},{'in':'path',name:'e',required:true},{'in':'query',name:'b',description:'Test2.e'},{'in':'query',name:'b2',description:'Test2.i'},{'in':'query',name:'f'}]", s.getPaths().get("/{a}").get("post").getParameters());
+ assertObjectEquals("{'200':{description:'OK2'},'201':{description:'Test2.l'}}", s.getPaths().get("/{a}").get("post").getResponses());
+ }
+
+ // ====================================================================================================
+ // test3 - Pull labels from resource bundles only - keys with class names.
+ // ====================================================================================================
+ @Test
+ public void test3() throws Exception {
+
+ Swagger s = client.doOptions(URL + "/test3").getResponse(Swagger.class);
+ assertObjectEquals("{title:'Test3.a',description:'Test3.b'}", s.getInfo());
+ assertObjectEquals("[{'in':'body',description:'Test3.f'},{'in':'header',name:'D',description:'Test3.g'},{'in':'header',name:'D2',description:'Test3.j'},{'in':'header',name:'g'},{'in':'path',name:'a',description:'Test3.d',required:true},{'in':'path',name:'a2',description:'Test3.h',required:true},{'in':'path',name:'e',required:true},{'in':'query',name:'b',description:'Test3.e'},{'in':'query',name:'b2',description:'Test3.i'},{'in':'query',name:'f'}]", s.getPaths().get("/{a}").get("post").getParameters());
+ assertObjectEquals("{'200':{description:'OK3'},'201':{description:'Test3.l'}}", s.getPaths().get("/{a}").get("post").getResponses());
+ }
+
+ // ====================================================================================================
+ // test4 - Pull labels from resource bundles only. Values have localized variables to resolve.
+ // ====================================================================================================
+ @Test
+ public void test4() throws Exception {
+
+ Swagger s = client.doOptions(URL + "/test4").getResponse(Swagger.class);
+ assertObjectEquals("{title:'baz',description:'baz'}", s.getInfo());
+ assertObjectEquals("[{'in':'body',description:'baz'},{'in':'header',name:'D',description:'baz'},{'in':'header',name:'D2',description:'baz'},{'in':'header',name:'g'},{'in':'path',name:'a',description:'baz',required:true},{'in':'path',name:'a2',description:'baz',required:true},{'in':'path',name:'e',required:true},{'in':'query',name:'b',description:'baz'},{'in':'query',name:'b2',description:'baz'},{'in':'query',name:'f'}]", s.getPaths().get("/{a}").get("post").getParameters());
+ assertObjectEquals("{'200':{description:'foobazfoobazfoo'},'201':{description:'baz'}}", s.getPaths().get("/{a}").get("post").getResponses());
+ }
+
+ // ====================================================================================================
+ // test5 - Pull labels from resource bundles only. Values have request variables to resolve.
+ // ====================================================================================================
+ @Test
+ public void test5() throws Exception {
+
+ Swagger s = client.doOptions(URL + "/test5").getResponse(Swagger.class);
+ assertObjectEquals("{title:'baz2',description:'baz2'}", s.getInfo());
+ assertObjectEquals("[{'in':'body',description:'baz2'},{'in':'header',name:'D',description:'baz2'},{'in':'header',name:'D2',description:'baz2'},{'in':'header',name:'g'},{'in':'path',name:'a',description:'baz2',required:true},{'in':'path',name:'a2',description:'baz2',required:true},{'in':'path',name:'e',required:true},{'in':'query',name:'b',description:'baz2'},{'in':'query',name:'b2',description:'baz2'},{'in':'query',name:'f'}]", s.getPaths().get("/{a}").get("post").getParameters());
+ assertObjectEquals("{'200':{description:'foobaz2foobaz2foo'},'201':{description:'baz2'}}", s.getPaths().get("/{a}").get("post").getResponses());
+ }
+
+ // ====================================================================================================
+ // test6 - Pull labels from annotations only, but annotations contain variables.
+ // ====================================================================================================
+ @Test
+ public void test6() throws Exception {
+
+ Swagger s = client.doOptions(URL + "/test6").getResponse(Swagger.class);
+ assertObjectEquals("{title:'baz',description:'baz'}", s.getInfo());
+ assertObjectEquals("[{'in':'body',description:'baz'},{'in':'header',name:'D',type:'string',description:'baz'},{'in':'header',name:'D2',type:'string',description:'baz'},{'in':'header',name:'g'},{'in':'path',name:'a',type:'string',description:'baz',required:true},{'in':'path',name:'a2',type:'string',description:'baz',required:true},{'in':'path',name:'e',required:true},{'in':'query',name:'b',type:'string',description:'baz'},{'in':'query',name:'b2',type:'string',description:'baz'},{'in':'query',name:'f'}]", s.getPaths().get("/{a}").get("post").getParameters());
+ assertObjectEquals("{'200':{description:'OK'},'201':{description:'baz',headers:{bar:{description:'baz',type:'string'}}}}", s.getPaths().get("/{a}").get("post").getResponses());
+ }
+}
Propchange: release/incubator/juneau/juneau-microservice-test/src/test/java/org/apache/juneau/rest/test/NlsTest.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: release/incubator/juneau/juneau-microservice-test/src/test/java/org/apache/juneau/rest/test/NoParserInputTest.java
==============================================================================
--- release/incubator/juneau/juneau-microservice-test/src/test/java/org/apache/juneau/rest/test/NoParserInputTest.java (added)
+++ release/incubator/juneau/juneau-microservice-test/src/test/java/org/apache/juneau/rest/test/NoParserInputTest.java Fri Sep 8 23:21:12 2017
@@ -0,0 +1,61 @@
+// ***************************************************************************************************************************
+// * 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 org.apache.juneau.rest.client.*;
+import org.junit.*;
+
+public class NoParserInputTest extends RestTestcase {
+
+ private static String URL = "/testNoParserInput";
+ private static boolean debug = false;
+ RestClient plainTextClient = TestMicroservice.DEFAULT_CLIENT_PLAINTEXT;
+
+ //====================================================================================================
+ // @Body annotated InputStream.
+ //====================================================================================================
+ @Test
+ public void testInputStream() throws Exception {
+ String r = plainTextClient.doPut(URL + "/testInputStream", "foo").getResponseAsString();
+ assertEquals("foo", r);
+ }
+
+ //====================================================================================================
+ // @Body annotated Reader.
+ //====================================================================================================
+ @Test
+ public void testReader() throws Exception {
+ String r = plainTextClient.doPut(URL + "/testReader", "foo").getResponseAsString();
+ assertEquals("foo", r);
+ }
+
+ //====================================================================================================
+ // @Body annotated PushbackReader.
+ // This should always fail since the servlet reader is not a pushback reader.
+ //====================================================================================================
+ @Test
+ public void testPushbackReader() throws Exception {
+ try {
+ plainTextClient.doPut(URL + "/testPushbackReader?noTrace=true", "foo").getResponseAsString();
+ fail("Exception expected");
+ } catch (RestCallException e) {
+ checkErrorResponse(debug, e, SC_BAD_REQUEST,
+ "Invalid argument type passed to the following method:",
+ "'public java.lang.String org.apache.juneau.rest.test.NoParserInputResource.testPushbackReader(java.io.PushbackReader) throws java.lang.Exception'");
+ }
+ }
+}
Propchange: release/incubator/juneau/juneau-microservice-test/src/test/java/org/apache/juneau/rest/test/NoParserInputTest.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: release/incubator/juneau/juneau-microservice-test/src/test/java/org/apache/juneau/rest/test/OnPostCallTest.java
==============================================================================
--- release/incubator/juneau/juneau-microservice-test/src/test/java/org/apache/juneau/rest/test/OnPostCallTest.java (added)
+++ release/incubator/juneau/juneau-microservice-test/src/test/java/org/apache/juneau/rest/test/OnPostCallTest.java Fri Sep 8 23:21:12 2017
@@ -0,0 +1,121 @@
+// ***************************************************************************************************************************
+// * 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 org.apache.juneau.rest.client.*;
+import org.junit.*;
+
+public class OnPostCallTest extends RestTestcase {
+
+ private static String URL = "/testOnPostCall";
+
+ //====================================================================================================
+ // Properties overridden via properties annotation.
+ //====================================================================================================
+ @Test
+ public void testPropertiesOverridenByAnnotation() throws Exception {
+ RestClient client = TestMicroservice.client().accept("text/s1").build();
+ String url = URL + "/testPropertiesOverridenByAnnotation";
+ String r;
+ RestCall rc;
+
+ r = client.doPut(url, new StringReader("")).getResponseAsString();
+ assertEquals("p1=sp1,p2=xp2,p3=mp3,p4=xp4,p5=xp5,contentType=text/s1", r);
+
+ r = client.doPut(url, new StringReader("")).header("Override-Accept", "text/s2").getResponseAsString();
+ assertEquals("p1=sp1,p2=xp2,p3=mp3,p4=xp4,p5=xp5,contentType=text/s2", r);
+
+ rc = client.doPut(url, new StringReader("")).header("Override-Content-Type", "text/s3").connect();
+ r = rc.getResponseAsString();
+ assertEquals("p1=sp1,p2=xp2,p3=mp3,p4=xp4,p5=xp5,contentType=text/s1", r);
+ assertTrue(rc.getResponse().getFirstHeader("Content-Type").getValue().startsWith("text/s3"));
+
+ client.closeQuietly();
+ }
+
+ //====================================================================================================
+ // Properties overridden via properties annotation. Default Accept header.
+ //====================================================================================================
+ @Test
+ public void testPropertiesOverridenByAnnotationDefaultAccept() throws Exception {
+ RestClient client = TestMicroservice.client().accept("").build();
+ String url = URL + "/testPropertiesOverridenByAnnotation";
+ String r;
+ RestCall rc;
+
+ r = client.doPut(url, new StringReader("")).getResponseAsString();
+ assertEquals("p1=sp1,p2=xp2,p3=mp3,p4=xp4,p5=xp5,contentType=text/s2", r);
+
+ r = client.doPut(url, new StringReader("")).header("Override-Accept", "text/s3").getResponseAsString();
+ assertEquals("p1=sp1,p2=xp2,p3=mp3,p4=xp4,p5=xp5,contentType=text/s3", r);
+
+ rc = client.doPut(url, new StringReader("")).header("Override-Content-Type", "text/s3").connect();
+ r = rc.getResponseAsString();
+ assertEquals("p1=sp1,p2=xp2,p3=mp3,p4=xp4,p5=xp5,contentType=text/s2", r);
+ assertTrue(rc.getResponse().getFirstHeader("Content-Type").getValue().startsWith("text/s3"));
+
+ client.closeQuietly();
+ }
+
+ //====================================================================================================
+ // Properties overridden programmatically.
+ //====================================================================================================
+ @Test
+ public void testPropertiesOverriddenProgramatically() throws Exception {
+ RestClient client = TestMicroservice.client().accept("text/s1").build();
+ String url = URL + "/testPropertiesOverriddenProgramatically";
+ String r;
+ RestCall rc;
+
+ r = client.doPut(url, new StringReader("")).getResponseAsString();
+ assertEquals("p1=sp1,p2=xp2,p3=pp3,p4=xp4,p5=xp5,contentType=text/s1", r);
+
+ r = client.doPut(url, new StringReader("")).header("Override-Accept", "text/s2").getResponseAsString();
+ assertEquals("p1=sp1,p2=xp2,p3=pp3,p4=xp4,p5=xp5,contentType=text/s2", r);
+
+ rc = client.doPut(url, new StringReader("")).header("Override-Content-Type", "text/s3").connect();
+ r = rc.getResponseAsString();
+ assertEquals("p1=sp1,p2=xp2,p3=pp3,p4=xp4,p5=xp5,contentType=text/s1", r);
+ assertTrue(rc.getResponse().getFirstHeader("Content-Type").getValue().startsWith("text/s3"));
+
+ client.closeQuietly();
+ }
+
+ //====================================================================================================
+ // Properties overridden programmatically. Default Accept header.
+ //====================================================================================================
+ @Test
+ public void testPropertiesOverriddenProgramaticallyDefaultAccept() throws Exception {
+ RestClient client = TestMicroservice.client().accept("").build();
+ String url = URL + "/testPropertiesOverriddenProgramatically";
+ String r;
+ RestCall rc;
+
+ r = client.doPut(url, new StringReader("")).getResponseAsString();
+ assertEquals("p1=sp1,p2=xp2,p3=pp3,p4=xp4,p5=xp5,contentType=text/s2", r);
+
+ r = client.doPut(url, new StringReader("")).header("Override-Accept", "text/s3").getResponseAsString();
+ assertEquals("p1=sp1,p2=xp2,p3=pp3,p4=xp4,p5=xp5,contentType=text/s3", r);
+
+ rc = client.doPut(url, new StringReader("")).header("Override-Content-Type", "text/s3").connect();
+ r = rc.getResponseAsString();
+ assertEquals("p1=sp1,p2=xp2,p3=pp3,p4=xp4,p5=xp5,contentType=text/s2", r);
+ assertTrue(rc.getResponse().getFirstHeader("Content-Type").getValue().startsWith("text/s3"));
+
+ client.closeQuietly();
+ }
+}
Propchange: release/incubator/juneau/juneau-microservice-test/src/test/java/org/apache/juneau/rest/test/OnPostCallTest.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: release/incubator/juneau/juneau-microservice-test/src/test/java/org/apache/juneau/rest/test/OnPreCallTest.java
==============================================================================
--- release/incubator/juneau/juneau-microservice-test/src/test/java/org/apache/juneau/rest/test/OnPreCallTest.java (added)
+++ release/incubator/juneau/juneau-microservice-test/src/test/java/org/apache/juneau/rest/test/OnPreCallTest.java Fri Sep 8 23:21:12 2017
@@ -0,0 +1,61 @@
+// ***************************************************************************************************************************
+// * 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 org.apache.juneau.rest.client.*;
+import org.junit.*;
+
+public class OnPreCallTest extends RestTestcase {
+
+ private static String URL = "/testOnPreCall";
+
+ //====================================================================================================
+ // Properties overridden via properties annotation.
+ //====================================================================================================
+ @Test
+ public void testPropertiesOverriddenByAnnotation() throws Exception {
+ RestClient client = TestMicroservice.client().contentType("text/a1").accept("text/plain").build();
+ String url = URL + "/testPropertiesOverriddenByAnnotation";
+ String r;
+
+ r = client.doPut(url, new StringReader("")).getResponseAsString();
+ assertEquals("p1=sp1,p2=xp2,p3=mp3,p4=xp4,p5=xp5,contentType=text/a1", r);
+
+ r = client.doPut(url, new StringReader("")).header("Override-Content-Type", "text/a2").getResponseAsString();
+ assertEquals("p1=sp1,p2=xp2,p3=mp3,p4=xp4,p5=xp5,contentType=text/a2", r);
+
+ client.closeQuietly();
+ }
+
+ //====================================================================================================
+ // Properties overridden programmatically.
+ //====================================================================================================
+ @Test
+ public void testPropertiesOverriddenProgrammatically() throws Exception {
+ RestClient client = TestMicroservice.client().contentType("text/a1").accept("text/plain").build();
+ String url = URL + "/testPropertiesOverriddenProgrammatically";
+ String r;
+
+ r = client.doPut(url, new StringReader("")).getResponseAsString();
+ assertEquals("p1=sp1,p2=xp2,p3=pp3,p4=pp4,p5=xp5,contentType=text/a1", r);
+
+ r = client.doPut(url, new StringReader("")).header("Override-Content-Type", "text/a2").getResponseAsString();
+ assertEquals("p1=sp1,p2=xp2,p3=pp3,p4=pp4,p5=xp5,contentType=text/a2", r);
+
+ client.closeQuietly();
+ }
+}
Propchange: release/incubator/juneau/juneau-microservice-test/src/test/java/org/apache/juneau/rest/test/OnPreCallTest.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: release/incubator/juneau/juneau-microservice-test/src/test/java/org/apache/juneau/rest/test/OptionsWithoutNlsTest.java
==============================================================================
--- release/incubator/juneau/juneau-microservice-test/src/test/java/org/apache/juneau/rest/test/OptionsWithoutNlsTest.java (added)
+++ release/incubator/juneau/juneau-microservice-test/src/test/java/org/apache/juneau/rest/test/OptionsWithoutNlsTest.java Fri Sep 8 23:21:12 2017
@@ -0,0 +1,45 @@
+// ***************************************************************************************************************************
+// * 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.dto.swagger.*;
+import org.apache.juneau.rest.client.*;
+import org.junit.*;
+
+public class OptionsWithoutNlsTest extends RestTestcase {
+
+ private static String URL = "/testOptionsWithoutNls";
+ private RestClient client = TestMicroservice.DEFAULT_CLIENT;
+
+ //====================================================================================================
+ // Should get to the options page without errors
+ //====================================================================================================
+ @Test
+ public void testOptions() throws Exception {
+ RestCall r = client.doOptions(URL + "/testOptions");
+ Swagger o = r.getResponse(Swagger.class);
+ assertNotNull(o.getInfo());
+ }
+
+ //====================================================================================================
+ // Missing resource bundle should cause {!!x} string.
+ //====================================================================================================
+ @Test
+ public void testMissingResourceBundle() throws Exception {
+ RestCall r = client.doGet(URL + "/testMissingResourceBundle");
+ String o = r.getResponse(String.class);
+ assertEquals("{!!bad}", o);
+ }
+}
Propchange: release/incubator/juneau/juneau-microservice-test/src/test/java/org/apache/juneau/rest/test/OptionsWithoutNlsTest.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: release/incubator/juneau/juneau-microservice-test/src/test/java/org/apache/juneau/rest/test/OverlappingMethodsTest.java
==============================================================================
--- release/incubator/juneau/juneau-microservice-test/src/test/java/org/apache/juneau/rest/test/OverlappingMethodsTest.java (added)
+++ release/incubator/juneau/juneau-microservice-test/src/test/java/org/apache/juneau/rest/test/OverlappingMethodsTest.java Fri Sep 8 23:21:12 2017
@@ -0,0 +1,170 @@
+// ***************************************************************************************************************************
+// * 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 org.apache.juneau.rest.client.*;
+import org.junit.*;
+
+public class OverlappingMethodsTest extends RestTestcase {
+
+ private static String URL = "/testOverlappingMethods";
+ private static boolean debug = false;
+
+ //====================================================================================================
+ // Overlapping guards
+ //====================================================================================================
+ @Test
+ public void testOverlappingGuards1() throws Exception {
+ RestClient client = TestMicroservice.client().accept("text/plain").build();
+ String r;
+ String url = URL + "/testOverlappingGuards1";
+
+ r = client.doGet(url + "?t1=1").getResponseAsString();
+ assertEquals("test1_doGet", r);
+
+ try {
+ client.doGet(url + "?noTrace=true").connect();
+ fail("Exception expected");
+ } catch (RestCallException e) {
+ checkErrorResponse(debug, e, SC_FORBIDDEN, "Access denied by guard");
+ }
+
+ client.closeQuietly();
+ }
+
+ //====================================================================================================
+ // Overlapping guards
+ //====================================================================================================
+ @Test
+ public void testOverlappingGuards2() throws Exception {
+ RestClient client = TestMicroservice.client().accept("text/plain").build();
+ String r;
+ String url = URL + "/testOverlappingGuards2";
+ try {
+ client.doGet(url + "?noTrace=true").connect();
+ fail("Exception expected");
+ } catch (RestCallException e) {
+ checkErrorResponse(debug, e, SC_FORBIDDEN, "Access denied by guard");
+ }
+
+ try {
+ client.doGet(url + "?t1=1&noTrace=true").connect();
+ fail("Exception expected");
+ } catch (RestCallException e) {
+ checkErrorResponse(debug, e, SC_FORBIDDEN, "Access denied by guard");
+ }
+
+ try {
+ client.doGet(url + "?t2=2&noTrace=true").connect();
+ fail("Exception expected");
+ } catch (RestCallException e) {
+ checkErrorResponse(debug, e, SC_FORBIDDEN, "Access denied by guard");
+ }
+
+ r = client.doGet(url + "?t1=1&t2=2").getResponseAsString();
+ assertEquals("test2_doGet", r);
+
+ client.closeQuietly();
+ }
+
+ //====================================================================================================
+ // Overlapping matchers
+ //====================================================================================================
+ @Test
+ public void testOverlappingMatchers1() throws Exception {
+ RestClient client = TestMicroservice.client().accept("text/plain").build();
+ String r;
+ String url = URL + "/testOverlappingMatchers1";
+
+ r = client.doGet(url + "?t1=1").getResponseAsString();
+ assertEquals("test3a", r);
+
+ r = client.doGet(url + "?t2=2").getResponseAsString();
+ assertEquals("test3b", r);
+
+ r = client.doGet(url).getResponseAsString();
+ assertEquals("test3c", r);
+
+ client.closeQuietly();
+ }
+
+ //====================================================================================================
+ // Overlapping matchers
+ //====================================================================================================
+ @Test
+ public void testOverlappingMatchers2() throws Exception {
+ RestClient client = TestMicroservice.client().accept("text/plain").build();
+ String r;
+ String url = URL + "/testOverlappingMatchers2";
+
+ r = client.doGet(url + "?t1=1").getResponseAsString();
+ assertEquals("test4b", r);
+
+ r = client.doGet(url + "?t2=2").getResponseAsString();
+ assertEquals("test4b", r);
+
+ r = client.doGet(url + "?t1=1&t2=2").getResponseAsString();
+ assertEquals("test4b", r);
+
+ r = client.doGet(url + "?tx=x").getResponseAsString();
+ assertEquals("test4a", r);
+
+ client.closeQuietly();
+ }
+
+ //====================================================================================================
+ // Overlapping URL patterns
+ //====================================================================================================
+ @Test
+ public void testOverlappingUrlPatterns() throws Exception {
+ RestClient client = TestMicroservice.client().accept("text/plain").build();
+ String r;
+ String url = URL + "/testOverlappingUrlPatterns";
+
+ // [/test5] = [test5a]
+ // [/test5/*] = [test5b] -- Cannot get called.
+ // [/test5/foo] = [test5c]
+ // [/test5/foo/*] = [test5d]
+ // [/test5/{id}] = [test5e]
+ // [/test5/{id}/*] = [test5f]
+ // [/test5/{id}/foo] = [test5g]
+ // [/test5/{id}/foo/*] = [test5h]
+
+ r = client.doGet(url).getResponseAsString();
+ assertEquals("test5a", r);
+
+ r = client.doGet(url + "/foo").getResponseAsString();
+ assertEquals("test5c", r);
+
+ r = client.doGet(url + "/foo/x").getResponseAsString();
+ assertEquals("test5d", r);
+
+ r = client.doGet(url + "/x").getResponseAsString();
+ assertEquals("test5e", r);
+
+ r = client.doGet(url + "/x/x").getResponseAsString();
+ assertEquals("test5f", r);
+
+ r = client.doGet(url + "/x/foo").getResponseAsString();
+ assertEquals("test5g", r);
+
+ r = client.doGet(url + "/x/foo/x").getResponseAsString();
+ assertEquals("test5h", r);
+
+ client.closeQuietly();
+ }
+}
Propchange: release/incubator/juneau/juneau-microservice-test/src/test/java/org/apache/juneau/rest/test/OverlappingMethodsTest.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: release/incubator/juneau/juneau-microservice-test/src/test/java/org/apache/juneau/rest/test/ParamsTest.java
==============================================================================
--- release/incubator/juneau/juneau-microservice-test/src/test/java/org/apache/juneau/rest/test/ParamsTest.java (added)
+++ release/incubator/juneau/juneau-microservice-test/src/test/java/org/apache/juneau/rest/test/ParamsTest.java Fri Sep 8 23:21:12 2017
@@ -0,0 +1,855 @@
+// ***************************************************************************************************************************
+// * 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 java.util.*;
+
+import org.apache.http.*;
+import org.apache.http.client.entity.*;
+import org.apache.http.entity.*;
+import org.apache.http.message.*;
+import org.apache.juneau.*;
+import org.apache.juneau.rest.client.*;
+import org.junit.*;
+
+public class ParamsTest extends RestTestcase {
+
+ private static String URL = "/testParams";
+ private static boolean debug = false;
+
+ private static RestClient CLIENT = TestMicroservice.DEFAULT_CLIENT;
+
+ //====================================================================================================
+ // Basic tests
+ //====================================================================================================
+ @Test
+ public void testBasic() throws Exception {
+ RestClient client = TestMicroservice.DEFAULT_CLIENT;
+ RestCall r;
+
+ // @Override
+ // @RestMethod(name="GET",pattern="/")
+ // public void doGet(RestRequest req, RestResponse res) {
+ // res.setOutput("No args");
+ // }
+ r = client.doGet(URL);
+ assertEquals("GET", r.getResponse(String.class));
+
+ r = client.doGet(URL + "/getx?noTrace=true");
+ try {
+ r.connect();
+ fail("Connection should have failed.");
+ } catch (RestCallException e) {
+ checkErrorResponse(debug, e, SC_NOT_FOUND, "Method 'GET' not found on resource with matching pattern on path '/getx'");
+ }
+
+ // @RestMethod(name="GET",pattern="/get1")
+ // public void doGet1(RestRequest req, RestResponse res) {
+ // res.setOutput("/get1");
+ // }
+ r = client.doGet(URL + "/get1");
+ assertEquals("GET /get1", r.getResponse(String.class));
+
+ r = client.doGet(URL + "/get1a?noTrace=true");
+ try {
+ r.connect();
+ fail("Connection should have failed.");
+ } catch (RestCallException e) {
+ checkErrorResponse(debug, e, SC_NOT_FOUND, "Method 'GET' not found on resource with matching pattern on path '/get1a'");
+ }
+
+ // @RestMethod(name="GET",pattern="/get1/{foo}")
+ // public void doGet(RestRequest req, RestResponse res, String foo) {
+ // res.setOutput("/get1/" + foo);
+ // }
+ r = client.doGet(URL + "/get1/foo");
+ assertEquals("GET /get1a foo", r.getResponse(String.class));
+
+ // URL-encoded part should not get decoded before finding method to invoke.
+ // This should match /get1/{foo} and not /get1/{foo}/{bar}
+ // NOTE: When testing on Tomcat, must specify the following system property:
+ // -Dorg.apache.tomcat.util.buf.UDecoder.ALLOW_ENCODED_SLASH=true
+ String x = "x%2Fy"; // [x/y]
+ r = client.doGet(URL + "/get1/"+x);
+ assertEquals("GET /get1a x/y", r.getResponse(String.class));
+
+ r = client.doGet(URL + "/get1/"+x+"/"+x);
+ assertEquals("GET /get1b x/y,x/y", r.getResponse(String.class));
+
+ r = client.doGet(URL + "/get1/foo");
+ assertEquals("GET /get1a foo", r.getResponse(String.class));
+
+ r = client.doGet(URL + "/get1/foo/bar/baz?noTrace=true");
+ try {
+ r.connect();
+ fail("Connection should have failed.");
+ } catch (RestCallException e) {
+ checkErrorResponse(debug, e, SC_NOT_FOUND, "Method 'GET' not found on resource with matching pattern on path '/get1/foo/bar/baz'");
+ }
+
+ // @RestMethod(name="GET",pattern="/get3/{foo}/{bar}/*")
+ // public void doGet3(RestRequest req, RestResponse res, String foo, int bar) {
+ // res.setOutput("/get3/"+foo+"/"+bar+", remainder="+req.getRemainder());
+ // }
+ r = client.doGet(URL + "/get3/foo/123");
+ assertEquals("GET /get3/foo/123 remainder=null", r.getResponse(String.class));
+
+ r = client.doGet(URL + "/get3/foo/123/xxx");
+ assertEquals("GET /get3/foo/123 remainder=xxx", r.getResponse(String.class));
+
+ // // Test method name with overlapping name, remainder allowed.
+ // @RestMethod(name="GET2")
+ // public void get2(RestRequest req, RestResponse res) {
+ // res.setOutput("GET2, remainder="+req.getRemainder());
+ // }
+ r = client.doGet(URL + "?method=get2");
+ assertEquals("GET2 remainder=null", r.getResponse(String.class));
+ r = client.doGet(URL + "/foo/bar?method=get2");
+ assertEquals("GET2 remainder=foo/bar", r.getResponse(String.class));
+ r = client.doGet(URL + "/foo/bar?method=GET2");
+ assertEquals("GET2 remainder=foo/bar", r.getResponse(String.class));
+
+ // // Default POST
+ // @Override
+ // public void doPost(RestRequest req, RestResponse res) {
+ // res.setOutput("POST, remainder="+req.getRemainder());
+ // }
+ r = client.doPost(URL, "");
+ assertEquals("POST remainder=null", r.getResponse(String.class));
+ r = client.doPost(URL + "/foo", "");
+ assertEquals("POST remainder=foo", r.getResponse(String.class));
+
+ // // Bunch of different argument types
+ // @RestMethod(name="POST",pattern="/person/{person}")
+ // public void doPost(RestRequest req, RestResponse res, Person p) {
+ // res.setOutput("POST, /person, name="+p.name+", age="+p.age+" remainder="+req.getRemainder());
+ // }
+ r = client.doPost(URL + "/person/(name='John+Smith',birthDate='Jan+12,+1952')", "");
+ assertEquals("POST /person/{name=John Smith,birthDate.year=1952} remainder=null", r.getResponse(String.class));
+
+ // Fall through to top-level POST
+ r = client.doPost(URL + "/person/(name:'John+Smith',age:123)/foo", "");
+ assertEquals("POST remainder=person/(name:'John Smith',age:123)/foo", r.getResponse(String.class));
+
+ // // Various primitive types
+ // @RestMethod(name="PUT",pattern="/primitives/{xInt}.{xShort},{xLong}/{xChar}/{xFloat}/{xDouble}/{xByte}/{xBoolean}")
+ // public void doPut1(RestRequest req, RestResponse res, int xInt, short xShort, long xLong, char xChar, float xFloat, double xDouble, byte xByte, boolean xBoolean) {
+ // res.setOutput("PUT, /primitives/"+xInt+"."+xShort+","+xLong+"/"+xChar+"/"+xFloat+"/"+xDouble+"/"+xByte+"/"+xBoolean);
+ // }
+ r = client.doPut(URL + "/primitives/1/2/3/x/4/5/6/true", "");
+ assertEquals("PUT /primitives/1/2/3/x/4.0/5.0/6/true", r.getResponse(String.class));
+
+ // // Various primitive objects
+ // @RestMethod(name="PUT",pattern="/primitiveObjects/{xInt}/{xShort}/{xLong}/{xChar}/{xFloat}/{xDouble}/{xByte}/{xBoolean}")
+ // public void doPut1(RestRequest req, RestResponse res, Integer xInt, Short xShort, Long xLong, Character xChar, Float xFloat, Double xDouble, Byte xByte, Boolean xBoolean) {
+ // res.setOutput("PUT /primitives/"+xInt+"/"+xShort+"/"+xLong+"/"+xChar+"/"+xFloat+"/"+xDouble+"/"+xByte+"/"+xBoolean);
+ // }
+ r = client.doPut(URL + "/primitiveObjects/1/2/3/x/4/5/6/true", "");
+ assertEquals("PUT /primitiveObjects/1/2/3/x/4.0/5.0/6/true", r.getResponse(String.class));
+
+ // // Object with forString(String) method
+ // @RestMethod(name="PUT",pattern="/uuid/{uuid}")
+ // public void doPut1(RestRequest req, RestResponse res, UUID uuid) {
+ // res.setOutput("PUT /uuid/"+uuid);
+ // }
+ UUID uuid = UUID.randomUUID();
+ r = client.doPut(URL + "/uuid/"+uuid, "");
+ assertEquals("PUT /uuid/"+uuid, r.getResponse(String.class));
+ }
+
+ //====================================================================================================
+ // @FormData annotation - GET
+ //====================================================================================================
+ @Test
+ public void testParamGet() throws Exception {
+ RestClient client = TestMicroservice.client().accept("text/plain").build();
+ String r;
+ String url = URL + "/testParamGet";
+
+ r = client.doGet(url + "?p1=p1&p2=2").getResponseAsString();
+ assertEquals("p1=[p1,p1,p1],p2=[2,2,2]", r);
+
+ r = client.doGet(url + "?p1&p2").getResponseAsString();
+ assertEquals("p1=[,,],p2=[0,,0]", r);
+
+ r = client.doGet(url).getResponseAsString();
+ assertEquals("p1=[null,null,null],p2=[0,null,0]", r);
+
+ r = client.doGet(url + "?p1").getResponseAsString();
+ assertEquals("p1=[,,],p2=[0,null,0]", r);
+
+ r = client.doGet(url + "?p2").getResponseAsString();
+ assertEquals("p1=[null,null,null],p2=[0,,0]", r);
+
+ r = client.doGet(url + "?p1=foo&p2").getResponseAsString();
+ assertEquals("p1=[foo,foo,foo],p2=[0,,0]", r);
+
+ r = client.doGet(url + "?p1&p2=1").getResponseAsString();
+ assertEquals("p1=[,,],p2=[1,1,1]", r);
+
+ String x = "a%2Fb%25c%3Dd+e"; // [x/y%z=a+b]
+ r = client.doGet(url + "?p1="+x+"&p2=1").getResponseAsString();
+ assertEquals("p1=[a/b%c=d e,a/b%c=d e,a/b%c=d e],p2=[1,1,1]", r);
+
+ client.closeQuietly();
+ }
+
+ //====================================================================================================
+ // @FormData(format=PLAIN) annotation - GET
+ //====================================================================================================
+ @Test
+ public void testPlainParamGet() throws Exception {
+ RestClient client = TestMicroservice.client().accept("text/plain").build();
+ String r;
+ String url = URL + "/testPlainParamGet";
+
+ r = client.doGet(url + "?p1=p1").getResponseAsString();
+ assertEquals("p1=[p1,p1,p1]", r);
+
+ r = client.doGet(url + "?p1='p1'").getResponseAsString();
+ assertEquals("p1=['p1','p1',p1]", r);
+
+ client.closeQuietly();
+ }
+
+ //====================================================================================================
+ // @FormData annotation - POST
+ //====================================================================================================
+ @Test
+ public void testParamPost() throws Exception {
+ RestClient client = TestMicroservice.client().accept("text/plain").build();
+ String r;
+ String url = URL + "/testParamPost";
+
+ r = client.doFormPost(url, new ObjectMap("{p1:'p1',p2:2}")).getResponseAsString();
+ assertEquals("p1=[p1,p1,p1],p2=[2,2,2]", r);
+
+ r = client.doFormPost(url, new ObjectMap("{p1:null,p2:0}")).getResponseAsString();
+ assertEquals("p1=[null,null,null],p2=[0,0,0]", r);
+
+ r = client.doFormPost(url, new ObjectMap("{}")).getResponseAsString();
+ assertEquals("p1=[null,null,null],p2=[0,null,0]", r);
+
+ r = client.doFormPost(url, new ObjectMap("{p1:null}")).getResponseAsString();
+ assertEquals("p1=[null,null,null],p2=[0,null,0]", r);
+
+ r = client.doFormPost(url, new ObjectMap("{p2:0}")).getResponseAsString();
+ assertEquals("p1=[null,null,null],p2=[0,0,0]", r);
+
+ r = client.doFormPost(url, new ObjectMap("{p1:'foo',p2:0}")).getResponseAsString();
+ assertEquals("p1=[foo,foo,foo],p2=[0,0,0]", r);
+
+ r = client.doFormPost(url, new ObjectMap("{p1:null,p2:1}")).getResponseAsString();
+ assertEquals("p1=[null,null,null],p2=[1,1,1]", r);
+
+ r = client.doFormPost(url, new ObjectMap("{p1:'a/b%c=d e,f/g%h=i j',p2:1}")).getResponseAsString();
+ assertEquals("p1=[a/b%c=d e,f/g%h=i j,'a/b%c=d e,f/g%h=i j',a/b%c=d e,f/g%h=i j],p2=[1,1,1]", r);
+
+ client.closeQuietly();
+ }
+
+ //====================================================================================================
+ // @FormData(format=PLAIN) annotation - POST
+ //====================================================================================================
+ @Test
+ public void testPlainParamPost() throws Exception {
+ RestClient client = TestMicroservice.client().accept("text/plain").build();
+ String r;
+ String url = URL + "/testPlainParamPost";
+
+ List<NameValuePair> nvps = new ArrayList<NameValuePair>();
+ nvps.add(new BasicNameValuePair("p1", "p1"));
+ HttpEntity he = new UrlEncodedFormEntity(nvps);
+
+ r = client.doPost(url, he).getResponseAsString();
+ assertEquals("p1=[p1,p1,p1]", r);
+
+ nvps = new ArrayList<NameValuePair>();
+ nvps.add(new BasicNameValuePair("p1", "'p1'"));
+ he = new UrlEncodedFormEntity(nvps);
+
+ r = client.doFormPost(url, he).getResponseAsString();
+ assertEquals("p1=['p1','p1',p1]", r);
+
+ client.closeQuietly();
+ }
+
+ //====================================================================================================
+ // @Query annotation - GET
+ //====================================================================================================
+ @Test
+ public void testQParamGet() throws Exception {
+ RestClient client = TestMicroservice.client().accept("text/plain").build();
+ String r;
+ String url = URL + "/testQParamGet";
+
+ r = client.doGet(url + "?p1=p1&p2=2").getResponseAsString();
+ assertEquals("p1=[p1,p1,p1],p2=[2,2,2]", r);
+
+ r = client.doGet(url + "?p1&p2").getResponseAsString();
+ assertEquals("p1=[,,],p2=[0,,0]", r);
+
+ r = client.doGet(url).getResponseAsString();
+ assertEquals("p1=[null,null,null],p2=[0,null,0]", r);
+
+ r = client.doGet(url + "?p1").getResponseAsString();
+ assertEquals("p1=[,,],p2=[0,null,0]", r);
+
+ r = client.doGet(url + "?p2").getResponseAsString();
+ assertEquals("p1=[null,null,null],p2=[0,,0]", r);
+
+ r = client.doGet(url + "?p1=foo&p2").getResponseAsString();
+ assertEquals("p1=[foo,foo,foo],p2=[0,,0]", r);
+
+ r = client.doGet(url + "?p1&p2=1").getResponseAsString();
+ assertEquals("p1=[,,],p2=[1,1,1]", r);
+
+ String x = "a%2Fb%25c%3Dd+e"; // [x/y%z=a+b]
+ r = client.doGet(url + "?p1="+x+"&p2=1").getResponseAsString();
+ assertEquals("p1=[a/b%c=d e,a/b%c=d e,a/b%c=d e],p2=[1,1,1]", r);
+
+ client.closeQuietly();
+ }
+
+ //====================================================================================================
+ // @Query(format=PLAIN) annotation - GET
+ //====================================================================================================
+ @Test
+ public void testPlainQParamGet() throws Exception {
+ RestClient client = TestMicroservice.client().accept("text/plain").build();
+ String r;
+ String url = URL + "/testPlainQParamGet";
+
+ r = client.doGet(url + "?p1=p1").getResponseAsString();
+ assertEquals("p1=[p1,p1,p1]", r);
+
+ r = client.doGet(url + "?p1='p1'").getResponseAsString();
+ assertEquals("p1=['p1','p1',p1]", r);
+
+ client.closeQuietly();
+ }
+
+ //====================================================================================================
+ // @Query annotation - POST
+ //====================================================================================================
+ @Test
+ public void testQParamPost() throws Exception {
+ RestClient client = TestMicroservice.client().accept("text/plain").build();
+ String r;
+ String url = URL + "/testQParamPost";
+
+ r = client.doFormPost(url, new ObjectMap("{p1:'p1',p2:2}")).getResponseAsString();
+ assertEquals("p1=[null,null,null],p2=[0,null,0]", r);
+
+ r = client.doFormPost(url, new ObjectMap("{p1:null,p2:0}")).getResponseAsString();
+ assertEquals("p1=[null,null,null],p2=[0,null,0]", r);
+
+ r = client.doFormPost(url, new ObjectMap("{}")).getResponseAsString();
+ assertEquals("p1=[null,null,null],p2=[0,null,0]", r);
+
+ r = client.doFormPost(url, new ObjectMap("{p1:null}")).getResponseAsString();
+ assertEquals("p1=[null,null,null],p2=[0,null,0]", r);
+
+ r = client.doFormPost(url, new ObjectMap("{p2:0}")).getResponseAsString();
+ assertEquals("p1=[null,null,null],p2=[0,null,0]", r);
+
+ r = client.doFormPost(url, new ObjectMap("{p1:'foo',p2:0}")).getResponseAsString();
+ assertEquals("p1=[null,null,null],p2=[0,null,0]", r);
+
+ r = client.doFormPost(url, new ObjectMap("{p1:null,p2:1}")).getResponseAsString();
+ assertEquals("p1=[null,null,null],p2=[0,null,0]", r);
+
+ r = client.doFormPost(url, new ObjectMap("{p1:'a/b%c=d e,f/g%h=i j',p2:1}")).getResponseAsString();
+ assertEquals("p1=[null,null,null],p2=[0,null,0]", r);
+
+ client.closeQuietly();
+ }
+
+ //====================================================================================================
+ // @HasQuery annotation - GET
+ //====================================================================================================
+ @Test
+ public void testHasParamGet() throws Exception {
+ RestClient client = TestMicroservice.client().accept("text/plain").build();
+ String r;
+ String url = URL + "/testHasParamGet";
+
+ r = client.doGet(url + "?p1=p1&p2=2").getResponseAsString();
+ assertEquals("p1=[true,true],p2=[true,true]", r);
+
+ r = client.doGet(url + "?p1&p2").getResponseAsString();
+ assertEquals("p1=[true,true],p2=[true,true]", r);
+
+ r = client.doGet(url).getResponseAsString();
+ assertEquals("p1=[false,false],p2=[false,false]", r);
+
+ r = client.doGet(url + "?p1").getResponseAsString();
+ assertEquals("p1=[true,true],p2=[false,false]", r);
+
+ r = client.doGet(url + "?p2").getResponseAsString();
+ assertEquals("p1=[false,false],p2=[true,true]", r);
+
+ r = client.doGet(url + "?p1=foo&p2").getResponseAsString();
+ assertEquals("p1=[true,true],p2=[true,true]", r);
+
+ r = client.doGet(url + "?p1&p2=1").getResponseAsString();
+ assertEquals("p1=[true,true],p2=[true,true]", r);
+
+ String x = "x%2Fy%25z%3Da+b"; // [x/y%z=a+b]
+ r = client.doGet(url + "?p1="+x+"&p2=1").getResponseAsString();
+ assertEquals("p1=[true,true],p2=[true,true]", r);
+
+ client.closeQuietly();
+ }
+
+ //====================================================================================================
+ // @HasQuery annotation - POST
+ //====================================================================================================
+ @Test
+ public void testHasParamPost() throws Exception {
+ RestClient client = TestMicroservice.client().accept("text/plain").build();
+ String r;
+ String url = URL + "/testHasParamPost";
+
+ r = client.doFormPost(url, new ObjectMap("{p1:'p1',p2:2}")).getResponseAsString();
+ assertEquals("p1=[true,true],p2=[true,true]", r);
+
+ r = client.doFormPost(url, new ObjectMap("{p1:null,p2:0}")).getResponseAsString();
+ assertEquals("p1=[true,true],p2=[true,true]", r);
+
+ r = client.doFormPost(url, new ObjectMap("{}")).getResponseAsString();
+ assertEquals("p1=[false,false],p2=[false,false]", r);
+
+ r = client.doFormPost(url, new ObjectMap("{p1:null}")).getResponseAsString();
+ assertEquals("p1=[true,true],p2=[false,false]", r);
+
+ r = client.doFormPost(url, new ObjectMap("{p2:0}")).getResponseAsString();
+ assertEquals("p1=[false,false],p2=[true,true]", r);
+
+ r = client.doFormPost(url, new ObjectMap("{p1:'foo',p2:0}")).getResponseAsString();
+ assertEquals("p1=[true,true],p2=[true,true]", r);
+
+ r = client.doFormPost(url, new ObjectMap("{p1:null,p2:1}")).getResponseAsString();
+ assertEquals("p1=[true,true],p2=[true,true]", r);
+
+ r = client.doFormPost(url, new ObjectMap("{p1:'a/b%c=d e,f/g%h=i j',p2:1}")).getResponseAsString();
+ assertEquals("p1=[true,true],p2=[true,true]", r);
+
+ client.closeQuietly();
+ }
+
+ //====================================================================================================
+ // @HasQuery annotation - GET
+ //====================================================================================================
+ @Test
+ public void testHasQParamGet() throws Exception {
+ RestClient client = TestMicroservice.client().accept("text/plain").build();
+ String r;
+ String url = URL + "/testHasQParamGet";
+
+ r = client.doGet(url + "?p1=p1&p2=2").getResponseAsString();
+ assertEquals("p1=[true,true],p2=[true,true]", r);
+
+ r = client.doGet(url + "?p1&p2").getResponseAsString();
+ assertEquals("p1=[true,true],p2=[true,true]", r);
+
+ r = client.doGet(url).getResponseAsString();
+ assertEquals("p1=[false,false],p2=[false,false]", r);
+
+ r = client.doGet(url + "?p1").getResponseAsString();
+ assertEquals("p1=[true,true],p2=[false,false]", r);
+
+ r = client.doGet(url + "?p2").getResponseAsString();
+ assertEquals("p1=[false,false],p2=[true,true]", r);
+
+ r = client.doGet(url + "?p1=foo&p2").getResponseAsString();
+ assertEquals("p1=[true,true],p2=[true,true]", r);
+
+ r = client.doGet(url + "?p1&p2=1").getResponseAsString();
+ assertEquals("p1=[true,true],p2=[true,true]", r);
+
+ String x = "x%2Fy%25z%3Da+b"; // [x/y%z=a+b]
+ r = client.doGet(url + "?p1="+x+"&p2=1").getResponseAsString();
+ assertEquals("p1=[true,true],p2=[true,true]", r);
+
+ client.closeQuietly();
+ }
+
+ //====================================================================================================
+ // @HasQuery annotation - POST
+ //====================================================================================================
+ @Test
+ public void testHasQParamPost() throws Exception {
+ RestClient client = TestMicroservice.client().accept("text/plain").build();
+ String r;
+ String url = URL + "/testHasQParamPost";
+
+ r = client.doFormPost(url, new ObjectMap("{p1:'p1',p2:2}")).getResponseAsString();
+ assertEquals("p1=[false,false],p2=[false,false]", r);
+
+ r = client.doFormPost(url, new ObjectMap("{p1:null,p2:0}")).getResponseAsString();
+ assertEquals("p1=[false,false],p2=[false,false]", r);
+
+ r = client.doFormPost(url, new ObjectMap("{}")).getResponseAsString();
+ assertEquals("p1=[false,false],p2=[false,false]", r);
+
+ r = client.doFormPost(url, new ObjectMap("{p1:null}")).getResponseAsString();
+ assertEquals("p1=[false,false],p2=[false,false]", r);
+
+ r = client.doFormPost(url, new ObjectMap("{p2:0}")).getResponseAsString();
+ assertEquals("p1=[false,false],p2=[false,false]", r);
+
+ r = client.doFormPost(url, new ObjectMap("{p1:'foo',p2:0}")).getResponseAsString();
+ assertEquals("p1=[false,false],p2=[false,false]", r);
+
+ r = client.doFormPost(url, new ObjectMap("{p1:null,p2:1}")).getResponseAsString();
+ assertEquals("p1=[false,false],p2=[false,false]", r);
+
+ r = client.doFormPost(url, new ObjectMap("{p1:'a/b%c=d e,f/g%h=i j',p2:1}")).getResponseAsString();
+ assertEquals("p1=[false,false],p2=[false,false]", r);
+
+ client.closeQuietly();
+ }
+
+ //====================================================================================================
+ // Form POSTS with @Body parameter
+ //====================================================================================================
+ @Test
+ public void testFormPostAsContent() throws Exception {
+ RestClient client = TestMicroservice.client().accept("text/plain").build();
+ String r;
+ String url = URL + "/testFormPostAsContent";
+
+ r = client.doFormPost(url, new ObjectMap("{p1:'p1',p2:2}")).getResponseAsString();
+ assertEquals("bean=[{p1:'p1',p2:2}],qp1=[null],qp2=[0],hqp1=[false],hqp2=[false]", r);
+
+ r = client.doFormPost(url, new ObjectMap("{}")).getResponseAsString();
+ assertEquals("bean=[{p2:0}],qp1=[null],qp2=[0],hqp1=[false],hqp2=[false]", r);
+
+ r = client.doFormPost(url+"?p1=p3&p2=4", new ObjectMap("{p1:'p1',p2:2}")).getResponseAsString();
+ assertEquals("bean=[{p1:'p1',p2:2}],qp1=[p3],qp2=[4],hqp1=[true],hqp2=[true]", r);
+
+ r = client.doFormPost(url+"?p1=p3&p2=4", new ObjectMap("{}")).getResponseAsString();
+ assertEquals("bean=[{p2:0}],qp1=[p3],qp2=[4],hqp1=[true],hqp2=[true]", r);
+
+ client.closeQuietly();
+ }
+
+ //====================================================================================================
+ // Test @FormData and @Query annotations when using multi-part parameters (e.g. &key=val1,&key=val2).
+ //====================================================================================================
+ @Test
+ public void testMultiPartParams() throws Exception {
+ RestClient client = TestMicroservice.client().accept("text/plain").build();
+ String r;
+ String url = URL + "/testMultiPartParams";
+
+ String in = ""
+ + "?p1=a&p1=b"
+ + "&p2=1&p2=2"
+ + "&p3=a&p3=b"
+ + "&p4=1&p4=2"
+ + "&p5=a&p5=b"
+ + "&p6=1&p6=2"
+ + "&p7=a&p7=b"
+ + "&p8=1&p8=2"
+ + "&p9=(a=1,b=2,c=false)&p9=(a=3,b=4,c=true)"
+ + "&p10=(a=1,b=2,c=false)&p10=(a=3,b=4,c=true)"
+ + "&p11=(a=1,b=2,c=false)&p11=(a=3,b=4,c=true)"
+ + "&p12=(a=1,b=2,c=false)&p12=(a=3,b=4,c=true)";
+ r = client.doGet(url + in).getResponseAsString();
+ String e = "{"
+ + "p1:['a','b'],"
+ + "p2:[1,2],"
+ + "p3:['a','b'],"
+ + "p4:[1,2],"
+ + "p5:['a','b'],"
+ + "p6:[1,2],"
+ + "p7:['a','b'],"
+ + "p8:[1,2],"
+ + "p9:[{a:'1',b:2,c:false},{a:'3',b:4,c:true}],"
+ + "p10:[{a:'1',b:2,c:false},{a:'3',b:4,c:true}],"
+ + "p11:[{a:'1',b:2,c:false},{a:'3',b:4,c:true}],"
+ + "p12:[{a:'1',b:2,c:false},{a:'3',b:4,c:true}]"
+ +"}";
+ assertEquals(e, r);
+
+ client.closeQuietly();
+ }
+
+ //====================================================================================================
+ // Same as testMultiPartParams(), except make sure single values are still interpreted as collections.
+ //====================================================================================================
+ @Test
+ public void testMultiPartParamsSingleValues() throws Exception {
+ RestClient client = TestMicroservice.client().accept("text/plain").build();
+ String r;
+ String url = URL + "/testMultiPartParams";
+
+ String in = ""
+ + "?p1=a"
+ + "&p2=1"
+ + "&p3=a"
+ + "&p4=1"
+ + "&p5=a"
+ + "&p6=1"
+ + "&p7=a"
+ + "&p8=1"
+ + "&p9=(a=1,b=2,c=false)"
+ + "&p10=(a=1,b=2,c=false)"
+ + "&p11=(a=1,b=2,c=false)"
+ + "&p12=(a=1,b=2,c=false)";
+ r = client.doGet(url + in).getResponseAsString();
+ String e = "{"
+ + "p1:['a'],"
+ + "p2:[1],"
+ + "p3:['a'],"
+ + "p4:[1],"
+ + "p5:['a'],"
+ + "p6:[1],"
+ + "p7:['a'],"
+ + "p8:[1],"
+ + "p9:[{a:'1',b:2,c:false}],"
+ + "p10:[{a:'1',b:2,c:false}],"
+ + "p11:[{a:'1',b:2,c:false}],"
+ + "p12:[{a:'1',b:2,c:false}]"
+ +"}";
+ assertEquals(e, r);
+
+ client.closeQuietly();
+ }
+
+ //====================================================================================================
+ // Test multi-part parameter keys on bean properties of type array/Collection (i.e. &key=val1,&key=val2)
+ // using URLENC_expandedParams property.
+ // A simple round-trip test to verify that both serializing and parsing works.
+ //====================================================================================================
+ @Test
+ public void testFormPostsWithMultiParamsUsingProperty() throws Exception {
+ RestClient client = TestMicroservice.client()
+ .contentType("application/x-www-form-urlencoded")
+ .accept("application/x-www-form-urlencoded")
+ .build();
+ String r;
+ String url = URL + "/testFormPostsWithMultiParamsUsingProperty";
+
+ String in = ""
+ + "f01=a&f01=b"
+ + "&f02=c&f02=d"
+ + "&f03=1&f03=2"
+ + "&f04=3&f04=4"
+ + "&f05=@(e,f)&f05=@(g,h)"
+ + "&f06=@(i,j)&f06=@(k,l)"
+ + "&f07=(a=a,b=1,c=true)&f07=(a=b,b=2,c=false)"
+ + "&f08=(a=a,b=1,c=true)&f08=(a=b,b=2,c=false)"
+ + "&f09=@((a=a,b=1,c=true))&f09=@((a=b,b=2,c=false))"
+ + "&f10=@((a=a,b=1,c=true))&f10=@((a=b,b=2,c=false))"
+ + "&f11=a&f11=b"
+ + "&f12=c&f12=d"
+ + "&f13=1&f13=2"
+ + "&f14=3&f14=4"
+ + "&f15=@(e,f)&f15=@(g,h)"
+ + "&f16=@(i,j)&f16=@(k,l)"
+ + "&f17=(a=a,b=1,c=true)&f17=(a=b,b=2,c=false)"
+ + "&f18=(a=a,b=1,c=true)&f18=(a=b,b=2,c=false)"
+ + "&f19=@((a=a,b=1,c=true))&f19=@((a=b,b=2,c=false))"
+ + "&f20=@((a=a,b=1,c=true))&f20=@((a=b,b=2,c=false))";
+ r = client.doPost(url, new StringEntity(in)).getResponseAsString();
+ assertEquals(in, r);
+
+ client.closeQuietly();
+ }
+
+ //====================================================================================================
+ // Test multi-part parameter keys on bean properties of type array/Collection (i.e. &key=val1,&key=val2)
+ // using @UrlEncoding(expandedParams=true) annotation.
+ // A simple round-trip test to verify that both serializing and parsing works.
+ //====================================================================================================
+ @Test
+ public void testFormPostsWithMultiParamsUsingAnnotation() throws Exception {
+ RestClient client = TestMicroservice.client()
+ .contentType("application/x-www-form-urlencoded")
+ .accept("application/x-www-form-urlencoded")
+ .build();
+ String r;
+ String url = URL + "/testFormPostsWithMultiParamsUsingAnnotation";
+
+ String in = ""
+ + "f01=a&f01=b"
+ + "&f02=c&f02=d"
+ + "&f03=1&f03=2"
+ + "&f04=3&f04=4"
+ + "&f05=@(e,f)&f05=@(g,h)"
+ + "&f06=@(i,j)&f06=@(k,l)"
+ + "&f07=(a=a,b=1,c=true)&f07=(a=b,b=2,c=false)"
+ + "&f08=(a=a,b=1,c=true)&f08=(a=b,b=2,c=false)"
+ + "&f09=@((a=a,b=1,c=true))&f09=@((a=b,b=2,c=false))"
+ + "&f10=@((a=a,b=1,c=true))&f10=@((a=b,b=2,c=false))"
+ + "&f11=a&f11=b"
+ + "&f12=c&f12=d"
+ + "&f13=1&f13=2"
+ + "&f14=3&f14=4"
+ + "&f15=@(e,f)&f15=@(g,h)"
+ + "&f16=@(i,j)&f16=@(k,l)"
+ + "&f17=(a=a,b=1,c=true)&f17=(a=b,b=2,c=false)"
+ + "&f18=(a=a,b=1,c=true)&f18=(a=b,b=2,c=false)"
+ + "&f19=@((a=a,b=1,c=true))&f19=@((a=b,b=2,c=false))"
+ + "&f20=@((a=a,b=1,c=true))&f20=@((a=b,b=2,c=false))";
+ r = client.doPost(url, new StringEntity(in)).getResponseAsString();
+ assertEquals(in, r);
+
+ client.closeQuietly();
+ }
+
+
+ //====================================================================================================
+ // Test other available object types as parameters.
+ //====================================================================================================
+
+ @Test
+ public void testOtherResourceBundle() throws Exception {
+ String r = CLIENT.doGet(URL + "/otherObjects/ResourceBundle").acceptLanguage("en-US").getResponseAsString();
+ assertEquals("\"bar\"", r);
+ r = CLIENT.doGet(URL + "/otherObjects/ResourceBundle").acceptLanguage("ja-JP").getResponseAsString();
+ assertEquals("\"baz\"", r);
+ }
+
+ @Test
+ public void testOtherMessages() throws Exception {
+ String r = CLIENT.doGet(URL + "/otherObjects/MessageBundle").acceptLanguage("en-US").getResponseAsString();
+ assertEquals("\"bar\"", r);
+ r = CLIENT.doGet(URL + "/otherObjects/MessageBundle").acceptLanguage("ja-JP").getResponseAsString();
+ assertEquals("\"baz\"", r);
+ }
+
+ @Test
+ public void testOtherInputStream() throws IOException {
+ String r = CLIENT.doPost(URL + "/otherObjects/InputStream").input(new StringReader("foo")).getResponseAsString();
+ assertEquals("\"foo\"", r);
+ }
+
+ @Test
+ public void testOtherServletInputStream() throws Exception {
+ String r = CLIENT.doPost(URL + "/otherObjects/ServletInputStream").input(new StringReader("foo")).getResponseAsString();
+ assertEquals("\"foo\"", r);
+ }
+
+ @Test
+ public void testOtherReader() throws Exception {
+ String r = CLIENT.doPost(URL + "/otherObjects/Reader").input(new StringReader("foo")).getResponseAsString();
+ assertEquals("\"foo\"", r);
+ }
+
+ @Test
+ public void testOtherOutputStream() throws Exception {
+ String r = CLIENT.doGet(URL + "/otherObjects/OutputStream").getResponseAsString();
+ assertEquals("OK", r);
+ }
+
+ @Test
+ public void testOtherServletOutputStream() throws Exception {
+ String r = CLIENT.doGet(URL + "/otherObjects/ServletOutputStream").getResponseAsString();
+ assertEquals("OK", r);
+ }
+
+ @Test
+ public void testOtherWriter() throws Exception {
+ String r = CLIENT.doGet(URL + "/otherObjects/Writer").getResponseAsString();
+ assertEquals("OK", r);
+ }
+
+ @Test
+ public void testOtherRequestHeaders() throws Exception {
+ String r = CLIENT.doGet(URL + "/otherObjects/RequestHeaders").getResponseAsString();
+ assertEquals("true", r);
+ }
+
+ @Test
+ public void testOtherRequestQuery() throws Exception {
+ String r = CLIENT.doGet(URL + "/otherObjects/RequestQuery").getResponseAsString();
+ assertEquals("true", r);
+ }
+
+ @Test
+ public void testOtherRequestFormData() throws Exception {
+ String r = CLIENT.doGet(URL + "/otherObjects/RequestFormData").getResponseAsString();
+ assertEquals("true", r);
+ }
+
+ @Test
+ public void testOtherHttpMethod() throws Exception {
+ String r = CLIENT.doGet(URL + "/otherObjects/HttpMethod").getResponseAsString();
+ assertEquals("\"GET\"", r);
+ }
+
+ @Test
+ public void testOtherLogger() throws Exception {
+ String r = CLIENT.doGet(URL + "/otherObjects/Logger").getResponseAsString();
+ assertEquals("true", r);
+ }
+
+ @Test
+ public void testOtherJuneauLogger() throws Exception {
+ String r = CLIENT.doGet(URL + "/otherObjects/JuneauLogger").getResponseAsString();
+ assertEquals("true", r);
+ }
+
+ @Test
+ public void testOtherRestContext() throws Exception {
+ String r = CLIENT.doGet(URL + "/otherObjects/RestContext").getResponseAsString();
+ assertEquals("true", r);
+ }
+
+ @Test
+ public void testOtherParser() throws Exception {
+ String r = CLIENT.doGet(URL + "/otherObjects/Parser").getResponseAsString();
+ assertEquals("\"org.apache.juneau.json.JsonParser\"", r);
+ }
+
+ @Test
+ public void testOtherLocale() throws Exception {
+ String r = CLIENT.doGet(URL + "/otherObjects/Locale").acceptLanguage("en-US").getResponseAsString();
+ assertEquals("\"en_US\"", r);
+ r = CLIENT.doGet(URL + "/otherObjects/Locale").acceptLanguage("ja-JP").getResponseAsString();
+ assertEquals("\"ja_JP\"", r);
+ }
+
+ @Test
+ public void testOtherSwagger() throws Exception {
+ String r = CLIENT.doGet(URL + "/otherObjects/Swagger").getResponseAsString();
+ assertEquals("true", r);
+ }
+
+ @Test
+ public void testOtherRequestPathMatch() throws Exception {
+ String r = CLIENT.doGet(URL + "/otherObjects/RequestPathMatch").getResponseAsString();
+ assertEquals("true", r);
+ }
+
+ @Test
+ public void testOtherRequestBody() throws Exception {
+ String r = CLIENT.doGet(URL + "/otherObjects/RequestBody").getResponseAsString();
+ assertEquals("true", r);
+ }
+
+ @Test
+ public void testOtherConfigFile() throws Exception {
+ String r = CLIENT.doGet(URL + "/otherObjects/ConfigFile").getResponseAsString();
+ assertEquals("true", r);
+ }
+}
Propchange: release/incubator/juneau/juneau-microservice-test/src/test/java/org/apache/juneau/rest/test/ParamsTest.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: release/incubator/juneau/juneau-microservice-test/src/test/java/org/apache/juneau/rest/test/ParsersTest.java
==============================================================================
--- release/incubator/juneau/juneau-microservice-test/src/test/java/org/apache/juneau/rest/test/ParsersTest.java (added)
+++ release/incubator/juneau/juneau-microservice-test/src/test/java/org/apache/juneau/rest/test/ParsersTest.java Fri Sep 8 23:21:12 2017
@@ -0,0 +1,138 @@
+// ***************************************************************************************************************************
+// * 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 org.apache.juneau.rest.client.*;
+import org.junit.*;
+
+public class ParsersTest extends RestTestcase {
+
+ private static String URL = "/testParsers";
+ private static boolean debug = false;
+
+ //====================================================================================================
+ // Parser defined on class.
+ //====================================================================================================
+ @Test
+ public void testParserOnClass() throws Exception {
+ RestClient client = TestMicroservice.DEFAULT_CLIENT_PLAINTEXT;
+ String url = URL + "/testParserOnClass";
+
+ String r = client.doPut(url, "test1").contentType("text/a").getResponseAsString();
+ assertEquals("text/a - test1", r);
+
+ try {
+ client.doPut(url + "?noTrace=true", "test1").contentType("text/b").getResponseAsString();
+ fail("Exception expected");
+ } catch (RestCallException e) {
+ checkErrorResponse(debug, e, SC_UNSUPPORTED_MEDIA_TYPE,
+ "Unsupported media-type in request header 'Content-Type': 'text/b'",
+ "Supported media-types: ['text/a"
+ );
+ }
+
+ r = client.doPut(url, "'test1'").contentType("text/json").accept("text/json").getResponseAsString();
+ assertEquals("\"test1\"", r);
+ }
+
+ //====================================================================================================
+ // Parser defined on method.
+ //====================================================================================================
+ @Test
+ public void testParserOnMethod() throws Exception {
+ RestClient client = TestMicroservice.DEFAULT_CLIENT_PLAINTEXT;
+ String url = URL + "/testParserOnMethod";
+
+ String r = client.doPut(url, "test2").contentType("text/b").getResponseAsString();
+ assertEquals("text/b - test2", r);
+
+ try {
+ client.doPut(url + "?noTrace=true", "test2").contentType("text/a").getResponseAsString();
+ fail("Exception expected");
+ } catch (RestCallException e) {
+ checkErrorResponse(debug, e, SC_UNSUPPORTED_MEDIA_TYPE,
+ "Unsupported media-type in request header 'Content-Type': 'text/a'",
+ "Supported media-types: ['text/b']"
+ );
+ }
+
+ try {
+ r = client.doPut(url + "?noTrace=true", "'test2'").contentType("text/json").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/b']"
+ );
+ }
+ }
+
+ //====================================================================================================
+ // Parser overridden on method.
+ //====================================================================================================
+ @Test
+ public void testParserOverriddenOnMethod() throws Exception {
+ RestClient client = TestMicroservice.DEFAULT_CLIENT_PLAINTEXT;
+ String url = URL + "/testParserOverriddenOnMethod";
+
+ String r = client.doPut(url, "test3").contentType("text/a").getResponseAsString();
+ assertEquals("text/a - test3", r);
+
+ r = client.doPut(url, "test3").contentType("text/b").getResponseAsString();
+ assertEquals("text/b - test3", r);
+
+ r = client.doPut(url, "'test3'").contentType("text/json").getResponseAsString();
+ assertEquals("test3", r);
+ }
+
+ //====================================================================================================
+ // Parser with different Accept than Content-Type.
+ //====================================================================================================
+ @Test
+ public void testParserWithDifferentMediaTypes() throws Exception {
+ RestClient client = TestMicroservice.DEFAULT_CLIENT_PLAINTEXT;
+ String url = URL + "/testParserWithDifferentMediaTypes";
+
+ String r = client.doPut(url, "test4").contentType("text/a").getResponseAsString();
+ assertEquals("text/a - test4", r);
+
+ r = client.doPut(url, "test4").contentType("text/d").getResponseAsString();
+ assertEquals("text/d - test4", r);
+
+ r = client.doPut(url, "'test4'").contentType("text/json").getResponseAsString();
+ assertEquals("test4", r);
+ }
+
+ //====================================================================================================
+ // Check for valid error response.
+ //====================================================================================================
+ @Test
+ public void testValidErrorResponse() throws Exception {
+ RestClient client = TestMicroservice.DEFAULT_CLIENT_PLAINTEXT;
+ String url = URL + "/testValidErrorResponse";
+
+ try {
+ client.doPut(url + "?noTrace=true", "test1").contentType("text/bad").getResponseAsString();
+ fail("Exception expected");
+ } catch (RestCallException e) {
+ checkErrorResponse(debug, e, SC_UNSUPPORTED_MEDIA_TYPE,
+ "Unsupported media-type in request header 'Content-Type': 'text/bad'",
+ "Supported media-types: ['text/a"
+ );
+ }
+ }
+}
Propchange: release/incubator/juneau/juneau-microservice-test/src/test/java/org/apache/juneau/rest/test/ParsersTest.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: release/incubator/juneau/juneau-microservice-test/src/test/java/org/apache/juneau/rest/test/PathTest.java
==============================================================================
--- release/incubator/juneau/juneau-microservice-test/src/test/java/org/apache/juneau/rest/test/PathTest.java (added)
+++ release/incubator/juneau/juneau-microservice-test/src/test/java/org/apache/juneau/rest/test/PathTest.java Fri Sep 8 23:21:12 2017
@@ -0,0 +1,41 @@
+// ***************************************************************************************************************************
+// * 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 PathTest extends RestTestcase {
+
+ private static String URL = "/testPath";
+
+ //====================================================================================================
+ // Basic tests
+ //====================================================================================================
+ @Test
+ public void testBasic() throws Exception {
+ RestClient client = TestMicroservice.DEFAULT_CLIENT;
+ String r = null;
+
+ r = client.doGet(URL).getResponse(String.class);
+ assertEquals("/testPath", r);
+
+ r = client.doGet(URL + "/testPath2").getResponse(String.class);
+ assertEquals("/testPath/testPath2", r);
+
+ r = client.doGet(URL + "/testPath2/testPath3").getResponse(String.class);
+ assertEquals("/testPath/testPath2/testPath3", r);
+ }
+}
Propchange: release/incubator/juneau/juneau-microservice-test/src/test/java/org/apache/juneau/rest/test/PathTest.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: release/incubator/juneau/juneau-microservice-test/src/test/java/org/apache/juneau/rest/test/PathVariableTest.java
==============================================================================
--- release/incubator/juneau/juneau-microservice-test/src/test/java/org/apache/juneau/rest/test/PathVariableTest.java (added)
+++ release/incubator/juneau/juneau-microservice-test/src/test/java/org/apache/juneau/rest/test/PathVariableTest.java Fri Sep 8 23:21:12 2017
@@ -0,0 +1,51 @@
+// ***************************************************************************************************************************
+// * 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.*;
+
+/**
+ * Tests the <code>@RestMethod.path()</code> annotation.
+ */
+public class PathVariableTest extends RestTestcase {
+
+ private static String URL = "/testPathVariables";
+ RestClient client = TestMicroservice.DEFAULT_CLIENT;
+
+ @Test
+ public void test1() throws Exception {
+ String r = client.doGet(URL + "/test1/xxx/foo/123/bar/true").getResponseAsString();
+ assertEquals("x=xxx,y=123,z=true", r);
+ }
+
+ @Test
+ public void test2() throws Exception {
+ String r = client.doGet(URL + "/test2/true/foo/123/bar/xxx").getResponseAsString();
+ assertEquals("x=xxx,y=123,z=true", r);
+ }
+
+ @Test
+ public void test3() throws Exception {
+ String r = client.doGet(URL + "/test3/xxx/foo/123/bar/true").getResponseAsString();
+ assertEquals("x=xxx,y=123,z=true", r);
+ }
+
+ @Test
+ public void test4() throws Exception {
+ String r = client.doGet(URL + "/test4/true/foo/123/bar/xxx").getResponseAsString();
+ assertEquals("x=xxx,y=123,z=true", r);
+ }
+}
Propchange: release/incubator/juneau/juneau-microservice-test/src/test/java/org/apache/juneau/rest/test/PathVariableTest.java
------------------------------------------------------------------------------
svn:mime-type = text/plain