Skip to content

Commit

Permalink
Merge branch 'wildfly-31' into wildfly-32
Browse files Browse the repository at this point in the history
  • Loading branch information
kifj committed Apr 28, 2024
2 parents aac7469 + a3bfec9 commit 39ac9bf
Show file tree
Hide file tree
Showing 11 changed files with 57 additions and 42 deletions.
2 changes: 1 addition & 1 deletion src/test/java/x1/arquillian/Containers.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public final class Containers implements ArquillianTestContainers {

private final GenericContainer<?> database = new GenericContainer<>(
DockerImageName.parse("registry.x1/j7beck/x1-postgres-stomp-test:1.8")).withNetwork(network)
.withNetworkAliases("db").withLogConsumer(new Slf4jLogConsumer(LOGGER).withSeparateOutputStreams());
.withNetworkAliases("postgres").withLogConsumer(new Slf4jLogConsumer(LOGGER).withSeparateOutputStreams());

private final GenericContainer<?> etcd = new GenericContainer<>(DockerImageName.parse("quay.io/coreos/etcd:v3.5.13"))
.withEnv("ETCD_ENABLE_V2", "true").withNetwork(network).withNetworkAliases("etcd").withCommand("etcd",
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/x1/arquillian/WildflyContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public WildflyContainer withEnv(String file) {

public WildflyContainer withConfigurationDirectory(String directory) {
var target = System.getProperty("x1.arquillian.wildfly.configuration", "/srv/wildfly/standalone/configuration");
LOGGER.info("Source configuration folder: {}", new File(directory).getAbsolutePath(), target);
LOGGER.info("Source configuration folder {} -> {}", new File(directory).getAbsolutePath(), target);
for (var source : Objects.requireNonNullElse(new File(directory).listFiles(), new File[0])) {
LOGGER.debug("Copy {} to {}", source.getAbsolutePath(), target);
try (var fis = new FileInputStream(source)) {
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/x1/stomp/test/AbstractIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ public static Archive<?> createTestArchive() {
}

@BeforeEach
public void setup() {
void setup() {
client = ClientBuilder.newClient().register(JacksonConfig.class);
}

@AfterEach
public void tearDown() {
void tearDown() {
client.close();
}

Expand Down
15 changes: 5 additions & 10 deletions src/test/java/x1/stomp/test/ContainerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Tag;
Expand Down Expand Up @@ -58,38 +57,34 @@ public class ContainerTest {
DockerImageName.parse("registry.x1/j7beck/x1-wildfly-stomp-test:1.8")).dependsOn(postgres).withNetwork(network)
.withEnv("DB_SERVER", "postgres").withEnv("DB_PORT", "5432").withEnv("DB_USER", postgres.getUsername())
.withEnv("DB_PASSWORD", postgres.getPassword()).withExposedPorts(8080)
.withLogConsumer(new Slf4jLogConsumer(LOGGER).withSeparateOutputStreams())
.waitingFor(Wait.forHttp("/").forStatusCode(Status.OK.getStatusCode()));

private URI baseUrl;
private Client client;

@BeforeAll
static void enableLogging() {
wildfly.followOutput(new Slf4jLogConsumer(LOGGER).withSeparateOutputStreams());
}

@BeforeEach
public void setup() {
void setup() {
client = ClientBuilder.newClient().register(JacksonConfig.class);
baseUrl = UriBuilder.fromUri("http://" + wildfly.getHost() + ":" + wildfly.getFirstMappedPort()).path("rest")
.build();
}

@AfterEach
public void tearDown() {
void tearDown() {
client.close();
}

@Test
public void testFindShareNotFound() {
void testFindShareNotFound() {
try (var response = client.target(baseUrl).path(PATH_SHARES).path(PATH_PARAM_KEY)
.resolveTemplate(PARAM_KEY, TEST_SHARE).request(APPLICATION_JSON).get()) {
assertThat(response).hasStatus(NOT_FOUND);
}
}

@Test
public void testAddShareInvalid() {
void testAddShareInvalid() {
var key = "GOOG";
var share = new Share(key);

Expand Down
40 changes: 30 additions & 10 deletions src/test/java/x1/stomp/test/JaxbMarshallerTest.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package x1.stomp.test;

import static org.assertj.core.api.Assertions.assertThat;
import static x1.stomp.test.JaxbMarshallerTest.QuickQuoteAssert.assertThat;

import java.util.Objects;

import jakarta.xml.bind.JAXBContext;

import org.assertj.core.api.AbstractAssert;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.Test;

import x1.stomp.control.QuickQuote;
Expand All @@ -14,7 +17,7 @@
public class JaxbMarshallerTest extends AbstractIT {

@Test
public void readQuickQuote() throws Exception {
void readQuickQuote() throws Exception {
var ctx = JAXBContext.newInstance(QuickQuoteResult.class, QuickQuote.class);
var unmarshaller = ctx.createUnmarshaller();
var is = Objects.requireNonNull(getClass().getClassLoader().getResource("quickquoteresult.xml"));
Expand All @@ -23,15 +26,32 @@ public void readQuickQuote() throws Exception {
assertThat(result).isNotNull();
assertThat(result.getQuotes()).hasSize(1);
var quote = result.getQuotes().getFirst();
assertThat(quote).isNotNull();
assertThat(quote.getCountryCode()).isNotNull();
assertThat(quote.getCurrencyCode()).isNotNull();
assertThat(quote.getExchange()).isNotNull();
assertThat(quote.getLast()).isNotNull();
assertThat(quote.getLastTime()).isNotNull();
assertThat(quote.getName()).isNotNull();
assertThat(quote.getSymbol()).isNotNull();
assertThat(quote.getVolume()).isNotNull();
assertThat(quote).hasValues();
}

static class QuickQuoteAssert extends AbstractAssert<QuickQuoteAssert, QuickQuote> {

private QuickQuoteAssert(QuickQuote actual) {
super(actual, QuickQuoteAssert.class);
}

public static QuickQuoteAssert assertThat(QuickQuote actual) {
return new QuickQuoteAssert(actual);
}

@SuppressWarnings("UnusedReturnValue")
public QuickQuoteAssert hasValues() {
isNotNull();
Assertions.assertThat(actual.getCountryCode()).isNotNull();
Assertions.assertThat(actual.getCurrencyCode()).isNotNull();
Assertions.assertThat(actual.getExchange()).isNotNull();
Assertions.assertThat(actual.getLast()).isNotNull();
Assertions.assertThat(actual.getLastTime()).isNotNull();
Assertions.assertThat(actual.getName()).isNotNull();
Assertions.assertThat(actual.getSymbol()).isNotNull();
Assertions.assertThat(actual.getVolume()).isNotNull();
return this;
}
}

}
8 changes: 4 additions & 4 deletions src/test/java/x1/stomp/test/MetricsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class MetricsTest extends AbstractIT {
private String metricsBaseUrl;

@BeforeEach
public void setup() {
void setup() {
super.setup();
baseUrl = url.toString() + "rest";
metricsBaseUrl = getBaseUrlForMetrics();
Expand All @@ -45,7 +45,7 @@ private String getBaseUrlForMetrics() {

@Test
@DisplayName("test health")
public void testHealth() {
void testHealth() {
var response = client.target(metricsBaseUrl).path("health").request(APPLICATION_JSON).get();
assertThat(response).hasStatus(OK);

Expand All @@ -61,7 +61,7 @@ public void testHealth() {

@Test
@DisplayName("test metrics")
public void testMetrics() {
void testMetrics() {
var shares = client.target(baseUrl).path(PATH_SHARES).request(APPLICATION_JSON).get(new Shares());
assertThat(shares).isEmpty();

Expand All @@ -71,7 +71,7 @@ public void testMetrics() {
assertThat(counters).anyMatch(counter -> counter.getId().getTag("method").equals("listAllShares"));
}

private final class Shares extends GenericType<List<Share>> {
private static final class Shares extends GenericType<List<Share>> {
}

}
2 changes: 1 addition & 1 deletion src/test/java/x1/stomp/test/SchemaExportTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
@Tag("Unittests")
public class SchemaExportTest {
@Test
public void testSchemaExport() {
void testSchemaExport() {
var metadata = new MetadataSources(
new StandardServiceRegistryBuilder().applySetting(AvailableSettings.DIALECT, PostgreSQLDialect.class.getName())
.applySetting(AvailableSettings.DEFAULT_SCHEMA, "stocks").build());
Expand Down
16 changes: 8 additions & 8 deletions src/test/java/x1/stomp/test/ShareResourceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,21 @@ public class ShareResourceTest extends AbstractIT {
private String baseUrl;

@BeforeEach
public void setup() {
void setup() {
super.setup();
baseUrl = url.toString() + "rest";
}

@Test
public void testFindShareNotFound() {
void testFindShareNotFound() {
try (var response = client.target(baseUrl).path(PATH_SHARES).path(PATH_PARAM_KEY)
.resolveTemplate(PARAM_KEY, TEST_SHARE).request(APPLICATION_JSON).get()) {
assertThat(response).hasStatus(NOT_FOUND);
}
}

@Test
public void testAddAndFindShare() throws Exception {
void testAddAndFindShare() throws Exception {
var share = new Share();
var key = "MSFT";
var name = "Microsoft Corporation";
Expand Down Expand Up @@ -114,7 +114,7 @@ public void testAddAndFindShare() throws Exception {
}

@Test
public void testAddShareInvalid() {
void testAddShareInvalid() {
var key = "GOOG";
var share = new Share(key);

Expand All @@ -132,25 +132,25 @@ public void testAddShareInvalid() {
}

@Test
public void testGetQuoteNotFound() {
void testGetQuoteNotFound() {
try (var response = client.target(baseUrl).path(PATH_QUOTES).path(PATH_PARAM_KEY)
.resolveTemplate(PARAM_KEY, TEST_SHARE).request(APPLICATION_JSON).get()) {
assertThat(response).hasStatus(NOT_FOUND);
}
}

@Test
public void testGetQuotesNotFound() {
void testGetQuotesNotFound() {
try (var response = client.target(baseUrl).path(PATH_QUOTES).queryParam(PARAM_KEY, TEST_SHARE, TEST_SHARE_INVALID)
.request(APPLICATION_JSON).get()) {
assertThat(response).hasStatus(NOT_FOUND);
}
}

private final class Shares extends GenericType<List<Share>> {
private static final class Shares extends GenericType<List<Share>> {
}

private final class Quotes extends GenericType<List<Quote>> {
private static final class Quotes extends GenericType<List<Quote>> {
}

}
4 changes: 2 additions & 2 deletions src/test/java/x1/stomp/test/ShareSubscriptionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class ShareSubscriptionTest extends AbstractIT {
private Logger log;

@Test
public void testSubscribe() {
void testSubscribe() {
var share = new Share();
share.setKey("MSFT");
share.setName("Microsoft Corporation");
Expand Down Expand Up @@ -53,7 +53,7 @@ public void testSubscribe() {
}

@Test
public void testQuoteUpdater() throws Exception {
void testQuoteUpdater() throws Exception {
var share = new Share();
share.setKey("GOOG");
share.setName("Google");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class ShareSubscriptionWebSocketTest extends AbstractIT implements WebSoc
private WebSocketClient webSocketClient;

@Override
public WebSocketClient getWebSocketClient() {
public WebSocketClient getWebSocketClient() {
return webSocketClient;
}

Expand All @@ -49,7 +49,7 @@ public String getPath() {
}

@Test
public void testWebSocket() throws Exception {
void testWebSocket() throws Exception {
var command = new Command(SUBSCRIBE, TEST_SHARE);
var message = jsonHelper.toJSON(command);
log.debug("Sending {}", command);
Expand Down
2 changes: 1 addition & 1 deletion src/test/resources/wildfly-testcontainers.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
DB_SERVER=db
DB_SERVER=postgres
DB_PORT=5432
DB_USER=stocks
DB_PASSWORD=stocks
Expand Down

0 comments on commit 39ac9bf

Please sign in to comment.