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 Sun, 13 May 2018 19:47:38 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 6f4dcc8  Tests.
6f4dcc8 is described below

commit 6f4dcc8e849ae984349268b590a4c2b849a6095e
Author: JamesBognar <jamesbognar@apache.org>
AuthorDate: Sun May 13 15:47:24 2018 -0400

    Tests.
---
 .../juneau/rest/test/OnPostCallResource.java       | 110 -----------------
 .../apache/juneau/rest/test/OnPreCallResource.java |  96 ---------------
 .../java/org/apache/juneau/rest/test/Root.java     |   2 -
 .../apache/juneau/rest/test/OnPostCallTest.java    | 121 -------------------
 .../org/apache/juneau/rest/test/OnPreCallTest.java |  61 ----------
 .../org/apache/juneau/rest/test/_TestSuite.java    |   2 -
 .../rest/annotation/RestHookPostCallTest.java      | 133 +++++++++++++++++++++
 .../rest/annotation/RestHookPreCallTest.java       | 104 ++++++++++++++++
 8 files changed, 237 insertions(+), 392 deletions(-)

diff --git a/juneau-microservice/juneau-microservice-test/src/main/java/org/apache/juneau/rest/test/OnPostCallResource.java
b/juneau-microservice/juneau-microservice-test/src/main/java/org/apache/juneau/rest/test/OnPostCallResource.java
deleted file mode 100644
index 6ec2414..0000000
--- a/juneau-microservice/juneau-microservice-test/src/main/java/org/apache/juneau/rest/test/OnPostCallResource.java
+++ /dev/null
@@ -1,110 +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.rest.annotation.HookEvent.*;
-import static org.apache.juneau.http.HttpMethodName.*;
-
-import java.util.*;
-
-import org.apache.juneau.*;
-import org.apache.juneau.rest.*;
-import org.apache.juneau.rest.annotation.*;
-import org.apache.juneau.serializer.*;
-import org.apache.juneau.utils.*;
-
-/**
- * JUnit automated testcase resource.
- * Validates that headers
- */
-@RestResource(
-	path="/testOnPostCall",
-	serializers=OnPostCallResource.TestSerializer.class,
-	properties={
-		@Property(name="p1",value="sp1"), // Unchanged servlet-level property.
-		@Property(name="p2",value="sp2"), // Servlet-level property overridden by onPostCall.
-		@Property(name="p3",value="sp3"), // Servlet-level property overridded by method.
-		@Property(name="p4",value="sp4")  // Servlet-level property overridden by method then onPostCall.
-	}
-)
-public class OnPostCallResource extends RestServlet {
-	private static final long serialVersionUID = 1L;
-
-	public static class TestSerializer extends WriterSerializer {
-
-		public TestSerializer(PropertyStore ps) {
-			super(ps, "test/s1", "text/s1,text/s2,text/s3");
-		}
-
-		@Override /* Serializer */
-		public WriterSerializerSession createSession(SerializerSessionArgs args) {
-			return new WriterSerializerSession(args) {
-
-				@Override /* SerializerSession */
-				protected void doSerialize(SerializerPipe out, Object o) throws Exception {
-					out.getWriter().write("p1="+getProperty("p1", String.class)+",p2="+getProperty("p2",
String.class)+",p3="+getProperty("p3", String.class)+",p4="+getProperty("p4", String.class)+",p5="+getProperty("p5",
String.class)+",contentType="+getProperty("mediaType", String.class));
-				}
-
-				@Override /* SerializerSession */
-				public Map<String,String> getResponseHeaders() {
-					ObjectMap p = getProperties();
-					if (p.containsKey("Override-Content-Type"))
-						return new AMap<String,String>().append("Content-Type", p.getString("Override-Content-Type"));
-					return Collections.emptyMap();
-				}
-			};
-		}
-	}
-
-	@RestHook(POST_CALL)
-	public void onPostCall(RestRequest req, RestResponse res) {
-		RequestProperties properties = req.getProperties();
-		properties.put("p2", "xp2");
-		properties.put("p4", "xp4");
-		properties.put("p5", "xp5"); // New property
-		String overrideAccept = req.getHeader("Override-Accept");
-		if (overrideAccept != null)
-			req.getHeaders().put("Accept", overrideAccept);
-		String overrideContentType = req.getHeader("Override-Content-Type");
-		if (overrideContentType != null)
-			properties.put("Override-Content-Type", overrideContentType);
-	}
-
-
-	//====================================================================================================
-	// Test1 - Properties overridden via properties annotation.
-	//====================================================================================================
-	@RestMethod(name=PUT, path="/testPropertiesOverridenByAnnotation",
-		properties={
-			@Property(name="p3",value="mp3"),
-			@Property(name="p4",value="mp4")
-		},
-		defaultRequestHeaders="Accept: text/s2"
-	)
-	public String testPropertiesOverridenByAnnotation() {
-		return "";
-	}
-
-	//====================================================================================================
-	// Test2 - Properties overridden programmatically.
-	//====================================================================================================
-	@RestMethod(name=PUT, path="/testPropertiesOverriddenProgramatically")
-	public String testPropertiesOverriddenProgramatically(RestRequest req, RequestProperties
properties) throws Exception {
-		properties.put("p3", "pp3");
-		properties.put("p4", "pp4");
-		String accept = req.getHeader("Accept");
-		if (accept == null || accept.isEmpty())
-			req.getHeaders().put("Accept", "text/s2");
-		return "";
-	}
-}
diff --git a/juneau-microservice/juneau-microservice-test/src/main/java/org/apache/juneau/rest/test/OnPreCallResource.java
b/juneau-microservice/juneau-microservice-test/src/main/java/org/apache/juneau/rest/test/OnPreCallResource.java
deleted file mode 100644
index b341256..0000000
--- a/juneau-microservice/juneau-microservice-test/src/main/java/org/apache/juneau/rest/test/OnPreCallResource.java
+++ /dev/null
@@ -1,96 +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.rest.annotation.HookEvent.*;
-import static org.apache.juneau.http.HttpMethodName.*;
-
-import org.apache.juneau.*;
-import org.apache.juneau.parser.*;
-import org.apache.juneau.plaintext.*;
-import org.apache.juneau.rest.*;
-import org.apache.juneau.rest.annotation.*;
-
-/**
- * JUnit automated testcase resource.
- * Validates that headers
- */
-@RestResource(
-	path="/testOnPreCall",
-	parsers=OnPreCallResource.TestParserA.class,
-	serializers=PlainTextSerializer.class,
-	properties={
-		@Property(name="p1",value="sp1"), // Unchanged servlet-level property.
-		@Property(name="p2",value="sp2"), // Servlet-level property overridden by onPreCall.
-		@Property(name="p3",value="sp3"), // Servlet-level property overridded by method.
-		@Property(name="p4",value="sp4")  // Servlet-level property overridden by method then onPreCall.
-	}
-)
-public class OnPreCallResource extends RestServlet {
-	private static final long serialVersionUID = 1L;
-
-	public static class TestParserA extends ReaderParser {
-
-		public TestParserA(PropertyStore ps) {
-			super(ps, "text/a1", "text/a2", "text/a3");
-		}
-
-		@Override /* Parser */
-		public ReaderParserSession createSession(ParserSessionArgs args) {
-			return new ReaderParserSession(args) {
-
-				@Override /* ParserSession */
-				@SuppressWarnings("unchecked")
-				protected <T> T doParse(ParserPipe pipe, ClassMeta<T> type) throws Exception
{
-					String matchingContentType = getProperty("mediaType", String.class);
-					return (T)("p1="+getProperty("p1", String.class)+",p2="+getProperty("p2", String.class)+",p3="+getProperty("p3",
String.class)+",p4="+getProperty("p4", String.class)+",p5="+getProperty("p5", String.class)+",contentType="+matchingContentType);
-				}
-			};
-		}
-	}
-
-	@RestHook(PRE_CALL)
-	public void onPreCall(RestRequest req) {
-		RequestProperties properties = req.getProperties();
-		properties.put("p2", "xp2");
-		properties.put("p4", "xp4");
-		properties.put("p5", "xp5"); // New property
-		String overrideContentType = req.getHeader("Override-Content-Type");
-		if (overrideContentType != null)
-			req.getHeaders().put("Content-Type", overrideContentType);
-	}
-
-
-	//====================================================================================================
-	// Properties overridden via properties annotation.
-	//====================================================================================================
-	@RestMethod(name=PUT, path="/testPropertiesOverriddenByAnnotation",
-		properties={
-			@Property(name="p3",value="mp3"),
-			@Property(name="p4",value="mp4")
-		}
-	)
-	public String testPropertiesOverriddenByAnnotation(@Body String in) {
-		return in;
-	}
-
-	//====================================================================================================
-	// Properties overridden programmatically.
-	//====================================================================================================
-	@RestMethod(name=PUT, path="/testPropertiesOverriddenProgrammatically")
-	public String testPropertiesOverriddenProgrammatically(RestRequest req, RequestProperties
properties) throws Exception {
-		properties.put("p3", "pp3");
-		properties.put("p4", "pp4");
-		return req.getBody().asType(String.class);
-	}
-}
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 cdfc172..de2a8fe 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
@@ -35,8 +35,6 @@ import org.apache.juneau.rest.test.client.*;
 		HtmlDocLinksResource.class,
 		InterfaceProxyResource.class,
 		LargePojosResource.class,
-		OnPostCallResource.class,
-		OnPreCallResource.class,
 		OptionsWithoutNlsResource.class,
 		OverlappingMethodsResource.class,
 		ParsersResource.class,
diff --git a/juneau-microservice/juneau-microservice-test/src/test/java/org/apache/juneau/rest/test/OnPostCallTest.java
b/juneau-microservice/juneau-microservice-test/src/test/java/org/apache/juneau/rest/test/OnPostCallTest.java
deleted file mode 100644
index e7786b9..0000000
--- a/juneau-microservice/juneau-microservice-test/src/test/java/org/apache/juneau/rest/test/OnPostCallTest.java
+++ /dev/null
@@ -1,121 +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 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();
-	}
-}
diff --git a/juneau-microservice/juneau-microservice-test/src/test/java/org/apache/juneau/rest/test/OnPreCallTest.java
b/juneau-microservice/juneau-microservice-test/src/test/java/org/apache/juneau/rest/test/OnPreCallTest.java
deleted file mode 100644
index 12a4201..0000000
--- a/juneau-microservice/juneau-microservice-test/src/test/java/org/apache/juneau/rest/test/OnPreCallTest.java
+++ /dev/null
@@ -1,61 +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 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();
-	}
-}
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 eb14165..ecca8bf 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
@@ -34,8 +34,6 @@ import org.junit.runners.Suite.*;
 	InterfaceProxyTest.class,
 	JacocoDummyTest.class,
 	LargePojosTest.class,
-	OnPostCallTest.class,
-	OnPreCallTest.class,
 	OptionsWithoutNlsTest.class,
 	OverlappingMethodsTest.class,
 	ParsersTest.class,
diff --git a/juneau-rest/juneau-rest-server/src/test/java/org/apache/juneau/rest/annotation/RestHookPostCallTest.java
b/juneau-rest/juneau-rest-server/src/test/java/org/apache/juneau/rest/annotation/RestHookPostCallTest.java
new file mode 100644
index 0000000..1c632fd
--- /dev/null
+++ b/juneau-rest/juneau-rest-server/src/test/java/org/apache/juneau/rest/annotation/RestHookPostCallTest.java
@@ -0,0 +1,133 @@
+// ***************************************************************************************************************************
+// * 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 static org.apache.juneau.rest.annotation.HookEvent.*;
+
+import java.util.*;
+
+import org.apache.juneau.*;
+import org.apache.juneau.rest.*;
+import org.apache.juneau.rest.mock.*;
+import org.apache.juneau.serializer.*;
+import org.apache.juneau.utils.*;
+import org.junit.*;
+import org.junit.runners.*;
+
+/**
+ * Tests aspects of @RestHook(POST_CALL).
+ */
+@SuppressWarnings({"javadoc"})
+@FixMethodOrder(MethodSorters.NAME_ASCENDING)
+public class RestHookPostCallTest {
+
+	//=================================================================================================================
+	// @RestHook(POST_CALL)
+	//=================================================================================================================
+
+	@RestResource(
+		serializers=A01.class,
+		properties={
+			@Property(name="p1",value="sp1"), // Unchanged servlet-level property.
+			@Property(name="p2",value="sp2"), // Servlet-level property overridden by onPostCall.
+			@Property(name="p3",value="sp3"), // Servlet-level property overridded by method.
+			@Property(name="p4",value="sp4")  // Servlet-level property overridden by method then
onPostCall.
+		}
+	)
+	public static class A {
+
+		@RestHook(POST_CALL)
+		public void onPostCall(RestRequest req, RestResponse res) {
+			RequestProperties properties = req.getProperties();
+			properties.put("p2", "xp2");
+			properties.put("p4", "xp4");
+			properties.put("p5", "xp5"); // New property
+			String overrideAccept = req.getHeader("Override-Accept");
+			if (overrideAccept != null)
+				req.getHeaders().put("Accept", overrideAccept);
+			String overrideContentType = req.getHeader("Override-Content-Type");
+			if (overrideContentType != null)
+				properties.put("Override-Content-Type", overrideContentType);
+		}
+
+		@RestMethod(name=PUT, path="/propertiesOverridenByAnnotation",
+			properties={
+				@Property(name="p3",value="mp3"),
+				@Property(name="p4",value="mp4")
+			},
+			defaultRequestHeaders="Accept: text/s2"
+		)
+		public String a01() {
+			return null;
+		}
+
+		@RestMethod(name=PUT, path="/propertiesOverriddenProgramatically")
+		public String a02(RestRequest req, RequestProperties properties) throws Exception {
+			properties.put("p3", "pp3");
+			properties.put("p4", "pp4");
+			String accept = req.getHeader("Accept");
+			if (accept == null || accept.isEmpty())
+				req.getHeaders().put("Accept", "text/s2");
+			return null;
+		}
+	}
+	static MockRest a = MockRest.create(A.class);
+
+	public static class A01 extends WriterSerializer {
+		public A01(PropertyStore ps) {
+			super(ps, "test/s1", "text/s1,text/s2,text/s3");
+		}
+		@Override /* Serializer */
+		public WriterSerializerSession createSession(SerializerSessionArgs args) {
+			return new WriterSerializerSession(args) {
+				@Override /* SerializerSession */
+				protected void doSerialize(SerializerPipe out, Object o) throws Exception {
+					out.getWriter().write("p1="+getProperty("p1", String.class)+",p2="+getProperty("p2",
String.class)+",p3="+getProperty("p3", String.class)+",p4="+getProperty("p4", String.class)+",p5="+getProperty("p5",
String.class)+",contentType="+getProperty("mediaType", String.class));
+				}
+				@Override /* SerializerSession */
+				public Map<String,String> getResponseHeaders() {
+					ObjectMap p = getProperties();
+					if (p.containsKey("Override-Content-Type"))
+						return new AMap<String,String>().append("Content-Type", p.getString("Override-Content-Type"));
+					return Collections.emptyMap();
+				}
+			};
+		}
+	}
+
+	@Test
+	public void a01a_propertiesOverridenByAnnotation() throws Exception {
+		a.request("PUT", "/propertiesOverridenByAnnotation").accept("text/s1").execute().assertBody("p1=sp1,p2=xp2,p3=mp3,p4=xp4,p5=xp5,contentType=text/s1");
+		a.request("PUT", "/propertiesOverridenByAnnotation").accept("text/s1").header("Override-Accept",
"text/s2").execute().assertBody("p1=sp1,p2=xp2,p3=mp3,p4=xp4,p5=xp5,contentType=text/s2");
+		a.request("PUT", "/propertiesOverridenByAnnotation").accept("text/s1").header("Override-Content-Type",
"text/s3").execute().assertBody("p1=sp1,p2=xp2,p3=mp3,p4=xp4,p5=xp5,contentType=text/s1");
+	}
+	@Test
+	public void a01b_propertiesOverridenByAnnotation_defaultAccept() throws Exception {
+		a.request("PUT", "/propertiesOverridenByAnnotation").execute().assertBody("p1=sp1,p2=xp2,p3=mp3,p4=xp4,p5=xp5,contentType=text/s2");
+		a.request("PUT", "/propertiesOverridenByAnnotation").header("Override-Accept", "text/s3").execute().assertBody("p1=sp1,p2=xp2,p3=mp3,p4=xp4,p5=xp5,contentType=text/s3");
+		a.request("PUT", "/propertiesOverridenByAnnotation").header("Override-Content-Type", "text/s3").execute().assertBody("p1=sp1,p2=xp2,p3=mp3,p4=xp4,p5=xp5,contentType=text/s2");
+	}
+	@Test
+	public void a02a_propertiesOverriddenProgramatically() throws Exception {
+		a.request("PUT", "/propertiesOverriddenProgramatically").accept("text/s1").execute().assertBody("p1=sp1,p2=xp2,p3=pp3,p4=xp4,p5=xp5,contentType=text/s1");
+		a.request("PUT", "/propertiesOverriddenProgramatically").accept("text/s1").header("Override-Accept",
"text/s2").execute().assertBody("p1=sp1,p2=xp2,p3=pp3,p4=xp4,p5=xp5,contentType=text/s2");
+		a.request("PUT", "/propertiesOverriddenProgramatically").accept("text/s1").header("Override-Content-Type",
"text/s3").execute().assertBody("p1=sp1,p2=xp2,p3=pp3,p4=xp4,p5=xp5,contentType=text/s1");
+	}
+	@Test
+	public void a02b_propertiesOverriddenProgramatically_defaultAccept() throws Exception {
+		a.request("PUT", "/propertiesOverriddenProgramatically").execute().assertBody("p1=sp1,p2=xp2,p3=pp3,p4=xp4,p5=xp5,contentType=text/s2");
+		a.request("PUT", "/propertiesOverriddenProgramatically").header("Override-Accept", "text/s3").execute().assertBody("p1=sp1,p2=xp2,p3=pp3,p4=xp4,p5=xp5,contentType=text/s3");
+		a.request("PUT", "/propertiesOverriddenProgramatically").header("Override-Content-Type",
"text/s3").execute().assertBody("p1=sp1,p2=xp2,p3=pp3,p4=xp4,p5=xp5,contentType=text/s2");
+	}
+}
diff --git a/juneau-rest/juneau-rest-server/src/test/java/org/apache/juneau/rest/annotation/RestHookPreCallTest.java
b/juneau-rest/juneau-rest-server/src/test/java/org/apache/juneau/rest/annotation/RestHookPreCallTest.java
new file mode 100644
index 0000000..ca63420
--- /dev/null
+++ b/juneau-rest/juneau-rest-server/src/test/java/org/apache/juneau/rest/annotation/RestHookPreCallTest.java
@@ -0,0 +1,104 @@
+// ***************************************************************************************************************************
+// * 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 static org.apache.juneau.rest.annotation.HookEvent.*;
+
+import org.apache.juneau.*;
+import org.apache.juneau.parser.*;
+import org.apache.juneau.rest.*;
+import org.apache.juneau.rest.mock.*;
+import org.junit.*;
+import org.junit.runners.*;
+
+/**
+ * Tests aspects of @RestHook(PRE_CALL).
+ */
+@SuppressWarnings({"javadoc"})
+@FixMethodOrder(MethodSorters.NAME_ASCENDING)
+public class RestHookPreCallTest {
+
+	//=================================================================================================================
+	// @RestHook(PRE_CALL)
+	//=================================================================================================================
+	@RestResource(
+		parsers=A01.class,
+		properties={
+			@Property(name="p1",value="sp1"), // Unchanged servlet-level property.
+			@Property(name="p2",value="sp2"), // Servlet-level property overridden by onPreCall.
+			@Property(name="p3",value="sp3"), // Servlet-level property overridded by method.
+			@Property(name="p4",value="sp4")  // Servlet-level property overridden by method then
onPreCall.
+		}
+	)
+	public static class A {
+
+		@RestHook(PRE_CALL)
+		public void onPreCall(RestRequest req) {
+			RequestProperties properties = req.getProperties();
+			properties.put("p2", "xp2");
+			properties.put("p4", "xp4");
+			properties.put("p5", "xp5"); // New property
+			String overrideContentType = req.getHeader("Override-Content-Type");
+			if (overrideContentType != null)
+				req.getHeaders().put("Content-Type", overrideContentType);
+		}
+
+		@RestMethod(name=PUT, path="/propertiesOverriddenByAnnotation",
+			properties={
+				@Property(name="p3",value="mp3"),
+				@Property(name="p4",value="mp4")
+			}
+		)
+		public String a01(@Body String in) {
+			return in;
+		}
+
+		@RestMethod(name=PUT, path="/propertiesOverriddenProgrammatically")
+		public String a02(RestRequest req, RequestProperties properties) throws Exception {
+			properties.put("p3", "pp3");
+			properties.put("p4", "pp4");
+			return req.getBody().asType(String.class);
+		}
+	}
+	static MockRest a = MockRest.create(A.class);
+
+	public static class A01 extends ReaderParser {
+		public A01(PropertyStore ps) {
+			super(ps, "text/a1", "text/a2", "text/a3");
+		}
+		@Override /* Parser */
+		public ReaderParserSession createSession(ParserSessionArgs args) {
+			return new ReaderParserSession(args) {
+				@Override /* ParserSession */
+				@SuppressWarnings("unchecked")
+				protected <T> T doParse(ParserPipe pipe, ClassMeta<T> type) throws Exception
{
+					String matchingContentType = getProperty("mediaType", String.class);
+					return (T)("p1="+getProperty("p1", String.class)+",p2="+getProperty("p2", String.class)+",p3="+getProperty("p3",
String.class)+",p4="+getProperty("p4", String.class)+",p5="+getProperty("p5", String.class)+",contentType="+matchingContentType);
+				}
+			};
+		}
+	}
+
+	@Test
+	public void a01_propertiesOverriddenByAnnotation() throws Exception {
+		a.request("PUT", "/propertiesOverriddenByAnnotation").contentType("text/a1").execute().assertBody("p1=sp1,p2=xp2,p3=mp3,p4=xp4,p5=xp5,contentType=text/a1");
+		a.request("PUT", "/propertiesOverriddenByAnnotation").contentType("text/a1").header("Override-Content-Type",
"text/a2").execute().assertBody("p1=sp1,p2=xp2,p3=mp3,p4=xp4,p5=xp5,contentType=text/a2");
+	}
+
+	@Test
+	public void a02_propertiesOverriddenProgrammatically() throws Exception {
+		a.request("PUT", "/propertiesOverriddenProgrammatically").contentType("text/a1").execute().assertBody("p1=sp1,p2=xp2,p3=pp3,p4=pp4,p5=xp5,contentType=text/a1");
+		a.request("PUT", "/propertiesOverriddenProgrammatically").contentType("text/a1").header("Override-Content-Type",
"text/a2").execute().assertBody("p1=sp1,p2=xp2,p3=pp3,p4=pp4,p5=xp5,contentType=text/a2");
+	}
+}

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

Mime
View raw message