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 Tue, 28 Aug 2018 19:54:27 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 f6d2ad4  Tests.
f6d2ad4 is described below

commit f6d2ad461de9ad9a3121d4226a62805c1a524e2d
Author: JamesBognar <jamesbognar@apache.org>
AuthorDate: Tue Aug 28 15:54:14 2018 -0400

    Tests.
---
 juneau-rest/juneau-rest-client/pom.xml             |  7 +++
 .../rest/client/remote/FormDataAnnotationTest.java | 61 +++++++++++++++++++++
 .../rest/client/remote/HeaderAnnotationTest.java   | 63 ++++++++++++++++++++++
 .../rest/client/remote/PathAnnotationTest.java     | 27 ++++++++++
 .../rest/client/remote/QueryAnnotationTest.java    | 61 +++++++++++++++++++++
 5 files changed, 219 insertions(+)

diff --git a/juneau-rest/juneau-rest-client/pom.xml b/juneau-rest/juneau-rest-client/pom.xml
index 13329d4..d19aee1 100644
--- a/juneau-rest/juneau-rest-client/pom.xml
+++ b/juneau-rest/juneau-rest-client/pom.xml
@@ -57,6 +57,13 @@
 			<scope>test</scope>
 		</dependency>
 		<dependency>
+			<groupId>org.apache.juneau</groupId>
+			<artifactId>juneau-rest-server</artifactId>
+			<version>${project.version}</version>
+			<type>test-jar</type>
+			<scope>test</scope>
+		</dependency>
+		<dependency>
 			<groupId>javax.servlet</groupId>
 			<artifactId>javax.servlet-api</artifactId>
 			<scope>test</scope>
diff --git a/juneau-rest/juneau-rest-client/src/test/java/org/apache/juneau/rest/client/remote/FormDataAnnotationTest.java
b/juneau-rest/juneau-rest-client/src/test/java/org/apache/juneau/rest/client/remote/FormDataAnnotationTest.java
index c6b8d7a..dd49872 100644
--- a/juneau-rest/juneau-rest-client/src/test/java/org/apache/juneau/rest/client/remote/FormDataAnnotationTest.java
+++ b/juneau-rest/juneau-rest-client/src/test/java/org/apache/juneau/rest/client/remote/FormDataAnnotationTest.java
@@ -26,6 +26,7 @@ import org.apache.juneau.http.annotation.Header;
 import org.apache.juneau.rest.annotation.*;
 import org.apache.juneau.rest.client.*;
 import org.apache.juneau.rest.mock.*;
+import org.apache.juneau.rest.testutils.*;
 import org.apache.juneau.utils.*;
 import org.junit.*;
 import org.junit.runners.*;
@@ -968,4 +969,64 @@ public class FormDataAnnotationTest {
 		assertEquals("{x:'1'}", hr.postH03("1"));
 		try { hr.postH03(null); fail(); } catch (Exception e) { assertContains(e, "Required value
not provided."); }
 	}
+
+	//=================================================================================================================
+	// @FormData(skipIfEmpty)
+	//=================================================================================================================
+
+	@RestResource
+	public static class I {
+		@RestMethod
+		public String post(@FormData("*") ObjectMap m) {
+			return m.toString();
+		}
+	}
+	private static MockRest i = MockRest.create(I.class);
+
+	@RemoteResource
+	public static interface IR {
+		@RemoteMethod(path="/") String postI01(@FormData(name="x",allowEmptyValue=true) String
b);
+		@RemoteMethod(path="/") String postI02(@FormData(name="x",allowEmptyValue=true,skipIfEmpty=false)
String b);
+		@RemoteMethod(path="/") String postI03(@FormData(name="x",skipIfEmpty=true) String b);
+	}
+
+	private static IR ir = RestClient.create().mockHttpConnection(i).build().getRemoteResource(IR.class);
+
+	@Test
+	public void h01_skipIfEmpty_default() throws Exception {
+		assertEquals("{x:''}", ir.postI01(""));
+	}
+	@Test
+	public void h02_skipIfEmpty_false() throws Exception {
+		assertEquals("{x:''}", ir.postI02(""));
+	}
+	@Test
+	public void h03_skipIfEmpty_true() throws Exception {
+		assertEquals("{}", ir.postI03(""));
+	}
+
+	//=================================================================================================================
+	// @FormData(serializer)
+	//=================================================================================================================
+
+	@RestResource
+	public static class J {
+		@RestMethod
+		public String post(@FormData("*") ObjectMap m) {
+			return m.toString();
+		}
+	}
+	private static MockRest j = MockRest.create(J.class);
+
+	@RemoteResource
+	public static interface JR {
+		@RemoteMethod(path="/") String postJ01(@FormData(name="x",serializer=XPartSerializer.class)
String b);
+	}
+
+	private static JR jr = RestClient.create().mockHttpConnection(j).build().getRemoteResource(JR.class);
+
+	@Test
+	public void j01_serializer() throws Exception {
+		assertEquals("{x:'xXx'}", jr.postJ01("X"));
+	}
 }
diff --git a/juneau-rest/juneau-rest-client/src/test/java/org/apache/juneau/rest/client/remote/HeaderAnnotationTest.java
b/juneau-rest/juneau-rest-client/src/test/java/org/apache/juneau/rest/client/remote/HeaderAnnotationTest.java
index e75854e..7cb54c9 100644
--- a/juneau-rest/juneau-rest-client/src/test/java/org/apache/juneau/rest/client/remote/HeaderAnnotationTest.java
+++ b/juneau-rest/juneau-rest-client/src/test/java/org/apache/juneau/rest/client/remote/HeaderAnnotationTest.java
@@ -25,6 +25,7 @@ import org.apache.juneau.http.annotation.*;
 import org.apache.juneau.rest.annotation.*;
 import org.apache.juneau.rest.client.*;
 import org.apache.juneau.rest.mock.*;
+import org.apache.juneau.rest.testutils.*;
 import org.apache.juneau.utils.*;
 import org.junit.*;
 import org.junit.runners.*;
@@ -913,4 +914,66 @@ public class HeaderAnnotationTest {
 		assertEquals("{x:'1'}", hr.getH03("1"));
 		try { hr.getH03(null); fail(); } catch (Exception e) { assertContains(e, "Required value
not provided."); }
 	}
+
+	//=================================================================================================================
+	// @Header(skipIfEmpty)
+	//=================================================================================================================
+
+	@RestResource
+	public static class I {
+		@RestMethod
+		public String get(@Header("*") ObjectMap m) {
+			m.removeAll("Accept-Encoding","Connection","Host","User-Agent");
+			return m.toString();
+		}
+	}
+	private static MockRest i = MockRest.create(I.class);
+
+	@RemoteResource
+	public static interface IR {
+		@RemoteMethod(path="/") String getI01(@Header(name="x",allowEmptyValue=true) String b);
+		@RemoteMethod(path="/") String getI02(@Header(name="x",allowEmptyValue=true,skipIfEmpty=false)
String b);
+		@RemoteMethod(path="/") String getI03(@Header(name="x",skipIfEmpty=true) String b);
+	}
+
+	private static IR ir = RestClient.create().mockHttpConnection(i).build().getRemoteResource(IR.class);
+
+	@Test
+	public void h01_skipIfEmpty_default() throws Exception {
+		assertEquals("{x:''}", ir.getI01(""));
+	}
+	@Test
+	public void h02_skipIfEmpty_false() throws Exception {
+		assertEquals("{x:''}", ir.getI02(""));
+	}
+	@Test
+	public void h03_skipIfEmpty_true() throws Exception {
+		assertEquals("{}", ir.getI03(""));
+	}
+
+	//=================================================================================================================
+	// @Header(serializer)
+	//=================================================================================================================
+
+	@RestResource
+	public static class J {
+		@RestMethod
+		public String get(@Header("*") ObjectMap m) {
+			m.removeAll("Accept-Encoding","Connection","Host","User-Agent");
+			return m.toString();
+		}
+	}
+	private static MockRest j = MockRest.create(J.class);
+
+	@RemoteResource
+	public static interface JR {
+		@RemoteMethod(path="/") String getJ01(@Header(name="x",serializer=XPartSerializer.class)
String b);
+	}
+
+	private static JR jr = RestClient.create().mockHttpConnection(j).build().getRemoteResource(JR.class);
+
+	@Test
+	public void j01_serializer() throws Exception {
+		assertEquals("{x:'xXx'}", jr.getJ01("X"));
+	}
 }
diff --git a/juneau-rest/juneau-rest-client/src/test/java/org/apache/juneau/rest/client/remote/PathAnnotationTest.java
b/juneau-rest/juneau-rest-client/src/test/java/org/apache/juneau/rest/client/remote/PathAnnotationTest.java
index 5a40045..ecf25d1 100644
--- a/juneau-rest/juneau-rest-client/src/test/java/org/apache/juneau/rest/client/remote/PathAnnotationTest.java
+++ b/juneau-rest/juneau-rest-client/src/test/java/org/apache/juneau/rest/client/remote/PathAnnotationTest.java
@@ -25,6 +25,7 @@ import org.apache.juneau.http.annotation.*;
 import org.apache.juneau.rest.annotation.*;
 import org.apache.juneau.rest.client.*;
 import org.apache.juneau.rest.mock.*;
+import org.apache.juneau.rest.testutils.*;
 import org.apache.juneau.utils.*;
 import org.junit.*;
 import org.junit.runners.*;
@@ -815,4 +816,30 @@ public class PathAnnotationTest {
 	public void h01_required_default() throws Exception {
 		try { hr.getH01(null); fail(); } catch (Exception e) { assertContains(e, "Required value
not provided."); }
 	}
+
+	//=================================================================================================================
+	// @Path(serializer)
+	//=================================================================================================================
+
+	@RestResource
+	public static class J {
+		@RestMethod(path="/{x}")
+		public String get(@Path("*") ObjectMap m) {
+			m.removeAll("/*","/**");
+			return m.toString();
+		}
+	}
+	private static MockRest j = MockRest.create(J.class);
+
+	@RemoteResource
+	public static interface JR {
+		@RemoteMethod(path="/{x}") String getJ01(@Path(name="x",serializer=XPartSerializer.class)
String b);
+	}
+
+	private static JR jr = RestClient.create().mockHttpConnection(j).build().getRemoteResource(JR.class);
+
+	@Test
+	public void j01_serializer() throws Exception {
+		assertEquals("{x:'xXx'}", jr.getJ01("X"));
+	}
 }
diff --git a/juneau-rest/juneau-rest-client/src/test/java/org/apache/juneau/rest/client/remote/QueryAnnotationTest.java
b/juneau-rest/juneau-rest-client/src/test/java/org/apache/juneau/rest/client/remote/QueryAnnotationTest.java
index 7552389..af93f36 100644
--- a/juneau-rest/juneau-rest-client/src/test/java/org/apache/juneau/rest/client/remote/QueryAnnotationTest.java
+++ b/juneau-rest/juneau-rest-client/src/test/java/org/apache/juneau/rest/client/remote/QueryAnnotationTest.java
@@ -27,6 +27,7 @@ import org.apache.juneau.rest.*;
 import org.apache.juneau.rest.annotation.*;
 import org.apache.juneau.rest.client.*;
 import org.apache.juneau.rest.mock.*;
+import org.apache.juneau.rest.testutils.*;
 import org.apache.juneau.utils.*;
 import org.junit.*;
 import org.junit.runners.*;
@@ -967,4 +968,64 @@ public class QueryAnnotationTest {
 		assertEquals("{x:'1'}", hr.getH03("1"));
 		try { hr.getH03(null); fail(); } catch (Exception e) { assertContains(e, "Required value
not provided."); }
 	}
+
+	//=================================================================================================================
+	// @Query(skipIfEmpty)
+	//=================================================================================================================
+
+	@RestResource
+	public static class I {
+		@RestMethod
+		public String get(@Query("*") ObjectMap m) {
+			return m.toString();
+		}
+	}
+	private static MockRest i = MockRest.create(I.class);
+
+	@RemoteResource
+	public static interface IR {
+		@RemoteMethod(path="/") String getI01(@Query(name="x",allowEmptyValue=true) String b);
+		@RemoteMethod(path="/") String getI02(@Query(name="x",allowEmptyValue=true,skipIfEmpty=false)
String b);
+		@RemoteMethod(path="/") String getI03(@Query(name="x",skipIfEmpty=true) String b);
+	}
+
+	private static IR ir = RestClient.create().mockHttpConnection(i).build().getRemoteResource(IR.class);
+
+	@Test
+	public void h01_skipIfEmpty_default() throws Exception {
+		assertEquals("{x:''}", ir.getI01(""));
+	}
+	@Test
+	public void h02_skipIfEmpty_false() throws Exception {
+		assertEquals("{x:''}", ir.getI02(""));
+	}
+	@Test
+	public void h03_skipIfEmpty_true() throws Exception {
+		assertEquals("{}", ir.getI03(""));
+	}
+
+	//=================================================================================================================
+	// @Query(serializer)
+	//=================================================================================================================
+
+	@RestResource
+	public static class J {
+		@RestMethod
+		public String get(@Query("*") ObjectMap m) {
+			return m.toString();
+		}
+	}
+	private static MockRest j = MockRest.create(J.class);
+
+	@RemoteResource
+	public static interface JR {
+		@RemoteMethod(path="/") String getJ01(@Query(name="x",serializer=XPartSerializer.class)
String b);
+	}
+
+	private static JR jr = RestClient.create().mockHttpConnection(j).build().getRemoteResource(JR.class);
+
+	@Test
+	public void j01_serializer() throws Exception {
+		assertEquals("{x:'xXx'}", jr.getJ01("X"));
+	}
 }


Mime
View raw message