This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/master by this push: new 29e402d Migrates camel-xmpp to the new test infra (#4718) 29e402d is described below commit 29e402d87c408b41f6705a8f2cc767100e3874a0 Author: Otavio Rodolfo Piske <orpi...@users.noreply.github.com> AuthorDate: Thu Dec 3 18:57:01 2020 +0100 Migrates camel-xmpp to the new test infra (#4718) --- components/camel-xmpp/pom.xml | 17 +++++ ...mppBaseTest.java => XmppBaseContainerTest.java} | 23 ++----- .../apache/camel/component/xmpp/XmppBaseTest.java | 23 +++---- .../component/xmpp/XmppDeferredConnectionTest.java | 6 +- .../component/xmpp/XmppMultiUserChatTest.java | 4 +- .../component/xmpp/XmppProducerConcurrentTest.java | 2 +- .../component/xmpp/XmppRobustConnectionTest.java | 2 +- .../camel/component/xmpp/XmppRouteChatTest.java | 4 +- ...ppRouteMultipleProducersSingleConsumerTest.java | 6 +- .../apache/camel/component/xmpp/XmppRouteTest.java | 2 +- .../apache/camel/component/xmpp/XmppTestUtil.java | 57 +++++++++++++++++ test-infra/camel-test-infra-xmpp/pom.xml | 60 ++++++++++++++++++ .../src/main/resources/META-INF/MANIFEST.MF | 0 .../test/infra/xmpp/common/XmppProperties.java | 31 ++------- .../xmpp/services/XmppLocalContainerService.java | 74 ++++++++++++++++++++++ .../infra/xmpp/services/XmppRemoteService.java | 48 ++++++++------ .../infra/xmpp/services}/XmppServerContainer.java | 46 +++----------- .../test/infra/xmpp/services/XmppService.java | 37 +++++------ .../infra/xmpp/services/XmppServiceFactory.java | 41 ++++++------ test-infra/pom.xml | 1 + 20 files changed, 321 insertions(+), 163 deletions(-) diff --git a/components/camel-xmpp/pom.xml b/components/camel-xmpp/pom.xml index 10505b6..896401f 100644 --- a/components/camel-xmpp/pom.xml +++ b/components/camel-xmpp/pom.xml @@ -87,6 +87,23 @@ <artifactId>camel-testcontainers</artifactId> <scope>test</scope> </dependency> + + <!-- test infra --> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-test-infra-common</artifactId> + <version>${project.version}</version> + <type>test-jar</type> + <scope>test</scope> + </dependency> + + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-test-infra-xmpp</artifactId> + <version>${project.version}</version> + <type>test-jar</type> + <scope>test</scope> + </dependency> </dependencies> <!-- skip tests on AIX --> diff --git a/components/camel-xmpp/src/test/java/org/apache/camel/component/xmpp/XmppBaseTest.java b/components/camel-xmpp/src/test/java/org/apache/camel/component/xmpp/XmppBaseContainerTest.java similarity index 72% copy from components/camel-xmpp/src/test/java/org/apache/camel/component/xmpp/XmppBaseTest.java copy to components/camel-xmpp/src/test/java/org/apache/camel/component/xmpp/XmppBaseContainerTest.java index ab5a101..19cc2a2 100644 --- a/components/camel-xmpp/src/test/java/org/apache/camel/component/xmpp/XmppBaseTest.java +++ b/components/camel-xmpp/src/test/java/org/apache/camel/component/xmpp/XmppBaseContainerTest.java @@ -14,33 +14,22 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.apache.camel.component.xmpp; import org.apache.camel.spi.Registry; import org.apache.camel.support.SimpleRegistry; +import org.apache.camel.test.infra.xmpp.services.XmppServerContainer; import org.apache.camel.test.junit5.CamelTestSupport; -import org.junit.jupiter.api.AfterEach; -public class XmppBaseTest extends CamelTestSupport { - protected XmppServerContainer xmppServer; +public class XmppBaseContainerTest extends CamelTestSupport { + protected XmppServerContainer xmppServer = new XmppServerContainer(); @Override protected Registry createCamelRegistry() throws Exception { Registry registry = new SimpleRegistry(); - xmppServer.bindSSLContextTo(registry); - return registry; - } - - @Override - public void doPreSetup() { - xmppServer = new XmppServerContainer(); - xmppServer.start(); - } - @Override - @AfterEach - public void tearDown() throws Exception { - super.tearDown(); - xmppServer.stop(); + XmppTestUtil.bindSSLContextTo(registry, xmppServer.getHost(), xmppServer.getPortDefault()); + return registry; } } diff --git a/components/camel-xmpp/src/test/java/org/apache/camel/component/xmpp/XmppBaseTest.java b/components/camel-xmpp/src/test/java/org/apache/camel/component/xmpp/XmppBaseTest.java index ab5a101..bd86ec6 100644 --- a/components/camel-xmpp/src/test/java/org/apache/camel/component/xmpp/XmppBaseTest.java +++ b/components/camel-xmpp/src/test/java/org/apache/camel/component/xmpp/XmppBaseTest.java @@ -18,29 +18,24 @@ package org.apache.camel.component.xmpp; import org.apache.camel.spi.Registry; import org.apache.camel.support.SimpleRegistry; +import org.apache.camel.test.infra.xmpp.services.XmppService; +import org.apache.camel.test.infra.xmpp.services.XmppServiceFactory; import org.apache.camel.test.junit5.CamelTestSupport; -import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.extension.RegisterExtension; public class XmppBaseTest extends CamelTestSupport { - protected XmppServerContainer xmppServer; + @RegisterExtension + static XmppService service = XmppServiceFactory.createService(); @Override protected Registry createCamelRegistry() throws Exception { Registry registry = new SimpleRegistry(); - xmppServer.bindSSLContextTo(registry); - return registry; - } - @Override - public void doPreSetup() { - xmppServer = new XmppServerContainer(); - xmppServer.start(); + XmppTestUtil.bindSSLContextTo(registry, service.host(), service.port()); + return registry; } - @Override - @AfterEach - public void tearDown() throws Exception { - super.tearDown(); - xmppServer.stop(); + protected String getUrl() { + return service.getUrl(); } } diff --git a/components/camel-xmpp/src/test/java/org/apache/camel/component/xmpp/XmppDeferredConnectionTest.java b/components/camel-xmpp/src/test/java/org/apache/camel/component/xmpp/XmppDeferredConnectionTest.java index 4b53874..9095d1c 100644 --- a/components/camel-xmpp/src/test/java/org/apache/camel/component/xmpp/XmppDeferredConnectionTest.java +++ b/components/camel-xmpp/src/test/java/org/apache/camel/component/xmpp/XmppDeferredConnectionTest.java @@ -30,16 +30,18 @@ import org.slf4j.LoggerFactory; * expected. */ -public class XmppDeferredConnectionTest extends XmppBaseTest { +public class XmppDeferredConnectionTest extends XmppBaseContainerTest { private static final Logger LOG = LoggerFactory.getLogger(XmppDeferredConnectionTest.class); /** * Ensures that the XMPP server instance is created and 'stopped' before the camel routes are initialized */ @Override - public void doPreSetup() { + public void doPreSetup() throws Exception { super.doPreSetup(); try { + xmppServer.start(); + xmppServer.stopXmppEndpoint(); } catch (IOException e) { LOG.warn("Failed to stop XMPP endpoint: {}", e.getMessage(), e); diff --git a/components/camel-xmpp/src/test/java/org/apache/camel/component/xmpp/XmppMultiUserChatTest.java b/components/camel-xmpp/src/test/java/org/apache/camel/component/xmpp/XmppMultiUserChatTest.java index 3bd4750..bbad499 100644 --- a/components/camel-xmpp/src/test/java/org/apache/camel/component/xmpp/XmppMultiUserChatTest.java +++ b/components/camel-xmpp/src/test/java/org/apache/camel/component/xmpp/XmppMultiUserChatTest.java @@ -59,14 +59,14 @@ public class XmppMultiUserChatTest extends XmppBaseTest { // here on purpose we provide the room query parameter without the domain name as 'camel-test', and Camel // will resolve it properly to 'camel-test@conference.apache.camel' - return "xmpp://localhost:" + xmppServer.getUrl() + return "xmpp://localhost:" + getUrl() + "/?connectionConfig=#customConnectionConfig&room=camel-test&user=camel_producer@apache.camel&password=secret&nickname=camel_producer"; } protected String getConsumerUri() { // however here we provide the room query parameter as fully qualified, including the domain name as // 'camel-test@conference.apache.camel' - return "xmpp://localhost:" + xmppServer.getUrl() + return "xmpp://localhost:" + getUrl() + "/?connectionConfig=#customConnectionConfig&room=camel-test@conference.apache.camel&user=camel_consumer@apache.camel&password=secret&nickname=camel_consumer"; } } diff --git a/components/camel-xmpp/src/test/java/org/apache/camel/component/xmpp/XmppProducerConcurrentTest.java b/components/camel-xmpp/src/test/java/org/apache/camel/component/xmpp/XmppProducerConcurrentTest.java index 66bf669..f50457c 100644 --- a/components/camel-xmpp/src/test/java/org/apache/camel/component/xmpp/XmppProducerConcurrentTest.java +++ b/components/camel-xmpp/src/test/java/org/apache/camel/component/xmpp/XmppProducerConcurrentTest.java @@ -56,7 +56,7 @@ public class XmppProducerConcurrentTest extends XmppBaseTest { @Override public void configure() throws Exception { from("direct:start") - .to("xmpp://" + xmppServer.getUrl() + .to("xmpp://" + getUrl() + "?connectionConfig=#customConnectionConfig&room=camel-test&user=camel_consumer&password=secret&serviceName=apache.camel") .to("mock:result"); } diff --git a/components/camel-xmpp/src/test/java/org/apache/camel/component/xmpp/XmppRobustConnectionTest.java b/components/camel-xmpp/src/test/java/org/apache/camel/component/xmpp/XmppRobustConnectionTest.java index 2f29895..268ec1e 100644 --- a/components/camel-xmpp/src/test/java/org/apache/camel/component/xmpp/XmppRobustConnectionTest.java +++ b/components/camel-xmpp/src/test/java/org/apache/camel/component/xmpp/XmppRobustConnectionTest.java @@ -27,7 +27,7 @@ import static org.apache.camel.test.junit5.TestSupport.isPlatform; * Test to verify that the XMPP consumer will reconnect when the connection is lost. Also verifies that the XMPP * producer will lazily re-establish a lost connection. */ -public class XmppRobustConnectionTest extends XmppBaseTest { +public class XmppRobustConnectionTest extends XmppBaseContainerTest { @Disabled("Since upgrade to smack 4.2.0 the robust connection handling doesn't seem to work, as consumerEndpoint below receives only 5 payloads instead of the expected 9") @Test diff --git a/components/camel-xmpp/src/test/java/org/apache/camel/component/xmpp/XmppRouteChatTest.java b/components/camel-xmpp/src/test/java/org/apache/camel/component/xmpp/XmppRouteChatTest.java index 03418de..85c9133 100644 --- a/components/camel-xmpp/src/test/java/org/apache/camel/component/xmpp/XmppRouteChatTest.java +++ b/components/camel-xmpp/src/test/java/org/apache/camel/component/xmpp/XmppRouteChatTest.java @@ -70,12 +70,12 @@ public class XmppRouteChatTest extends XmppBaseTest { } protected String getProducerUri() { - return "xmpp://" + xmppServer.getUrl() + return "xmpp://" + getUrl() + "/camel_producer@apache.camel?connectionConfig=#customConnectionConfig&room=camel-test-producer@conference.apache.camel&user=camel_producer&password=secret&serviceName=apache.camel"; } protected String getConsumerUri() { - return "xmpp://" + xmppServer.getUrl() + return "xmpp://" + getUrl() + "/camel_consumer@apache.camel?connectionConfig=#customConnectionConfig&room=camel-test-consumer@conference.apache.camel&user=camel_consumer&password=secret&serviceName=apache.camel"; } diff --git a/components/camel-xmpp/src/test/java/org/apache/camel/component/xmpp/XmppRouteMultipleProducersSingleConsumerTest.java b/components/camel-xmpp/src/test/java/org/apache/camel/component/xmpp/XmppRouteMultipleProducersSingleConsumerTest.java index 0705c27..856680d 100644 --- a/components/camel-xmpp/src/test/java/org/apache/camel/component/xmpp/XmppRouteMultipleProducersSingleConsumerTest.java +++ b/components/camel-xmpp/src/test/java/org/apache/camel/component/xmpp/XmppRouteMultipleProducersSingleConsumerTest.java @@ -68,17 +68,17 @@ public class XmppRouteMultipleProducersSingleConsumerTest extends XmppBaseTest { } protected String getProducer1Uri() { - return "xmpp://localhost:" + xmppServer.getUrl() + return "xmpp://localhost:" + getUrl() + "/camel_consumer@apache.camel?connectionConfig=#customConnectionConfig&room=camel-test-room@conference.apache.camel&user=camel_producer&password=secret&serviceName=apache.camel"; } protected String getProducer2Uri() { - return "xmpp://localhost:" + xmppServer.getUrl() + return "xmpp://localhost:" + getUrl() + "/camel_consumer@apache.camel?connectionConfig=#customConnectionConfig&user=camel_producer1&password=secret&serviceName=apache.camel"; } protected String getConsumerUri() { - return "xmpp://localhost:" + xmppServer.getUrl() + return "xmpp://localhost:" + getUrl() + "/camel_producer@apache.camel?connectionConfig=#customConnectionConfig&room=camel-test-room@conference.apache.camel&user=camel_consumer&password=secret&serviceName=apache.camel"; } } diff --git a/components/camel-xmpp/src/test/java/org/apache/camel/component/xmpp/XmppRouteTest.java b/components/camel-xmpp/src/test/java/org/apache/camel/component/xmpp/XmppRouteTest.java index a1e6c23..a73230a 100644 --- a/components/camel-xmpp/src/test/java/org/apache/camel/component/xmpp/XmppRouteTest.java +++ b/components/camel-xmpp/src/test/java/org/apache/camel/component/xmpp/XmppRouteTest.java @@ -97,7 +97,7 @@ public class XmppRouteTest extends XmppBaseTest { } protected String getUriPrefix() { - return "xmpp://" + xmppServer.getUrl() + return "xmpp://" + getUrl() + "/camel?connectionConfig=#customConnectionConfig&room=camel-anon&user=camel_consumer&password=secret&serviceName=apache.camel"; } diff --git a/components/camel-xmpp/src/test/java/org/apache/camel/component/xmpp/XmppTestUtil.java b/components/camel-xmpp/src/test/java/org/apache/camel/component/xmpp/XmppTestUtil.java new file mode 100644 index 0000000..cede7e8 --- /dev/null +++ b/components/camel-xmpp/src/test/java/org/apache/camel/component/xmpp/XmppTestUtil.java @@ -0,0 +1,57 @@ +/* + * 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.camel.component.xmpp; + +import java.net.InetAddress; +import java.security.KeyStore; + +import javax.net.ssl.SSLContext; +import javax.net.ssl.TrustManagerFactory; + +import org.apache.camel.spi.Registry; +import org.apache.camel.util.ObjectHelper; +import org.jivesoftware.smack.ConnectionConfiguration; +import org.jivesoftware.smack.tcp.XMPPTCPConnectionConfiguration; +import org.jxmpp.jid.impl.JidCreate; + +public final class XmppTestUtil { + + private XmppTestUtil() { + + } + + public static void bindSSLContextTo(Registry registry, String hostAddress, int port) throws Exception { + KeyStore keyStore = KeyStore.getInstance("JKS"); + + keyStore.load(ObjectHelper.loadResourceAsStream("bogus_mina_tls.cert"), "boguspw".toCharArray()); + TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm()); + trustManagerFactory.init(keyStore); + SSLContext sslContext = SSLContext.getInstance("TLS"); + sslContext.init(null, trustManagerFactory.getTrustManagers(), null); + + ConnectionConfiguration connectionConfig = XMPPTCPConnectionConfiguration.builder() + .setXmppDomain(JidCreate.domainBareFrom("apache.camel")) + .setHostAddress(InetAddress.getByName(hostAddress)) + .setPort(port) + .setCustomSSLContext(sslContext) + .setHostnameVerifier((hostname, session) -> true) + .build(); + + registry.bind("customConnectionConfig", connectionConfig); + } +} diff --git a/test-infra/camel-test-infra-xmpp/pom.xml b/test-infra/camel-test-infra-xmpp/pom.xml new file mode 100644 index 0000000..2e58649 --- /dev/null +++ b/test-infra/camel-test-infra-xmpp/pom.xml @@ -0,0 +1,60 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + + 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. + +--> +<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"> + <parent> + <artifactId>camel-test-infra-parent</artifactId> + <groupId>org.apache.camel</groupId> + <relativePath>../camel-test-infra-parent/pom.xml</relativePath> + <version>3.7.0-SNAPSHOT</version> + </parent> + + <modelVersion>4.0.0</modelVersion> + + <artifactId>camel-test-infra-xmpp</artifactId> + <name>Camel :: Test Infra :: Xmpp</name> + + <dependencies> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-test-infra-common</artifactId> + <version>${project.version}</version> + <type>test-jar</type> + <scope>test</scope> + </dependency> + + <dependency> + <groupId>org.testcontainers</groupId> + <artifactId>testcontainers</artifactId> + </dependency> + </dependencies> + + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-jar-plugin</artifactId> + </plugin> + </plugins> + </build> + + +</project> \ No newline at end of file diff --git a/test-infra/camel-test-infra-xmpp/src/main/resources/META-INF/MANIFEST.MF b/test-infra/camel-test-infra-xmpp/src/main/resources/META-INF/MANIFEST.MF new file mode 100644 index 0000000..e69de29 diff --git a/components/camel-xmpp/src/test/java/org/apache/camel/component/xmpp/XmppBaseTest.java b/test-infra/camel-test-infra-xmpp/src/test/java/org/apache/camel/test/infra/xmpp/common/XmppProperties.java similarity index 51% copy from components/camel-xmpp/src/test/java/org/apache/camel/component/xmpp/XmppBaseTest.java copy to test-infra/camel-test-infra-xmpp/src/test/java/org/apache/camel/test/infra/xmpp/common/XmppProperties.java index ab5a101..dc45ed6 100644 --- a/components/camel-xmpp/src/test/java/org/apache/camel/component/xmpp/XmppBaseTest.java +++ b/test-infra/camel-test-infra-xmpp/src/test/java/org/apache/camel/test/infra/xmpp/common/XmppProperties.java @@ -14,33 +14,16 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.camel.component.xmpp; -import org.apache.camel.spi.Registry; -import org.apache.camel.support.SimpleRegistry; -import org.apache.camel.test.junit5.CamelTestSupport; -import org.junit.jupiter.api.AfterEach; +package org.apache.camel.test.infra.xmpp.common; -public class XmppBaseTest extends CamelTestSupport { - protected XmppServerContainer xmppServer; +public final class XmppProperties { + public static final String XMPP_URL = "xmpp.url"; + public static final String XMPP_HOST = "xmpp.host"; + public static final String XMPP_PORT = "xmpp.port"; + public static final Integer PORT_DEFAULT = 5222; - @Override - protected Registry createCamelRegistry() throws Exception { - Registry registry = new SimpleRegistry(); - xmppServer.bindSSLContextTo(registry); - return registry; - } - - @Override - public void doPreSetup() { - xmppServer = new XmppServerContainer(); - xmppServer.start(); - } + private XmppProperties() { - @Override - @AfterEach - public void tearDown() throws Exception { - super.tearDown(); - xmppServer.stop(); } } diff --git a/test-infra/camel-test-infra-xmpp/src/test/java/org/apache/camel/test/infra/xmpp/services/XmppLocalContainerService.java b/test-infra/camel-test-infra-xmpp/src/test/java/org/apache/camel/test/infra/xmpp/services/XmppLocalContainerService.java new file mode 100644 index 0000000..3bdfb20 --- /dev/null +++ b/test-infra/camel-test-infra-xmpp/src/test/java/org/apache/camel/test/infra/xmpp/services/XmppLocalContainerService.java @@ -0,0 +1,74 @@ +/* + * 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.camel.test.infra.xmpp.services; + +import org.apache.camel.test.infra.common.services.ContainerService; +import org.apache.camel.test.infra.xmpp.common.XmppProperties; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class XmppLocalContainerService implements XmppService, ContainerService<XmppServerContainer> { + private static final Logger LOG = LoggerFactory.getLogger(XmppLocalContainerService.class); + + private XmppServerContainer container; + + public XmppLocalContainerService() { + container = new XmppServerContainer(); + } + + @Override + public void registerProperties() { + System.setProperty(XmppProperties.XMPP_URL, getUrl()); + System.setProperty(XmppProperties.XMPP_HOST, container.getHost()); + System.setProperty(XmppProperties.XMPP_PORT, String.valueOf(container.getPortDefault())); + } + + @Override + public void initialize() { + LOG.info("Trying to start the Xmpp container"); + container.start(); + + registerProperties(); + LOG.info("Xmpp instance running at {}", getUrl()); + } + + @Override + public void shutdown() { + LOG.info("Stopping the Xmpp container"); + container.stop(); + } + + @Override + public XmppServerContainer getContainer() { + return container; + } + + @Override + public String getUrl() { + return container.getUrl(); + } + + @Override + public String host() { + return container.getHost(); + } + + @Override + public int port() { + return container.getPortDefault(); + } +} diff --git a/components/camel-xmpp/src/test/java/org/apache/camel/component/xmpp/XmppBaseTest.java b/test-infra/camel-test-infra-xmpp/src/test/java/org/apache/camel/test/infra/xmpp/services/XmppRemoteService.java similarity index 52% copy from components/camel-xmpp/src/test/java/org/apache/camel/component/xmpp/XmppBaseTest.java copy to test-infra/camel-test-infra-xmpp/src/test/java/org/apache/camel/test/infra/xmpp/services/XmppRemoteService.java index ab5a101..67911fe 100644 --- a/components/camel-xmpp/src/test/java/org/apache/camel/component/xmpp/XmppBaseTest.java +++ b/test-infra/camel-test-infra-xmpp/src/test/java/org/apache/camel/test/infra/xmpp/services/XmppRemoteService.java @@ -14,33 +14,45 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.camel.component.xmpp; +package org.apache.camel.test.infra.xmpp.services; -import org.apache.camel.spi.Registry; -import org.apache.camel.support.SimpleRegistry; -import org.apache.camel.test.junit5.CamelTestSupport; -import org.junit.jupiter.api.AfterEach; +import org.apache.camel.test.infra.xmpp.common.XmppProperties; -public class XmppBaseTest extends CamelTestSupport { - protected XmppServerContainer xmppServer; +public class XmppRemoteService implements XmppService { @Override - protected Registry createCamelRegistry() throws Exception { - Registry registry = new SimpleRegistry(); - xmppServer.bindSSLContextTo(registry); - return registry; + public void registerProperties() { + // NO-OP } @Override - public void doPreSetup() { - xmppServer = new XmppServerContainer(); - xmppServer.start(); + public void initialize() { + registerProperties(); } @Override - @AfterEach - public void tearDown() throws Exception { - super.tearDown(); - xmppServer.stop(); + public void shutdown() { + // NO-OP + } + + @Override + public String getUrl() { + return System.getProperty(XmppProperties.XMPP_URL); + } + + @Override + public String host() { + return System.getProperty(XmppProperties.XMPP_HOST); + } + + @Override + public int port() { + String port = System.getProperty(XmppProperties.XMPP_PORT); + + if (port == null) { + return XmppProperties.PORT_DEFAULT; + } + + return Integer.valueOf(port); } } diff --git a/components/camel-xmpp/src/test/java/org/apache/camel/component/xmpp/XmppServerContainer.java b/test-infra/camel-test-infra-xmpp/src/test/java/org/apache/camel/test/infra/xmpp/services/XmppServerContainer.java similarity index 57% rename from components/camel-xmpp/src/test/java/org/apache/camel/component/xmpp/XmppServerContainer.java rename to test-infra/camel-test-infra-xmpp/src/test/java/org/apache/camel/test/infra/xmpp/services/XmppServerContainer.java index bf0259f..032ee0d 100644 --- a/components/camel-xmpp/src/test/java/org/apache/camel/component/xmpp/XmppServerContainer.java +++ b/test-infra/camel-test-infra-xmpp/src/test/java/org/apache/camel/test/infra/xmpp/services/XmppServerContainer.java @@ -14,20 +14,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.camel.component.xmpp; +package org.apache.camel.test.infra.xmpp.services; import java.io.IOException; -import java.net.*; -import java.security.KeyStore; +import java.net.HttpURLConnection; +import java.net.URL; -import javax.net.ssl.SSLContext; -import javax.net.ssl.TrustManagerFactory; - -import org.apache.camel.spi.Registry; -import org.apache.camel.util.ObjectHelper; -import org.jivesoftware.smack.ConnectionConfiguration; -import org.jivesoftware.smack.tcp.XMPPTCPConnectionConfiguration; -import org.jxmpp.jid.impl.JidCreate; +import org.apache.camel.test.infra.xmpp.common.XmppProperties; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.testcontainers.containers.GenericContainer; @@ -39,42 +32,19 @@ public class XmppServerContainer extends GenericContainer { private static final String CONTAINER_NAME = "vysper-wrapper"; private static final String VYSPER_IMAGE = "5mattho/vysper-wrapper:0.3"; - private static final Integer PORT_DEFAULT = 5222; private static final Integer PORT_REST = 8080; public XmppServerContainer() { super(VYSPER_IMAGE); setWaitStrategy(Wait.forListeningPort()); - withExposedPorts(PORT_DEFAULT, PORT_REST); + withExposedPorts(XmppProperties.PORT_DEFAULT, PORT_REST); withNetworkAliases(CONTAINER_NAME); withLogConsumer(new Slf4jLogConsumer(LOGGER)); waitingFor(Wait.forLogMessage(".*Started Application in.*", 1)); } public String getUrl() { - return String.format("%s:%d", this.getContainerIpAddress(), this.getMappedPort(PORT_DEFAULT)); - } - - public void bindSSLContextTo(Registry registry) throws Exception { - KeyStore keyStore = KeyStore.getInstance("JKS"); - - keyStore.load(ObjectHelper.loadResourceAsStream("bogus_mina_tls.cert"), "boguspw".toCharArray()); - TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm()); - trustManagerFactory.init(keyStore); - SSLContext sslContext = SSLContext.getInstance("TLS"); - sslContext.init(null, trustManagerFactory.getTrustManagers(), null); - - ConnectionConfiguration connectionConfig = XMPPTCPConnectionConfiguration.builder() - .setXmppDomain(JidCreate.domainBareFrom("apache.camel")) - .setHostAddress(InetAddress.getByName(this.getContainerIpAddress())) - .setPort(this.getMappedPort(PORT_DEFAULT)) - // .setHostAddress(InetAddress.getLocalHost()) - // .setPort(PORT_DEFAULT) - .setCustomSSLContext(sslContext) - .setHostnameVerifier((hostname, session) -> true) - .build(); - - registry.bind("customConnectionConfig", connectionConfig); + return String.format("%s:%d", this.getContainerIpAddress(), this.getMappedPort(XmppProperties.PORT_DEFAULT)); } public void stopXmppEndpoint() throws IOException { @@ -93,4 +63,8 @@ public class XmppServerContainer extends GenericContainer { conn.getInputStream(); conn.disconnect(); } + + public int getPortDefault() { + return getMappedPort(XmppProperties.PORT_DEFAULT); + } } diff --git a/components/camel-xmpp/src/test/java/org/apache/camel/component/xmpp/XmppBaseTest.java b/test-infra/camel-test-infra-xmpp/src/test/java/org/apache/camel/test/infra/xmpp/services/XmppService.java similarity index 53% copy from components/camel-xmpp/src/test/java/org/apache/camel/component/xmpp/XmppBaseTest.java copy to test-infra/camel-test-infra-xmpp/src/test/java/org/apache/camel/test/infra/xmpp/services/XmppService.java index ab5a101..8797f1b 100644 --- a/components/camel-xmpp/src/test/java/org/apache/camel/component/xmpp/XmppBaseTest.java +++ b/test-infra/camel-test-infra-xmpp/src/test/java/org/apache/camel/test/infra/xmpp/services/XmppService.java @@ -14,33 +14,30 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.camel.component.xmpp; +package org.apache.camel.test.infra.xmpp.services; -import org.apache.camel.spi.Registry; -import org.apache.camel.support.SimpleRegistry; -import org.apache.camel.test.junit5.CamelTestSupport; -import org.junit.jupiter.api.AfterEach; +import org.apache.camel.test.infra.common.services.TestService; +import org.junit.jupiter.api.extension.AfterAllCallback; +import org.junit.jupiter.api.extension.BeforeAllCallback; +import org.junit.jupiter.api.extension.ExtensionContext; -public class XmppBaseTest extends CamelTestSupport { - protected XmppServerContainer xmppServer; +/** + * Test infra service for Xmpp + */ +public interface XmppService extends BeforeAllCallback, AfterAllCallback, TestService { + String host(); - @Override - protected Registry createCamelRegistry() throws Exception { - Registry registry = new SimpleRegistry(); - xmppServer.bindSSLContextTo(registry); - return registry; - } + int port(); + + String getUrl(); @Override - public void doPreSetup() { - xmppServer = new XmppServerContainer(); - xmppServer.start(); + default void beforeAll(ExtensionContext extensionContext) throws Exception { + initialize(); } @Override - @AfterEach - public void tearDown() throws Exception { - super.tearDown(); - xmppServer.stop(); + default void afterAll(ExtensionContext extensionContext) throws Exception { + shutdown(); } } diff --git a/components/camel-xmpp/src/test/java/org/apache/camel/component/xmpp/XmppBaseTest.java b/test-infra/camel-test-infra-xmpp/src/test/java/org/apache/camel/test/infra/xmpp/services/XmppServiceFactory.java similarity index 50% copy from components/camel-xmpp/src/test/java/org/apache/camel/component/xmpp/XmppBaseTest.java copy to test-infra/camel-test-infra-xmpp/src/test/java/org/apache/camel/test/infra/xmpp/services/XmppServiceFactory.java index ab5a101..d41c9d4 100644 --- a/components/camel-xmpp/src/test/java/org/apache/camel/component/xmpp/XmppBaseTest.java +++ b/test-infra/camel-test-infra-xmpp/src/test/java/org/apache/camel/test/infra/xmpp/services/XmppServiceFactory.java @@ -14,33 +14,30 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.camel.component.xmpp; +package org.apache.camel.test.infra.xmpp.services; -import org.apache.camel.spi.Registry; -import org.apache.camel.support.SimpleRegistry; -import org.apache.camel.test.junit5.CamelTestSupport; -import org.junit.jupiter.api.AfterEach; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; -public class XmppBaseTest extends CamelTestSupport { - protected XmppServerContainer xmppServer; +public final class XmppServiceFactory { + private static final Logger LOG = LoggerFactory.getLogger(XmppServiceFactory.class); - @Override - protected Registry createCamelRegistry() throws Exception { - Registry registry = new SimpleRegistry(); - xmppServer.bindSSLContextTo(registry); - return registry; - } + private XmppServiceFactory() { - @Override - public void doPreSetup() { - xmppServer = new XmppServerContainer(); - xmppServer.start(); } - @Override - @AfterEach - public void tearDown() throws Exception { - super.tearDown(); - xmppServer.stop(); + public static XmppService createService() { + String instanceType = System.getProperty("xmpp.instance.type"); + + if (instanceType == null || instanceType.equals("local-xmpp-container")) { + return new XmppLocalContainerService(); + } + + if (instanceType.equals("remote")) { + return new XmppRemoteService(); + } + + LOG.error("Xmpp instance must be one of 'local-xmpp-container' or 'remote"); + throw new UnsupportedOperationException("Invalid Xmpp instance type"); } } diff --git a/test-infra/pom.xml b/test-infra/pom.xml index 2e41de1..598481c 100644 --- a/test-infra/pom.xml +++ b/test-infra/pom.xml @@ -62,5 +62,6 @@ <module>camel-test-infra-nats</module> <module>camel-test-infra-nsq</module> <module>camel-test-infra-pulsar</module> + <module>camel-test-infra-xmpp</module> </modules> </project>