From 9158f28b018c258205ea0beea2484fd68762f577 Mon Sep 17 00:00:00 2001 From: Andre Kurait Date: Tue, 3 Nov 2026 19:32:52 -0600 Subject: [PATCH] test(iot): share the lazy MQTT integration profile (#7456) --- .../IotMqttLazyStartupIntegrationTest.java | 19 ++++--------------- ...MqttWebSocketLazyStartIntegrationTest.java | 18 ++++-------------- .../services/iot/LazyMqttTestProfile.java | 19 +++++++++++++++++++ 3 files changed, 27 insertions(+), 29 deletions(-) create mode 100644 src/test/java/io/github/hectorvent/floci/services/iot/LazyMqttTestProfile.java diff --git a/src/test/java/io/github/hectorvent/floci/services/iot/IotMqttLazyStartupIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/iot/IotMqttLazyStartupIntegrationTest.java index 6d5894bbf4..9a24df614f 100644 --- a/src/test/java/io/github/hectorvent/floci/services/iot/IotMqttLazyStartupIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/iot/IotMqttLazyStartupIntegrationTest.java @@ -1,15 +1,14 @@ package io.github.hectorvent.floci.services.iot; import io.quarkus.test.junit.QuarkusTest; -import io.quarkus.test.junit.QuarkusTestProfile; import io.quarkus.test.junit.TestProfile; import jakarta.inject.Inject; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import java.net.InetSocketAddress; import java.net.Socket; -import java.util.Map; import static io.restassured.RestAssured.given; import static org.hamcrest.Matchers.equalTo; @@ -17,15 +16,16 @@ import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; @QuarkusTest -@TestProfile(IotMqttLazyStartupIntegrationTest.LazyMqttProfile.class) +@TestProfile(LazyMqttTestProfile.class) class IotMqttLazyStartupIntegrationTest { - private static final int PORT = 18832; + private static final int PORT = LazyMqttTestProfile.PORT; @Inject IotMqttBrokerService mqttBrokerService; @BeforeEach + @AfterEach void stopBroker() throws InterruptedException { mqttBrokerService.stop(); awaitPortClosed(PORT); @@ -93,15 +93,4 @@ class IotMqttLazyStartupIntegrationTest { } } - public static final class LazyMqttProfile implements QuarkusTestProfile { - @Override - public Map getConfigOverrides() { - return Map.of( - "floci.services.iot.mqtt.enabled", "true", - "floci.services.iot.mqtt.auto-start", "false", - "floci.services.iot.mqtt.host", "127.0.0.1", - "floci.services.iot.mqtt.port", Integer.toString(PORT) - ); - } - } } diff --git a/src/test/java/io/github/hectorvent/floci/services/iot/IotMqttWebSocketLazyStartIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/iot/IotMqttWebSocketLazyStartIntegrationTest.java index da0f22da26..5503368533 100644 --- a/src/test/java/io/github/hectorvent/floci/services/iot/IotMqttWebSocketLazyStartIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/iot/IotMqttWebSocketLazyStartIntegrationTest.java @@ -1,7 +1,6 @@ package io.github.hectorvent.floci.services.iot; import io.quarkus.test.junit.QuarkusTest; -import io.quarkus.test.junit.QuarkusTestProfile; import io.quarkus.test.junit.TestProfile; import jakarta.inject.Inject; import org.eclipse.microprofile.config.inject.ConfigProperty; @@ -11,6 +10,7 @@ import org.eclipse.paho.client.mqttv3.MqttClient; import org.eclipse.paho.client.mqttv3.MqttConnectOptions; import org.eclipse.paho.client.mqttv3.MqttMessage; import org.eclipse.paho.client.mqttv3.persist.MemoryPersistence; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -18,7 +18,6 @@ import java.net.InetSocketAddress; import java.net.Socket; import java.util.ArrayList; import java.util.List; -import java.util.Map; import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; @@ -33,10 +32,10 @@ import static org.junit.jupiter.api.Assertions.assertTrue; * broker, concurrent first ones all get a session, and an upgrade after a stop starts it again. */ @QuarkusTest -@TestProfile(IotMqttWebSocketLazyStartIntegrationTest.Profile.class) +@TestProfile(LazyMqttTestProfile.class) class IotMqttWebSocketLazyStartIntegrationTest { - private static final int PORT = 18838; + private static final int PORT = LazyMqttTestProfile.PORT; @ConfigProperty(name = "quarkus.http.test-port", defaultValue = "0") int testHttpPort; @@ -45,6 +44,7 @@ class IotMqttWebSocketLazyStartIntegrationTest { IotMqttBrokerService broker; @BeforeEach + @AfterEach void stopBroker() throws InterruptedException { broker.stop(); awaitPortClosed(); @@ -165,14 +165,4 @@ class IotMqttWebSocketLazyStartIntegrationTest { }, "the broker port is still accepting after stop()"); } - public static final class Profile implements QuarkusTestProfile { - @Override - public Map getConfigOverrides() { - return Map.of( - "floci.services.iot.mqtt.enabled", "true", - "floci.services.iot.mqtt.auto-start", "false", - "floci.services.iot.mqtt.host", "127.0.0.1", - "floci.services.iot.mqtt.port", Integer.toString(PORT)); - } - } } diff --git a/src/test/java/io/github/hectorvent/floci/services/iot/LazyMqttTestProfile.java b/src/test/java/io/github/hectorvent/floci/services/iot/LazyMqttTestProfile.java new file mode 100644 index 0000000000..badfd983a8 --- /dev/null +++ b/src/test/java/io/github/hectorvent/floci/services/iot/LazyMqttTestProfile.java @@ -0,0 +1,19 @@ +package io.github.hectorvent.floci.services.iot; + +import io.quarkus.test.junit.QuarkusTestProfile; + +import java.util.Map; + +public final class LazyMqttTestProfile implements QuarkusTestProfile { + + static final int PORT = 18838; + + @Override + public Map getConfigOverrides() { + return Map.of( + "floci.services.iot.mqtt.enabled", "true", + "floci.services.iot.mqtt.auto-start", "false", + "floci.services.iot.mqtt.host", "127.0.0.1", + "floci.services.iot.mqtt.port", Integer.toString(PORT)); + } +}