Polish "Move xmpp testcontainer to function-test-support"
- Removed custom container - Removed extra whitespace - Moved static props to SBT.properties
This commit is contained in:
@@ -1,46 +0,0 @@
|
||||
/*
|
||||
* Copyright 2014-2022 the original author or authors.
|
||||
*
|
||||
* Licensed 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
|
||||
*
|
||||
* https://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.springframework.cloud.fn.test.support.xmpp;
|
||||
|
||||
import org.testcontainers.containers.BindMode;
|
||||
import org.testcontainers.containers.GenericContainer;
|
||||
import org.testcontainers.containers.wait.strategy.Wait;
|
||||
import org.testcontainers.utility.DockerImageName;
|
||||
|
||||
/**
|
||||
* @author Chris Bono
|
||||
*/
|
||||
public class XmppContainer extends GenericContainer<XmppContainer> {
|
||||
|
||||
private static final DockerImageName DEFAULT_IMAGE_NAME = DockerImageName.parse("fishbowler/openfire:v4.7.0");
|
||||
|
||||
private static final int XMPP_INTERNAL_PORT = 5222;
|
||||
|
||||
public XmppContainer() {
|
||||
this(DEFAULT_IMAGE_NAME);
|
||||
}
|
||||
|
||||
public XmppContainer(DockerImageName dockerImageName) {
|
||||
super(dockerImageName);
|
||||
dockerImageName.assertCompatibleWith(DEFAULT_IMAGE_NAME);
|
||||
withExposedPorts(XMPP_INTERNAL_PORT);
|
||||
withClasspathResourceMapping("xmpp/conf", "/var/lib/openfire/conf", BindMode.READ_ONLY);
|
||||
withCommand("-demoboot");
|
||||
setWaitStrategy(Wait.defaultWaitStrategy());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -17,6 +17,8 @@
|
||||
package org.springframework.cloud.fn.test.support.xmpp;
|
||||
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.testcontainers.containers.BindMode;
|
||||
import org.testcontainers.containers.GenericContainer;
|
||||
import org.testcontainers.junit.jupiter.Testcontainers;
|
||||
|
||||
/**
|
||||
@@ -40,7 +42,6 @@ public interface XmppTestContainerSupport {
|
||||
*/
|
||||
String JANE_USER = "jane";
|
||||
|
||||
|
||||
/**
|
||||
* Password for sample users.
|
||||
*/
|
||||
@@ -54,7 +55,10 @@ public interface XmppTestContainerSupport {
|
||||
/**
|
||||
* The container.
|
||||
*/
|
||||
XmppContainer XMPP_CONTAINER = new XmppContainer();
|
||||
GenericContainer<?> XMPP_CONTAINER = new GenericContainer<>("fishbowler/openfire:v4.7.0")
|
||||
.withExposedPorts(5222)
|
||||
.withClasspathResourceMapping("xmpp/conf", "/var/lib/openfire/conf", BindMode.READ_ONLY)
|
||||
.withCommand("-demoboot");
|
||||
|
||||
@BeforeAll
|
||||
static void startContainer() {
|
||||
|
||||
@@ -15,24 +15,17 @@
|
||||
<description>XMPP consumer</description>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud.fn</groupId>
|
||||
<artifactId>xmpp-common</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud.fn</groupId>
|
||||
<artifactId>function-test-support</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
||||
</build>
|
||||
|
||||
</project>
|
||||
|
||||
@@ -48,25 +48,29 @@ import org.springframework.test.context.DynamicPropertySource;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.awaitility.Awaitility.await;
|
||||
import static org.springframework.cloud.fn.test.support.xmpp.XmppTestContainerSupport.JOHN_USER;
|
||||
import static org.springframework.cloud.fn.test.support.xmpp.XmppTestContainerSupport.SERVICE_NAME;
|
||||
import static org.springframework.cloud.fn.test.support.xmpp.XmppTestContainerSupport.USER_PW;
|
||||
|
||||
/**
|
||||
* @author Daniel Frey
|
||||
* @author Chris Bono
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
@SpringBootTest
|
||||
@SpringBootTest(
|
||||
properties = {
|
||||
"xmpp.factory.user=" + JOHN_USER,
|
||||
"xmpp.factory.password=" + USER_PW,
|
||||
"xmpp.factory.service-name=" + SERVICE_NAME,
|
||||
"xmpp.factory.security-mode=disabled"
|
||||
}
|
||||
)
|
||||
@DirtiesContext
|
||||
public class XmppConsumerConfigurationTests implements XmppTestContainerSupport {
|
||||
|
||||
@DynamicPropertySource
|
||||
static void registerConfigurationProperties(DynamicPropertyRegistry registry) {
|
||||
registry.add("xmpp.factory.user", () -> JOHN_USER);
|
||||
registry.add("xmpp.factory.password", () -> USER_PW);
|
||||
registry.add("xmpp.factory.host", () -> XmppTestContainerSupport.getXmppHost());
|
||||
registry.add("xmpp.factory.port", () -> XmppTestContainerSupport.getXmppMappedPort());
|
||||
registry.add("xmpp.factory.service-name", () -> SERVICE_NAME);
|
||||
registry.add("xmpp.factory.security-mode", () -> "disabled");
|
||||
}
|
||||
|
||||
@Autowired
|
||||
@@ -78,7 +82,6 @@ public class XmppConsumerConfigurationTests implements XmppTestContainerSupport
|
||||
|
||||
@BeforeEach
|
||||
void setup() throws IOException, SmackException, XMPPException, InterruptedException {
|
||||
|
||||
XMPPTCPConnectionConfiguration.Builder builder = XMPPTCPConnectionConfiguration.builder();
|
||||
builder.setSecurityMode(ConnectionConfiguration.SecurityMode.disabled);
|
||||
builder.setHost(XmppTestContainerSupport.getXmppHost());
|
||||
@@ -86,23 +89,18 @@ public class XmppConsumerConfigurationTests implements XmppTestContainerSupport
|
||||
builder.setResource(SERVICE_NAME);
|
||||
builder.setUsernameAndPassword(JANE_USER, USER_PW)
|
||||
.setXmppDomain(SERVICE_NAME);
|
||||
|
||||
this.clientConnection = new XMPPTCPConnection(builder.build());
|
||||
this.clientConnection.connect();
|
||||
this.clientConnection.login();
|
||||
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
void teardown() {
|
||||
|
||||
this.clientConnection.instantShutdown();
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
void messageHandlerConfiguration() {
|
||||
|
||||
StanzaCollector collector
|
||||
= this.clientConnection.createStanzaCollector(StanzaTypeFilter.MESSAGE);
|
||||
|
||||
@@ -113,19 +111,14 @@ public class XmppConsumerConfigurationTests implements XmppTestContainerSupport
|
||||
|
||||
await().atMost(Duration.ofSeconds(20)).pollDelay(Duration.ofMillis(100))
|
||||
.untilAsserted(() -> {
|
||||
|
||||
xmppConsumer.accept(testMessage);
|
||||
|
||||
Stanza stanza = collector.nextResult();
|
||||
assertStanza(stanza);
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
void xmppMessageHandlerConfiguration() throws XmppStringprepException {
|
||||
|
||||
StanzaCollector collector
|
||||
= this.clientConnection.createStanzaCollector(StanzaTypeFilter.MESSAGE);
|
||||
|
||||
@@ -135,14 +128,10 @@ public class XmppConsumerConfigurationTests implements XmppTestContainerSupport
|
||||
|
||||
await().atMost(Duration.ofSeconds(20)).pollDelay(Duration.ofMillis(100))
|
||||
.untilAsserted(() -> {
|
||||
|
||||
xmppConsumer.accept(testMessage);
|
||||
|
||||
Stanza stanza = collector.nextResult();
|
||||
assertStanza(stanza);
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private void assertStanza(Stanza stanza) {
|
||||
@@ -151,15 +140,11 @@ public class XmppConsumerConfigurationTests implements XmppTestContainerSupport
|
||||
}
|
||||
|
||||
private void assertTo(Stanza stanza) {
|
||||
|
||||
assertThat(stanza.getTo().asBareJid().asUnescapedString()).isEqualTo(JANE_USER + "@" + SERVICE_NAME);
|
||||
|
||||
}
|
||||
|
||||
private void assertFrom(Stanza stanza) {
|
||||
|
||||
assertThat(stanza.getFrom().asBareJid().asUnescapedString()).isEqualTo(JOHN_USER + "@" + SERVICE_NAME);
|
||||
|
||||
}
|
||||
|
||||
@SpringBootConfiguration
|
||||
|
||||
Reference in New Issue
Block a user