Repository: tomee Updated Branches: refs/heads/master 4573e844f -> d08f37411
test for CDI container request filter Project: http://git-wip-us.apache.org/repos/asf/tomee/repo Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/d08f3741 Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/d08f3741 Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/d08f3741 Branch: refs/heads/master Commit: d08f37411b41e19a3e5c2ff1c1620acb27c94d5b Parents: 4573e84 Author: Romain Manni-Bucau <[email protected]> Authored: Thu Apr 9 15:44:26 2015 +0200 Committer: Romain Manni-Bucau <[email protected]> Committed: Thu Apr 9 15:44:26 2015 +0200 ---------------------------------------------------------------------- .../CDIProviderContainerRequestFilterTest.java | 85 ++++++++++++++++++++ 1 file changed, 85 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/tomee/blob/d08f3741/server/openejb-cxf-rs/src/test/java/org/apache/openejb/server/cxf/rs/CDIProviderContainerRequestFilterTest.java ---------------------------------------------------------------------- diff --git a/server/openejb-cxf-rs/src/test/java/org/apache/openejb/server/cxf/rs/CDIProviderContainerRequestFilterTest.java b/server/openejb-cxf-rs/src/test/java/org/apache/openejb/server/cxf/rs/CDIProviderContainerRequestFilterTest.java new file mode 100644 index 0000000..6c1802c --- /dev/null +++ b/server/openejb-cxf-rs/src/test/java/org/apache/openejb/server/cxf/rs/CDIProviderContainerRequestFilterTest.java @@ -0,0 +1,85 @@ +/* + * 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.server.cxf.rs; + +import org.apache.openejb.junit.ApplicationComposer; +import org.apache.openejb.loader.IO; +import org.apache.openejb.testing.Classes; +import org.apache.openejb.testing.EnableServices; +import org.apache.openejb.testing.RandomPort; +import org.junit.Test; +import org.junit.runner.RunWith; + +import java.io.IOException; +import java.net.URL; +import javax.annotation.Priority; +import javax.enterprise.context.ApplicationScoped; +import javax.inject.Inject; +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Priorities; +import javax.ws.rs.container.ContainerRequestContext; +import javax.ws.rs.container.ContainerRequestFilter; +import javax.ws.rs.container.ResourceInfo; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.Response; +import javax.ws.rs.ext.Provider; + +import static org.junit.Assert.assertEquals; + +@Classes(cdi = true, innerClassesAsBean = true) +@RunWith(ApplicationComposer.class) +@EnableServices("jaxrs") +public class CDIProviderContainerRequestFilterTest { + @RandomPort("http") + private URL http; + + @Test + public void run() throws IOException { + assertEquals("mock@get", IO.slurp(new URL(http.toExternalForm() + "openejb/e"))); + } + + @Path("e") + public static class Endpoint { + @GET + public String get() { + return "e"; + } + } + + @ApplicationScoped + public static class ABean { + public String user() { + return "mock"; + } + } + + @Provider + @Priority(Priorities.AUTHENTICATION) + public static class JWTAuthenticationFilter implements ContainerRequestFilter { + @Context + private ResourceInfo resourceInfo; + + @Inject + private ABean bean; + + @Override + public void filter(final ContainerRequestContext request) throws IOException { + request.abortWith(Response.ok(bean.user() + "@" + resourceInfo.getResourceMethod().getName()).build()); + } + } +}
