You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by db...@apache.org on 2012/12/29 22:41:42 UTC

svn commit: r1426847 - /openejb/trunk/openejb/arquillian/arquillian-tomee-tests/arquillian-tomee-jaxrs-tests/src/test/java/org/apache/openejb/arquillian/tests/jaxrs/context/

Author: dblevins
Date: Sat Dec 29 21:41:42 2012
New Revision: 1426847

URL: http://svn.apache.org/viewvc?rev=1426847&view=rev
Log:
Testcases with appropriate @Ignore for  
TOMEE-686 - JAX-RS @Context injection for EJB interceptors
TOMEE-685 - JAX-RS @Context ServletConfig broken for EJBs in WARs
TOMEE-684 - JAX-RS @Context ServletRequest broken for EJBs in WARs

Added:
    openejb/trunk/openejb/arquillian/arquillian-tomee-tests/arquillian-tomee-jaxrs-tests/src/test/java/org/apache/openejb/arquillian/tests/jaxrs/context/
    openejb/trunk/openejb/arquillian/arquillian-tomee-tests/arquillian-tomee-jaxrs-tests/src/test/java/org/apache/openejb/arquillian/tests/jaxrs/context/EjbContextInjectionServletConfigTest.java   (with props)
    openejb/trunk/openejb/arquillian/arquillian-tomee-tests/arquillian-tomee-jaxrs-tests/src/test/java/org/apache/openejb/arquillian/tests/jaxrs/context/EjbContextInjectionServletRequestTest.java   (with props)
    openejb/trunk/openejb/arquillian/arquillian-tomee-tests/arquillian-tomee-jaxrs-tests/src/test/java/org/apache/openejb/arquillian/tests/jaxrs/context/EjbContextInjectionTest.java   (with props)
    openejb/trunk/openejb/arquillian/arquillian-tomee-tests/arquillian-tomee-jaxrs-tests/src/test/java/org/apache/openejb/arquillian/tests/jaxrs/context/EjbInterceptorContextInjectionTest.java   (with props)

Added: openejb/trunk/openejb/arquillian/arquillian-tomee-tests/arquillian-tomee-jaxrs-tests/src/test/java/org/apache/openejb/arquillian/tests/jaxrs/context/EjbContextInjectionServletConfigTest.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/arquillian/arquillian-tomee-tests/arquillian-tomee-jaxrs-tests/src/test/java/org/apache/openejb/arquillian/tests/jaxrs/context/EjbContextInjectionServletConfigTest.java?rev=1426847&view=auto
==============================================================================
--- openejb/trunk/openejb/arquillian/arquillian-tomee-tests/arquillian-tomee-jaxrs-tests/src/test/java/org/apache/openejb/arquillian/tests/jaxrs/context/EjbContextInjectionServletConfigTest.java (added)
+++ openejb/trunk/openejb/arquillian/arquillian-tomee-tests/arquillian-tomee-jaxrs-tests/src/test/java/org/apache/openejb/arquillian/tests/jaxrs/context/EjbContextInjectionServletConfigTest.java Sat Dec 29 21:41:42 2012
@@ -0,0 +1,87 @@
+/*
+ * 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.openejb.arquillian.tests.jaxrs.context;
+
+import org.apache.openejb.loader.IO;
+import org.jboss.arquillian.container.test.api.Deployment;
+import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.arquillian.test.api.ArquillianResource;
+import org.jboss.shrinkwrap.api.ShrinkWrap;
+import org.jboss.shrinkwrap.api.spec.WebArchive;
+import org.junit.Assert;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import javax.ejb.Singleton;
+import javax.servlet.ServletConfig;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.core.Context;
+import java.io.IOException;
+import java.net.URL;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ * TODO Merge with EjbContextInjectionTest once fixed
+ *
+ * TOMEE-685 - JAX-RS @Context ServletConfig broken for EJBs in WARs
+ *
+ * @version $Rev$ $Date$
+ */
+@RunWith(Arquillian.class)
+@Ignore
+public class EjbContextInjectionServletConfigTest {
+
+
+    @ArquillianResource
+    private URL url;
+
+    @Deployment
+    public static WebArchive archive() {
+        return ShrinkWrap.create(WebArchive.class)
+                .addClasses(RsInjection.class);
+    }
+
+    @Test
+    public void rest() throws IOException {
+        final String response = IO.slurp(new URL(url.toExternalForm() + "injections/check"));
+        assertEquals("true", response);
+    }
+
+
+    @Singleton
+    @Path("/injections")
+    public static class RsInjection {
+
+        @Context
+        private ServletConfig servletConfig;
+
+        @GET
+        @Path("/check")
+        public boolean check() {
+            // Are they injected?
+            Assert.assertNotNull("servletConfig", servletConfig);
+
+            // Do the thread locals actually point anywhere?
+            Assert.assertTrue(servletConfig.getInitParameter("doesNotExist") == null);
+
+            return true;
+        }
+    }
+}

Propchange: openejb/trunk/openejb/arquillian/arquillian-tomee-tests/arquillian-tomee-jaxrs-tests/src/test/java/org/apache/openejb/arquillian/tests/jaxrs/context/EjbContextInjectionServletConfigTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openejb/trunk/openejb/arquillian/arquillian-tomee-tests/arquillian-tomee-jaxrs-tests/src/test/java/org/apache/openejb/arquillian/tests/jaxrs/context/EjbContextInjectionServletRequestTest.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/arquillian/arquillian-tomee-tests/arquillian-tomee-jaxrs-tests/src/test/java/org/apache/openejb/arquillian/tests/jaxrs/context/EjbContextInjectionServletRequestTest.java?rev=1426847&view=auto
==============================================================================
--- openejb/trunk/openejb/arquillian/arquillian-tomee-tests/arquillian-tomee-jaxrs-tests/src/test/java/org/apache/openejb/arquillian/tests/jaxrs/context/EjbContextInjectionServletRequestTest.java (added)
+++ openejb/trunk/openejb/arquillian/arquillian-tomee-tests/arquillian-tomee-jaxrs-tests/src/test/java/org/apache/openejb/arquillian/tests/jaxrs/context/EjbContextInjectionServletRequestTest.java Sat Dec 29 21:41:42 2012
@@ -0,0 +1,96 @@
+/*
+ * 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.openejb.arquillian.tests.jaxrs.context;
+
+import org.apache.openejb.loader.IO;
+import org.jboss.arquillian.container.test.api.Deployment;
+import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.arquillian.test.api.ArquillianResource;
+import org.jboss.shrinkwrap.api.ShrinkWrap;
+import org.jboss.shrinkwrap.api.spec.WebArchive;
+import org.junit.Assert;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import javax.ejb.Singleton;
+import javax.servlet.ServletConfig;
+import javax.servlet.ServletRequest;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.HttpHeaders;
+import javax.ws.rs.core.Request;
+import javax.ws.rs.core.SecurityContext;
+import javax.ws.rs.core.UriInfo;
+import javax.ws.rs.ext.ContextResolver;
+import javax.ws.rs.ext.Providers;
+import java.io.IOException;
+import java.net.URL;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ * TODO Merge with EjbContextInjectionTest once fixed
+ *
+ * TOMEE-684 - JAX-RS @Context ServletRequest broken for EJBs in WARs
+ *
+ * @version $Rev$ $Date$
+ */
+@RunWith(Arquillian.class)
+@Ignore
+public class EjbContextInjectionServletRequestTest {
+
+
+    @ArquillianResource
+    private URL url;
+
+    @Deployment
+    public static WebArchive archive() {
+        return ShrinkWrap.create(WebArchive.class)
+                .addClasses(RsInjection.class);
+    }
+
+    @Test
+    public void rest() throws IOException {
+        final String response = IO.slurp(new URL(url.toExternalForm() + "injections/check"));
+        assertEquals("true", response);
+    }
+
+
+    @Singleton
+    @Path("/injections")
+    public static class RsInjection {
+
+        @Context
+        private ServletRequest servletRequest;
+
+        @GET
+        @Path("/check")
+        public boolean check() {
+            // Are they injected?
+            Assert.assertNotNull("servletRequest", servletRequest);
+
+            // Do the thread locals actually point anywhere?
+            Assert.assertTrue(servletRequest.getScheme() != null);
+
+            return true;
+        }
+    }
+}

Propchange: openejb/trunk/openejb/arquillian/arquillian-tomee-tests/arquillian-tomee-jaxrs-tests/src/test/java/org/apache/openejb/arquillian/tests/jaxrs/context/EjbContextInjectionServletRequestTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openejb/trunk/openejb/arquillian/arquillian-tomee-tests/arquillian-tomee-jaxrs-tests/src/test/java/org/apache/openejb/arquillian/tests/jaxrs/context/EjbContextInjectionTest.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/arquillian/arquillian-tomee-tests/arquillian-tomee-jaxrs-tests/src/test/java/org/apache/openejb/arquillian/tests/jaxrs/context/EjbContextInjectionTest.java?rev=1426847&view=auto
==============================================================================
--- openejb/trunk/openejb/arquillian/arquillian-tomee-tests/arquillian-tomee-jaxrs-tests/src/test/java/org/apache/openejb/arquillian/tests/jaxrs/context/EjbContextInjectionTest.java (added)
+++ openejb/trunk/openejb/arquillian/arquillian-tomee-tests/arquillian-tomee-jaxrs-tests/src/test/java/org/apache/openejb/arquillian/tests/jaxrs/context/EjbContextInjectionTest.java Sat Dec 29 21:41:42 2012
@@ -0,0 +1,126 @@
+/*
+ * 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.openejb.arquillian.tests.jaxrs.context;
+
+import org.apache.openejb.loader.IO;
+import org.jboss.arquillian.container.test.api.Deployment;
+import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.arquillian.test.api.ArquillianResource;
+import org.jboss.shrinkwrap.api.ShrinkWrap;
+import org.jboss.shrinkwrap.api.spec.WebArchive;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import javax.ejb.Singleton;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.HttpHeaders;
+import javax.ws.rs.core.Request;
+import javax.ws.rs.core.SecurityContext;
+import javax.ws.rs.core.UriInfo;
+import javax.ws.rs.ext.ContextResolver;
+import javax.ws.rs.ext.Providers;
+import java.io.IOException;
+import java.net.URL;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ * @version $Rev$ $Date$
+ */
+@RunWith(Arquillian.class)
+public class EjbContextInjectionTest {
+
+
+    @ArquillianResource
+    private URL url;
+
+    @Deployment
+    public static WebArchive archive() {
+        return ShrinkWrap.create(WebArchive.class)
+                .addClasses(RsInjection.class);
+    }
+
+    @Test
+    public void rest() throws IOException {
+        final String response = IO.slurp(new URL(url.toExternalForm() + "injections/check"));
+        assertEquals("true", response);
+    }
+
+
+    @Singleton
+    @Path("/injections")
+    public static class RsInjection {
+
+        @Context
+        private HttpHeaders httpHeaders;
+
+        @Context
+        private Providers providers;
+
+        @Context
+        private HttpServletResponse response;
+
+        @Context
+        private Request request;
+
+        @Context
+        private HttpServletRequest httpServletRequest;
+
+        @Context
+        private UriInfo uriInfo;
+
+        @Context
+        private SecurityContext securityContext;
+
+        @Context
+        private ContextResolver contextResolver;
+
+        @GET
+        @Path("/check")
+        public boolean check() {
+            // Are they injected?
+            Assert.assertNotNull("httpHeaders", httpHeaders);
+            Assert.assertNotNull("providers", providers);
+            Assert.assertNotNull("response", response);
+            Assert.assertNotNull("request", request);
+            Assert.assertNotNull("httpServletRequest", httpServletRequest);
+            Assert.assertNotNull("uriInfo", uriInfo);
+            Assert.assertNotNull("securityContext", securityContext);
+            Assert.assertNotNull("contextResolver", contextResolver);
+
+            // Do the thread locals actually point anywhere?
+            Assert.assertTrue(httpHeaders.getRequestHeaders().size() > 0);
+            Assert.assertTrue(providers.getExceptionMapper(FooException.class) == null);
+            Assert.assertTrue(response.getHeaderNames() != null);
+            Assert.assertTrue(request.getMethod() != null);
+            Assert.assertTrue(httpServletRequest.getMethod() != null);
+            Assert.assertTrue(uriInfo.getPath() != null);
+            Assert.assertTrue(!securityContext.isUserInRole("Foo"));
+            Assert.assertTrue(contextResolver.getContext(null) == null);
+
+            return true;
+        }
+    }
+
+    public static class FooException extends RuntimeException {
+    }
+}

Propchange: openejb/trunk/openejb/arquillian/arquillian-tomee-tests/arquillian-tomee-jaxrs-tests/src/test/java/org/apache/openejb/arquillian/tests/jaxrs/context/EjbContextInjectionTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openejb/trunk/openejb/arquillian/arquillian-tomee-tests/arquillian-tomee-jaxrs-tests/src/test/java/org/apache/openejb/arquillian/tests/jaxrs/context/EjbInterceptorContextInjectionTest.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/arquillian/arquillian-tomee-tests/arquillian-tomee-jaxrs-tests/src/test/java/org/apache/openejb/arquillian/tests/jaxrs/context/EjbInterceptorContextInjectionTest.java?rev=1426847&view=auto
==============================================================================
--- openejb/trunk/openejb/arquillian/arquillian-tomee-tests/arquillian-tomee-jaxrs-tests/src/test/java/org/apache/openejb/arquillian/tests/jaxrs/context/EjbInterceptorContextInjectionTest.java (added)
+++ openejb/trunk/openejb/arquillian/arquillian-tomee-tests/arquillian-tomee-jaxrs-tests/src/test/java/org/apache/openejb/arquillian/tests/jaxrs/context/EjbInterceptorContextInjectionTest.java Sat Dec 29 21:41:42 2012
@@ -0,0 +1,154 @@
+/*
+ * 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.openejb.arquillian.tests.jaxrs.context;
+
+import org.apache.openejb.loader.IO;
+import org.jboss.arquillian.container.test.api.Deployment;
+import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.arquillian.test.api.ArquillianResource;
+import org.jboss.shrinkwrap.api.ShrinkWrap;
+import org.jboss.shrinkwrap.api.spec.WebArchive;
+import org.junit.Assert;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import javax.ejb.Singleton;
+import javax.interceptor.AroundInvoke;
+import javax.interceptor.Interceptors;
+import javax.interceptor.InvocationContext;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.HttpHeaders;
+import javax.ws.rs.core.Request;
+import javax.ws.rs.core.SecurityContext;
+import javax.ws.rs.core.UriInfo;
+import javax.ws.rs.ext.ContextResolver;
+import javax.ws.rs.ext.Providers;
+import java.io.IOException;
+import java.net.URL;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ * TOMEE-686 - JAX-RS @Context injection for EJB interceptors
+ *
+ * @version $Rev$ $Date$
+ */
+@RunWith(Arquillian.class)
+@Ignore
+public class EjbInterceptorContextInjectionTest {
+
+    @ArquillianResource
+    private URL url;
+
+    @Deployment
+    public static WebArchive archive() {
+        return ShrinkWrap.create(WebArchive.class)
+                .addClass(RsInjection.class)
+                .addClass(RsEjbInterceptor.class)
+                ;
+    }
+
+    @Test
+    public void rest() throws IOException {
+        final String response = IO.slurp(new URL(url.toExternalForm() + "injections/check"));
+        assertEquals("true", response);
+    }
+
+
+    @Singleton
+    @Interceptors(RsEjbInterceptor.class)
+    @Path("/injections")
+    public static class RsInjection {
+
+        @GET
+        @Path("/check")
+        public boolean check() {
+            return false;
+        }
+    }
+
+    public static class FooException extends RuntimeException {
+    }
+
+    public static class RsEjbInterceptor {
+        @Context
+        private HttpHeaders httpHeaders;
+
+        @Context
+        private Providers providers;
+
+        @Context
+        private HttpServletResponse response;
+
+        @Context
+        private Request request;
+
+        @Context
+        private HttpServletRequest httpServletRequest;
+
+        @Context
+        private UriInfo uriInfo;
+
+        @Context
+        private SecurityContext securityContext;
+
+        @Context
+        private ContextResolver contextResolver;
+
+        @AroundInvoke
+        private Object invoke(InvocationContext context) throws Exception {
+            // Are they injected?
+            Assert.assertNotNull("httpHeaders", httpHeaders);
+            Assert.assertNotNull("providers", providers);
+            Assert.assertNotNull("response", response);
+            Assert.assertNotNull("request", request);
+            Assert.assertNotNull("httpServletRequest", httpServletRequest);
+            Assert.assertNotNull("uriInfo", uriInfo);
+            Assert.assertNotNull("securityContext", securityContext);
+            Assert.assertNotNull("contextResolver", contextResolver);
+
+            // Do the thread locals actually point anywhere?
+            Assert.assertTrue(httpHeaders.getRequestHeaders().size() > 0);
+            Assert.assertTrue(providers.getExceptionMapper(FooException.class) == null);
+            Assert.assertTrue(response.getHeaderNames() != null);
+            Assert.assertTrue(request.getMethod() != null);
+            Assert.assertTrue(httpServletRequest.getMethod() != null);
+            Assert.assertTrue(uriInfo.getPath() != null);
+            Assert.assertTrue(!securityContext.isUserInRole("Foo"));
+            Assert.assertTrue(contextResolver.getContext(null) == null);
+
+            context.proceed();
+
+            // Test again to ensure thread locals are still valid
+            Assert.assertTrue(httpHeaders.getRequestHeaders().size() > 0);
+            Assert.assertTrue(providers.getExceptionMapper(FooException.class) == null);
+            Assert.assertTrue(response.getHeaderNames() != null);
+            Assert.assertTrue(request.getMethod() != null);
+            Assert.assertTrue(httpServletRequest.getMethod() != null);
+            Assert.assertTrue(uriInfo.getPath() != null);
+            Assert.assertTrue(!securityContext.isUserInRole("Foo"));
+            Assert.assertTrue(contextResolver.getContext(null) == null);
+
+            return true;
+        }
+    }
+}

Propchange: openejb/trunk/openejb/arquillian/arquillian-tomee-tests/arquillian-tomee-jaxrs-tests/src/test/java/org/apache/openejb/arquillian/tests/jaxrs/context/EjbInterceptorContextInjectionTest.java
------------------------------------------------------------------------------
    svn:eol-style = native