Add additional test for deprecated http whiteboard filter
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1717448 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/http/itest/pom.xml b/http/itest/pom.xml
index 704148f..a3dcf5b 100644
--- a/http/itest/pom.xml
+++ b/http/itest/pom.xml
@@ -35,7 +35,7 @@
<pax.exam.version>4.4.0</pax.exam.version>
<pax.url.aether.version>2.4.1</pax.url.aether.version>
<http.servlet.api.version>1.1.3-SNAPSHOT</http.servlet.api.version>
- <http.jetty.version>3.1.3-SNAPSHOT</http.jetty.version>
+ <http.jetty.version>3.1.5-SNAPSHOT</http.jetty.version>
</properties>
<build>
diff --git a/http/itest/src/test/java/org/apache/felix/http/itest/BaseIntegrationTest.java b/http/itest/src/test/java/org/apache/felix/http/itest/BaseIntegrationTest.java
index 902c050..620ef1e 100644
--- a/http/itest/src/test/java/org/apache/felix/http/itest/BaseIntegrationTest.java
+++ b/http/itest/src/test/java/org/apache/felix/http/itest/BaseIntegrationTest.java
@@ -324,6 +324,7 @@
mavenBundle("org.apache.felix", "org.apache.felix.http.servlet-api", System.getProperty("http.servlet.api.version")).startLevel(START_LEVEL_SYSTEM_BUNDLES),
mavenBundle("org.apache.felix", ORG_APACHE_FELIX_HTTP_JETTY, System.getProperty("http.jetty.version")).startLevel(START_LEVEL_SYSTEM_BUNDLES),
+ mavenBundle("org.apache.felix", "org.apache.felix.http.whiteboard", "3.0.0").startLevel(START_LEVEL_SYSTEM_BUNDLES),
mavenBundle("org.apache.felix", "org.apache.felix.configadmin").version("1.8.8"),
mavenBundle("org.apache.httpcomponents", "httpcore-osgi", "4.3.2").startLevel(START_LEVEL_SYSTEM_BUNDLES),
diff --git a/http/itest/src/test/java/org/apache/felix/http/itest/HttpServiceTest.java b/http/itest/src/test/java/org/apache/felix/http/itest/HttpServiceTest.java
new file mode 100644
index 0000000..518e55b
--- /dev/null
+++ b/http/itest/src/test/java/org/apache/felix/http/itest/HttpServiceTest.java
@@ -0,0 +1,145 @@
+/*
+ * 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.felix.http.itest;
+
+import static org.junit.Assert.assertTrue;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Dictionary;
+import java.util.Hashtable;
+import java.util.List;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+
+import javax.servlet.Filter;
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.junit.After;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.junit.PaxExam;
+import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
+import org.ops4j.pax.exam.spi.reactors.PerMethod;
+import org.osgi.framework.ServiceRegistration;
+import org.osgi.service.http.HttpService;
+import org.osgi.service.http.runtime.HttpServiceRuntime;
+
+@RunWith(PaxExam.class)
+@ExamReactorStrategy(PerMethod.class)
+public class HttpServiceTest extends BaseIntegrationTest
+{
+
+ private List<ServiceRegistration<?>> registrations = new ArrayList<ServiceRegistration<?>>();
+
+ private CountDownLatch initLatch;
+ private CountDownLatch destroyLatch;
+
+ public void setupLatches(int count)
+ {
+ initLatch = new CountDownLatch(count);
+ destroyLatch = new CountDownLatch(count);
+ }
+
+ public void setupOldWhiteboardFilter(final String pattern) throws Exception
+ {
+ Dictionary<String, Object> servletProps = new Hashtable<String, Object>();
+ servletProps.put("pattern", pattern);
+
+ final Filter f = new Filter()
+ {
+
+ @Override
+ public void init(FilterConfig filterConfig) throws ServletException
+ {
+ initLatch.countDown();
+ }
+
+ @Override
+ public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
+ throws IOException, ServletException
+ {
+ response.getWriter().print("FILTER-");
+ response.flushBuffer();
+ chain.doFilter(request, response);
+ }
+
+ @Override
+ public void destroy()
+ {
+ destroyLatch.countDown();
+ }
+ };
+
+ registrations.add(m_context.registerService(Filter.class.getName(), f, servletProps));
+ }
+
+ @After
+ public void unregisterServices() throws InterruptedException
+ {
+ for (ServiceRegistration<?> serviceRegistration : registrations)
+ {
+ serviceRegistration.unregister();
+ }
+
+ assertTrue(destroyLatch.await(5, TimeUnit.SECONDS));
+
+ Thread.sleep(500);
+ }
+
+ @Test
+ public void testServletAndOldWhiteboardFilter() throws Exception
+ {
+ final HttpService service = this.getHttpService();
+ service.registerServlet("/tesths", new TestServlet()
+ {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ protected void doGet(HttpServletRequest req, HttpServletResponse resp)
+ throws IOException
+ {
+ resp.getWriter().print("helloworld");
+ resp.flushBuffer();
+ }
+ }, null, null);
+
+ this.setupLatches(1);
+ this.setupOldWhiteboardFilter(".*");
+ assertTrue(initLatch.await(5, TimeUnit.SECONDS));
+ final HttpServiceRuntime rt = this.getService(HttpServiceRuntime.class.getName());
+ System.out.println(rt.getRuntimeDTO());
+ try
+ {
+ assertContent("FILTER-helloworld", createURL("/tesths"));
+ }
+ finally
+ {
+ service.unregister("/tesths");
+ }
+ }
+
+}