You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@clerezza.apache.org by re...@apache.org on 2009/12/23 11:45:26 UTC
svn commit: r893466 -
/incubator/clerezza/issues/CLEREZZA-48/org.apache.clerezza.triaxrs/org.apache.clerezza.triaxrs/src/test/java/org/apache/clerezza/triaxrs/blackbox/AutoGeneratedOptionsTest.java
Author: reto
Date: Wed Dec 23 10:45:25 2009
New Revision: 893466
URL: http://svn.apache.org/viewvc?rev=893466&view=rev
Log:
CLEREZZA-48: the forgotten test file
Added:
incubator/clerezza/issues/CLEREZZA-48/org.apache.clerezza.triaxrs/org.apache.clerezza.triaxrs/src/test/java/org/apache/clerezza/triaxrs/blackbox/AutoGeneratedOptionsTest.java
Added: incubator/clerezza/issues/CLEREZZA-48/org.apache.clerezza.triaxrs/org.apache.clerezza.triaxrs/src/test/java/org/apache/clerezza/triaxrs/blackbox/AutoGeneratedOptionsTest.java
URL: http://svn.apache.org/viewvc/incubator/clerezza/issues/CLEREZZA-48/org.apache.clerezza.triaxrs/org.apache.clerezza.triaxrs/src/test/java/org/apache/clerezza/triaxrs/blackbox/AutoGeneratedOptionsTest.java?rev=893466&view=auto
==============================================================================
--- incubator/clerezza/issues/CLEREZZA-48/org.apache.clerezza.triaxrs/org.apache.clerezza.triaxrs/src/test/java/org/apache/clerezza/triaxrs/blackbox/AutoGeneratedOptionsTest.java (added)
+++ incubator/clerezza/issues/CLEREZZA-48/org.apache.clerezza.triaxrs/org.apache.clerezza.triaxrs/src/test/java/org/apache/clerezza/triaxrs/blackbox/AutoGeneratedOptionsTest.java Wed Dec 23 10:45:25 2009
@@ -0,0 +1,123 @@
+/*
+ * 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.clerezza.triaxrs.blackbox;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+import java.util.Hashtable;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.HttpMethod;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+
+import javax.ws.rs.Produces;
+import javax.ws.rs.ext.RuntimeDelegate;
+import org.apache.clerezza.triaxrs.JaxRsHandler;
+import org.apache.clerezza.triaxrs.delegate.RuntimeDelegateImpl;
+import org.apache.clerezza.triaxrs.mock.RequestImpl;
+import org.apache.clerezza.triaxrs.mock.RequestURIImpl;
+import org.apache.clerezza.triaxrs.mock.ResponseImpl;
+import org.apache.clerezza.triaxrs.testutils.HandlerCreator;
+
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import org.wymiwyg.wrhapi.HeaderName;
+import org.wymiwyg.wrhapi.Method;
+
+public class AutoGeneratedOptionsTest {
+
+ @Target(ElementType.METHOD)
+ @Retention(RetentionPolicy.RUNTIME)
+ @HttpMethod("PROPFIND")
+ private @interface PROPFIND {
+ }
+
+ @HttpMethod("FOO")
+ private @interface TEST {
+ }
+
+ @Path("/")
+ public static class MyResource {
+
+ @PROPFIND
+ @Produces("*/*")
+ public void propfind() {
+ System.out.println("PROPFIND Method was executed");
+ }
+
+ @POST
+ public void postIt() {
+ System.out.println("PROPFIND Method was executed");
+ }
+
+ @TEST
+ public void fooIt() {
+ }
+
+ @GET
+ @Path("sub")
+ public void sub() {
+ }
+ }
+
+ @Test
+ public void testAutoGeneratedOptions() throws Exception {
+ JaxRsHandler handler = HandlerCreator.getHandler(MyResource.class);
+ RequestURIImpl uri = new RequestURIImpl();
+ RequestImpl request = new RequestImpl();
+ ResponseImpl response = new ResponseImpl();
+ uri.setPath("/");
+ request.setRequestURI(uri);
+ request.setMethod(Method.OPTIONS);
+ handler.handle(request, response);
+ Hashtable<HeaderName, Object> headers = response.getHeaders();
+ Object allowHeader = headers.get(HeaderName.ALLOW);
+ Assert.assertNotNull(allowHeader);
+ String allow = allowHeader.toString();
+ Assert.assertTrue(allow.contains("PROPFIND"));
+ Assert.assertFalse(allow.contains("GET"));
+ Assert.assertTrue(allow.contains("POST"));
+ Assert.assertTrue(allow.contains("FOO"));
+ }
+
+ @Test
+ public void testAutoGeneratedOptionsOnSubresource() throws Exception {
+ JaxRsHandler handler = HandlerCreator.getHandler(MyResource.class);
+ RequestURIImpl uri = new RequestURIImpl();
+ RequestImpl request = new RequestImpl();
+ ResponseImpl response = new ResponseImpl();
+ uri.setPath("/sub");
+ request.setRequestURI(uri);
+ request.setMethod(Method.OPTIONS);
+ handler.handle(request, response);
+ Hashtable<HeaderName, Object> headers = response.getHeaders();
+ Object allowHeader = headers.get(HeaderName.ALLOW);
+ Assert.assertNotNull(allowHeader);
+ String allow = allowHeader.toString();
+ Assert.assertFalse(allow.contains("PROPFIND"));
+ Assert.assertTrue(allow.contains("GET"));
+ Assert.assertFalse(allow.contains("POST"));
+ }
+}