Repository: cxf
Updated Branches:
  refs/heads/3.0.x-fixes 751183b2e -> 82bb06eec


[CXF-7367] Adding a test


Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/82bb06ee
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/82bb06ee
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/82bb06ee

Branch: refs/heads/3.0.x-fixes
Commit: 82bb06eec7cab58dd9ee5bdd98d8acba711515c1
Parents: 751183b
Author: Sergey Beryozkin <sberyoz...@gmail.com>
Authored: Thu May 11 14:01:02 2017 +0100
Committer: Sergey Beryozkin <sberyoz...@gmail.com>
Committed: Thu May 11 14:03:06 2017 +0100

----------------------------------------------------------------------
 .../systest/jaxrs/ApplicationController.java    | 46 ++++++++++++
 .../jaxrs/ApplicationInfoJaxrsFilter.java       | 44 +++++++++++
 .../cxf/systest/jaxrs/JAXRSFiltersTest.java     | 78 ++++++++++++++++++++
 3 files changed, 168 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/82bb06ee/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/ApplicationController.java
----------------------------------------------------------------------
diff --git 
a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/ApplicationController.java
 
b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/ApplicationController.java
new file mode 100644
index 0000000..3ac0bb2
--- /dev/null
+++ 
b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/ApplicationController.java
@@ -0,0 +1,46 @@
+/**
+ * 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.cxf.systest.jaxrs;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.HeaderParam;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.container.ResourceContext;
+import javax.ws.rs.core.Context;
+
+@Path("app")
+public class ApplicationController {
+
+    @Context
+    private ResourceContext resourceContext;
+
+    @Path("nav")
+    public ApplicationControllerSub getNavigationDrawer() {
+        return resourceContext.initResource(new ApplicationControllerSub());
+    }
+    
+    public static class ApplicationControllerSub {
+        @GET
+        @Produces("text/plain")
+        public String getApplicationInfo(@HeaderParam("ApplicationInfo") 
String appInfo) {
+            return appInfo == null ? "DefaultAppInfo" : appInfo;
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/cxf/blob/82bb06ee/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/ApplicationInfoJaxrsFilter.java
----------------------------------------------------------------------
diff --git 
a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/ApplicationInfoJaxrsFilter.java
 
b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/ApplicationInfoJaxrsFilter.java
new file mode 100644
index 0000000..9ca6690
--- /dev/null
+++ 
b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/ApplicationInfoJaxrsFilter.java
@@ -0,0 +1,44 @@
+/**
+ * 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.cxf.systest.jaxrs;
+
+import java.io.IOException;
+import java.util.List;
+
+import javax.annotation.Priority;
+import javax.ws.rs.Priorities;
+import javax.ws.rs.container.ContainerRequestContext;
+import javax.ws.rs.container.ContainerRequestFilter;
+import javax.ws.rs.ext.Provider;
+
+@Provider
+@Priority(Priorities.AUTHENTICATION + 1)
+public class ApplicationInfoJaxrsFilter implements ContainerRequestFilter {
+
+    @Override
+    public void filter(ContainerRequestContext context) throws IOException {
+        List<Object> matched = context.getUriInfo().getMatchedResources();
+        if (matched.size() == 2 
+            && ApplicationController.ApplicationControllerSub.class == 
matched.get(0)
+            && ApplicationController.class == matched.get(1)) {
+            context.getHeaders().putSingle("ApplicationInfo", 
"FilteredApplicationInfo");
+        }
+    }
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cxf/blob/82bb06ee/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSFiltersTest.java
----------------------------------------------------------------------
diff --git 
a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSFiltersTest.java
 
b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSFiltersTest.java
new file mode 100644
index 0000000..07a75af
--- /dev/null
+++ 
b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSFiltersTest.java
@@ -0,0 +1,78 @@
+/**
+ * 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.cxf.systest.jaxrs;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.cxf.jaxrs.JAXRSServerFactoryBean;
+import org.apache.cxf.jaxrs.client.WebClient;
+import org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider;
+import org.apache.cxf.jaxrs.model.AbstractResourceInfo;
+import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase;
+import org.apache.cxf.testutil.common.AbstractBusTestServerBase;
+
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class JAXRSFiltersTest extends AbstractBusClientServerTestBase {
+    
+    @BeforeClass
+    public static void startServers() throws Exception {
+        AbstractResourceInfo.clearAllMaps();
+        assertTrue("server did not launch correctly",
+                   launchServer(AppServer.class, true));
+        createStaticBus();
+    }
+
+    public static class AppServer extends AbstractBusTestServerBase {
+        public static final String PORT = allocatePort(BookServer.class);
+
+        org.apache.cxf.endpoint.Server server;
+        
+        public AppServer() {
+        }
+
+        protected void run() {
+            JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
+            sf.setResourceClasses(ApplicationController.class);
+            List<Object> providers = new ArrayList<Object>();
+            providers.add(new ApplicationInfoJaxrsFilter());
+            sf.setProviders(providers);
+            sf.setResourceProvider(ApplicationController.class,
+                                   new SingletonResourceProvider(new 
ApplicationController()));
+            sf.setAddress("http://localhost:"; + PORT + "/info");
+            server = sf.create();
+        }
+
+        public void tearDown() throws Exception {
+            server.stop();
+            server.destroy();
+            server = null;
+        }
+    }
+    
+    @Test
+    public void testPostMatchingFilterOnSubresource() throws Exception {
+        WebClient wc = WebClient.create("http://localhost:"; + AppServer.PORT + 
"/info/app/nav");
+        wc.accept("text/plain");
+        assertEquals("FilteredApplicationInfo", wc.get(String.class));
+    }
+}

Reply via email to