From 16861fe005d6d0d204e6c6369a310a51e2d9f3f4 Mon Sep 17 00:00:00 2001 From: Marco Bungart Date: Fri, 12 Jul 2024 00:07:48 +0200 Subject: [PATCH] Maintenance: - 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 20b09eef9d8086a0653cf90e01ca837ecf15aa51) --- .../DevServicesArtemisProcessor.java | 8 +++--- .../ArtemisDevServicesBuildTimeConfig.java | 2 +- .../artemis/core/runtime/ArtemisUtil.java | 3 +-- .../io/quarkus/it/artemis/ra/JcaResource.java | 13 +++++----- .../it/artemis/ra/MyQueueMessageEndpoint.java | 3 +-- .../quarkus/it/artemis/ra/SalesEndpoint.java | 12 +++++---- .../quarkus/it/artemis/ra/InjectionTest.java | 8 +++--- .../it/artemis/ra/IronJacamarConfigTest.java | 18 ++++++------- .../quarkus/it/artemis/ra/JcaResourceIT.java | 2 +- .../it/artemis/ra/JcaResourceTest.java | 26 +++++++------------ .../io/quarkus/it/artemis/ra/MetricsTest.java | 5 ++-- .../it/artemis/ra/TransactionTest.java | 12 ++++----- .../jms/runtime/ArtemisJmsRecorder.java | 4 +-- 13 files changed, 53 insertions(+), 63 deletions(-) diff --git a/core/deployment/src/main/java/io/quarkus/artemis/core/deployment/DevServicesArtemisProcessor.java b/core/deployment/src/main/java/io/quarkus/artemis/core/deployment/DevServicesArtemisProcessor.java index a64c2ac9..2a8a5627 100644 --- a/core/deployment/src/main/java/io/quarkus/artemis/core/deployment/DevServicesArtemisProcessor.java +++ b/core/deployment/src/main/java/io/quarkus/artemis/core/deployment/DevServicesArtemisProcessor.java @@ -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); } } } @@ -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); } @@ -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; diff --git a/core/runtime/src/main/java/io/quarkus/artemis/core/runtime/ArtemisDevServicesBuildTimeConfig.java b/core/runtime/src/main/java/io/quarkus/artemis/core/runtime/ArtemisDevServicesBuildTimeConfig.java index f5750306..35837b8c 100644 --- a/core/runtime/src/main/java/io/quarkus/artemis/core/runtime/ArtemisDevServicesBuildTimeConfig.java +++ b/core/runtime/src/main/java/io/quarkus/artemis/core/runtime/ArtemisDevServicesBuildTimeConfig.java @@ -58,7 +58,7 @@ public interface ArtemisDevServicesBuildTimeConfig { Optional 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 password(); diff --git a/core/runtime/src/main/java/io/quarkus/artemis/core/runtime/ArtemisUtil.java b/core/runtime/src/main/java/io/quarkus/artemis/core/runtime/ArtemisUtil.java index 3abd4157..9bb06c2e 100644 --- a/core/runtime/src/main/java/io/quarkus/artemis/core/runtime/ArtemisUtil.java +++ b/core/runtime/src/main/java/io/quarkus/artemis/core/runtime/ArtemisUtil.java @@ -51,8 +51,7 @@ public static Map extractIdentifiers(Class clazz, Set 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(); } } diff --git a/integration-tests/ra/src/main/java/io/quarkus/it/artemis/ra/JcaResource.java b/integration-tests/ra/src/main/java/io/quarkus/it/artemis/ra/JcaResource.java index 74688189..64b45cc6 100644 --- a/integration-tests/ra/src/main/java/io/quarkus/it/artemis/ra/JcaResource.java +++ b/integration-tests/ra/src/main/java/io/quarkus/it/artemis/ra/JcaResource.java @@ -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; @@ -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 @@ -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); @@ -72,7 +73,7 @@ public long countGifts() { @GET @Path("/transacted") @Transactional - public boolean Transacted() { + public boolean transacted() { return isTransacted(); } diff --git a/integration-tests/ra/src/main/java/io/quarkus/it/artemis/ra/MyQueueMessageEndpoint.java b/integration-tests/ra/src/main/java/io/quarkus/it/artemis/ra/MyQueueMessageEndpoint.java index bff9d3d3..f94ccb63 100644 --- a/integration-tests/ra/src/main/java/io/quarkus/it/artemis/ra/MyQueueMessageEndpoint.java +++ b/integration-tests/ra/src/main/java/io/quarkus/it/artemis/ra/MyQueueMessageEndpoint.java @@ -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 diff --git a/integration-tests/ra/src/main/java/io/quarkus/it/artemis/ra/SalesEndpoint.java b/integration-tests/ra/src/main/java/io/quarkus/it/artemis/ra/SalesEndpoint.java index 051377ea..4be1b6b6 100644 --- a/integration-tests/ra/src/main/java/io/quarkus/it/artemis/ra/SalesEndpoint.java +++ b/integration-tests/ra/src/main/java/io/quarkus/it/artemis/ra/SalesEndpoint.java @@ -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; @@ -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 diff --git a/integration-tests/ra/src/test/java/io/quarkus/it/artemis/ra/InjectionTest.java b/integration-tests/ra/src/test/java/io/quarkus/it/artemis/ra/InjectionTest.java index 966030f2..83428da3 100644 --- a/integration-tests/ra/src/test/java/io/quarkus/it/artemis/ra/InjectionTest.java +++ b/integration-tests/ra/src/test/java/io/quarkus/it/artemis/ra/InjectionTest.java @@ -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(); } diff --git a/integration-tests/ra/src/test/java/io/quarkus/it/artemis/ra/IronJacamarConfigTest.java b/integration-tests/ra/src/test/java/io/quarkus/it/artemis/ra/IronJacamarConfigTest.java index 6a4eab9a..469e3659 100644 --- a/integration-tests/ra/src/test/java/io/quarkus/it/artemis/ra/IronJacamarConfigTest.java +++ b/integration-tests/ra/src/test/java/io/quarkus/it/artemis/ra/IronJacamarConfigTest.java @@ -13,22 +13,20 @@ @QuarkusTest @TestProfile(DisableDataBaseService.class) -public class IronJacamarConfigTest { - +class IronJacamarConfigTest { @Inject IronJacamarRuntimeConfig runtimeConfig; @Test void shouldReadConfig() { assertThat(runtimeConfig.resourceAdapters().get("").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")); } } diff --git a/integration-tests/ra/src/test/java/io/quarkus/it/artemis/ra/JcaResourceIT.java b/integration-tests/ra/src/test/java/io/quarkus/it/artemis/ra/JcaResourceIT.java index 7264c6d4..bf6e8a48 100644 --- a/integration-tests/ra/src/test/java/io/quarkus/it/artemis/ra/JcaResourceIT.java +++ b/integration-tests/ra/src/test/java/io/quarkus/it/artemis/ra/JcaResourceIT.java @@ -3,5 +3,5 @@ import io.quarkus.test.junit.QuarkusIntegrationTest; @QuarkusIntegrationTest -public class JcaResourceIT extends JcaResourceTest { +class JcaResourceIT extends JcaResourceTest { } diff --git a/integration-tests/ra/src/test/java/io/quarkus/it/artemis/ra/JcaResourceTest.java b/integration-tests/ra/src/test/java/io/quarkus/it/artemis/ra/JcaResourceTest.java index 51b2988d..93f6daec 100644 --- a/integration-tests/ra/src/test/java/io/quarkus/it/artemis/ra/JcaResourceTest.java +++ b/integration-tests/ra/src/test/java/io/quarkus/it/artemis/ra/JcaResourceTest.java @@ -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; @@ -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") @@ -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() @@ -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") @@ -87,7 +81,7 @@ public void testTransacted() { } @Test - public void testNotTransacted() { + void testNotTransacted() { // @formatter:off RestAssured .when().get("/jca/not-transacted") diff --git a/integration-tests/ra/src/test/java/io/quarkus/it/artemis/ra/MetricsTest.java b/integration-tests/ra/src/test/java/io/quarkus/it/artemis/ra/MetricsTest.java index 3e346898..ead57925 100644 --- a/integration-tests/ra/src/test/java/io/quarkus/it/artemis/ra/MetricsTest.java +++ b/integration-tests/ra/src/test/java/io/quarkus/it/artemis/ra/MetricsTest.java @@ -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=\"\"}")); // @formatter:on diff --git a/integration-tests/ra/src/test/java/io/quarkus/it/artemis/ra/TransactionTest.java b/integration-tests/ra/src/test/java/io/quarkus/it/artemis/ra/TransactionTest.java index af26416f..4fef8b57 100644 --- a/integration-tests/ra/src/test/java/io/quarkus/it/artemis/ra/TransactionTest.java +++ b/integration-tests/ra/src/test/java/io/quarkus/it/artemis/ra/TransactionTest.java @@ -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()) { diff --git a/jms/runtime/src/main/java/io/quarkus/artemis/jms/runtime/ArtemisJmsRecorder.java b/jms/runtime/src/main/java/io/quarkus/artemis/jms/runtime/ArtemisJmsRecorder.java index f1152f32..c10688f5 100644 --- a/jms/runtime/src/main/java/io/quarkus/artemis/jms/runtime/ArtemisJmsRecorder.java +++ b/jms/runtime/src/main/java/io/quarkus/artemis/jms/runtime/ArtemisJmsRecorder.java @@ -36,11 +36,11 @@ public Supplier getConnectionFactoryProducer( return () -> connectionFactory; } - private ConnectionFactory extractConnectionFactory(boolean isXAenabled, ArtemisRuntimeConfig runtimeConfig, + private ConnectionFactory extractConnectionFactory(boolean isXaEnabled, ArtemisRuntimeConfig runtimeConfig, Function wrapper) { String url = runtimeConfig.getUrl(); if (url != null) { - if (isXAenabled) { + if (isXaEnabled) { return (ConnectionFactory) wrapper.apply(new ActiveMQXAConnectionFactory( url, runtimeConfig.getUsername(),