[DOSGI-249] Change itests to use new examples
Project: http://git-wip-us.apache.org/repos/asf/cxf-dosgi/repo Commit: http://git-wip-us.apache.org/repos/asf/cxf-dosgi/commit/3f8afd08 Tree: http://git-wip-us.apache.org/repos/asf/cxf-dosgi/tree/3f8afd08 Diff: http://git-wip-us.apache.org/repos/asf/cxf-dosgi/diff/3f8afd08 Branch: refs/heads/master Commit: 3f8afd08cd0037dc2afd43c136f4797075640dbe Parents: 37cf7d3 Author: Christian Schneider <[email protected]> Authored: Tue Aug 16 14:05:24 2016 +0200 Committer: Christian Schneider <[email protected]> Committed: Tue Aug 16 14:05:24 2016 +0200 ---------------------------------------------------------------------- .../src/main/xsl/felix_distro_config.xslt | 62 +--- .../src/main/xsl/filter_features.xslt | 4 + distribution/repository/pom.xml | 17 +- itests/multi-bundle/pom.xml | 16 +- .../dosgi/itests/multi/AbstractDosgiTest.java | 303 +++++++++++++++++++ .../dosgi/itests/multi/MultiBundleTools.java | 102 +++++++ .../itests/multi/TaskServiceProxyFactory.java | 36 +++ .../dosgi/itests/multi/TestCustomIntent.java | 73 +++++ .../dosgi/itests/multi/TestExportService.java | 123 ++++++++ .../dosgi/itests/multi/TestImportService.java | 107 +++++++ .../dosgi/itests/multi/TestTaskServiceImpl.java | 49 +++ .../customintent/ChangeTitleInterceptor.java | 47 +++ .../multi/customintent/CustomFeature.java | 32 ++ .../customintent/CustomIntentActivator.java | 47 +++ .../systests2/multi/AbstractDosgiTest.java | 248 --------------- .../multi/GreeterServiceProxyFactory.java | 44 --- .../dosgi/systests2/multi/MultiBundleTools.java | 102 ------- .../dosgi/systests2/multi/TestCustomIntent.java | 91 ------ .../systests2/multi/TestDiscoveryExport.java | 53 ---- .../systests2/multi/TestExportRestService.java | 77 ----- .../systests2/multi/TestExportService.java | 117 ------- .../systests2/multi/TestImportService.java | 104 ------- .../AddGreetingPhraseInterceptor.java | 44 --- .../multi/customintent/CustomFeature.java | 33 -- .../customintent/CustomIntentActivator.java | 37 --- .../service/EmptyGreeterService.java | 41 --- ...GreeterServiceWithCustomIntentActivator.java | 42 --- .../multi/importservice/SimpleGreeter.java | 41 --- .../systests2/multi/rest/RestTranslate.java | 34 --- .../systests2/multi/rest/RestTranslateImpl.java | 41 --- .../multi/rest/TranslateActivator.java | 40 --- .../src/test/resources/rs-test1.xml | 4 +- parent/pom.xml | 2 +- samples/rest/api/bnd.bnd | 5 +- .../cxf/jaxrs/GreeterService2-model.xml | 7 - .../samples/rest/impl/TaskResourceImpl.java | 76 +++++ .../samples/rest/impl/TaskServiceImpl.java | 74 ----- .../samples/soap/impl/TaskServiceImpl.java | 18 +- 38 files changed, 1039 insertions(+), 1354 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/3f8afd08/distribution/multi-bundle/src/main/xsl/felix_distro_config.xslt ---------------------------------------------------------------------- diff --git a/distribution/multi-bundle/src/main/xsl/felix_distro_config.xslt b/distribution/multi-bundle/src/main/xsl/felix_distro_config.xslt index eeb88b5..979cd6d 100644 --- a/distribution/multi-bundle/src/main/xsl/felix_distro_config.xslt +++ b/distribution/multi-bundle/src/main/xsl/felix_distro_config.xslt @@ -11,65 +11,5 @@ org.osgi.framework.startlevel.beginning=200 felix.auto.start.<xsl:value-of select="$i"/>=file:dosgi_bundles/<xsl:value-of select="@name"/> </xsl:for-each> -org.osgi.framework.system.packages=org.osgi.framework; version=1.5.0, \ - org.osgi.framework.launch; version=1.0.0, \ - org.osgi.framework.hooks.service; version=1.0.0, \ - org.osgi.framework.wiring; version=1.0.0 , \ - org.osgi.service.packageadmin; version=1.2.0, \ - org.osgi.service.startlevel; version=1.1.0, \ - org.osgi.service.url; version=1.0.0, \ - org.osgi.util.tracker; version=1.4.0, \ - org.apache.karaf.jaas.boot; version=2.2.9, \ - org.apache.karaf.version; version=2.2.9, \ - javax.annotation.processing, \ - javax.crypto, \ - javax.crypto.spec, \ - javax.imageio, \ - javax.imageio.stream, \ - javax.lang.model, \ - javax.lang.model.element, \ - javax.lang.model.type, \ - javax.lang.model.util, \ - javax.naming, \ - javax.xml.bind.annotation, \ - javax.xml.datatype, \ - javax.xml.parsers, \ - javax.xml.namespace, \ - javax.xml.transform, \ - javax.xml.transform.dom, \ - javax.xml.transform.sax, \ - javax.xml.transform.stream, \ - javax.xml.validation, \ - javax.xml.xpath, \ - javax.management, \ - javax.management.modelmbean, \ - javax.management.remote, \ - javax.naming.directory, \ - javax.naming.spi, \ - javax.net, \ - javax.net.ssl, \ - javax.security.auth, \ - javax.security.auth.callback, \ - javax.security.auth.login, \ - javax.security.auth.spi, \ - javax.security.auth.x500, \ - javax.security.cert, \ - javax.sql, \ - javax.swing, \ - javax.swing.border, \ - javax.swing.tree, \ - javax.tools, \ - javax.transaction; javax.transaction.xa; partial=true; mandatory:=partial, \ - javax.xml.transform.stax, \ - javax.wsdl, \ - javax.wsdl.extensions, \ - org.ietf.jgss, \ - org.xml.sax, \ - org.xml.sax.ext, \ - org.xml.sax.helpers, \ - org.w3c.dom, \ - org.w3c.dom.bootstrap, \ - org.w3c.dom.ls - - </xsl:template> +</xsl:template> </xsl:transform> http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/3f8afd08/distribution/multi-bundle/src/main/xsl/filter_features.xslt ---------------------------------------------------------------------- diff --git a/distribution/multi-bundle/src/main/xsl/filter_features.xslt b/distribution/multi-bundle/src/main/xsl/filter_features.xslt index 81b33a3..096c8a3 100644 --- a/distribution/multi-bundle/src/main/xsl/filter_features.xslt +++ b/distribution/multi-bundle/src/main/xsl/filter_features.xslt @@ -12,6 +12,10 @@ <xsl:template match="bundle[@artifactId='org.apache.karaf.scr.command']"></xsl:template> <xsl:template match="bundle[@artifactId='org.apache.felix.webconsole.plugins.ds']"></xsl:template> <xsl:template match="bundle[@artifactId='org.apache.aries.rsa.discovery.command']"></xsl:template> + <xsl:template match="bundle[@artifactId='woodstox-core-asl']"></xsl:template> + <xsl:template match="bundle[@artifactId='org.apache.servicemix.specs.jaxb-api']"></xsl:template> + <xsl:template match="bundle[@artifactId='org.apache.servicemix.bundles.jaxb-xjc']"></xsl:template> + <xsl:template match="bundle[@artifactId='org.apache.servicemix.bundles.jaxb-impl']"></xsl:template> <!-- Copy the rest unachanged --> <xsl:template match="@* | node()"> http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/3f8afd08/distribution/repository/pom.xml ---------------------------------------------------------------------- diff --git a/distribution/repository/pom.xml b/distribution/repository/pom.xml index b8bc426..f87ce62 100644 --- a/distribution/repository/pom.xml +++ b/distribution/repository/pom.xml @@ -8,9 +8,14 @@ <relativePath>../../parent/pom.xml</relativePath> </parent> <artifactId>cxf-dosgi-ri-repository</artifactId> - <packaging>pom</packaging> <dependencies> <dependency> + <groupId>org.apache.aries.rsa</groupId> + <artifactId>repository</artifactId> + <version>1.9.0</version> + <type>pom</type> + </dependency> + <dependency> <groupId>org.apache.cxf.dosgi</groupId> <artifactId>cxf-dosgi-ri-provider-ws</artifactId> <version>${project.version}</version> @@ -21,11 +26,11 @@ <version>${project.version}</version> </dependency> <dependency> - <groupId>org.apache.servicemix.bundles</groupId> - <artifactId> - org.apache.servicemix.bundles.wsdl4j - </artifactId> - <version>1.6.3_1</version> + <groupId>org.apache.servicemix.bundles</groupId> + <artifactId> + org.apache.servicemix.bundles.wsdl4j + </artifactId> + <version>1.6.3_1</version> </dependency> </dependencies> <name>CXF DOSGi Distribution Repository</name> http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/3f8afd08/itests/multi-bundle/pom.xml ---------------------------------------------------------------------- diff --git a/itests/multi-bundle/pom.xml b/itests/multi-bundle/pom.xml index e588d4b..2dae19b 100644 --- a/itests/multi-bundle/pom.xml +++ b/itests/multi-bundle/pom.xml @@ -110,6 +110,11 @@ </dependency> <dependency> <groupId>org.apache.cxf</groupId> + <artifactId>cxf-rt-frontend-jaxws</artifactId> + <version>${cxf.version}</version> + </dependency> + <dependency> + <groupId>org.apache.cxf</groupId> <artifactId>cxf-rt-frontend-jaxrs</artifactId> <version>${cxf.version}</version> </dependency> @@ -143,29 +148,29 @@ <!-- Samples --> <dependency> <groupId>org.apache.cxf.dosgi.samples</groupId> - <artifactId>cxf-dosgi-ri-samples-greeter-impl</artifactId> + <artifactId>cxf-dosgi-samples-soap-api</artifactId> <version>${project.version}</version> <scope>test</scope> </dependency> <dependency> <groupId>org.apache.cxf.dosgi.samples</groupId> - <artifactId>cxf-dosgi-ri-samples-greeter-interface</artifactId> + <artifactId>cxf-dosgi-samples-soap-impl</artifactId> <version>${project.version}</version> <scope>test</scope> </dependency> <dependency> <groupId>org.apache.cxf.dosgi.samples</groupId> - <artifactId>cxf-dosgi-ri-samples-greeter-rest-impl</artifactId> + <artifactId>cxf-dosgi-samples-rest-api</artifactId> <version>${project.version}</version> <scope>test</scope> </dependency> <dependency> <groupId>org.apache.cxf.dosgi.samples</groupId> - <artifactId>cxf-dosgi-ri-samples-greeter-rest-interface</artifactId> + <artifactId>cxf-dosgi-samples-rest-impl</artifactId> <version>${project.version}</version> <scope>test</scope> </dependency> - + <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> @@ -225,6 +230,7 @@ </systemPropertyVariables> </configuration> </plugin> + </plugins> </build> </project> http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/3f8afd08/itests/multi-bundle/src/test/java/org/apache/cxf/dosgi/itests/multi/AbstractDosgiTest.java ---------------------------------------------------------------------- diff --git a/itests/multi-bundle/src/test/java/org/apache/cxf/dosgi/itests/multi/AbstractDosgiTest.java b/itests/multi-bundle/src/test/java/org/apache/cxf/dosgi/itests/multi/AbstractDosgiTest.java new file mode 100644 index 0000000..2a1b148 --- /dev/null +++ b/itests/multi-bundle/src/test/java/org/apache/cxf/dosgi/itests/multi/AbstractDosgiTest.java @@ -0,0 +1,303 @@ +/** + * 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.dosgi.itests.multi; + +import static org.ops4j.pax.exam.CoreOptions.composite; +import static org.ops4j.pax.exam.CoreOptions.frameworkStartLevel; +import static org.ops4j.pax.exam.CoreOptions.mavenBundle; +import static org.ops4j.pax.exam.CoreOptions.systemProperty; +import static org.ops4j.pax.exam.cm.ConfigurationAdminOptions.newConfiguration; + +import java.io.File; +import java.io.IOException; +import java.net.ConnectException; +import java.net.HttpURLConnection; +import java.net.InetSocketAddress; +import java.net.MalformedURLException; +import java.net.ServerSocket; +import java.net.Socket; +import java.net.URL; +import java.util.Collection; +import java.util.concurrent.Callable; +import java.util.concurrent.TimeoutException; + +import javax.inject.Inject; + +import org.apache.zookeeper.ZooKeeper; +import org.apache.zookeeper.data.Stat; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.ops4j.pax.exam.CoreOptions; +import org.ops4j.pax.exam.Option; +import org.ops4j.pax.exam.cm.ConfigurationAdminOptions; +import org.ops4j.pax.exam.options.MavenArtifactProvisionOption; +import org.ops4j.pax.exam.options.extra.VMOption; +import org.osgi.framework.Bundle; +import org.osgi.framework.BundleContext; +import org.osgi.framework.BundleException; +import org.osgi.framework.ServiceReference; + +public class AbstractDosgiTest { + static final int ZK_PORT = 35101; + private static final int TIMEOUT = 20; + + @Inject + BundleContext bundleContext; + + @BeforeClass + public static void log() { + System.out.println("-----------------------------------------------------------------"); + } + + public <T> T tryTo(String message, Callable<T> func) throws TimeoutException { + return tryTo(message, func, 5000); + } + + public <T> T tryTo(String message, Callable<T> func, long timeout) throws TimeoutException { + Throwable lastException = null; + long startTime = System.currentTimeMillis(); + while (System.currentTimeMillis() - startTime < timeout) { + try { + T result = func.call(); + if (result != null) { + return result; + } + lastException = null; + } catch (Throwable e) { + lastException = e; + e.printStackTrace(); + } + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + continue; + } + } + TimeoutException ex = new TimeoutException("Timeout while trying to " + message); + if (lastException != null) { + ex.addSuppressed(lastException); + } + throw ex; + } + + + /** + * Sleeps for a short interval, throwing an exception if timeout has been reached. Used to facilitate a + * retry interval with timeout when used in a loop. + * + * @param startTime the start time of the entire operation in milliseconds + * @param timeout the timeout duration for the entire operation in seconds + * @param message the error message to use when timeout occurs + * @throws InterruptedException if interrupted while sleeping + */ + private static void sleepOrTimeout(long startTime, long timeout, String message) + throws InterruptedException, TimeoutException { + timeout *= 1000; // seconds to millis + long elapsed = System.currentTimeMillis() - startTime; + long remaining = timeout - elapsed; + if (remaining <= 0) { + throw new TimeoutException(message); + } + long interval = Math.min(remaining, 1000); + Thread.sleep(interval); + } + + @SuppressWarnings({ + "rawtypes", "unchecked" + }) + protected ServiceReference waitService(BundleContext bc, Class cls, String filter, int timeout) + throws Exception { + System.out.println("Waiting for service: " + cls + " " + filter); + long startTime = System.currentTimeMillis(); + while (true) { + Collection refs = bc.getServiceReferences(cls, filter); + if (refs != null && refs.size() > 0) { + return (ServiceReference)refs.iterator().next(); + } + sleepOrTimeout(startTime, timeout, "Service not found: " + cls + " " + filter); + } + } + + protected void waitPort(int port) throws Exception { + System.out.println("Waiting for server to appear on port: " + port); + long startTime = System.currentTimeMillis(); + while (true) { + Socket s = null; + try { + s = new Socket((String)null, port); + // yep, its available + System.out.println("Port: " + port + " is listening now"); + return; + } catch (IOException e) { + sleepOrTimeout(startTime, TIMEOUT, "Timeout waiting for port " + port); + } finally { + if (s != null) { + try { + s.close(); + } catch (IOException e) { + // ignore + } + } + } + } + } + + protected Bundle getBundleByName(BundleContext bc, String name) { + for (Bundle bundle : bc.getBundles()) { + if (bundle.getSymbolicName().equals(name)) { + return bundle; + } + } + return null; + } + + protected static int getFreePort() { + try (ServerSocket socket = new ServerSocket()) { + socket.setReuseAddress(true); // enables quickly reopening socket on same port + socket.bind(new InetSocketAddress(0)); // zero finds a free port + return socket.getLocalPort(); + } catch (Exception e) { + throw new RuntimeException(e.getMessage(), e); + } + } + + protected void waitWebPage(String urlSt) throws InterruptedException, TimeoutException { + System.out.println("Waiting for url " + urlSt); + HttpURLConnection con = null; + long startTime = System.currentTimeMillis(); + while (true) { + try { + URL url = new URL(urlSt); + con = (HttpURLConnection)url.openConnection(); + int status = con.getResponseCode(); + if (status == 200) { + return; + } + } catch (ConnectException e) { + // Ignore connection refused + } catch (MalformedURLException e) { + throw new RuntimeException(e.getMessage(), e); + } catch (IOException e) { + throw new RuntimeException(e.getMessage(), e); + } finally { + if (con != null) { + con.disconnect(); + } + } + sleepOrTimeout(startTime, TIMEOUT, "Timeout waiting for web page " + urlSt); + } + } + + protected void assertBundlesStarted() { + for (Bundle bundle : bundleContext.getBundles()) { + System.out + .println(bundle.getSymbolicName() + ":" + bundle.getVersion() + ": " + bundle.getState()); + if (bundle.getState() != Bundle.ACTIVE) { + try { + bundle.start(); + } catch (BundleException e) { + e.printStackTrace(); + } + } + } + } + + protected ZooKeeper createZookeeperClient() throws Exception { + waitPort(ZK_PORT); + return new ZooKeeper("localhost:" + ZK_PORT, 1000, null); + } + + protected void assertNodeExists(ZooKeeper zk, String zNode, int timeout) { + long endTime = System.currentTimeMillis() + timeout; + Stat stat = null; + while (stat == null && System.currentTimeMillis() < endTime) { + try { + stat = zk.exists(zNode, null); + Thread.sleep(200); + } catch (Exception e) { + // Ignore + } + } + Assert.assertNotNull("ZooKeeper node " + zNode + " was not found", stat); + } + + protected static Option configZKConsumer() { + return newConfiguration("org.apache.aries.rsa.discovery.zookeeper") // + .put("zookeeper.host", "127.0.0.1") // + .put("zookeeper.port", "" + ZK_PORT).asOption(); + } + + protected static Option configZKServer() { + return newConfiguration("org.apache.aries.rsa.discovery.zookeeper.server") + .put("clientPort", "" + ZK_PORT) // + .asOption(); + } + + protected static Option configLogging() { + return ConfigurationAdminOptions.configurationFolder(new File("src/test/resources/cfg")); + } + + + protected static MavenArtifactProvisionOption taskServiceAPI() { + return mavenBundle().groupId("org.apache.cxf.dosgi.samples") + .artifactId("cxf-dosgi-samples-soap-api").versionAsInProject(); + } + + protected static MavenArtifactProvisionOption taskServiceImpl() { + return mavenBundle().groupId("org.apache.cxf.dosgi.samples") + .artifactId("cxf-dosgi-samples-soap-impl").versionAsInProject(); + } + + + protected static MavenArtifactProvisionOption taskRESTAPI() { + return mavenBundle().groupId("org.apache.cxf.dosgi.samples") + .artifactId("cxf-dosgi-samples-rest-api").versionAsInProject(); + } + + + protected static MavenArtifactProvisionOption taskRESTImpl() { + return mavenBundle().groupId("org.apache.cxf.dosgi.samples") + .artifactId("cxf-dosgi-samples-rest-impl").versionAsInProject(); + } + + + protected static Option basicTestOptions() throws Exception { + return composite(MultiBundleTools.getDistro(), // + CoreOptions.junitBundles(), // + + // Enable JAXB from JRE + CoreOptions.bootDelegationPackages("com.sun.*"), + CoreOptions.systemPackages( + "javax.xml.bind.annotation;version=2.2.1", + "javax.xml.bind;version=2.2.1"), + + systemProperty("org.ops4j.pax.logging.DefaultServiceLog.level").value("INFO"), // + systemProperty("pax.exam.osgi.unresolved.fail").value("true"), // + systemProperty("org.apache.cxf.stax.allowInsecureParser").value("true"), // + configLogging(), + frameworkStartLevel(100) + ); + } + + + protected static VMOption debug() { + return CoreOptions.vmOption("-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005"); + } + +} http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/3f8afd08/itests/multi-bundle/src/test/java/org/apache/cxf/dosgi/itests/multi/MultiBundleTools.java ---------------------------------------------------------------------- diff --git a/itests/multi-bundle/src/test/java/org/apache/cxf/dosgi/itests/multi/MultiBundleTools.java b/itests/multi-bundle/src/test/java/org/apache/cxf/dosgi/itests/multi/MultiBundleTools.java new file mode 100644 index 0000000..f7d43be --- /dev/null +++ b/itests/multi-bundle/src/test/java/org/apache/cxf/dosgi/itests/multi/MultiBundleTools.java @@ -0,0 +1,102 @@ +/** + * 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.dosgi.itests.multi; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.net.URL; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Properties; +import java.util.TreeMap; + +import org.ops4j.pax.exam.CoreOptions; +import org.ops4j.pax.exam.Option; + +public final class MultiBundleTools { + + private MultiBundleTools() { + } + + private static Properties getProps(File distroDir) throws FileNotFoundException, IOException { + Properties p = new Properties(); + File confFile = new File(distroDir, "conf/felix.config.properties.append"); + p.load(new FileInputStream(confFile)); + return p; + } + + private static int getDistroBundles(File distroDir, + Properties props, + Map<Integer, String> bundles) throws Exception { + int startLevel = Integer.parseInt(props.getProperty("org.osgi.framework.startlevel.beginning")); + for (int i = 0; i <= startLevel; i++) { + String val = props.getProperty("felix.auto.start." + i); + if (val != null) { + if (val.startsWith("file:")) { + File fullDir = new File(distroDir, val.substring("file:".length())); + bundles.put(i, fullDir.toURI().toASCIIString()); + } else { + if (!val.contains("org.osgi.compendium")) { + // We're skipping that one as it's pulled in explicitly in the test + bundles.put(i, val); + } + } + } + } + return startLevel + 1; // Add 1 to start level to be on the safe side + } + + private static File getRootDirectory() { + String resourceName = "/" + MultiBundleTools.class.getName().replace('.', '/') + ".class"; + URL curURL = MultiBundleTools.class.getResource(resourceName); + File curFile = new File(curURL.getFile()); + String curString = curFile.getAbsolutePath(); + File curBase = new File(curString.substring(0, curString.length() - resourceName.length())); + return curBase.getParentFile().getParentFile(); + } + + private static Option[] getDistroBundleOptions() throws Exception { + Map<Integer, String> bundles = new TreeMap<Integer, String>(); + File root = getRootDirectory(); + File depRoot = new File(root, "target/dependency"); + File distroDir = depRoot.listFiles()[0]; + Properties props = getProps(distroDir); + getDistroBundles(distroDir, props, bundles); + List<Option> opts = new ArrayList<Option>(); + + /* + String sysPackagesValue = props.getProperty("org.osgi.framework.system.packages"); + opts.add(CoreOptions.frameworkProperty("org.osgi.framework.system.packages") + .value(sysPackagesValue)); + */ + + for (Map.Entry<Integer, String> entry : bundles.entrySet()) { + String bundleUri = entry.getValue(); + opts.add(CoreOptions.bundle(bundleUri)); + } + return opts.toArray(new Option[opts.size()]); + } + + public static Option getDistro() throws Exception { + return CoreOptions.composite(getDistroBundleOptions()); + } +} http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/3f8afd08/itests/multi-bundle/src/test/java/org/apache/cxf/dosgi/itests/multi/TaskServiceProxyFactory.java ---------------------------------------------------------------------- diff --git a/itests/multi-bundle/src/test/java/org/apache/cxf/dosgi/itests/multi/TaskServiceProxyFactory.java b/itests/multi-bundle/src/test/java/org/apache/cxf/dosgi/itests/multi/TaskServiceProxyFactory.java new file mode 100644 index 0000000..d2614a2 --- /dev/null +++ b/itests/multi-bundle/src/test/java/org/apache/cxf/dosgi/itests/multi/TaskServiceProxyFactory.java @@ -0,0 +1,36 @@ +/** + * 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.dosgi.itests.multi; + +import org.apache.cxf.dosgi.samples.soap.TaskService; +import org.apache.cxf.jaxws.JaxWsProxyFactoryBean; + +public final class TaskServiceProxyFactory { + + private TaskServiceProxyFactory() { + } + + protected static TaskService create(String serviceUri) { + JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean(); + factory.setServiceClass(TaskService.class); + factory.setAddress(serviceUri); + return (TaskService)factory.create(); + } + +} http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/3f8afd08/itests/multi-bundle/src/test/java/org/apache/cxf/dosgi/itests/multi/TestCustomIntent.java ---------------------------------------------------------------------- diff --git a/itests/multi-bundle/src/test/java/org/apache/cxf/dosgi/itests/multi/TestCustomIntent.java b/itests/multi-bundle/src/test/java/org/apache/cxf/dosgi/itests/multi/TestCustomIntent.java new file mode 100644 index 0000000..a237834 --- /dev/null +++ b/itests/multi-bundle/src/test/java/org/apache/cxf/dosgi/itests/multi/TestCustomIntent.java @@ -0,0 +1,73 @@ +/** + * 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.dosgi.itests.multi; + +import static org.apache.cxf.dosgi.itests.multi.TaskServiceProxyFactory.create; +import static org.ops4j.pax.exam.CoreOptions.streamBundle; + +import java.io.InputStream; + +import org.apache.cxf.dosgi.itests.multi.customintent.ChangeTitleInterceptor; +import org.apache.cxf.dosgi.itests.multi.customintent.CustomFeature; +import org.apache.cxf.dosgi.itests.multi.customintent.CustomIntentActivator; +import org.apache.cxf.dosgi.samples.soap.Task; +import org.apache.cxf.dosgi.samples.soap.TaskService; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.ops4j.pax.exam.Configuration; +import org.ops4j.pax.exam.Option; +import org.ops4j.pax.exam.junit.PaxExam; +import org.ops4j.pax.tinybundles.core.TinyBundles; +import org.osgi.framework.Constants; + +@RunWith(PaxExam.class) +public class TestCustomIntent extends AbstractDosgiTest { + + @Configuration + public static Option[] configure() throws Exception { + return new Option[] // + { + basicTestOptions(), // + taskServiceAPI(), // + streamBundle(getCustomIntentBundle()), // + //debug() + }; + } + + @Test + public void testCustomIntent() throws Exception { + Thread.sleep(1000); + TaskService greeterService = create("http://localhost:8080/cxf/taskservice"); + Task task = greeterService.get(1); + Assert.assertEquals("changed", task.getTitle()); + } + + private static InputStream getCustomIntentBundle() { + return TinyBundles.bundle() // + .add(CustomIntentActivator.class) // + .add(CustomFeature.class) // + .add(ChangeTitleInterceptor.class) // + .add(TestTaskServiceImpl.class) // + .set(Constants.BUNDLE_SYMBOLICNAME, "CustomIntent") // + .set(Constants.BUNDLE_ACTIVATOR, CustomIntentActivator.class.getName()) + .build(TinyBundles.withBnd()); + } + +} http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/3f8afd08/itests/multi-bundle/src/test/java/org/apache/cxf/dosgi/itests/multi/TestExportService.java ---------------------------------------------------------------------- diff --git a/itests/multi-bundle/src/test/java/org/apache/cxf/dosgi/itests/multi/TestExportService.java b/itests/multi-bundle/src/test/java/org/apache/cxf/dosgi/itests/multi/TestExportService.java new file mode 100644 index 0000000..150d1d7 --- /dev/null +++ b/itests/multi-bundle/src/test/java/org/apache/cxf/dosgi/itests/multi/TestExportService.java @@ -0,0 +1,123 @@ +/** + * 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.dosgi.itests.multi; + +import java.io.IOException; +import java.net.URL; +import java.util.concurrent.TimeoutException; + +import javax.ws.rs.core.MediaType; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; + +import org.apache.cxf.dosgi.samples.soap.Task; +import org.apache.cxf.dosgi.samples.soap.TaskService; +import org.apache.cxf.jaxrs.client.WebClient; +import org.apache.zookeeper.ZooKeeper; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.ops4j.pax.exam.Configuration; +import org.ops4j.pax.exam.Option; +import org.ops4j.pax.exam.junit.PaxExam; +import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy; +import org.ops4j.pax.exam.spi.reactors.PerClass; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.xml.sax.SAXException; + +/** + * Deploys the sample SOAP service and zookeeper discovery. + * Then checks the service can be called via plain CXF and is announced in zookeeper + */ +@RunWith(PaxExam.class) +@ExamReactorStrategy(PerClass.class) +public class TestExportService extends AbstractDosgiTest { + + private static final String SERVICE_URI = "http://localhost:8080/cxf/taskservice"; + private static final String REST_SERVICE_URI = "http://localhost:8080/cxf/tasks"; + + private static final String GREETER_ZOOKEEPER_NODE = // + "/osgi/service_registry/org/apache/cxf/dosgi/samples/soap/TaskService/localhost#8181##cxf#taskservice"; + + @Configuration + public static Option[] configure() throws Exception { + return new Option[] // + {// + basicTestOptions(), // + configZKServer(), // + configZKConsumer(), // + taskServiceAPI(), // + taskServiceImpl(), // + taskRESTAPI(), // + taskRESTImpl(), // + //debug(), + }; + } + + @Test + public void testSOAPCall() throws Exception { + waitPort(8080); + Thread.sleep(1000); + checkWsdl(new URL(SERVICE_URI + "?wsdl")); + checkServiceCall(SERVICE_URI); + } + + @Test + public void testRESTCall() throws Exception { + waitPort(8080); + Thread.sleep(1000); + checkRESTCall(REST_SERVICE_URI); + } + + @Test + public void testDiscoveryExport() throws Exception { + ZooKeeper zk = createZookeeperClient(); + assertNodeExists(zk, GREETER_ZOOKEEPER_NODE, 5000); + zk.close(); + } + + private void checkWsdl(URL wsdlURL) throws ParserConfigurationException, SAXException, IOException { + DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + dbf.setNamespaceAware(true); + dbf.setValidating(false); + DocumentBuilder db = dbf.newDocumentBuilder(); + Document doc = db.parse(wsdlURL.openStream()); + Element el = doc.getDocumentElement(); + Assert.assertEquals("definitions", el.getLocalName()); + Assert.assertEquals("http://schemas.xmlsoap.org/wsdl/", el.getNamespaceURI()); + Assert.assertEquals("TaskServiceService", el.getAttribute("name")); + } + + private void checkServiceCall(String serviceUri) { + TaskService taskService = TaskServiceProxyFactory.create(serviceUri); + Task task = taskService.get(1); + Assert.assertEquals("Buy some coffee", task.getTitle()); + } + + private void checkRESTCall(String restServiceUri) throws InterruptedException, TimeoutException { + waitWebPage(REST_SERVICE_URI); + WebClient client = WebClient.create(REST_SERVICE_URI + "/1"); + client.accept(MediaType.APPLICATION_XML_TYPE); + org.apache.cxf.dosgi.samples.rest.Task task = client.get(org.apache.cxf.dosgi.samples.rest.Task.class); + Assert.assertEquals("Buy some coffee", task.getTitle()); + } + +} http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/3f8afd08/itests/multi-bundle/src/test/java/org/apache/cxf/dosgi/itests/multi/TestImportService.java ---------------------------------------------------------------------- diff --git a/itests/multi-bundle/src/test/java/org/apache/cxf/dosgi/itests/multi/TestImportService.java b/itests/multi-bundle/src/test/java/org/apache/cxf/dosgi/itests/multi/TestImportService.java new file mode 100644 index 0000000..61517f3 --- /dev/null +++ b/itests/multi-bundle/src/test/java/org/apache/cxf/dosgi/itests/multi/TestImportService.java @@ -0,0 +1,107 @@ +/** + * 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.dosgi.itests.multi; + +import static org.ops4j.pax.exam.CoreOptions.provision; +import static org.ops4j.pax.exam.CoreOptions.systemProperty; + +import java.io.InputStream; + +import javax.inject.Inject; + +import org.apache.cxf.dosgi.samples.soap.Task; +import org.apache.cxf.dosgi.samples.soap.TaskService; +import org.apache.cxf.endpoint.Server; +import org.apache.cxf.frontend.ServerFactoryBean; +import org.apache.cxf.jaxws.JaxWsServerFactoryBean; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.ops4j.pax.exam.Configuration; +import org.ops4j.pax.exam.Option; +import org.ops4j.pax.exam.junit.PaxExam; +import org.ops4j.pax.tinybundles.core.TinyBundles; +import org.osgi.framework.Constants; + +/** + * Creates a service outside OSGi, + * announces the service via the xml based discovery. + * Checks that the service proxy is created by CXF DOSGi and can be called. + */ +@RunWith(PaxExam.class) +public class TestImportService extends AbstractDosgiTest { + @Inject + TaskService taskService; + + private Server server; + + @Configuration + public static Option[] configure() throws Exception { + return new Option[] // + {// + basicTestOptions(), // + taskServiceAPI(), // + provision(importConfigBundle()), // + // increase for debugging + systemProperty("org.apache.cxf.dosgi.test.serviceWaitTimeout") + .value(System.getProperty("org.apache.cxf.dosgi.test.serviceWaitTimeout", "200")), + }; + } + + protected static InputStream importConfigBundle() { + return TinyBundles.bundle() // + .add("OSGI-INF/remote-service/remote-services.xml", + TestImportService.class.getResource("/rs-test1.xml")) // + .set(Constants.BUNDLE_SYMBOLICNAME, "importConfig") // + .build(TinyBundles.withBnd()); + } + + @Before + public void createCXFService() { + server = publishService(); + } + + @Test + public void testClientConsumer() throws Exception { + Task task = taskService.get(1); + Assert.assertEquals("test", task.getTitle()); + } + + @After + public void stopCXFService() { + server.stop(); + } + + private Server publishService() { + System.out.println("Publishing service"); + ClassLoader cl = Thread.currentThread().getContextClassLoader(); + try { + Thread.currentThread().setContextClassLoader(ServerFactoryBean.class.getClassLoader()); + JaxWsServerFactoryBean factory = new JaxWsServerFactoryBean(); + factory.setServiceClass(TaskService.class); + factory.setAddress("http://localhost:9191/taskservice"); + factory.setServiceBean(new TestTaskServiceImpl()); + return factory.create(); + } finally { + Thread.currentThread().setContextClassLoader(cl); + } + } +} http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/3f8afd08/itests/multi-bundle/src/test/java/org/apache/cxf/dosgi/itests/multi/TestTaskServiceImpl.java ---------------------------------------------------------------------- diff --git a/itests/multi-bundle/src/test/java/org/apache/cxf/dosgi/itests/multi/TestTaskServiceImpl.java b/itests/multi-bundle/src/test/java/org/apache/cxf/dosgi/itests/multi/TestTaskServiceImpl.java new file mode 100644 index 0000000..72a16d5 --- /dev/null +++ b/itests/multi-bundle/src/test/java/org/apache/cxf/dosgi/itests/multi/TestTaskServiceImpl.java @@ -0,0 +1,49 @@ +/** + * 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.dosgi.itests.multi; + +import java.util.Collection; + +import org.apache.cxf.dosgi.samples.soap.Task; +import org.apache.cxf.dosgi.samples.soap.TaskService; + +public class TestTaskServiceImpl implements TaskService { + + @Override + public Task get(Integer id) { + return new Task(1, "test", ""); + } + + @Override + public void addOrUpdate(Task task) { + throw new UnsupportedOperationException(); + } + + @Override + public void delete(Integer id) { + throw new UnsupportedOperationException(); + + } + + @Override + public Collection<Task> getAll() { + throw new UnsupportedOperationException(); + } + +} http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/3f8afd08/itests/multi-bundle/src/test/java/org/apache/cxf/dosgi/itests/multi/customintent/ChangeTitleInterceptor.java ---------------------------------------------------------------------- diff --git a/itests/multi-bundle/src/test/java/org/apache/cxf/dosgi/itests/multi/customintent/ChangeTitleInterceptor.java b/itests/multi-bundle/src/test/java/org/apache/cxf/dosgi/itests/multi/customintent/ChangeTitleInterceptor.java new file mode 100644 index 0000000..fcec431 --- /dev/null +++ b/itests/multi-bundle/src/test/java/org/apache/cxf/dosgi/itests/multi/customintent/ChangeTitleInterceptor.java @@ -0,0 +1,47 @@ +/** + * 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.dosgi.itests.multi.customintent; + +import java.lang.reflect.Method; + +import org.apache.cxf.dosgi.samples.soap.Task; +import org.apache.cxf.interceptor.Fault; +import org.apache.cxf.message.Message; +import org.apache.cxf.message.MessageContentsList; +import org.apache.cxf.phase.AbstractPhaseInterceptor; +import org.apache.cxf.phase.Phase; + +public final class ChangeTitleInterceptor extends AbstractPhaseInterceptor<Message> { + + ChangeTitleInterceptor() { + super(Phase.USER_LOGICAL); + } + + public void handleMessage(Message message) throws Fault { + MessageContentsList contents = MessageContentsList.getContentsList(message); + Object response = contents.get(0); + Method method = response.getClass().getMethods()[0]; + try { + Task task = (Task)method.invoke(response); + task.setTitle("changed"); + } catch (Exception e) { + } + + } +} http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/3f8afd08/itests/multi-bundle/src/test/java/org/apache/cxf/dosgi/itests/multi/customintent/CustomFeature.java ---------------------------------------------------------------------- diff --git a/itests/multi-bundle/src/test/java/org/apache/cxf/dosgi/itests/multi/customintent/CustomFeature.java b/itests/multi-bundle/src/test/java/org/apache/cxf/dosgi/itests/multi/customintent/CustomFeature.java new file mode 100644 index 0000000..7d46c87 --- /dev/null +++ b/itests/multi-bundle/src/test/java/org/apache/cxf/dosgi/itests/multi/customintent/CustomFeature.java @@ -0,0 +1,32 @@ +/** + * 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.dosgi.itests.multi.customintent; + +import org.apache.cxf.Bus; +import org.apache.cxf.feature.AbstractFeature; +import org.apache.cxf.interceptor.InterceptorProvider; + +public final class CustomFeature extends AbstractFeature { + + @Override + protected void initializeProvider(InterceptorProvider provider, Bus bus) { + provider.getOutInterceptors().add(0, new ChangeTitleInterceptor()); + super.initializeProvider(provider, bus); + } +} http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/3f8afd08/itests/multi-bundle/src/test/java/org/apache/cxf/dosgi/itests/multi/customintent/CustomIntentActivator.java ---------------------------------------------------------------------- diff --git a/itests/multi-bundle/src/test/java/org/apache/cxf/dosgi/itests/multi/customintent/CustomIntentActivator.java b/itests/multi-bundle/src/test/java/org/apache/cxf/dosgi/itests/multi/customintent/CustomIntentActivator.java new file mode 100644 index 0000000..ec9db36 --- /dev/null +++ b/itests/multi-bundle/src/test/java/org/apache/cxf/dosgi/itests/multi/customintent/CustomIntentActivator.java @@ -0,0 +1,47 @@ +/** + * 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.dosgi.itests.multi.customintent; + +import java.util.Dictionary; +import java.util.Hashtable; + +import org.apache.cxf.dosgi.itests.multi.TestTaskServiceImpl; +import org.apache.cxf.dosgi.samples.soap.TaskService; +import org.osgi.framework.BundleActivator; +import org.osgi.framework.BundleContext; +import org.osgi.service.remoteserviceadmin.RemoteConstants; + +public class CustomIntentActivator implements BundleActivator { + + public void start(BundleContext context) throws Exception { + Dictionary<String, String> props = new Hashtable<String, String>(); + props.put("org.apache.cxf.dosgi.IntentName", "myIntent"); + context.registerService(CustomFeature.class, new CustomFeature(), props); + + Dictionary<String, String> props2 = new Hashtable<String, String>(); + props2.put(RemoteConstants.SERVICE_EXPORTED_CONFIGS, "org.apache.cxf.ws"); + props2.put("org.apache.cxf.ws.address", "/taskservice"); + props2.put(RemoteConstants.SERVICE_EXPORTED_INTERFACES, "*"); + props2.put(RemoteConstants.SERVICE_EXPORTED_INTENTS, "myIntent"); + context.registerService(TaskService.class, new TestTaskServiceImpl(), props2); + } + + public void stop(BundleContext context) throws Exception { + } +} http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/3f8afd08/itests/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/AbstractDosgiTest.java ---------------------------------------------------------------------- diff --git a/itests/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/AbstractDosgiTest.java b/itests/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/AbstractDosgiTest.java deleted file mode 100644 index 383d7e9..0000000 --- a/itests/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/AbstractDosgiTest.java +++ /dev/null @@ -1,248 +0,0 @@ -/** - * 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.dosgi.systests2.multi; - -import static org.ops4j.pax.exam.CoreOptions.composite; -import static org.ops4j.pax.exam.CoreOptions.frameworkStartLevel; -import static org.ops4j.pax.exam.CoreOptions.mavenBundle; -import static org.ops4j.pax.exam.CoreOptions.systemProperty; -import static org.ops4j.pax.exam.cm.ConfigurationAdminOptions.newConfiguration; - -import java.io.File; -import java.io.IOException; -import java.net.ConnectException; -import java.net.HttpURLConnection; -import java.net.InetSocketAddress; -import java.net.MalformedURLException; -import java.net.ServerSocket; -import java.net.Socket; -import java.net.URL; -import java.util.Collection; -import java.util.concurrent.TimeoutException; - -import javax.inject.Inject; - -import org.apache.zookeeper.ZooKeeper; -import org.apache.zookeeper.data.Stat; -import org.junit.Assert; -import org.junit.BeforeClass; -import org.ops4j.pax.exam.CoreOptions; -import org.ops4j.pax.exam.Option; -import org.ops4j.pax.exam.cm.ConfigurationAdminOptions; -import org.ops4j.pax.exam.options.MavenArtifactProvisionOption; -import org.ops4j.pax.exam.options.extra.VMOption; -import org.osgi.framework.Bundle; -import org.osgi.framework.BundleContext; -import org.osgi.framework.BundleException; -import org.osgi.framework.ServiceReference; - -public class AbstractDosgiTest { - static final int ZK_PORT = 35101; - private static final int TIMEOUT = 20; - - @Inject - BundleContext bundleContext; - - @BeforeClass - public static void log() { - System.out.println("-----------------------------------------------------------------"); - } - - - /** - * Sleeps for a short interval, throwing an exception if timeout has been reached. Used to facilitate a - * retry interval with timeout when used in a loop. - * - * @param startTime the start time of the entire operation in milliseconds - * @param timeout the timeout duration for the entire operation in seconds - * @param message the error message to use when timeout occurs - * @throws InterruptedException if interrupted while sleeping - */ - private static void sleepOrTimeout(long startTime, long timeout, String message) - throws InterruptedException, TimeoutException { - timeout *= 1000; // seconds to millis - long elapsed = System.currentTimeMillis() - startTime; - long remaining = timeout - elapsed; - if (remaining <= 0) { - throw new TimeoutException(message); - } - long interval = Math.min(remaining, 1000); - Thread.sleep(interval); - } - - @SuppressWarnings({ - "rawtypes", "unchecked" - }) - protected ServiceReference waitService(BundleContext bc, Class cls, String filter, int timeout) - throws Exception { - System.out.println("Waiting for service: " + cls + " " + filter); - long startTime = System.currentTimeMillis(); - while (true) { - Collection refs = bc.getServiceReferences(cls, filter); - if (refs != null && refs.size() > 0) { - return (ServiceReference)refs.iterator().next(); - } - sleepOrTimeout(startTime, timeout, "Service not found: " + cls + " " + filter); - } - } - - protected void waitPort(int port) throws Exception { - System.out.println("Waiting for server to appear on port: " + port); - long startTime = System.currentTimeMillis(); - while (true) { - Socket s = null; - try { - s = new Socket((String)null, port); - // yep, its available - return; - } catch (IOException e) { - sleepOrTimeout(startTime, TIMEOUT, "Timeout waiting for port " + port); - } finally { - if (s != null) { - try { - s.close(); - } catch (IOException e) { - // ignore - } - } - } - } - } - - protected Bundle getBundleByName(BundleContext bc, String name) { - for (Bundle bundle : bc.getBundles()) { - if (bundle.getSymbolicName().equals(name)) { - return bundle; - } - } - return null; - } - - protected static int getFreePort() { - try (ServerSocket socket = new ServerSocket()) { - socket.setReuseAddress(true); // enables quickly reopening socket on same port - socket.bind(new InetSocketAddress(0)); // zero finds a free port - return socket.getLocalPort(); - } catch (Exception e) { - throw new RuntimeException(e.getMessage(), e); - } - } - - protected void waitWebPage(String urlSt) throws InterruptedException, TimeoutException { - System.out.println("Waiting for url " + urlSt); - HttpURLConnection con = null; - long startTime = System.currentTimeMillis(); - while (true) { - try { - URL url = new URL(urlSt); - con = (HttpURLConnection)url.openConnection(); - int status = con.getResponseCode(); - if (status == 200) { - return; - } - } catch (ConnectException e) { - // Ignore connection refused - } catch (MalformedURLException e) { - throw new RuntimeException(e.getMessage(), e); - } catch (IOException e) { - throw new RuntimeException(e.getMessage(), e); - } finally { - if (con != null) { - con.disconnect(); - } - } - sleepOrTimeout(startTime, TIMEOUT, "Timeout waiting for web page " + urlSt); - } - } - - protected void assertBundlesStarted() { - for (Bundle bundle : bundleContext.getBundles()) { - System.out - .println(bundle.getSymbolicName() + ":" + bundle.getVersion() + ": " + bundle.getState()); - if (bundle.getState() != Bundle.ACTIVE) { - try { - bundle.start(); - } catch (BundleException e) { - e.printStackTrace(); - } - } - } - } - - protected ZooKeeper createZookeeperClient() throws IOException { - return new ZooKeeper("localhost:" + ZK_PORT, 1000, null); - } - - protected void assertNodeExists(ZooKeeper zk, String zNode, int timeout) { - long endTime = System.currentTimeMillis() + timeout; - Stat stat = null; - while (stat == null && System.currentTimeMillis() < endTime) { - try { - stat = zk.exists(zNode, null); - Thread.sleep(200); - } catch (Exception e) { - // Ignore - } - } - Assert.assertNotNull("ZooKeeper node " + zNode + " was not found", stat); - } - - protected static Option configZKConsumer() { - return newConfiguration("org.apache.aries.rsa.discovery.zookeeper") // - .put("zookeeper.host", "127.0.0.1") // - .put("zookeeper.port", "" + ZK_PORT).asOption(); - } - - protected static Option configZKServer() { - return newConfiguration("org.apache.aries.rsa.discovery.zookeeper.server") - .put("clientPort", "" + ZK_PORT) // - .asOption(); - } - - protected static Option configLogging() { - return ConfigurationAdminOptions.configurationFolder(new File("src/test/resources/cfg")); - } - - - protected static MavenArtifactProvisionOption greeterImpl() { - return mavenBundle().groupId("org.apache.cxf.dosgi.samples") - .artifactId("cxf-dosgi-ri-samples-greeter-impl").versionAsInProject(); - } - - protected static MavenArtifactProvisionOption greeterInterface() { - return mavenBundle().groupId("org.apache.cxf.dosgi.samples") - .artifactId("cxf-dosgi-ri-samples-greeter-interface").versionAsInProject(); - } - - protected static Option basicTestOptions() throws Exception { - return composite(MultiBundleTools.getDistro(), // - CoreOptions.junitBundles(), // - systemProperty("org.ops4j.pax.logging.DefaultServiceLog.level").value("INFO"), // - systemProperty("pax.exam.osgi.unresolved.fail").value("true"), // - configLogging(), - frameworkStartLevel(100) - ); - } - - - protected static VMOption debug() { - return CoreOptions.vmOption("-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005"); - } - -} http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/3f8afd08/itests/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/GreeterServiceProxyFactory.java ---------------------------------------------------------------------- diff --git a/itests/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/GreeterServiceProxyFactory.java b/itests/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/GreeterServiceProxyFactory.java deleted file mode 100644 index 074a6f1..0000000 --- a/itests/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/GreeterServiceProxyFactory.java +++ /dev/null @@ -1,44 +0,0 @@ -/** - * 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.dosgi.systests2.multi; - -import org.apache.cxf.aegis.databinding.AegisDatabinding; -import org.apache.cxf.dosgi.samples.greeter.GreeterService; -import org.apache.cxf.frontend.ClientProxyFactoryBean; - -public final class GreeterServiceProxyFactory { - - private GreeterServiceProxyFactory() { - } - - protected static GreeterService createGreeterServiceProxy(String serviceUri) { - ClassLoader cl = Thread.currentThread().getContextClassLoader(); - Thread.currentThread().setContextClassLoader(ClientProxyFactoryBean.class.getClassLoader()); - try { - ClientProxyFactoryBean factory = new ClientProxyFactoryBean(); - factory.setServiceClass(GreeterService.class); - factory.setAddress(serviceUri); - factory.getServiceFactory().setDataBinding(new AegisDatabinding()); - return (GreeterService)factory.create(); - } finally { - Thread.currentThread().setContextClassLoader(cl); - } - } - -} http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/3f8afd08/itests/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/MultiBundleTools.java ---------------------------------------------------------------------- diff --git a/itests/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/MultiBundleTools.java b/itests/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/MultiBundleTools.java deleted file mode 100644 index 70e4816..0000000 --- a/itests/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/MultiBundleTools.java +++ /dev/null @@ -1,102 +0,0 @@ -/** - * 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.dosgi.systests2.multi; - -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.net.URL; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Properties; -import java.util.TreeMap; - -import org.ops4j.pax.exam.CoreOptions; -import org.ops4j.pax.exam.Option; - -public final class MultiBundleTools { - - private MultiBundleTools() { - } - - private static Properties getProps(File distroDir) throws FileNotFoundException, IOException { - Properties p = new Properties(); - File confFile = new File(distroDir, "conf/felix.config.properties.append"); - p.load(new FileInputStream(confFile)); - return p; - } - - private static int getDistroBundles(File distroDir, - Properties props, - Map<Integer, String> bundles) throws Exception { - int startLevel = Integer.parseInt(props.getProperty("org.osgi.framework.startlevel.beginning")); - for (int i = 0; i <= startLevel; i++) { - String val = props.getProperty("felix.auto.start." + i); - if (val != null) { - if (val.startsWith("file:")) { - File fullDir = new File(distroDir, val.substring("file:".length())); - bundles.put(i, fullDir.toURI().toASCIIString()); - } else { - if (!val.contains("org.osgi.compendium")) { - // We're skipping that one as it's pulled in explicitly in the test - bundles.put(i, val); - } - } - } - } - return startLevel + 1; // Add 1 to start level to be on the safe side - } - - private static File getRootDirectory() { - String resourceName = "/" + MultiBundleTools.class.getName().replace('.', '/') + ".class"; - URL curURL = MultiBundleTools.class.getResource(resourceName); - File curFile = new File(curURL.getFile()); - String curString = curFile.getAbsolutePath(); - File curBase = new File(curString.substring(0, curString.length() - resourceName.length())); - return curBase.getParentFile().getParentFile(); - } - - private static Option[] getDistroBundleOptions() throws Exception { - Map<Integer, String> bundles = new TreeMap<Integer, String>(); - File root = getRootDirectory(); - File depRoot = new File(root, "target/dependency"); - File distroDir = depRoot.listFiles()[0]; - Properties props = getProps(distroDir); - getDistroBundles(distroDir, props, bundles); - List<Option> opts = new ArrayList<Option>(); - - /* - String sysPackagesValue = props.getProperty("org.osgi.framework.system.packages"); - opts.add(CoreOptions.frameworkProperty("org.osgi.framework.system.packages") - .value(sysPackagesValue)); - */ - - for (Map.Entry<Integer, String> entry : bundles.entrySet()) { - String bundleUri = entry.getValue(); - opts.add(CoreOptions.bundle(bundleUri)); - } - return opts.toArray(new Option[opts.size()]); - } - - public static Option getDistro() throws Exception { - return CoreOptions.composite(getDistroBundleOptions()); - } -} http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/3f8afd08/itests/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/TestCustomIntent.java ---------------------------------------------------------------------- diff --git a/itests/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/TestCustomIntent.java b/itests/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/TestCustomIntent.java deleted file mode 100644 index 9928db0..0000000 --- a/itests/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/TestCustomIntent.java +++ /dev/null @@ -1,91 +0,0 @@ -/** - * 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.dosgi.systests2.multi; - -import static org.apache.cxf.dosgi.systests2.multi.GreeterServiceProxyFactory.createGreeterServiceProxy; -import static org.ops4j.pax.exam.CoreOptions.provision; -import static org.ops4j.pax.exam.CoreOptions.streamBundle; - -import java.io.InputStream; -import java.util.Map; - -import org.apache.cxf.dosgi.samples.greeter.GreeterService; -import org.apache.cxf.dosgi.samples.greeter.GreetingPhrase; -import org.apache.cxf.dosgi.systests2.multi.customintent.AddGreetingPhraseInterceptor; -import org.apache.cxf.dosgi.systests2.multi.customintent.CustomFeature; -import org.apache.cxf.dosgi.systests2.multi.customintent.CustomIntentActivator; -import org.apache.cxf.dosgi.systests2.multi.customintent.service.EmptyGreeterService; -import org.apache.cxf.dosgi.systests2.multi.customintent.service.GreeterServiceWithCustomIntentActivator; -import org.junit.Assert; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.ops4j.pax.exam.Configuration; -import org.ops4j.pax.exam.Option; -import org.ops4j.pax.exam.junit.PaxExam; -import org.ops4j.pax.tinybundles.core.TinyBundles; -import org.osgi.framework.Constants; - -@RunWith(PaxExam.class) -public class TestCustomIntent extends AbstractDosgiTest { - - @Configuration - public static Option[] configure() throws Exception { - return new Option[] // - { - basicTestOptions(), // - greeterInterface(), // - streamBundle(getCustomIntentBundle()).noStart(), // - provision(getServiceBundle()), - //debug() - }; - } - - @Test - public void testCustomIntent() throws Exception { - // There should be warnings of unsatisfied intent myIntent in the log at debug level - //Thread.sleep(2000); - getBundleByName(bundleContext, "CustomIntent").start(); - waitPort(9090); - - GreeterService greeterService = createGreeterServiceProxy("http://localhost:9090/greeter"); - Map<GreetingPhrase, String> result = greeterService.greetMe("Chris"); - Assert.assertEquals(1, result.size()); - GreetingPhrase phrase = result.keySet().iterator().next(); - Assert.assertEquals("Hi from custom intent", phrase.getPhrase()); - } - - private static InputStream getCustomIntentBundle() { - return TinyBundles.bundle() // - .add(CustomIntentActivator.class) // - .add(CustomFeature.class) // - .add(AddGreetingPhraseInterceptor.class) // - .set(Constants.BUNDLE_SYMBOLICNAME, "CustomIntent") // - .set(Constants.BUNDLE_ACTIVATOR, CustomIntentActivator.class.getName()) - .build(TinyBundles.withBnd()); - } - - private static InputStream getServiceBundle() { - return TinyBundles.bundle() // - .add(GreeterServiceWithCustomIntentActivator.class) // - .add(EmptyGreeterService.class) // - .set(Constants.BUNDLE_SYMBOLICNAME, "EmptyGreeterService") // - .set(Constants.BUNDLE_ACTIVATOR, GreeterServiceWithCustomIntentActivator.class.getName()) - .build(TinyBundles.withBnd()); - } -} http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/3f8afd08/itests/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/TestDiscoveryExport.java ---------------------------------------------------------------------- diff --git a/itests/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/TestDiscoveryExport.java b/itests/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/TestDiscoveryExport.java deleted file mode 100644 index b0113fd..0000000 --- a/itests/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/TestDiscoveryExport.java +++ /dev/null @@ -1,53 +0,0 @@ -/** - * 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.dosgi.systests2.multi; - -import org.apache.zookeeper.ZooKeeper; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.ops4j.pax.exam.Configuration; -import org.ops4j.pax.exam.Option; -import org.ops4j.pax.exam.junit.PaxExam; - -@RunWith(PaxExam.class) -public class TestDiscoveryExport extends AbstractDosgiTest { - - private static final String GREETER_ZOOKEEPER_NODE = // - "/osgi/service_registry/org/apache/cxf/dosgi/samples/greeter/GreeterService/localhost#9090##greeter"; - - @Configuration - public static Option[] configure() throws Exception { - return new Option[] // - { - basicTestOptions(), // - configZKServer(), // - configZKConsumer(), // - greeterInterface(), // - greeterImpl(), - }; - } - - @Test - public void testDiscoveryExport() throws Exception { - ZooKeeper zk = createZookeeperClient(); - assertNodeExists(zk, GREETER_ZOOKEEPER_NODE, 5000); - zk.close(); - } - -} http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/3f8afd08/itests/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/TestExportRestService.java ---------------------------------------------------------------------- diff --git a/itests/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/TestExportRestService.java b/itests/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/TestExportRestService.java deleted file mode 100644 index 0ed885a..0000000 --- a/itests/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/TestExportRestService.java +++ /dev/null @@ -1,77 +0,0 @@ -/** - * 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.dosgi.systests2.multi; - -import static org.ops4j.pax.exam.CoreOptions.provision; -import static org.ops4j.pax.exam.CoreOptions.systemProperty; - -import java.io.InputStream; - -import org.apache.cxf.dosgi.systests2.multi.rest.RestTranslate; -import org.apache.cxf.dosgi.systests2.multi.rest.RestTranslateImpl; -import org.apache.cxf.dosgi.systests2.multi.rest.TranslateActivator; -import org.apache.cxf.jaxrs.client.WebClient; -import org.junit.Assert; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.ops4j.pax.exam.Configuration; -import org.ops4j.pax.exam.Option; -import org.ops4j.pax.exam.junit.PaxExam; -import org.ops4j.pax.tinybundles.core.TinyBundles; -import org.osgi.framework.Constants; - -@RunWith(PaxExam.class) -public class TestExportRestService extends AbstractDosgiTest { - String webPort = "9091"; - - @Configuration - public Option[] configure() throws Exception { - return new Option[] // - {// - basicTestOptions(), // - systemProperty("org.osgi.service.http.port").value(webPort), // - provision(getServiceBundle()), - //debug() - }; - } - - @Test - public void testCallService() throws Exception { - waitWebPage("http://localhost:" + webPort + "/cxf/translate"); - try { - WebClient client = WebClient.create("http://localhost:" + webPort + "/cxf/translate/hello"); - String result = client.get(String.class); - Assert.assertEquals("hallo", result); - } catch (Exception e) { - // Avoid serialization problems when just letting the exception fly - e.printStackTrace(); - throw new RuntimeException(e.getMessage()); - } - } - - private InputStream getServiceBundle() { - return TinyBundles.bundle() // - .add(RestTranslate.class) // - .add(RestTranslateImpl.class) // - .add(TranslateActivator.class) // - .set(Constants.BUNDLE_SYMBOLICNAME, "RestTranslate") // - .set(Constants.BUNDLE_ACTIVATOR, TranslateActivator.class.getName()) // - .build(TinyBundles.withBnd()); - } -} http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/3f8afd08/itests/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/TestExportService.java ---------------------------------------------------------------------- diff --git a/itests/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/TestExportService.java b/itests/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/TestExportService.java deleted file mode 100644 index 27cc989..0000000 --- a/itests/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/TestExportService.java +++ /dev/null @@ -1,117 +0,0 @@ -/** - * 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.dosgi.systests2.multi; - -import java.io.IOException; -import java.net.URL; -import java.util.Map; - -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.parsers.ParserConfigurationException; - -import org.apache.cxf.dosgi.samples.greeter.GreeterData; -import org.apache.cxf.dosgi.samples.greeter.GreeterException; -import org.apache.cxf.dosgi.samples.greeter.GreeterService; -import org.apache.cxf.dosgi.samples.greeter.GreetingPhrase; -import org.junit.Assert; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.ops4j.pax.exam.Configuration; -import org.ops4j.pax.exam.Option; -import org.ops4j.pax.exam.junit.PaxExam; -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.xml.sax.SAXException; - -@RunWith(PaxExam.class) -public class TestExportService extends AbstractDosgiTest { - - @Configuration - public static Option[] configure() throws Exception { - return new Option[] // - {// - basicTestOptions(), // - greeterInterface(), // - greeterImpl(), // - //debug(), - }; - } - - @Test - public void testAccessEndpoint() throws Exception { - waitPort(9090); - checkWsdl(new URL("http://localhost:9090/greeter?wsdl")); - checkServiceCall("http://localhost:9090/greeter"); - } - - private void checkServiceCall(String serviceUri) { - GreeterService client = GreeterServiceProxyFactory.createGreeterServiceProxy(serviceUri); - - Map<GreetingPhrase, String> greetings = client.greetMe("Fred"); - Assert.assertEquals("Fred", greetings.get(new GreetingPhrase("Hello"))); - System.out.println("Invocation result: " + greetings); - - try { - GreeterData gd = new GreeterDataImpl("Stranger", 11, true); - client.greetMe(gd); - Assert.fail("GreeterException has to be thrown"); - } catch (GreeterException ex) { - Assert.assertEquals("Wrong exception message", "GreeterService can not greet Stranger", - ex.toString()); - } - } - - private void checkWsdl(URL wsdlURL) throws ParserConfigurationException, SAXException, IOException { - DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); - dbf.setNamespaceAware(true); - dbf.setValidating(false); - DocumentBuilder db = dbf.newDocumentBuilder(); - Document doc = db.parse(wsdlURL.openStream()); - Element el = doc.getDocumentElement(); - Assert.assertEquals("definitions", el.getLocalName()); - Assert.assertEquals("http://schemas.xmlsoap.org/wsdl/", el.getNamespaceURI()); - Assert.assertEquals("GreeterService", el.getAttribute("name")); - } - - class GreeterDataImpl implements GreeterData { - - private String name; - private int age; - private boolean exception; - - GreeterDataImpl(String n, int a, boolean ex) { - name = n; - age = a; - exception = ex; - } - - public String getName() { - return name; - } - - public int getAge() { - return age; - } - - public boolean isException() { - return exception; - } - } -}
