ace-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r1359756 - in /ace/sandbox/marrs/org.apache.ace.http.itest: ./ .settings/ src/ src/org/ src/org/apache/ src/org/apache/ace/ src/org/apache/ace/it/ src/org/apache/ace/it/http/ test/
Date Tue, 10 Jul 2012 16:23:28 GMT
Author: marrs
Date: Tue Jul 10 16:23:27 2012
New Revision: 1359756

URL: http://svn.apache.org/viewvc?rev=1359756&view=rev
Log:
Another itest.

Added:
    ace/sandbox/marrs/org.apache.ace.http.itest/
    ace/sandbox/marrs/org.apache.ace.http.itest/.classpath
    ace/sandbox/marrs/org.apache.ace.http.itest/.project
    ace/sandbox/marrs/org.apache.ace.http.itest/.settings/
    ace/sandbox/marrs/org.apache.ace.http.itest/.settings/org.eclipse.jdt.core.prefs
    ace/sandbox/marrs/org.apache.ace.http.itest/bnd.bnd
    ace/sandbox/marrs/org.apache.ace.http.itest/build.xml
    ace/sandbox/marrs/org.apache.ace.http.itest/src/
    ace/sandbox/marrs/org.apache.ace.http.itest/src/org/
    ace/sandbox/marrs/org.apache.ace.http.itest/src/org/apache/
    ace/sandbox/marrs/org.apache.ace.http.itest/src/org/apache/ace/
    ace/sandbox/marrs/org.apache.ace.http.itest/src/org/apache/ace/it/
    ace/sandbox/marrs/org.apache.ace.http.itest/src/org/apache/ace/it/http/
    ace/sandbox/marrs/org.apache.ace.http.itest/src/org/apache/ace/it/http/EchoServlet.java
    ace/sandbox/marrs/org.apache.ace.http.itest/src/org/apache/ace/it/http/MockHttpService.java
    ace/sandbox/marrs/org.apache.ace.http.itest/src/org/apache/ace/it/http/ServletConfiguratorIntegrationTest.java
    ace/sandbox/marrs/org.apache.ace.http.itest/test/

Added: ace/sandbox/marrs/org.apache.ace.http.itest/.classpath
URL: http://svn.apache.org/viewvc/ace/sandbox/marrs/org.apache.ace.http.itest/.classpath?rev=1359756&view=auto
==============================================================================
--- ace/sandbox/marrs/org.apache.ace.http.itest/.classpath (added)
+++ ace/sandbox/marrs/org.apache.ace.http.itest/.classpath Tue Jul 10 16:23:27 2012
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+	<classpathentry kind="src" path="src"/>
+	<classpathentry kind="src" output="bin_test" path="test"/>
+	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
+	<classpathentry kind="con" path="aQute.bnd.classpath.container"/>
+	<classpathentry kind="output" path="bin"/>
+</classpath>

Added: ace/sandbox/marrs/org.apache.ace.http.itest/.project
URL: http://svn.apache.org/viewvc/ace/sandbox/marrs/org.apache.ace.http.itest/.project?rev=1359756&view=auto
==============================================================================
--- ace/sandbox/marrs/org.apache.ace.http.itest/.project (added)
+++ ace/sandbox/marrs/org.apache.ace.http.itest/.project Tue Jul 10 16:23:27 2012
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+	<name>org.apache.ace.http.itest</name>
+	<comment></comment>
+	<projects>
+	</projects>
+	<buildSpec>
+		<buildCommand>
+			<name>org.eclipse.jdt.core.javabuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+		<buildCommand>
+			<name>bndtools.core.bndbuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+	</buildSpec>
+	<natures>
+		<nature>org.eclipse.jdt.core.javanature</nature>
+		<nature>bndtools.core.bndnature</nature>
+	</natures>
+</projectDescription>

Added: ace/sandbox/marrs/org.apache.ace.http.itest/.settings/org.eclipse.jdt.core.prefs
URL: http://svn.apache.org/viewvc/ace/sandbox/marrs/org.apache.ace.http.itest/.settings/org.eclipse.jdt.core.prefs?rev=1359756&view=auto
==============================================================================
--- ace/sandbox/marrs/org.apache.ace.http.itest/.settings/org.eclipse.jdt.core.prefs (added)
+++ ace/sandbox/marrs/org.apache.ace.http.itest/.settings/org.eclipse.jdt.core.prefs Tue Jul
10 16:23:27 2012
@@ -0,0 +1,11 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=1.6
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.6

Added: ace/sandbox/marrs/org.apache.ace.http.itest/bnd.bnd
URL: http://svn.apache.org/viewvc/ace/sandbox/marrs/org.apache.ace.http.itest/bnd.bnd?rev=1359756&view=auto
==============================================================================
--- ace/sandbox/marrs/org.apache.ace.http.itest/bnd.bnd (added)
+++ ace/sandbox/marrs/org.apache.ace.http.itest/bnd.bnd Tue Jul 10 16:23:27 2012
@@ -0,0 +1,28 @@
+Test-Cases: ${classes;CONCRETE;EXTENDS;org.apache.ace.it.IntegrationTestBase}
+-buildpath: junit.osgi,\
+	osgi.core,\
+	osgi.cmpn,\
+	org.apache.ace.util;version=latest,\
+	org.apache.felix.dependencymanager,\
+	org.apache.ace.itest;version=latest,\
+	org.apache.ace.log;version=latest,\
+	org.apache.ace.httplistener;version=latest,\
+	org.apache.ace.discovery.api;version=latest,\
+	org.apache.ace.discovery.property;version=latest,\
+	org.apache.ace.identification.api;version=latest,\
+	org.apache.ace.identification.property;version=latest,\
+	org.apache.ace.server.log.store;version=latest,\
+	javax.servlet
+-runfw: org.apache.felix.framework;version='[4,5)'
+-runbundles: org.apache.ace.itest;resolution=file:/Users/marcel/dev/ace-bndtools/org.apache.ace.itest/generated/org.apache.ace.itest.jar;version=latest,\
+	org.apache.felix.dependencymanager;resolution=file:/Users/marcel/dev/ace-bndtools/cnf/repo/org.apache.felix.dependencymanager/org.apache.felix.dependencymanager-3.1.0.jar;version='[3.1.0,3.1.1)',\
+	org.apache.felix.configadmin;resolution=http://bundles.bndtools.org.s3.amazonaws.com/org.apache.felix.configadmin/org.apache.felix.configadmin-1.2.8.jar;version='[1.2.8,1.2.9)',\
+	org.apache.ace.httplistener;resolution=file:/Users/marcel/dev/ace-bndtools/org.apache.ace.httplistener/generated/org.apache.ace.httplistener.jar;version=latest,\
+	osgi.cmpn;resolution=http://bundles.bndtools.org.s3.amazonaws.com/osgi.cmpn/osgi.cmpn-4.2.1.jar;version='[4.2.1,4.2.2)',\
+	org.apache.felix.eventadmin;resolution=file:/Users/marcel/dev/ace-bndtools/cnf/repo/org.apache.felix.eventadmin/org.apache.felix.eventadmin-1.2.14.jar;version='[1.2.14,1.2.15)',\
+	org.apache.felix.http.jetty,\
+	org.apache.felix.shell,\
+	org.apache.felix.shell.tui,\
+	org.apache.felix.dependencymanager.shell
+Private-Package: org.apache.ace.it.http
+-runvm: -Dorg.osgi.service.http.port=9000 -ea
\ No newline at end of file

Added: ace/sandbox/marrs/org.apache.ace.http.itest/build.xml
URL: http://svn.apache.org/viewvc/ace/sandbox/marrs/org.apache.ace.http.itest/build.xml?rev=1359756&view=auto
==============================================================================
--- ace/sandbox/marrs/org.apache.ace.http.itest/build.xml (added)
+++ ace/sandbox/marrs/org.apache.ace.http.itest/build.xml Tue Jul 10 16:23:27 2012
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project name="project" default="build"> 
+	<import file="../cnf/build.xml"/>
+</project>

Added: ace/sandbox/marrs/org.apache.ace.http.itest/src/org/apache/ace/it/http/EchoServlet.java
URL: http://svn.apache.org/viewvc/ace/sandbox/marrs/org.apache.ace.http.itest/src/org/apache/ace/it/http/EchoServlet.java?rev=1359756&view=auto
==============================================================================
--- ace/sandbox/marrs/org.apache.ace.http.itest/src/org/apache/ace/it/http/EchoServlet.java
(added)
+++ ace/sandbox/marrs/org.apache.ace.http.itest/src/org/apache/ace/it/http/EchoServlet.java
Tue Jul 10 16:23:27 2012
@@ -0,0 +1,52 @@
+/*
+ * 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.ace.it.http;
+
+import java.io.IOException;
+
+import javax.servlet.ServletOutputStream;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+public class EchoServlet extends HttpServlet {
+
+    private static final long serialVersionUID = 1L;
+
+    @Override
+    protected void doGet(HttpServletRequest request, HttpServletResponse response) {
+        ServletOutputStream output = null;
+        try {
+            output = response.getOutputStream();
+            output.println(request.getQueryString());
+        }
+        catch (IOException e) {
+            // not much we can do, the test will fail anyway
+        } finally {
+            if (output != null) {
+                try {
+                    output.close();
+                }
+                catch (IOException e) {
+                    // not much we can do, the test will fail anyway
+                }
+            }
+        }
+    }
+}

Added: ace/sandbox/marrs/org.apache.ace.http.itest/src/org/apache/ace/it/http/MockHttpService.java
URL: http://svn.apache.org/viewvc/ace/sandbox/marrs/org.apache.ace.http.itest/src/org/apache/ace/it/http/MockHttpService.java?rev=1359756&view=auto
==============================================================================
--- ace/sandbox/marrs/org.apache.ace.http.itest/src/org/apache/ace/it/http/MockHttpService.java
(added)
+++ ace/sandbox/marrs/org.apache.ace.http.itest/src/org/apache/ace/it/http/MockHttpService.java
Tue Jul 10 16:23:27 2012
@@ -0,0 +1,61 @@
+/*
+ * 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.ace.it.http;
+
+import java.util.Dictionary;
+
+import javax.servlet.Servlet;
+import javax.servlet.ServletException;
+
+import org.osgi.service.http.HttpContext;
+import org.osgi.service.http.HttpService;
+import org.osgi.service.http.NamespaceException;
+
+public class MockHttpService implements HttpService {
+
+    private boolean m_registerCalled = false;
+    private boolean m_unregisterCalled = false;
+
+    public HttpContext createDefaultHttpContext() {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    public void registerResources(String arg0, String arg1, HttpContext arg2) throws NamespaceException
{
+        // TODO Auto-generated method stub
+
+    }
+
+    @SuppressWarnings("unchecked")
+    public void registerServlet(String arg0, Servlet arg1, Dictionary arg2, HttpContext arg3)
throws ServletException, NamespaceException {
+        m_registerCalled = true;
+    }
+
+    public void unregister(String arg0) {
+        m_unregisterCalled = true;
+    }
+
+    public boolean isRegisterCalled() {
+        return m_registerCalled;
+    }
+
+    public boolean isUnregisterCalled() {
+        return m_unregisterCalled;
+    }
+}

Added: ace/sandbox/marrs/org.apache.ace.http.itest/src/org/apache/ace/it/http/ServletConfiguratorIntegrationTest.java
URL: http://svn.apache.org/viewvc/ace/sandbox/marrs/org.apache.ace.http.itest/src/org/apache/ace/it/http/ServletConfiguratorIntegrationTest.java?rev=1359756&view=auto
==============================================================================
--- ace/sandbox/marrs/org.apache.ace.http.itest/src/org/apache/ace/it/http/ServletConfiguratorIntegrationTest.java
(added)
+++ ace/sandbox/marrs/org.apache.ace.http.itest/src/org/apache/ace/it/http/ServletConfiguratorIntegrationTest.java
Tue Jul 10 16:23:27 2012
@@ -0,0 +1,166 @@
+/*
+ * 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.ace.it.http;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.Dictionary;
+import java.util.Hashtable;
+
+import javax.servlet.Servlet;
+import javax.servlet.http.HttpServlet;
+
+import org.apache.ace.http.listener.constants.HttpConstants;
+import org.apache.ace.it.IntegrationTestBase;
+import org.apache.ace.test.constants.TestConstants;
+import org.apache.felix.dm.Component;
+import org.osgi.service.http.HttpService;
+
+public class ServletConfiguratorIntegrationTest extends IntegrationTestBase {
+
+//    @Configuration
+//    public Option[] configuration() {
+//        return options(
+//            systemProperty("org.osgi.service.http.port").value("" + TestConstants.PORT),
+//            new VMOption("-ea"),
+//            junitBundles(),
+//            provision(
+//                Osgi.compendium(),
+//                Felix.dependencyManager(),
+//                jetty(),
+//                Felix.configAdmin(),
+//                Ace.httplistener()
+//            )
+//        );
+//    }
+
+	@Override
+	protected void before() throws Exception {
+        m_echoServlet = new EchoServlet();
+        Dictionary<String, String> dictionary = new Hashtable<String, String>();
+        dictionary.put(HttpConstants.ENDPOINT, "/echoServlet");
+        m_echoServletService = m_dependencyManager.createComponent()
+            .setImplementation(m_echoServlet)
+            .setInterface(Servlet.class.getName(), dictionary);
+
+        m_mockHttp = new MockHttpService();
+        m_mockHttpService = m_dependencyManager.createComponent()
+            .setImplementation(m_mockHttp)
+            .setInterface(HttpService.class.getName(), null);
+    }
+
+    // the echo servlet
+    private HttpServlet m_echoServlet;
+    // echo servlet service-reference
+    private Component m_echoServletService;
+    // mock http service
+    private MockHttpService m_mockHttp;
+
+    //mock http service-reference
+    private Component m_mockHttpService;
+
+    /**
+     * Start the http service and then register a servlet and see if it works
+     * After that, try to unregister
+     */
+    public void testRegisterServlet() throws Exception {
+        m_dependencyManager.add(m_echoServletService);
+        assert waitForEchoServlet(true) : "TestValue not echo'd back";
+
+        m_dependencyManager.remove(m_echoServletService);
+        assert !waitForEchoServlet(false) : "The servlet should not be available anymore";
+    }
+
+    /**
+     * Register a servlet with 2 http services, try to unregister and see if it is removed
from both
+     */
+    public void testServletOnTwoHttpServices() throws Exception {
+        // also use the mock version
+        m_dependencyManager.add(m_mockHttpService);
+        m_dependencyManager.add(m_echoServletService);
+        assert waitForEchoServlet(true) : "TestValue not echo'd back";
+        assert m_mockHttp.isRegisterCalled() : "Servlet not registered with the mock service";
+
+
+        m_dependencyManager.remove(m_echoServletService);
+        assert !waitForEchoServlet(false) : "The servlet should not be available anymore";
+        assert m_mockHttp.isUnregisterCalled() : "Servlet not unregistered with the mock
service";
+    }
+
+    /**
+     * Now the server should be made available at
+     * http://SERVER:PORT/echoservlet and if it is not available after
+     * some time, the test is failed anyway.
+     *
+     * The expectSuccess parameter indicated if this method should expect a working echoservlet
or a non-working one.
+     *
+     * This method returns whether the echo servlet worked. So if you expect
+     * it to work (and it does), true will be returned.
+     * If you expect it to NOT work (and it doesn't), false will be returned.
+     */
+    private boolean waitForEchoServlet(boolean expectedResult) {
+        BufferedReader bufReader = null;
+
+        long startTimeMillis = System.currentTimeMillis();
+        // make sure we iterate at least once
+        boolean success = !expectedResult;
+        try {
+            while ((expectedResult != success) && (System.currentTimeMillis() <
startTimeMillis + 30000)) {
+                URL echoServletUrl = new URL("http://localhost:" + TestConstants.PORT + "/echoServlet?test");
+                String echoString = null;
+                try {
+                    bufReader = new BufferedReader(new InputStreamReader(echoServletUrl.openStream()));
+                    echoString = bufReader.readLine();
+                } catch (IOException ioe) {
+                    // let's wait and try again.
+                }
+                boolean resultFromServlet = (echoString != null) && echoString.equals("test");
+                if (resultFromServlet == expectedResult) {
+                    success = expectedResult;
+                }
+                if ((expectedResult != success)) {
+                    Thread.sleep(100);
+                }
+            }
+        }catch (MalformedURLException e) {
+            e.printStackTrace();
+            assert false : "No MalformedURLException expected";
+        }
+        catch (InterruptedException e) {
+            e.printStackTrace();
+            assert false : "No interruptedException expected";
+        } catch (Throwable t) {
+            t.printStackTrace();
+        } finally {
+            if (bufReader != null) {
+                try {
+                    bufReader.close();
+                }
+                catch (Exception ex) {
+                    // not much we can do
+                }
+            }
+        }
+        return success;
+    }
+
+}



Mime
View raw message