juneau-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jamesbog...@apache.org
Subject [juneau] branch master updated: Tests.
Date Wed, 09 May 2018 23:47:43 GMT
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 63a6691  Tests.
63a6691 is described below

commit 63a66918f3af0c203fdbf1d44b11f73258ab8230
Author: JamesBognar <jamesbognar@apache.org>
AuthorDate: Wed May 9 19:47:24 2018 -0400

    Tests.
---
 .../juneau/rest/test/NoParserInputResource.java    |  58 -------
 .../java/org/apache/juneau/rest/test/Root.java     |   1 -
 .../apache/juneau/rest/test/NoParserInputTest.java |  52 -------
 .../org/apache/juneau/rest/test/_TestSuite.java    |   1 -
 .../java/org/apache/juneau/rest/util/MockRest.java |  56 +++++++
 .../juneau/rest/util/MockServletRequest.java       |  25 ++++
 .../src/test/java/org/apache/juneau/rest/DTOs.java | 139 +++++++++++++++++
 .../apache/juneau/rest/annotation/BodyTest.java    | 166 +++++++++++----------
 8 files changed, 309 insertions(+), 189 deletions(-)

diff --git a/juneau-microservice/juneau-microservice-test/src/main/java/org/apache/juneau/rest/test/NoParserInputResource.java
b/juneau-microservice/juneau-microservice-test/src/main/java/org/apache/juneau/rest/test/NoParserInputResource.java
deleted file mode 100644
index 6676015..0000000
--- a/juneau-microservice/juneau-microservice-test/src/main/java/org/apache/juneau/rest/test/NoParserInputResource.java
+++ /dev/null
@@ -1,58 +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.internal.IOUtils.*;
-import static org.apache.juneau.http.HttpMethodName.*;
-
-import java.io.*;
-
-import org.apache.juneau.plaintext.*;
-import org.apache.juneau.rest.*;
-import org.apache.juneau.rest.annotation.*;
-
-/**
- * JUnit automated testcase resource.
- */
-@RestResource(
-	path="/testNoParserInput",
-	serializers=PlainTextSerializer.class
-)
-public class NoParserInputResource extends RestServlet {
-	private static final long serialVersionUID = 1L;
-
-	//====================================================================================================
-	// @Body annotated InputStream.
-	//====================================================================================================
-	@RestMethod(name=PUT, path="/testInputStream")
-	public String testInputStream(@Body InputStream in) throws Exception {
-		return read(in);
-	}
-
-	//====================================================================================================
-	// @Body annotated Reader.
-	//====================================================================================================
-	@RestMethod(name=PUT, path="/testReader")
-	public String testReader(@Body Reader in) throws Exception {
-		return read(in);
-	}
-
-	//====================================================================================================
-	// @Body annotated PushbackReader.
-	// This should always fail since the servlet reader is not a pushback reader.
-	//====================================================================================================
-	@RestMethod(name=PUT, path="/testPushbackReader")
-	public String testPushbackReader(@Body PushbackReader in) throws Exception {
-		return read(in);
-	}
-}
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 b5fc1f4..ed3cdb1 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
@@ -54,7 +54,6 @@ import org.apache.juneau.rest.helper.*;
 		MessagesResource.class,
 		NlsResource.class,
 		NlsPropertyResource.class,
-		NoParserInputResource.class,
 		OnPostCallResource.class,
 		OnPreCallResource.class,
 		OptionsWithoutNlsResource.class,
diff --git a/juneau-microservice/juneau-microservice-test/src/test/java/org/apache/juneau/rest/test/NoParserInputTest.java
b/juneau-microservice/juneau-microservice-test/src/test/java/org/apache/juneau/rest/test/NoParserInputTest.java
deleted file mode 100644
index fa0ce0a..0000000
--- a/juneau-microservice/juneau-microservice-test/src/test/java/org/apache/juneau/rest/test/NoParserInputTest.java
+++ /dev/null
@@ -1,52 +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.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.
-	//====================================================================================================
-	@Test
-	public void testPushbackReader() throws Exception {
-		String r = plainTextClient.doPut(URL + "/testPushbackReader", "foo").getResponseAsString();
-		assertEquals("foo", r);
-	}
-}
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 3e44f10..c66cba4 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
@@ -47,7 +47,6 @@ import org.junit.runners.Suite.*;
 	MessagesTest.class,
 	NlsPropertyTest.class,
 	NlsTest.class,
-	NoParserInputTest.class,
 	OnPostCallTest.class,
 	OnPreCallTest.class,
 	OptionsWithoutNlsTest.class,
diff --git a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/util/MockRest.java
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/util/MockRest.java
new file mode 100644
index 0000000..452e6fa
--- /dev/null
+++ b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/util/MockRest.java
@@ -0,0 +1,56 @@
+// ***************************************************************************************************************************
+// * 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.util;
+
+import java.util.*;
+
+import org.apache.juneau.rest.*;
+
+/**
+ * Creates a mocked interface against a REST resource class.
+ */
+public class MockRest {
+	private static Map<Class<?>,RestContext> CONTEXTS = new HashMap<>();
+
+	private final RestContext rc;
+	
+	private MockRest(Class<?> c) throws Exception {
+		if (! CONTEXTS.containsKey(c))
+			CONTEXTS.put(c, RestContext.create(c.newInstance()).build());
+		rc = CONTEXTS.get(c);
+	}
+	
+	/**
+	 * Create a new mock REST interface 
+	 * 
+	 * @param c The REST class.
+	 * @return A new mock interface.
+	 * @throws Exception
+	 */
+	public static MockRest create(Class<?> c) throws Exception {
+		return new MockRest(c);
+	}
+	
+	/**
+	 * Performs a REST request against the REST interface.
+	 * 
+	 * @param method The HTTP method
+	 * @param path The URI path.
+	 * @param pathArgs Optional path arguments.
+	 * @return A new servlet request.
+	 * @throws Exception
+	 */
+	public MockServletRequest request(String method, String path, Object...pathArgs) throws
Exception {
+		return MockServletRequest.create(method, path, pathArgs).restContext(rc);
+	}
+}
diff --git a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/util/MockServletRequest.java
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/util/MockServletRequest.java
index c0691fc..54da1c2 100644
--- a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/util/MockServletRequest.java
+++ b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/util/MockServletRequest.java
@@ -20,6 +20,7 @@ import javax.servlet.*;
 import javax.servlet.http.*;
 
 import org.apache.juneau.internal.*;
+import org.apache.juneau.rest.*;
 
 /**
  * An implementation of {@link HttpServletRequest} for testing purposes.
@@ -59,6 +60,7 @@ public class MockServletRequest implements HttpServletRequest {
 	private String requestURI = "";
 	private String servletPath = "";
 	private HttpSession httpSession = MockHttpSession.create();
+	private RestContext restContext;
 	
 	/**
 	 * Creates a new servlet request.
@@ -101,6 +103,29 @@ public class MockServletRequest implements HttpServletRequest {
 	/**
 	 * Fluent setter.
 	 * 
+	 * @param restContext The rest context.
+	 * @return This object (for method chaining).
+	 */
+	public MockServletRequest restContext(RestContext restContext) {
+		this.restContext = restContext;
+		return this;
+	}
+	
+	/**
+	 * Executes this request and returns the response object.
+	 * 
+	 * @return The response object.
+	 * @throws Exception
+	 */
+	public MockServletResponse execute() throws Exception {
+		MockServletResponse res = MockServletResponse.create();
+		restContext.getCallHandler().service(this, res);
+		return res;
+	}
+
+	/**
+	 * Fluent setter.
+	 * 
 	 * @param value The method name for this request.
 	 * @return This object (for method chaining).
 	 */
diff --git a/juneau-rest/juneau-rest-server/src/test/java/org/apache/juneau/rest/DTOs.java
b/juneau-rest/juneau-rest-server/src/test/java/org/apache/juneau/rest/DTOs.java
new file mode 100644
index 0000000..2a44524
--- /dev/null
+++ b/juneau-rest/juneau-rest-server/src/test/java/org/apache/juneau/rest/DTOs.java
@@ -0,0 +1,139 @@
+// ***************************************************************************************************************************
+// * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
agreements.  See the NOTICE file *
+// * distributed with this work for additional information regarding copyright ownership.
 The ASF licenses this file        *
+// * to you under the Apache License, Version 2.0 (the "License"); you may not use this file
except in compliance            *
+// * with the License.  You may obtain a copy of the License at                         
                                    *
+// *                                                                                    
                                    *
+// *  http://www.apache.org/licenses/LICENSE-2.0                                        
                                    *
+// *                                                                                    
                                    *
+// * Unless required by applicable law or agreed to in writing, software distributed under
the License is distributed on an  *
+// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the        *
+// * specific language governing permissions and limitations under the License.         
                                    *
+// ***************************************************************************************************************************
+package org.apache.juneau.rest;
+
+import java.util.*;
+
+import org.apache.juneau.annotation.*;
+import org.apache.juneau.urlencoding.annotation.*;
+import org.apache.juneau.utils.*;
+
+@SuppressWarnings("javadoc")
+public class DTOs {
+
+	@Bean(sort=true)
+	public static class A {
+		public String a;
+		public int b;
+		public boolean c;
+
+		public static A create() {
+			A t = new A();
+			t.a = "a";
+			t.b = 1;
+			t.c = true;
+			return t;
+		}
+
+	}
+
+	@Bean(sort=true)
+	public static class B {
+		public String[] f01;
+		public List<String> f02;
+		public int[] f03;
+		public List<Integer> f04;
+		public String[][] f05;
+		public List<String[]> f06;
+		public A[] f07;
+		public List<A> f08;
+		public A[][] f09;
+		public List<List<A>> f10;
+
+		private String[] f11;
+		private List<String> f12;
+		private int[] f13;
+		private List<Integer> f14;
+		private String[][] f15;
+		private List<String[]> f16;
+		private A[] f17;
+		private List<A> f18;
+		private A[][] f19;
+		private List<List<A>> f20;
+
+		public String[] getF11() { return f11; }
+		public List<String> getF12() { return f12; }
+		public int[] getF13() { return f13; }
+		public List<Integer> getF14() { return f14; }
+		public String[][] getF15() { return f15; }
+		public List<String[]> getF16() { return f16; }
+		public A[] getF17() { return f17; }
+		public List<A> getF18() { return f18; }
+		public A[][] getF19() { return f19; }
+		public List<List<A>> getF20() { return f20; }
+
+		public void setF11(String[] f11) { this.f11 = f11; }
+		public void setF12(List<String> f12) { this.f12 = f12; }
+		public void setF13(int[] f13) { this.f13 = f13; }
+		public void setF14(List<Integer> f14) { this.f14 = f14; }
+		public void setF15(String[][] f15) { this.f15 = f15; }
+		public void setF16(List<String[]> f16) { this.f16 = f16; }
+		public void setF17(A[] f17) { this.f17 = f17; }
+		public void setF18(List<A> f18) { this.f18 = f18; }
+		public void setF19(A[][] f19) { this.f19 = f19; }
+		public void setF20(List<List<A>> f20) { this.f20 = f20; }
+
+		static B create() {
+			B t = new B();
+			t.f01 = new String[]{"a","b"};
+			t.f02 = new AList<String>().append("c").append("d");
+			t.f03 = new int[]{1,2};
+			t.f04 = new AList<Integer>().append(3).append(4);
+			t.f05 = new String[][]{{"e","f"},{"g","h"}};
+			t.f06 = new AList<String[]>().append(new String[]{"i","j"}).append(new String[]{"k","l"});
+			t.f07 = new A[]{A.create(),A.create()};
+			t.f08 = new AList<A>().append(A.create()).append(A.create());
+			t.f09 = new A[][]{{A.create()},{A.create()}};
+			t.f10 = new AList<List<A>>().append(Arrays.asList(A.create())).append(Arrays.asList(A.create()));
+			t.setF11(new String[]{"a","b"});
+			t.setF12(new AList<String>().append("c").append("d"));
+			t.setF13(new int[]{1,2});
+			t.setF14(new AList<Integer>().append(3).append(4));
+			t.setF15(new String[][]{{"e","f"},{"g","h"}});
+			t.setF16(new AList<String[]>().append(new String[]{"i","j"}).append(new String[]{"k","l"}));
+			t.setF17(new A[]{A.create(),A.create()});
+			t.setF18(new AList<A>().append(A.create()).append(A.create()));
+			t.setF19(new A[][]{{A.create()},{A.create()}});
+			t.setF20(new AList<List<A>>().append(Arrays.asList(A.create())).append(Arrays.asList(A.create())));
+			return t;
+		}
+	}
+
+	@UrlEncoding(expandedParams=true)
+	public static class C extends B {
+		static C create() {
+			C t = new C();
+			t.f01 = new String[]{"a","b"};
+			t.f02 = new AList<String>().append("c").append("d");
+			t.f03 = new int[]{1,2};
+			t.f04 = new AList<Integer>().append(3).append(4);
+			t.f05 = new String[][]{{"e","f"},{"g","h"}};
+			t.f06 = new AList<String[]>().append(new String[]{"i","j"}).append(new String[]{"k","l"});
+			t.f07 = new A[]{A.create(),A.create()};
+			t.f08 = new AList<A>().append(A.create()).append(A.create());
+			t.f09 = new A[][]{{A.create()},{A.create()}};
+			t.f10 = new AList<List<A>>().append(Arrays.asList(A.create())).append(Arrays.asList(A.create()));
+			t.setF11(new String[]{"a","b"});
+			t.setF12(new AList<String>().append("c").append("d"));
+			t.setF13(new int[]{1,2});
+			t.setF14(new AList<Integer>().append(3).append(4));
+			t.setF15(new String[][]{{"e","f"},{"g","h"}});
+			t.setF16(new AList<String[]>().append(new String[]{"i","j"}).append(new String[]{"k","l"}));
+			t.setF17(new A[]{A.create(),A.create()});
+			t.setF18(new AList<A>().append(A.create()).append(A.create()));
+			t.setF19(new A[][]{{A.create()},{A.create()}});
+			t.setF20(new AList<List<A>>().append(Arrays.asList(A.create())).append(Arrays.asList(A.create())));
+			return t;
+		}
+	}
+}
diff --git a/juneau-rest/juneau-rest-server/src/test/java/org/apache/juneau/rest/annotation/BodyTest.java
b/juneau-rest/juneau-rest-server/src/test/java/org/apache/juneau/rest/annotation/BodyTest.java
index f4aadef..40a070f 100644
--- a/juneau-rest/juneau-rest-server/src/test/java/org/apache/juneau/rest/annotation/BodyTest.java
+++ b/juneau-rest/juneau-rest-server/src/test/java/org/apache/juneau/rest/annotation/BodyTest.java
@@ -18,11 +18,9 @@ import static org.junit.Assert.*;
 import java.io.*;
 import java.util.*;
 
-import javax.servlet.http.*;
 
 import org.apache.juneau.internal.*;
 import org.apache.juneau.json.*;
-import org.apache.juneau.rest.*;
 import org.apache.juneau.rest.util.*;
 import org.junit.*;
 import org.junit.runners.*;
@@ -34,14 +32,6 @@ import org.junit.runners.*;
 @FixMethodOrder(MethodSorters.NAME_ASCENDING)
 public class BodyTest {
 	
-	private static Map<Class<?>,RestContext> CONTEXTS = new HashMap<>();
-	
-	private static void call(Class<?> c, HttpServletRequest req, HttpServletResponse res)
throws Exception {
-		if (! CONTEXTS.containsKey(c))
-			CONTEXTS.put(c, RestContext.create(c.newInstance()).build());
-		CONTEXTS.get(c).getCallHandler().service(req, res);
-	}
-	
 	//-----------------------------------------------------------------------------------------------------------------
 	// @Body on parameter
 	//-----------------------------------------------------------------------------------------------------------------
@@ -49,34 +39,64 @@ public class BodyTest {
 	@RestResource(serializers=JsonSerializer.Simple.class, parsers=JsonParser.class)
 	public static class A {
 		
-		@RestMethod(name=PUT, path="/string")
+		@RestMethod(name=PUT, path="/String")
 		public String a01(@Body String b) {
 			return b;
 		}
 
-		@RestMethod(name=PUT, path="/integer")
+		@RestMethod(name=PUT, path="/Integer")
 		public Integer a02(@Body Integer b) {
 			return b;
 		}
 
+		@RestMethod(name=PUT, path="/int")
+		public Integer a03(@Body int b) {
+			return b;
+		}
+
+		@RestMethod(name=PUT, path="/Boolean")
+		public Boolean a04(@Body Boolean b) {
+			return b;
+		}
+
 		@RestMethod(name=PUT, path="/boolean")
-		public Boolean a03(@Body Boolean b) {
+		public Boolean a05(@Body boolean b) {
 			return b;
 		}
 
-		public static class A04 {
+		@RestMethod(name=PUT, path="/float")
+		public float a06(@Body float f) {
+			return f;
+		}
+
+		@RestMethod(name=PUT, path="/Float")
+		public Float a07(@Body Float f) {
+			return f;
+		}
+
+		public static class A11 {
 			public String f1;
 		}
 		
 		@RestMethod(name=PUT, path="/bean")
-		public A04 a04(@Body A04 b) {
+		public A11 a11(@Body A11 b) {
 			return b;
 		}
 
-		public static class A05 {
+		@RestMethod(name=PUT, path="/inputStream")
+		public String a12(@Body InputStream b) throws Exception {
+			return IOUtils.read(b);
+		}
+
+		@RestMethod(name=PUT, path="/reader")
+		public String a13(@Body Reader b) throws Exception {
+			return IOUtils.read(b);
+		}
+
+		public static class A14 {
 			String s;
 			
-			public A05(InputStream in) throws Exception {
+			public A14(InputStream in) throws Exception {
 				this.s = IOUtils.read(in);
 			}
 			
@@ -86,15 +106,15 @@ public class BodyTest {
 			}
 		}
 		
-		@RestMethod(name=PUT, path="/inputStream")
-		public A05 a05(@Body A05 b) throws Exception {
+		@RestMethod(name=PUT, path="/inputStreamTransform")
+		public A14 a14(@Body A14 b) throws Exception {
 			return b;
 		}
 
-		public static class A06 {
+		public static class A15 {
 			private String s;
 			
-			public A06(Reader in) throws Exception {
+			public A15(Reader in) throws Exception {
 				this.s = IOUtils.read(in);
 			}
 			
@@ -104,55 +124,62 @@ public class BodyTest {
 			}
 		}
 		
-		@RestMethod(name=PUT, path="/reader")
-		public A06 a06(@Body A06 b) throws Exception {
+		@RestMethod(name=PUT, path="/readerTransform")
+		public A15 a15(@Body A15 b) throws Exception {
 			return b;
 		}
 	}
-	
+
 	@Test
-	public void a01_onParameter_string() throws Exception {
-		MockServletRequest req = MockServletRequest.create("PUT", "/string").body("'foo'");
-		MockServletResponse res = MockServletResponse.create();
-		call(A.class, req, res);
-		assertEquals("'foo'", res.getBodyAsString());
+	public void a01_onParameter_String() throws Exception {
+		assertEquals("'foo'", MockRest.create(A.class).request("PUT", "/String").body("'foo'").execute().getBodyAsString());
 	}
 	@Test
-	public void a02_onParameter_integer() throws Exception {
-		MockServletRequest req = MockServletRequest.create("PUT", "/integer").body("123");
-		MockServletResponse res = MockServletResponse.create();
-		call(A.class, req, res);
-		assertEquals("123", res.getBodyAsString());
+	public void a02_onParameter_Integer() throws Exception {
+		assertEquals("123", MockRest.create(A.class).request("PUT", "/Integer").body("123").execute().getBodyAsString());
 	}
 	@Test
-	public void a03_onParameter_boolean() throws Exception {
-		MockServletRequest req = MockServletRequest.create("PUT", "/boolean").body("true");
-		MockServletResponse res = MockServletResponse.create();
-		call(A.class, req, res);
-		assertEquals("true", res.getBodyAsString());
+	public void a03_onParameter_int() throws Exception {
+		assertEquals("123", MockRest.create(A.class).request("PUT", "/int").body("123").execute().getBodyAsString());
 	}
 	@Test
-	public void a04_onParameter_bean() throws Exception {
-		MockServletRequest req = MockServletRequest.create("PUT", "/bean").body("{f1:'a'}");
-		MockServletResponse res = MockServletResponse.create();
-		call(A.class, req, res);
-		assertEquals("{f1:'a'}", res.getBodyAsString());
+	public void a04_onParameter_Boolean() throws Exception {
+		assertEquals("true", MockRest.create(A.class).request("PUT", "/Boolean").body("true").execute().getBodyAsString());
 	}
 	@Test
-	public void a05_onParameter_inputStream() throws Exception {
-		MockServletRequest req = MockServletRequest.create("PUT", "/inputStream").body("a");
-		MockServletResponse res = MockServletResponse.create();
-		call(A.class, req, res);
-		assertEquals("'a'", res.getBodyAsString());
+	public void a05_onParameter_boolean() throws Exception {
+		assertEquals("true", MockRest.create(A.class).request("PUT", "/boolean").body("true").execute().getBodyAsString());
 	}
 	@Test
-	public void a06_onParameter_reader() throws Exception {
-		MockServletRequest req = MockServletRequest.create("PUT", "/reader").body("a");
-		MockServletResponse res = MockServletResponse.create();
-		call(A.class, req, res);
-		assertEquals("'a'", res.getBodyAsString());
+	public void a06_onParameter_float() throws Exception {
+		assertEquals("1.23", MockRest.create(A.class).request("PUT", "/float").body("1.23").execute().getBodyAsString());
 	}
-
+	@Test
+	public void a07_onParameter_Float() throws Exception {
+		assertEquals("1.23", MockRest.create(A.class).request("PUT", "/Float").body("1.23").execute().getBodyAsString());
+	}
+	@Test
+	public void a11_onParameter_bean() throws Exception {
+		assertEquals("{f1:'a'}", MockRest.create(A.class).request("PUT", "/bean").body("{f1:'a'}").execute().getBodyAsString());
+	}
+	@Test
+	public void a12_onParameter_inputStream() throws Exception {
+		assertEquals("'a'", MockRest.create(A.class).request("PUT", "/inputStream").body("a").execute().getBodyAsString());
+	}
+	@Test
+	public void a13_onParameter_reader() throws Exception {
+		assertEquals("'a'", MockRest.create(A.class).request("PUT", "/reader").body("a").execute().getBodyAsString());
+	}
+	@Test
+	public void a14_onParameter_inputStreamTransform() throws Exception {
+		assertEquals("'a'", MockRest.create(A.class).request("PUT", "/inputStreamTransform").body("a").execute().getBodyAsString());
+	}
+	@Test
+	public void a15_onParameter_readerTransform() throws Exception {
+		assertEquals("'a'", MockRest.create(A.class).request("PUT", "/readerTransform").body("a").execute().getBodyAsString());
+	}
+	
+	
 	//-----------------------------------------------------------------------------------------------------------------
 	// @Body on POJO
 	//-----------------------------------------------------------------------------------------------------------------
@@ -211,7 +238,7 @@ public class BodyTest {
 			}
 		}
 		
-		@RestMethod(name=PUT, path="/inputStream")
+		@RestMethod(name=PUT, path="/inputStreamTransform")
 		public B04 b04(B04 b) throws Exception {
 			return b;
 		}
@@ -230,7 +257,7 @@ public class BodyTest {
 			}
 		}
 		
-		@RestMethod(name=PUT, path="/reader")
+		@RestMethod(name=PUT, path="/readerTransform")
 		public B05 b05(B05 b) throws Exception {
 			return b;
 		}
@@ -238,37 +265,22 @@ public class BodyTest {
 	
 	@Test
 	public void b01_onPojo_string() throws Exception {
-		MockServletRequest req = MockServletRequest.create(PUT, "/string").body("'foo'");
-		MockServletResponse res = MockServletResponse.create();
-		call(B.class, req, res);
-		assertEquals("'foo'", res.getBodyAsString());
+		assertEquals("'foo'", MockRest.create(B.class).request("PUT", "/string").body("'foo'").execute().getBodyAsString());
 	}
 	@Test
 	public void b02_onPojo_bean() throws Exception {
-		MockServletRequest req = MockServletRequest.create(PUT, "/bean").body("{f1:'a'}");
-		MockServletResponse res = MockServletResponse.create();
-		call(B.class, req, res);
-		assertEquals("{f1:'a'}", res.getBodyAsString());
+		assertEquals("{f1:'a'}", MockRest.create(B.class).request("PUT", "/bean").body("{f1:'a'}").execute().getBodyAsString());
 	}
 	@Test
 	public void b03_onPojo_beanList() throws Exception {
-		MockServletRequest req = MockServletRequest.create(PUT, "/beanList").body("[{f1:'a'}]");
-		MockServletResponse res = MockServletResponse.create();
-		call(B.class, req, res);
-		assertEquals("[{f1:'a'}]", res.getBodyAsString());
+		assertEquals("[{f1:'a'}]", MockRest.create(B.class).request("PUT", "/beanList").body("[{f1:'a'}]").execute().getBodyAsString());
 	}
 	@Test
 	public void b04_onPojo_inputStream() throws Exception {
-		MockServletRequest req = MockServletRequest.create(PUT, "/inputStream").body("a");
-		MockServletResponse res = MockServletResponse.create();
-		call(B.class, req, res);
-		assertEquals("'a'", res.getBodyAsString());
+		assertEquals("'a'", MockRest.create(B.class).request("PUT", "/inputStreamTransform").body("a").execute().getBodyAsString());
 	}
 	@Test
 	public void b05_onPojo_reader() throws Exception {
-		MockServletRequest req = MockServletRequest.create(PUT, "/reader").body("a");
-		MockServletResponse res = MockServletResponse.create();
-		call(B.class, req, res);
-		assertEquals("'a'", res.getBodyAsString());
+		assertEquals("'a'", MockRest.create(B.class).request("PUT", "/readerTransform").body("a").execute().getBodyAsString());
 	}
 }

-- 
To stop receiving notification emails like this one, please contact
jamesbognar@apache.org.

Mime
View raw message