cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r1238819 - in /cxf/trunk/osgi/itests: ./ src/ src/test/ src/test/java/ src/test/java/org/ src/test/java/org/apache/ src/test/java/org/apache/cxf/ src/test/java/org/apache/cxf/osgi/ src/test/java/org/apache/cxf/osgi/itests/
Date Tue, 31 Jan 2012 21:28:45 GMT
Author: dkulp
Date: Tue Jan 31 21:28:45 2012
New Revision: 1238819

URL: http://svn.apache.org/viewvc?rev=1238819&view=rev
Log:
Try to write an initial pax-exam test, but it's failing completely.
Just committing it so Christian or JB can take a look and help me figure
out what is going on.

Added:
    cxf/trunk/osgi/itests/
    cxf/trunk/osgi/itests/pom.xml   (with props)
    cxf/trunk/osgi/itests/src/
    cxf/trunk/osgi/itests/src/test/
    cxf/trunk/osgi/itests/src/test/java/
    cxf/trunk/osgi/itests/src/test/java/org/
    cxf/trunk/osgi/itests/src/test/java/org/apache/
    cxf/trunk/osgi/itests/src/test/java/org/apache/cxf/
    cxf/trunk/osgi/itests/src/test/java/org/apache/cxf/osgi/
    cxf/trunk/osgi/itests/src/test/java/org/apache/cxf/osgi/itests/
    cxf/trunk/osgi/itests/src/test/java/org/apache/cxf/osgi/itests/BasicFeatureTest.java 
 (with props)
    cxf/trunk/osgi/itests/src/test/java/org/apache/cxf/osgi/itests/CXFOSGiTestSupport.java
  (with props)

Added: cxf/trunk/osgi/itests/pom.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/osgi/itests/pom.xml?rev=1238819&view=auto
==============================================================================
--- cxf/trunk/osgi/itests/pom.xml (added)
+++ cxf/trunk/osgi/itests/pom.xml Tue Jan 31 21:28:45 2012
@@ -0,0 +1,129 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+    <!--
+
+        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.
+    -->
+
+    <modelVersion>4.0.0</modelVersion>
+
+    <parent>
+        <groupId>org.apache.cxf</groupId>
+        <artifactId>cxf-parent</artifactId>
+        <version>2.6.0-SNAPSHOT</version>
+        <relativePath>../../parent/pom.xml</relativePath>
+    </parent>
+
+    <groupId>org.apache.cxf.osgi.itests</groupId>
+    <artifactId>org.apache.cxf.osgi.itests</artifactId>
+    <name>Apache CXF :: OSGi :: Integration Tests</name>
+    <packaging>jar</packaging>
+
+    <properties>
+        <pax.exam.version>2.3.0.M1</pax.exam.version>
+        <pax.exam.karaf.version>0.4.0</pax.exam.karaf.version>
+        <pax.url.version>1.2.8</pax.url.version>
+        <cxf.surefire.fork.mode>once</cxf.surefire.fork.mode>
+    </properties>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.ops4j.pax.url</groupId>
+            <artifactId>pax-url-mvn</artifactId>
+            <version>${pax.url.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.ops4j.pax.url</groupId>
+            <artifactId>pax-url-aether</artifactId>
+            <version>${pax.url.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.karaf</groupId>
+            <artifactId>apache-karaf</artifactId>
+            <version>${cxf.karaf.version}</version>
+            <type>tar.gz</type>
+        </dependency>
+        <dependency>
+            <groupId>org.openengsb.labs.paxexam.karaf</groupId>
+            <artifactId>paxexam-karaf-container</artifactId>
+            <version>${pax.exam.karaf.version}</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.ops4j.pax.exam</groupId>
+            <artifactId>pax-exam-junit4</artifactId>
+            <version>${pax.exam.version}</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <scope>test</scope>
+        </dependency>
+
+
+        <dependency>
+            <groupId>org.apache.cxf</groupId>
+            <artifactId>cxf-api</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+    </dependencies>
+
+    <build>
+        <plugins>
+            <!-- generate dependencies versions -->
+            <plugin>
+                <groupId>org.apache.servicemix.tooling</groupId>
+                <artifactId>depends-maven-plugin</artifactId>
+                <version>1.2</version>
+                <executions>
+                    <execution>
+                        <id>generate-depends-file</id>
+                        <goals>
+                            <goal>generate-depends-file</goal>
+                        </goals>
+                        <phase>compile</phase>
+                    </execution>
+                </executions>
+            </plugin> 
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-dependency-plugin</artifactId>
+                <executions>
+                    <execution>
+                        <id>unpack-unix</id>
+                        <phase>generate-resources</phase>
+                        <goals>
+                            <goal>unpack</goal>
+                        </goals>
+                        <configuration>
+                            <artifactItems>
+                                <artifactItem>
+                                    <groupId>org.apache.karaf</groupId>
+                                    <artifactId>apache-karaf</artifactId>
+                                    <type>tar.gz</type>
+                                    <outputDirectory>target/karaf-base</outputDirectory>
+                                </artifactItem>
+                            </artifactItems>
+                        </configuration>
+                    </execution>
+                </executions>
+            </plugin>
+        </plugins>
+    </build>
+
+</project>

Propchange: cxf/trunk/osgi/itests/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/trunk/osgi/itests/pom.xml
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: cxf/trunk/osgi/itests/pom.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml

Added: cxf/trunk/osgi/itests/src/test/java/org/apache/cxf/osgi/itests/BasicFeatureTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/osgi/itests/src/test/java/org/apache/cxf/osgi/itests/BasicFeatureTest.java?rev=1238819&view=auto
==============================================================================
--- cxf/trunk/osgi/itests/src/test/java/org/apache/cxf/osgi/itests/BasicFeatureTest.java (added)
+++ cxf/trunk/osgi/itests/src/test/java/org/apache/cxf/osgi/itests/BasicFeatureTest.java Tue
Jan 31 21:28:45 2012
@@ -0,0 +1,80 @@
+/**
+ * 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.osgi.itests;
+
+import java.io.File;
+
+import org.junit.After;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.openengsb.labs.paxexam.karaf.options.LogLevelOption;
+import org.ops4j.pax.exam.Option;
+import org.ops4j.pax.exam.junit.Configuration;
+import org.ops4j.pax.exam.junit.ExamReactorStrategy;
+import org.ops4j.pax.exam.junit.JUnit4TestRunner;
+import org.ops4j.pax.exam.spi.reactors.AllConfinedStagedReactorFactory;
+
+import static org.openengsb.labs.paxexam.karaf.options.KarafDistributionOption.keepRuntimeFolder;
+import static org.openengsb.labs.paxexam.karaf.options.KarafDistributionOption.logLevel;
+import static org.openengsb.labs.paxexam.karaf.options.KarafDistributionOption.replaceConfigurationFile;
+
+@RunWith(JUnit4TestRunner.class)
+@ExamReactorStrategy(AllConfinedStagedReactorFactory.class)
+public class BasicFeatureTest extends CXFOSGiTestSupport {
+    //private static final String UNINSTALLED = "[uninstalled]";
+    //private static final String INSTALLED = "[installed  ]";
+
+    @Test
+    public void testCXFFeaturesModule() throws InterruptedException {
+        installCXF();
+        Thread.sleep(DEFAULT_TIMEOUT);
+
+        System.err.println(executeCommand("list"));
+
+
+    }
+
+    @After
+    public void tearDown() {
+        try {
+            unInstallCXF();
+        } catch (Exception ex) {
+            //Ignore
+        }
+    }
+
+    @Configuration
+    public Option[] config() {
+        File file = new File("target/karaf-base/apache-karaf-2.2.5/etc/jre.properties.cxf")
+            .getAbsoluteFile();
+        System.out.println(file);
+        System.out.println();
+        System.out.println();
+        System.out.println();
+        System.out.println();
+        System.out.println();
+        System.out.println();
+        return new Option[]{
+                cxfDistributionConfiguration(), 
+                keepRuntimeFolder(),
+                replaceConfigurationFile("etc/jre.properties", file),
+                logLevel(LogLevelOption.LogLevel.INFO)};
+    }
+}

Propchange: cxf/trunk/osgi/itests/src/test/java/org/apache/cxf/osgi/itests/BasicFeatureTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/trunk/osgi/itests/src/test/java/org/apache/cxf/osgi/itests/BasicFeatureTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: cxf/trunk/osgi/itests/src/test/java/org/apache/cxf/osgi/itests/CXFOSGiTestSupport.java
URL: http://svn.apache.org/viewvc/cxf/trunk/osgi/itests/src/test/java/org/apache/cxf/osgi/itests/CXFOSGiTestSupport.java?rev=1238819&view=auto
==============================================================================
--- cxf/trunk/osgi/itests/src/test/java/org/apache/cxf/osgi/itests/CXFOSGiTestSupport.java
(added)
+++ cxf/trunk/osgi/itests/src/test/java/org/apache/cxf/osgi/itests/CXFOSGiTestSupport.java
Tue Jan 31 21:28:45 2012
@@ -0,0 +1,336 @@
+/**
+ * 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.osgi.itests;
+
+
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.IOException;
+import java.io.PrintStream;
+import java.net.DatagramSocket;
+import java.net.ServerSocket;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Dictionary;
+import java.util.Enumeration;
+import java.util.concurrent.Callable;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.FutureTask;
+import java.util.concurrent.TimeUnit;
+import javax.inject.Inject;
+
+import org.apache.felix.service.command.CommandProcessor;
+import org.apache.felix.service.command.CommandSession;
+import org.ops4j.pax.exam.MavenUtils;
+import org.ops4j.pax.exam.Option;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
+import org.osgi.framework.Filter;
+import org.osgi.framework.FrameworkUtil;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceReference;
+import org.osgi.util.tracker.ServiceTracker;
+
+import static org.openengsb.labs.paxexam.karaf.options.KarafDistributionOption.karafDistributionConfiguration;
+import static org.ops4j.pax.exam.CoreOptions.maven;
+
+/**
+ * 
+ */
+public class CXFOSGiTestSupport {
+    static final Long COMMAND_TIMEOUT = 10000L;
+    static final Long DEFAULT_TIMEOUT = 20000L;
+    static final Long SERVICE_TIMEOUT = 30000L;
+    static final String GROUP_ID = "org.apache.karaf";
+    static final String ARTIFACT_ID = "apache-karaf";
+
+    static final String INSTANCE_STARTED = "Started";
+    static final String INSTANCE_STARTING = "Starting";
+
+    static final String CXF_FEATURE_URL 
+        = "mvn:org.apache.cxf.karaf/apache-cxf/" 
+          //+ org.apache.cxf.version.Version.getCurrentVersion()
+          + "2.6.0-SNAPSHOT"
+          + "/xml/features";
+
+    static final String DEBUG_OPTS = " --java-opts \"-Xdebug -Xnoagent -Djava.compiler=NONE"

+        + " -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=%s\"";
+
+    @Inject
+    protected BundleContext bundleContext;
+
+    ExecutorService executor = Executors.newCachedThreadPool();
+
+
+    /**
+     * Installs the CXF feature
+     */
+    protected void installCXF() {
+        System.err.println(executeCommand("features:addurl " + CXF_FEATURE_URL));
+        System.err.println(executeCommand("features:listurl"));
+        System.err.println(executeCommand("features:list"));
+        //executeCommand("features:install cxf");
+    }
+
+    protected void unInstallCXF() {
+        System.err.println(executeCommand("features:uninstall cxf"));
+    }
+
+    /**
+     * Create an {@link org.ops4j.pax.exam.Option} for using a .
+     *
+     * @return
+     */
+    protected Option cxfDistributionConfiguration() {
+        return karafDistributionConfiguration().frameworkUrl(
+                maven().groupId(GROUP_ID).artifactId(ARTIFACT_ID).versionAsInProject().type("tar.gz"))
+                .karafVersion(MavenUtils.getArtifactVersion(GROUP_ID, ARTIFACT_ID))
+                .name("Apache Karaf")
+                .unpackDirectory(new File("target/paxexam/"));
+    }
+
+    /**
+     * Executes a shell command and returns output as a String.
+     * Commands have a default timeout of 10 seconds.
+     *
+     * @param command
+     * @return
+     */
+    protected String executeCommand(final String command) {
+        return executeCommand(command, COMMAND_TIMEOUT, false);
+    }
+
+    /**
+     * Executes a shell command and returns output as a String.
+     * Commands have a default timeout of 10 seconds.
+     *
+     * @param command The command to execute.
+     * @param timeout The amount of time in millis to wait for the command to execute.
+     * @param silent  Specifies if the command should be displayed in the screen.
+     * @return
+     */
+    protected String executeCommand(final String command, final Long timeout, final Boolean
silent) {
+        String response;
+        final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
+        final PrintStream printStream = new PrintStream(byteArrayOutputStream);
+        final CommandProcessor commandProcessor = getOsgiService(CommandProcessor.class);
+        final CommandSession commandSession 
+            = commandProcessor.createSession(System.in, printStream, System.err);
+        FutureTask<String> commandFuture = new FutureTask<String>(
+                new Callable<String>() {
+                    public String call() {
+                        try {
+                            if (!silent) {
+                                System.err.println(command);
+                            }
+                            commandSession.execute(command);
+                        } catch (Exception e) {
+                            e.printStackTrace(System.err);
+                        }
+                        printStream.flush();
+                        return byteArrayOutputStream.toString();
+                    }
+                });
+
+        try {
+            executor.submit(commandFuture);
+            response = commandFuture.get(timeout, TimeUnit.MILLISECONDS);
+        } catch (Exception e) {
+            e.printStackTrace(System.err);
+            response = "SHELL COMMAND TIMED OUT: ";
+        }
+
+        return response;
+    }
+
+    /**
+     * Executes multiple commands inside a Single Session.
+     * Commands have a default timeout of 10 seconds.
+     *
+     * @param commands
+     * @return
+     */
+    protected String executeCommands(final String... commands) {
+        String response;
+        final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
+        final PrintStream printStream = new PrintStream(byteArrayOutputStream);
+        final CommandProcessor commandProcessor = getOsgiService(CommandProcessor.class);
+        final CommandSession commandSession 
+            = commandProcessor.createSession(System.in, printStream, System.err);
+        FutureTask<String> commandFuture = new FutureTask<String>(
+                new Callable<String>() {
+                    public String call() {
+                        try {
+                            for (String command : commands) {
+                                System.err.println(command);
+                                commandSession.execute(command);
+                            }
+                        } catch (Exception e) {
+                            e.printStackTrace(System.err);
+                        }
+                        return byteArrayOutputStream.toString();
+                    }
+                });
+
+        try {
+            executor.submit(commandFuture);
+            response = commandFuture.get(COMMAND_TIMEOUT, TimeUnit.MILLISECONDS);
+        } catch (Exception e) {
+            e.printStackTrace(System.err);
+            response = "SHELL COMMAND TIMED OUT: ";
+        }
+
+        return response;
+    }
+
+    protected Bundle getInstalledBundle(String symbolicName) {
+        for (Bundle b : bundleContext.getBundles()) {
+            if (b.getSymbolicName().equals(symbolicName)) {
+                return b;
+            }
+        }
+        for (Bundle b : bundleContext.getBundles()) {
+            System.err.println("Bundle: " + b.getSymbolicName());
+        }
+        throw new RuntimeException("Bundle " + symbolicName + " does not exist");
+    }
+
+    /*
+    * Explode the dictionary into a ,-delimited list of key=value pairs
+    */
+    private static String explode(Dictionary<String, String> dictionary) {
+        Enumeration<String> keys = dictionary.keys();
+        StringBuffer result = new StringBuffer();
+        while (keys.hasMoreElements()) {
+            Object key = keys.nextElement();
+            result.append(String.format("%s=%s", key, dictionary.get(key)));
+            if (keys.hasMoreElements()) {
+                result.append(", ");
+            }
+        }
+        return result.toString();
+    }
+
+    protected <T> T getOsgiService(Class<T> type, long timeout) {
+        return getOsgiService(type, null, timeout);
+    }
+
+    protected <T> T getOsgiService(Class<T> type) {
+        return getOsgiService(type, null, SERVICE_TIMEOUT);
+    }
+
+    protected <T> T getOsgiService(Class<T> type, String filter, long timeout)
{
+        ServiceTracker tracker = null;
+        try {
+            String flt;
+            if (filter != null) {
+                if (filter.startsWith("(")) {
+                    flt = "(&(" + Constants.OBJECTCLASS + "=" + type.getName() + ")"
+ filter + ")";
+                } else {
+                    flt = "(&(" + Constants.OBJECTCLASS + "=" + type.getName() + ")("
+ filter + "))";
+                }
+            } else {
+                flt = "(" + Constants.OBJECTCLASS + "=" + type.getName() + ")";
+            }
+            Filter osgiFilter = FrameworkUtil.createFilter(flt);
+            tracker = new ServiceTracker(bundleContext, osgiFilter, null);
+            tracker.open(true);
+            // Note that the tracker is not closed to keep the reference
+            // This is buggy, as the service reference may change i think
+            Object svc = type.cast(tracker.waitForService(timeout));
+            if (svc == null) {
+                @SuppressWarnings("unchecked")
+                Dictionary<String, String> dic = bundleContext.getBundle().getHeaders();
+                System.err.println("Test bundle headers: " + explode(dic));
+
+                for (ServiceReference ref : asCollection(bundleContext.getAllServiceReferences(null,
null))) {
+                    System.err.println("ServiceReference: " + ref);
+                }
+
+                for (ServiceReference ref : asCollection(bundleContext.getAllServiceReferences(null,
flt))) {
+                    System.err.println("Filtered ServiceReference: " + ref);
+                }
+
+                throw new RuntimeException("Gave up waiting for service " + flt);
+            }
+            return type.cast(svc);
+        } catch (InvalidSyntaxException e) {
+            throw new IllegalArgumentException("Invalid filter", e);
+        } catch (InterruptedException e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+    /**
+     * Finds a free port starting from the give port numner.
+     *
+     * @return
+     */
+    protected int getFreePort(int port) {
+        while (!isPortAvailable(port)) {
+            port++;
+        }
+        return port;
+    }
+
+    /**
+     * Returns true if port is available for use.
+     *
+     * @param port
+     * @return
+     */
+    public static boolean isPortAvailable(int port) {
+        ServerSocket ss = null;
+        DatagramSocket ds = null;
+        try {
+            ss = new ServerSocket(port);
+            ss.setReuseAddress(true);
+            ds = new DatagramSocket(port);
+            ds.setReuseAddress(true);
+            return true;
+        } catch (IOException e) {
+            //ignore
+        } finally {
+            if (ds != null) {
+                ds.close();
+            }
+
+            if (ss != null) {
+                try {
+                    ss.close();
+                } catch (IOException e) {
+                    /* should not be thrown */
+                }
+            }
+        }
+
+        return false;
+    }
+
+    /**
+     * Provides an iterable collection of references, even if the original array is null
+     */
+    private static Collection<ServiceReference> asCollection(ServiceReference[] references)
{
+        return references != null ? Arrays.asList(references) : Collections.<ServiceReference>emptyList();
+    }
+}

Propchange: cxf/trunk/osgi/itests/src/test/java/org/apache/cxf/osgi/itests/CXFOSGiTestSupport.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/trunk/osgi/itests/src/test/java/org/apache/cxf/osgi/itests/CXFOSGiTestSupport.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date



Mime
View raw message