Skip to content

Commit

Permalink
Improve WildflyContainer
Browse files Browse the repository at this point in the history
  • Loading branch information
kifj committed Apr 15, 2024
1 parent 7ff4f1c commit b63458c
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/main/resources/META-INF/persistence.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="https://jakarta.ee/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://jakarta.ee/xml/ns/persistence https://jakarta.ee/xml/ns/persistence/persistence_2_2.xsd"
version="2.2">
xsi:schemaLocation="https://jakarta.ee/xml/ns/persistence https://jakarta.ee/xml/ns/persistence/persistence_3_0.xsd"
version="3.0">
<persistence-unit name="stomp-test">
<jta-data-source>java:jboss/datasources/stocksDS</jta-data-source>
<properties>
Expand Down
6 changes: 2 additions & 4 deletions src/test/java/x1/arquillian/Containers.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ public final class Containers implements ArquillianTestContainers {
"--listen-client-urls", "http://0.0.0.0:2379", "--advertise-client-urls", "http://etcd:2379");

private final WildflyContainer wildfly = new WildflyContainer("registry.x1/j7beck/x1-wildfly-stomp-test-it:1.8")
.dependsOn(database).dependsOn(etcd).withNetwork(network).withEnv("DB_SERVER", "db").withEnv("DB_PORT", "5432")
.withEnv("DB_USER", "stocks").withEnv("DB_PASSWORD", "stocks").withEnv("ETCD_SERVER", "etcd")
.withEnv("ETCD_PORT", "2379").withEnv("X1_SERVICE_REGISTRY_STAGE", "docker");
.dependsOn(database).dependsOn(etcd).withNetwork(network).withEnv("wildfly-testcontainers.properties");

private final List<GenericContainer<?>> instances = Arrays.asList(etcd, database, wildfly);

Expand Down Expand Up @@ -57,7 +55,7 @@ public void configureAfterStart(ContainerRegistry registry) {
public static boolean isRemoteArquillian() {
return System.getProperty("arquillian.launch").equals("remote");
}

@Override
public boolean isActive() {
return isRemoteArquillian();
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/x1/arquillian/TestContainersExtension.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ private void stopContainer(GenericContainer<?> container) {

private List<GenericContainer<?>> reverse(List<GenericContainer<?>> containers) {
var reverse = new ArrayList<>(containers);
Collections.reverse(containers);
Collections.reverse(reverse);
return reverse;
}

Expand Down
18 changes: 18 additions & 0 deletions src/test/java/x1/arquillian/WildflyContainer.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
package x1.arquillian;

import java.io.IOException;
import java.util.Properties;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.containers.wait.strategy.Wait;
import org.testcontainers.utility.DockerImageName;

import jakarta.ws.rs.core.Response.Status;

public class WildflyContainer extends GenericContainer<WildflyContainer> {
private static final Logger LOGGER = LoggerFactory.getLogger(WildflyContainer.class);

private static final int HTTP_PORT = 8080;
private static final int MGMT_PORT = 9990;

Expand All @@ -32,4 +39,15 @@ public Integer getManagementPort() {
public Integer getHttpPort() {
return getMappedPort(HTTP_PORT);
}

public WildflyContainer withEnv(String file) {
var p = new Properties();
try (var is = this.getClass().getClassLoader().getResourceAsStream(file)) {
p.load(is);
p.forEach(((key,value) -> this.withEnv(key.toString(), value.toString())));
} catch (IOException e) {
LOGGER.warn(e.getMessage());
}
return this;
}
}
4 changes: 2 additions & 2 deletions src/test/resources/META-INF/persistence.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="https://jakarta.ee/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://jakarta.ee/xml/ns/persistence https://jakarta.ee/xml/ns/persistence/persistence_2_2.xsd"
version="2.2">
xsi:schemaLocation="https://jakarta.ee/xml/ns/persistence https://jakarta.ee/xml/ns/persistence/persistence_3_0.xsd"
version="3.0">
<persistence-unit name="testcontainers">
<class>x1.stomp.model.Share</class>
<properties>
Expand Down
4 changes: 2 additions & 2 deletions src/test/resources/managed-persistence.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="https://jakarta.ee/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://jakarta.ee/xml/ns/persistence https://jakarta.ee/xml/ns/persistence/persistence_2_2.xsd"
version="2.2">
xsi:schemaLocation="https://jakarta.ee/xml/ns/persistence https://jakarta.ee/xml/ns/persistence/persistence_3_0.xsd"
version="3.0">
<persistence-unit name="stomp-test">
<jta-data-source>java:jboss/datasources/stockstestDS</jta-data-source>
<properties>
Expand Down
2 changes: 1 addition & 1 deletion src/test/resources/remote-persistence.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="https://jakarta.ee/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://jakarta.ee/xml/ns/persistence https://jakarta.ee/xml/ns/persistence/persistence_2_2.xsd"
version="2.2">
version="3.0">
<persistence-unit name="stomp-test">
<jta-data-source>java:jboss/datasources/stocksDS</jta-data-source>
<properties>
Expand Down
7 changes: 7 additions & 0 deletions src/test/resources/wildfly-testcontainers.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
DB_SERVER=db
DB_PORT=5432
DB_USER=stocks
DB_PASSWORD=stocks
ETCD_SERVER=etcd
ETCD_PORT=2379
X1_SERVICE_REGISTRY_STAGE=docker

0 comments on commit b63458c

Please sign in to comment.