This is an automated email from the ASF dual-hosted git repository.
jamesbognar pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/juneau.git
The following commit(s) were added to refs/heads/master by this push:
new 3b88a76 Tests.
3b88a76 is described below
commit 3b88a767783bd782d17d1c1ec4732dd88bc4bdd6
Author: JamesBognar <[email protected]>
AuthorDate: Sat May 12 18:34:25 2018 -0400
Tests.
---
.../apache/juneau/rest/test/ParamsResource.java | 97 --------
.../java/org/apache/juneau/rest/test/Root.java | 1 -
.../org/apache/juneau/rest/test/ParamsTest.java | 255 ---------------------
.../org/apache/juneau/rest/test/_TestSuite.java | 1 -
.../juneau/rest/annotation/BodyAnnotationTest.java | 89 +++++++
.../rest/annotation/HasFormDataAnnotationTest.java | 58 +++++
.../rest/annotation/HasQueryAnnotationTest.java | 77 +++++++
7 files changed, 224 insertions(+), 354 deletions(-)
diff --git
a/juneau-microservice/juneau-microservice-test/src/main/java/org/apache/juneau/rest/test/ParamsResource.java
b/juneau-microservice/juneau-microservice-test/src/main/java/org/apache/juneau/rest/test/ParamsResource.java
deleted file mode 100644
index d6097b5..0000000
---
a/juneau-microservice/juneau-microservice-test/src/main/java/org/apache/juneau/rest/test/ParamsResource.java
+++ /dev/null
@@ -1,97 +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.rest.test;
-
-import static org.apache.juneau.http.HttpMethodName.*;
-
-import org.apache.juneau.plaintext.*;
-import org.apache.juneau.rest.*;
-import org.apache.juneau.rest.annotation.*;
-import org.apache.juneau.rest.testutils.DTOs;
-import org.apache.juneau.transforms.*;
-import org.apache.juneau.urlencoding.*;
-
-/**
- * JUnit automated testcase resource.
- */
-@RestResource(
- path="/testParams",
- serializers=PlainTextSerializer.class,
- allowedMethodParams="*",
- pojoSwaps={CalendarSwap.DateMedium.class},
- messages="ParamsResource"
-)
-public class ParamsResource extends BasicRestServlet {
- private static final long serialVersionUID = 1L;
-
-
//====================================================================================================
- // @HasQuery annotation - GET
-
//====================================================================================================
- @RestMethod(name=GET, path="/testHasParamGet/*")
- public String testHasParamGet(RestRequest req, @HasQuery("p1") boolean
p1, @HasQuery("p2") Boolean p2) throws Exception {
- RequestQuery q = req.getQuery();
- return
"p1=["+p1+","+q.containsKey("p1")+"],p2=["+p2+","+q.containsKey("p2")+"]";
- }
-
-
//====================================================================================================
- // @HasQuery annotation - POST
-
//====================================================================================================
- @RestMethod(name=POST, path="/testHasParamPost/*")
- public String testHasParamPost(RestRequest req, @HasFormData("p1")
boolean p1, @HasFormData("p2") Boolean p2) throws Exception {
- RequestFormData f = req.getFormData();
- return
"p1=["+p1+","+f.containsKey("p1")+"],p2=["+p2+","+f.containsKey("p2")+"]";
- }
-
-
//====================================================================================================
- // @HasQuery annotation - GET
-
//====================================================================================================
- @RestMethod(name=GET, path="/testHasQParamGet/*")
- public String testHasQParamGet(RestRequest req, @HasQuery("p1") boolean
p1, @HasQuery("p2") Boolean p2) throws Exception {
- RequestQuery q = req.getQuery();
- return
"p1=["+p1+","+q.containsKey("p1")+"],p2=["+p2+","+q.containsKey("p2")+"]";
- }
-
-
//====================================================================================================
- // @HasQuery annotation - POST
-
//====================================================================================================
- @RestMethod(name=POST, path="/testHasQParamPost/*")
- public String testHasQParamPost_post(RestRequest req, @HasQuery("p1")
boolean p1, @HasQuery("p2") Boolean p2) throws Exception {
- RequestQuery q = req.getQuery();
- return
"p1=["+p1+","+q.containsKey("p1")+"],p2=["+p2+","+q.containsKey("p2")+"]";
- }
-
-
//====================================================================================================
- // 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.
-
//====================================================================================================
- @RestMethod(name=POST,
path="/testFormPostsWithMultiParamsUsingProperty",
- properties={
-
@Property(name=UrlEncodingSerializer.URLENC_expandedParams, value="true"),
- @Property(name=UrlEncodingParser.URLENC_expandedParams,
value="true")
- }
- )
- public DTOs.B testFormPostsWithMultiParamsViaProperty(@Body DTOs.B
content) throws Exception {
- return content;
- }
-
-
//====================================================================================================
- // 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.
-
//====================================================================================================
- @RestMethod(name=POST,
path="/testFormPostsWithMultiParamsUsingAnnotation")
- public DTOs.C testFormPostsWithMultiParamsUsingAnnotation(@Body DTOs.C
content) throws Exception {
- return content;
- }
-}
diff --git
a/juneau-microservice/juneau-microservice-test/src/main/java/org/apache/juneau/rest/test/Root.java
b/juneau-microservice/juneau-microservice-test/src/main/java/org/apache/juneau/rest/test/Root.java
index 119996e..dfabcf8 100644
---
a/juneau-microservice/juneau-microservice-test/src/main/java/org/apache/juneau/rest/test/Root.java
+++
b/juneau-microservice/juneau-microservice-test/src/main/java/org/apache/juneau/rest/test/Root.java
@@ -56,7 +56,6 @@ import org.apache.juneau.rest.helper.*;
OnPreCallResource.class,
OptionsWithoutNlsResource.class,
OverlappingMethodsResource.class,
- ParamsResource.class,
ParsersResource.class,
PathResource.class,
PathsResource.class,
diff --git
a/juneau-microservice/juneau-microservice-test/src/test/java/org/apache/juneau/rest/test/ParamsTest.java
b/juneau-microservice/juneau-microservice-test/src/test/java/org/apache/juneau/rest/test/ParamsTest.java
deleted file mode 100644
index aad3185..0000000
---
a/juneau-microservice/juneau-microservice-test/src/test/java/org/apache/juneau/rest/test/ParamsTest.java
+++ /dev/null
@@ -1,255 +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.rest.test;
-
-import static org.junit.Assert.*;
-
-
-import org.apache.http.entity.*;
-import org.apache.juneau.*;
-import org.apache.juneau.rest.client.*;
-import org.junit.*;
-
-public class ParamsTest extends RestTestcase {
-
- private static String URL = "/testParams";
-
-
-
//====================================================================================================
- // @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();
- }
-
-
//====================================================================================================
- // 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();
- }
-}
diff --git
a/juneau-microservice/juneau-microservice-test/src/test/java/org/apache/juneau/rest/test/_TestSuite.java
b/juneau-microservice/juneau-microservice-test/src/test/java/org/apache/juneau/rest/test/_TestSuite.java
index 724cf8d..c2a802a 100644
---
a/juneau-microservice/juneau-microservice-test/src/test/java/org/apache/juneau/rest/test/_TestSuite.java
+++
b/juneau-microservice/juneau-microservice-test/src/test/java/org/apache/juneau/rest/test/_TestSuite.java
@@ -49,7 +49,6 @@ import org.junit.runners.Suite.*;
OnPreCallTest.class,
OptionsWithoutNlsTest.class,
OverlappingMethodsTest.class,
- ParamsTest.class,
ParsersTest.class,
PathsTest.class,
PathTest.class,
diff --git
a/juneau-rest/juneau-rest-server/src/test/java/org/apache/juneau/rest/annotation/BodyAnnotationTest.java
b/juneau-rest/juneau-rest-server/src/test/java/org/apache/juneau/rest/annotation/BodyAnnotationTest.java
index c343f87..ee70efb 100644
---
a/juneau-rest/juneau-rest-server/src/test/java/org/apache/juneau/rest/annotation/BodyAnnotationTest.java
+++
b/juneau-rest/juneau-rest-server/src/test/java/org/apache/juneau/rest/annotation/BodyAnnotationTest.java
@@ -21,7 +21,9 @@ import org.apache.juneau.internal.*;
import org.apache.juneau.json.*;
import org.apache.juneau.rest.mock.*;
import org.apache.juneau.rest.testutils.*;
+import org.apache.juneau.rest.testutils.DTOs;
import org.apache.juneau.uon.*;
+import org.apache.juneau.urlencoding.*;
import org.junit.*;
import org.junit.runners.*;
@@ -669,4 +671,91 @@ public class BodyAnnotationTest {
f.request("POST",
"?p1=p3&p2=4").body("{p1:'p1',p2:2}").json().execute().assertBody("bean=[{p1:'p1',p2:2}],qp1=[p3],qp2=[4],hqp1=[true],hqp2=[true]");
f.request("POST",
"?p1=p3&p2=4").body("{}").json().execute().assertBody("bean=[{p2:0}],qp1=[p3],qp2=[4],hqp1=[true],hqp2=[true]");
}
+
+
+
//====================================================================================================
+ // Test multi-part parameter keys on bean properties of type
array/Collection (i.e. &key=val1,&key=val2)
+ // using @UrlEncoding(expandedParams=true) annotation on bean.
+ // A simple round-trip test to verify that both serializing and parsing
works.
+
//====================================================================================================
+
@RestResource(serializers=UrlEncodingSerializer.class,parsers=UrlEncodingParser.class)
+ public static class G {
+ @RestMethod(name=POST)
+ public DTOs.C g(@Body DTOs.C content) throws Exception {
+ return content;
+ }
+ }
+ static MockRest g = MockRest.create(G.class);
+
+ @Test
+ public void g01() throws Exception {
+ 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))";
+ g.request("POST",
"/").body(in).urlEnc().execute().assertBody(in);
+ }
+
+
+
//====================================================================================================
+ // 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.
+
//====================================================================================================
+
@RestResource(serializers=UrlEncodingSerializer.class,parsers=UrlEncodingParser.class)
+ public static class H {
+ @RestMethod(name=POST,
+ properties={
+
@Property(name=UrlEncodingSerializer.URLENC_expandedParams, value="true"),
+
@Property(name=UrlEncodingParser.URLENC_expandedParams, value="true")
+ }
+ )
+ public DTOs.B g(@Body DTOs.B content) throws Exception {
+ return content;
+ }
+ }
+ static MockRest h = MockRest.create(H.class);
+
+ @Test
+ public void h01() throws Exception {
+ 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))";
+ h.request("POST",
"/").body(in).urlEnc().execute().assertBody(in);
+ }
}
diff --git
a/juneau-rest/juneau-rest-server/src/test/java/org/apache/juneau/rest/annotation/HasFormDataAnnotationTest.java
b/juneau-rest/juneau-rest-server/src/test/java/org/apache/juneau/rest/annotation/HasFormDataAnnotationTest.java
new file mode 100644
index 0000000..4d894a1
--- /dev/null
+++
b/juneau-rest/juneau-rest-server/src/test/java/org/apache/juneau/rest/annotation/HasFormDataAnnotationTest.java
@@ -0,0 +1,58 @@
+//
***************************************************************************************************************************
+// * 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.annotation;
+
+import static org.apache.juneau.http.HttpMethodName.*;
+
+import org.apache.juneau.rest.*;
+import org.apache.juneau.rest.mock.*;
+import org.junit.*;
+import org.junit.runners.*;
+
+/**
+ * Tests related to @HasFormData annotation.
+ */
+@FixMethodOrder(MethodSorters.NAME_ASCENDING)
+@SuppressWarnings("javadoc")
+public class HasFormDataAnnotationTest {
+
+
//====================================================================================================
+ // Simple tests
+
//====================================================================================================
+ @RestResource
+ public static class A {
+ @RestMethod(name=POST)
+ public String post(RestRequest req, @HasFormData("p1") boolean
p1, @HasFormData("p2") Boolean p2) throws Exception {
+ RequestFormData f = req.getFormData();
+ return
"p1=["+p1+","+f.containsKey("p1")+"],p2=["+p2+","+f.containsKey("p2")+"]";
+ }
+
+ }
+ static MockRest a = MockRest.create(A.class);
+
+ @Test
+ public void a01_post() throws Exception {
+ a.request("POST",
"").body("p1=p1&p2=2").execute().assertBody("p1=[true,true],p2=[true,true]");
+ a.request("POST",
"").body("p1&p2").execute().assertBody("p1=[true,true],p2=[true,true]");
+ a.request("POST",
"").body("p1=&p2=").execute().assertBody("p1=[true,true],p2=[true,true]");
+ a.request("POST",
"/").execute().assertBody("p1=[false,false],p2=[false,false]");
+ a.request("POST",
"").body("p1").execute().assertBody("p1=[true,true],p2=[false,false]");
+ a.request("POST",
"").body("p1=").execute().assertBody("p1=[true,true],p2=[false,false]");
+ a.request("POST",
"").body("p2").execute().assertBody("p1=[false,false],p2=[true,true]");
+ a.request("POST",
"").body("p2=").execute().assertBody("p1=[false,false],p2=[true,true]");
+ a.request("POST",
"").body("p1=foo&p2").execute().assertBody("p1=[true,true],p2=[true,true]");
+ a.request("POST",
"").body("p1&p2=1").execute().assertBody("p1=[true,true],p2=[true,true]");
+ String x = "a%2Fb%25c%3Dd+e"; // [x/y%z=a+b]
+ a.request("POST",
"").body("p1="+x+"&p2=1").execute().assertBody("p1=[true,true],p2=[true,true]");
+ }
+}
diff --git
a/juneau-rest/juneau-rest-server/src/test/java/org/apache/juneau/rest/annotation/HasQueryAnnotationTest.java
b/juneau-rest/juneau-rest-server/src/test/java/org/apache/juneau/rest/annotation/HasQueryAnnotationTest.java
new file mode 100644
index 0000000..df7ad30
--- /dev/null
+++
b/juneau-rest/juneau-rest-server/src/test/java/org/apache/juneau/rest/annotation/HasQueryAnnotationTest.java
@@ -0,0 +1,77 @@
+//
***************************************************************************************************************************
+// * 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.annotation;
+
+import static org.apache.juneau.http.HttpMethodName.*;
+
+import org.apache.juneau.rest.*;
+import org.apache.juneau.rest.mock.*;
+import org.junit.*;
+import org.junit.runners.*;
+
+/**
+ * Tests related to @HasQuery annotation.
+ */
+@FixMethodOrder(MethodSorters.NAME_ASCENDING)
+@SuppressWarnings("javadoc")
+public class HasQueryAnnotationTest {
+
+
//====================================================================================================
+ // Simple tests
+
//====================================================================================================
+ @RestResource
+ public static class A {
+ @RestMethod(name=GET)
+ public String get(RestRequest req, @HasQuery("p1") boolean p1,
@HasQuery("p2") Boolean p2) throws Exception {
+ RequestQuery q = req.getQuery();
+ return
"p1=["+p1+","+q.containsKey("p1")+"],p2=["+p2+","+q.containsKey("p2")+"]";
+ }
+ @RestMethod(name=POST)
+ public String post(RestRequest req, @HasQuery("p1") boolean p1,
@HasQuery("p2") Boolean p2) throws Exception {
+ RequestQuery q = req.getQuery();
+ return
"p1=["+p1+","+q.containsKey("p1")+"],p2=["+p2+","+q.containsKey("p2")+"]";
+ }
+ }
+ static MockRest a = MockRest.create(A.class);
+
+ @Test
+ public void a01_get() throws Exception {
+ a.request("GET",
"?p1=p1&p2=2").execute().assertBody("p1=[true,true],p2=[true,true]");
+ a.request("GET",
"?p1&p2").execute().assertBody("p1=[true,true],p2=[true,true]");
+ a.request("GET",
"?p1=&p2=").execute().assertBody("p1=[true,true],p2=[true,true]");
+ a.request("GET",
"/").execute().assertBody("p1=[false,false],p2=[false,false]");
+ a.request("GET",
"?p1").execute().assertBody("p1=[true,true],p2=[false,false]");
+ a.request("GET",
"?p1=").execute().assertBody("p1=[true,true],p2=[false,false]");
+ a.request("GET",
"?p2").execute().assertBody("p1=[false,false],p2=[true,true]");
+ a.request("GET",
"?p2=").execute().assertBody("p1=[false,false],p2=[true,true]");
+ a.request("GET",
"?p1=foo&p2").execute().assertBody("p1=[true,true],p2=[true,true]");
+ a.request("GET",
"?p1&p2=1").execute().assertBody("p1=[true,true],p2=[true,true]");
+ String x = "a%2Fb%25c%3Dd+e"; // [x/y%z=a+b]
+ a.request("GET",
"?p1="+x+"&p2=1").execute().assertBody("p1=[true,true],p2=[true,true]");
+ }
+ @Test
+ public void a02_post() throws Exception {
+ a.request("POST",
"?p1=p1&p2=2").execute().assertBody("p1=[true,true],p2=[true,true]");
+ a.request("POST",
"?p1&p2").execute().assertBody("p1=[true,true],p2=[true,true]");
+ a.request("POST",
"?p1=&p2=").execute().assertBody("p1=[true,true],p2=[true,true]");
+ a.request("POST",
"/").execute().assertBody("p1=[false,false],p2=[false,false]");
+ a.request("POST",
"?p1").execute().assertBody("p1=[true,true],p2=[false,false]");
+ a.request("POST",
"?p1=").execute().assertBody("p1=[true,true],p2=[false,false]");
+ a.request("POST",
"?p2").execute().assertBody("p1=[false,false],p2=[true,true]");
+ a.request("POST",
"?p2=").execute().assertBody("p1=[false,false],p2=[true,true]");
+ a.request("POST",
"?p1=foo&p2").execute().assertBody("p1=[true,true],p2=[true,true]");
+ a.request("POST",
"?p1&p2=1").execute().assertBody("p1=[true,true],p2=[true,true]");
+ String x = "a%2Fb%25c%3Dd+e"; // [x/y%z=a+b]
+ a.request("POST",
"?p1="+x+"&p2=1").execute().assertBody("p1=[true,true],p2=[true,true]");
+ }
+}
--
To stop receiving notification emails like this one, please contact
[email protected].