Skip to content

Commit

Permalink
Make test methods package protected
Browse files Browse the repository at this point in the history
  • Loading branch information
kifj committed Apr 27, 2024
1 parent 9e0dada commit 6ca5046
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 36 deletions.
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;
}
}

}
6 changes: 3 additions & 3 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 Down
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
12 changes: 6 additions & 6 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,15 +132,15 @@ 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);
Expand Down
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

0 comments on commit 6ca5046

Please sign in to comment.