Skip to content

Commit

Permalink
Maintenance:
Browse files Browse the repository at this point in the history
- Change deprecated dockerStatusBuildItem.isDockerAvailable() to dockerStatusBuildItem.isContainerRuntimeAvailable()
- Resource Adapter integration tests:
  - Where possible, use constructor injection
  - Remove public modifier from all test classes and -method
  - Reformat code
- Fix typos

(cherry picked from commit 20b09ee)
  • Loading branch information
turing85 committed Jul 12, 2024
1 parent d4d57a7 commit 16861fe
Show file tree
Hide file tree
Showing 13 changed files with 53 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ private static DevServicesResultBuildItem start(
}
} catch (Throwable t) {
compressor.closeAndDumpCaptured();
throw t instanceof RuntimeException ? (RuntimeException) t : new RuntimeException(t);
throw t instanceof RuntimeException runtimeException ? runtimeException : new RuntimeException(t);
}
}
}
Expand Down Expand Up @@ -188,8 +188,8 @@ private static void shutdownBroker(String name) {
if (devServices.get(name) != null) {
try {
devServices.get(name).close();
} catch (Throwable e) {
LOGGER.error("Failed to stop the ActiveMQ Artemis broker", e);
} catch (Throwable t) {
LOGGER.error("Failed to stop the ActiveMQ Artemis broker", t);
} finally {
devServices.remove(name);
}
Expand Down Expand Up @@ -219,7 +219,7 @@ private static RunningDevService startArtemis(
return null;
}

if (!dockerStatusBuildItem.isDockerAvailable()) {
if (!dockerStatusBuildItem.isContainerRuntimeAvailable()) {
LOGGER.warn(
"Docker isn't working, please configure the ActiveMQ Artemis Url property (quarkus.artemis.url).");
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public interface ArtemisDevServicesBuildTimeConfig {
Optional<String> user();

/**
* Password to start artemis broker. Defaults to {@code admin} whne not set.
* Password to start artemis broker. Defaults to {@code admin} when not set.
*/
Optional<String> password();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ public static <T> Map<String, T> extractIdentifiers(Class<T> clazz, Set<String>

private static String extractIdentifier(InstanceHandle<?> handle) {
for (Annotation qualifier : handle.getBean().getQualifiers()) {
if (qualifier instanceof Identifier) {
Identifier identifier = (Identifier) qualifier;
if (qualifier instanceof Identifier identifier) {
return identifier.value();
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package io.quarkus.it.artemis.ra;

import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
import jakarta.jms.ConnectionFactory;
import jakarta.jms.JMSContext;
import jakarta.jms.JMSException;
import jakarta.jms.JMSProducer;
import jakarta.jms.Queue;
import jakarta.jms.TextMessage;
Expand All @@ -21,10 +21,11 @@
@Path("/jca")
@ApplicationScoped
public class JcaResource {
// add some rest methods here
private final ConnectionFactory factory;

@Inject
ConnectionFactory factory;
public JcaResource(@SuppressWarnings("CdiInjectionPointsInspection") ConnectionFactory factory) {
this.factory = factory;
}

@GET
@Transactional
Expand All @@ -46,7 +47,7 @@ public String hello(@QueryParam("name") @DefaultValue("JCA") String name) {
@POST
@Transactional
@Path("/sales")
public void sendToSalesQueue(@FormParam("name") String name) throws Exception {
public void sendToSalesQueue(@FormParam("name") String name) throws JMSException {
try (JMSContext context = factory.createContext()) {
JMSProducer producer = context.createProducer();
TextMessage msg = context.createTextMessage(name);
Expand All @@ -72,7 +73,7 @@ public long countGifts() {
@GET
@Path("/transacted")
@Transactional
public boolean Transacted() {
public boolean transacted() {
return isTransacted();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
@ResourceEndpoint(activationSpecConfigKey = "myqueue")
@Path("/myqueue")
public class MyQueueMessageEndpoint implements MessageListener {

AtomicInteger counter = new AtomicInteger(0);
private final AtomicInteger counter = new AtomicInteger(0);

@Override
@Transactional
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import java.util.concurrent.atomic.AtomicInteger;

import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
import jakarta.jms.ConnectionFactory;
import jakarta.jms.JMSContext;
import jakarta.jms.Message;
Expand All @@ -17,11 +16,14 @@
@ApplicationScoped
@ResourceEndpoint(activationSpecConfigKey = "sales")
public class SalesEndpoint implements MessageListener {
private final ConnectionFactory connectionFactory;
private final AtomicInteger count;

@Inject
ConnectionFactory connectionFactory;

AtomicInteger count = new AtomicInteger(0);
public SalesEndpoint(
@SuppressWarnings("CdiInjectionPointsInspection") ConnectionFactory connectionFactory) {
this.connectionFactory = connectionFactory;
count = new AtomicInteger(0);
}

@Override
@Transactional
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,18 @@

@QuarkusTest
@TestProfile(DisableAllServices.class)
public class InjectionTest {

class InjectionTest {
@Inject
@SuppressWarnings("CdiInjectionPointsInspection")
ConnectionFactory connectionFactory;

@Test
public void testProducer() {
void testProducer() {
assertThat(Arc.container().listAll(IronJacamarContainer.class)).hasSize(1);
}

@Test
public void shouldInjectConnectionFactory() {
void shouldInjectConnectionFactory() {
assertThat(Arc.container().listAll(ConnectionFactory.class)).hasSize(1);
assertThat(connectionFactory).isNotNull();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,20 @@

@QuarkusTest
@TestProfile(DisableDataBaseService.class)
public class IronJacamarConfigTest {

class IronJacamarConfigTest {
@Inject
IronJacamarRuntimeConfig runtimeConfig;

@Test
void shouldReadConfig() {
assertThat(runtimeConfig.resourceAdapters().get("<default>").ra()).satisfies(
ra -> {
assertThat(ra.config()).hasEntrySatisfying("connection-parameters", cp -> {
assertThat(cp).matches("host=localhost;port=[0-9]+;protocols=AMQP");
});
});
assertThat(runtimeConfig.activationSpecs().map().get("myqueue").config()).hasEntrySatisfying("destination", d -> {
assertThat(d).endsWith("MyQueue");
});
ra -> assertThat(ra.config())
.hasEntrySatisfying(
"connection-parameters",
cp -> assertThat(cp)
.matches("host=localhost;port=[0-9]+;protocols=AMQP")));
assertThat(runtimeConfig.activationSpecs().map().get("myqueue").config())
.hasEntrySatisfying("destination", d -> assertThat(d).endsWith("MyQueue"));

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
import io.quarkus.test.junit.QuarkusIntegrationTest;

@QuarkusIntegrationTest
public class JcaResourceIT extends JcaResourceTest {
class JcaResourceIT extends JcaResourceTest {
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import static org.hamcrest.Matchers.is;

import jakarta.transaction.Transactional;
import jakarta.ws.rs.core.Response;

import org.junit.jupiter.api.BeforeEach;
Expand All @@ -15,26 +14,21 @@

@QuarkusTest
@QuarkusTestResource(ArtemisTestResource.class)
public class JcaResourceTest {

class JcaResourceTest {
@BeforeEach
@Transactional
void setup() {
// @formatter:off
RestAssured
.when().delete("/jca/gifts")
.then()
.statusCode(Response.Status.NO_CONTENT.getStatusCode());
.then().statusCode(Response.Status.NO_CONTENT.getStatusCode());
RestAssured
.when().put("/myqueue/reset")
.then()
.statusCode(Response.Status.NO_CONTENT.getStatusCode());
.then().statusCode(Response.Status.NO_CONTENT.getStatusCode());
// @formatter:on
}

@Test
@Transactional
public void testProducer() {
void testProducer() {
// @formatter:off
RestAssured
.when().get("/jca?name=George")
Expand All @@ -55,14 +49,13 @@ public void testProducer() {
}

@Test
@Transactional
public void testProducerRollback() {
void testProducerRollback() {
// @formatter:off
RestAssured
.when().get("/jca?name=rollback")
.then()
.statusCode(Response.Status.OK.getStatusCode())
. body(is("Hello rollback"));
.body(is("Hello rollback"));
RestAssured
.when().get("/jca/gifts/count")
.then()
Expand All @@ -71,12 +64,13 @@ public void testProducerRollback() {
RestAssured
.when().get("/myqueue")
.then()
.statusCode(Response.Status.OK.getStatusCode()).body(is("0"));
.statusCode(Response.Status.OK.getStatusCode())
.body(is("0"));
// @formatter:on
}

@Test
public void testTransacted() {
void testTransacted() {
// @formatter:off
RestAssured
.when().get("/jca/transacted")
Expand All @@ -87,7 +81,7 @@ public void testTransacted() {
}

@Test
public void testNotTransacted() {
void testNotTransacted() {
// @formatter:off
RestAssured
.when().get("/jca/not-transacted")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,14 @@

@QuarkusTest
@TestProfile(DisableAllServices.class)
public class MetricsTest {

class MetricsTest {
@Test
void shouldHaveMetrics() {
// @formatter:off
RestAssured
.when().get("/q/metrics")
.then()
.log().ifValidationFails()
.log().ifValidationFails()
.statusCode(Response.Status.OK.getStatusCode())
.body(containsString("ironjacamar_pool_in_use_count_total{resourceAdapter=\"<default>\"}"));
// @formatter:on
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,21 @@

@QuarkusTest
@QuarkusTestResource(ArtemisTestResource.class)
public class TransactionTest {

class TransactionTest {
@Inject
@SuppressWarnings("CdiInjectionPointsInspection")
ConnectionFactory factory;

@Inject
SalesEndpoint endpoint;

@Test
public void retryMessagesOnRollback() {
void retryMessagesOnRollback() {
// @formatter:off
RestAssured
.given()
.formParam("name", "George")
.given().formParam("name", "George")
.when().post("/jca/sales")
.then()
.statusCode(Response.Status.NO_CONTENT.getStatusCode());
.then().statusCode(Response.Status.NO_CONTENT.getStatusCode());
// @formatter:on

try (JMSContext context = factory.createContext()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ public Supplier<ConnectionFactory> getConnectionFactoryProducer(
return () -> connectionFactory;
}

private ConnectionFactory extractConnectionFactory(boolean isXAenabled, ArtemisRuntimeConfig runtimeConfig,
private ConnectionFactory extractConnectionFactory(boolean isXaEnabled, ArtemisRuntimeConfig runtimeConfig,
Function<ConnectionFactory, Object> wrapper) {
String url = runtimeConfig.getUrl();
if (url != null) {
if (isXAenabled) {
if (isXaEnabled) {
return (ConnectionFactory) wrapper.apply(new ActiveMQXAConnectionFactory(
url,
runtimeConfig.getUsername(),
Expand Down

0 comments on commit 16861fe

Please sign in to comment.