From ed35024dbb85ee21799550ca78880c73991d879f Mon Sep 17 00:00:00 2001 From: Martin Ocenas Date: Tue, 7 Nov 2023 16:23:57 +0100 Subject: [PATCH 1/3] Add test coverage for issue 36402 Issue: https://github.com/quarkusio/quarkus/issues/36402. --- http/http-sse/pom.xml | 35 +++++++++ .../src/main/java/http/sse/MainCommand.java | 15 ++++ .../src/main/java/http/sse/SseClient.java | 71 +++++++++++++++++++ .../src/main/java/http/sse/SseResource.java | 24 +++++++ .../main/java/http/sse/UpdatesResource.java | 36 ++++++++++ .../src/main/resources/application.properties | 0 .../src/test/java/http/sse/HttpSseIT.java | 27 +++++++ 7 files changed, 208 insertions(+) create mode 100644 http/http-sse/pom.xml create mode 100644 http/http-sse/src/main/java/http/sse/MainCommand.java create mode 100644 http/http-sse/src/main/java/http/sse/SseClient.java create mode 100644 http/http-sse/src/main/java/http/sse/SseResource.java create mode 100644 http/http-sse/src/main/java/http/sse/UpdatesResource.java create mode 100644 http/http-sse/src/main/resources/application.properties create mode 100644 http/http-sse/src/test/java/http/sse/HttpSseIT.java diff --git a/http/http-sse/pom.xml b/http/http-sse/pom.xml new file mode 100644 index 000000000..7eea36057 --- /dev/null +++ b/http/http-sse/pom.xml @@ -0,0 +1,35 @@ + + + 4.0.0 + + io.quarkus.ts.qe + parent + 1.0.0-SNAPSHOT + ../.. + + http-sse + jar + + + io.quarkus + quarkus-picocli + + + io.quarkus + quarkus-resteasy-jsonb + + + io.quarkus + quarkus-rest-client-jsonb + + + + + + org.apache.maven.plugins + maven-compiler-plugin + ${compiler-plugin.version} + + + + diff --git a/http/http-sse/src/main/java/http/sse/MainCommand.java b/http/http-sse/src/main/java/http/sse/MainCommand.java new file mode 100644 index 000000000..c4aad8d51 --- /dev/null +++ b/http/http-sse/src/main/java/http/sse/MainCommand.java @@ -0,0 +1,15 @@ +package http.sse; + +import io.quarkus.picocli.runtime.annotations.TopCommand; +import io.quarkus.runtime.Quarkus; + +import picocli.CommandLine; + +@TopCommand +@CommandLine.Command(name = "test") +public class MainCommand implements Runnable { + @Override + public void run() { + Quarkus.waitForExit(); + } +} diff --git a/http/http-sse/src/main/java/http/sse/SseClient.java b/http/http-sse/src/main/java/http/sse/SseClient.java new file mode 100644 index 000000000..def0bda45 --- /dev/null +++ b/http/http-sse/src/main/java/http/sse/SseClient.java @@ -0,0 +1,71 @@ +package http.sse; + +import java.util.Arrays; +import java.util.concurrent.locks.LockSupport; + +import jakarta.annotation.PostConstruct; +import jakarta.annotation.PreDestroy; +import jakarta.enterprise.context.ApplicationScoped; +import jakarta.ws.rs.client.Client; +import jakarta.ws.rs.client.ClientBuilder; +import jakarta.ws.rs.client.WebTarget; +import jakarta.ws.rs.sse.SseEventSource; + +@ApplicationScoped +public class SseClient { + + private Client client; + private SseEventSource updateSource; + + @PostConstruct + void init() { + client = ClientBuilder.newClient(); + } + + @PreDestroy + void close() { + client.close(); + if (updateSource != null) + updateSource.close(); + } + + public String someMethod() { + StringBuilder response = new StringBuilder(); + + WebTarget target = client.target("http://localhost:" + getQuarkusPort() + "/updates"); + updateSource = SseEventSource.target(target).build(); + updateSource.register(ev -> { + response.append("ev.isEmpty() = ").append(ev.isEmpty()); + response.append("\n"); + response.append("event: ").append(ev.getName()).append(" ").append(ev.readData()); + response.append("\n"); + + }, thr -> { + response.append("Error in SSE updates\n"); + response.append(Arrays.toString(thr.getStackTrace())); + // thr.printStackTrace(); + }); + + response.append("SSE opened\n"); + updateSource.open(); + + // LockSupport.parkNanos(7_000_000_000L); + LockSupport.parkNanos(2_000_000_000L); + return response.toString(); + } + + /** + * Test runner assigns random ports, on which the app should run. + * Parse this port from the CLI and return it. + * If no parameter is specified, return the default (8080) + * + * @return port on which the application is running + */ + private int getQuarkusPort() { + String value = System.getProperty("quarkus.http.port"); + if (value == null || value.isEmpty()) { + return 8080; + } + return Integer.parseInt(value); + } +} diff --git a/http/http-sse/src/main/java/http/sse/SseResource.java b/http/http-sse/src/main/java/http/sse/SseResource.java new file mode 100644 index 000000000..dfa660261 --- /dev/null +++ b/http/http-sse/src/main/java/http/sse/SseResource.java @@ -0,0 +1,24 @@ +package http.sse; + +import jakarta.inject.Inject; +import jakarta.ws.rs.GET; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.Produces; +import jakarta.ws.rs.core.MediaType; + +@Path("/sse") +public class SseResource { + + @Inject + SseClient client; + + @GET + @Produces(MediaType.TEXT_PLAIN) + public String getSse() { + try { + return client.someMethod(); + } catch (RuntimeException exception) { + return exception.getMessage(); + } + } +} diff --git a/http/http-sse/src/main/java/http/sse/UpdatesResource.java b/http/http-sse/src/main/java/http/sse/UpdatesResource.java new file mode 100644 index 000000000..2f8a366b7 --- /dev/null +++ b/http/http-sse/src/main/java/http/sse/UpdatesResource.java @@ -0,0 +1,36 @@ +package http.sse; + +import java.util.concurrent.locks.LockSupport; + +import jakarta.enterprise.context.ApplicationScoped; +import jakarta.ws.rs.GET; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.Produces; +import jakarta.ws.rs.core.Context; +import jakarta.ws.rs.core.MediaType; +import jakarta.ws.rs.sse.OutboundSseEvent; +import jakarta.ws.rs.sse.Sse; +import jakarta.ws.rs.sse.SseEventSink; + +@ApplicationScoped +@Path("updates") +@Produces(MediaType.SERVER_SENT_EVENTS) +public class UpdatesResource { + + @Context + Sse sse; + + @GET + public void updates(@Context SseEventSink eventSink) { + eventSink.send(createEvent("test234", "test")); + LockSupport.parkNanos(1_000_000_000L); + } + + private OutboundSseEvent createEvent(String name, String data) { + return sse.newEventBuilder() + .name(name) + .data(data) + .build(); + } + +} diff --git a/http/http-sse/src/main/resources/application.properties b/http/http-sse/src/main/resources/application.properties new file mode 100644 index 000000000..e69de29bb diff --git a/http/http-sse/src/test/java/http/sse/HttpSseIT.java b/http/http-sse/src/test/java/http/sse/HttpSseIT.java new file mode 100644 index 000000000..c107bdab5 --- /dev/null +++ b/http/http-sse/src/test/java/http/sse/HttpSseIT.java @@ -0,0 +1,27 @@ +package http.sse; + +import static io.restassured.RestAssured.given; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; + +import io.quarkus.test.scenarios.QuarkusScenario; + +@QuarkusScenario +@Tag("QQE-257") +// validate issue from https://github.com/quarkusio/quarkus/issues/36402 +// this test should only fail on native +public class HttpSseIT { + private static final String SSE_ERROR_MESSAGE = "java.lang.ClassNotFoundException: Provider for jakarta.ws.rs.sse.SseEventSource.Builder cannot be found"; + + @Test + public void testWorkingSse() { + String response = given().when().get("/sse").thenReturn().body().asString(); + + assertFalse(response.contains(SSE_ERROR_MESSAGE), + "SSE failed, https://github.com/quarkusio/quarkus/issues/36402 not fixed"); + assertTrue(response.contains("event: test234 test"), "SSE failed, unknown bug. Response: " + response); + } +} From e860ed99cf32d397b0e050da4cfb546dc4938be8 Mon Sep 17 00:00:00 2001 From: Martin Ocenas Date: Wed, 8 Nov 2023 12:32:43 +0100 Subject: [PATCH 2/3] Refactor SSE test --- .../quarkus/ts/http/advanced/SseResource.java | 90 +++++++++++++++++++ .../quarkus/ts/http/advanced}/HttpSseIT.java | 23 +++-- http/http-sse/pom.xml | 35 -------- .../src/main/java/http/sse/MainCommand.java | 15 ---- .../src/main/java/http/sse/SseClient.java | 71 --------------- .../src/main/java/http/sse/SseResource.java | 24 ----- .../main/java/http/sse/UpdatesResource.java | 36 -------- .../src/main/resources/application.properties | 0 8 files changed, 104 insertions(+), 190 deletions(-) create mode 100644 http/http-advanced/src/main/java/io/quarkus/ts/http/advanced/SseResource.java rename http/{http-sse/src/test/java/http/sse => http-advanced/src/test/java/io/quarkus/ts/http/advanced}/HttpSseIT.java (58%) delete mode 100644 http/http-sse/pom.xml delete mode 100644 http/http-sse/src/main/java/http/sse/MainCommand.java delete mode 100644 http/http-sse/src/main/java/http/sse/SseClient.java delete mode 100644 http/http-sse/src/main/java/http/sse/SseResource.java delete mode 100644 http/http-sse/src/main/java/http/sse/UpdatesResource.java delete mode 100644 http/http-sse/src/main/resources/application.properties diff --git a/http/http-advanced/src/main/java/io/quarkus/ts/http/advanced/SseResource.java b/http/http-advanced/src/main/java/io/quarkus/ts/http/advanced/SseResource.java new file mode 100644 index 000000000..d513b2860 --- /dev/null +++ b/http/http-advanced/src/main/java/io/quarkus/ts/http/advanced/SseResource.java @@ -0,0 +1,90 @@ +package io.quarkus.ts.http.advanced; + +import java.util.Arrays; +import java.util.concurrent.locks.LockSupport; + +import jakarta.ws.rs.GET; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.Produces; +import jakarta.ws.rs.client.ClientBuilder; +import jakarta.ws.rs.client.WebTarget; +import jakarta.ws.rs.core.Context; +import jakarta.ws.rs.core.MediaType; +import jakarta.ws.rs.sse.OutboundSseEvent; +import jakarta.ws.rs.sse.Sse; +import jakarta.ws.rs.sse.SseEventSink; +import jakarta.ws.rs.sse.SseEventSource; + +@Path("/sse") +public class SseResource { + @Context + Sse sse; + + @GET + @Path("/client") + public String sseClient() { + try { + return consumeSse(); + } + // in case that https://github.com/quarkusio/quarkus/issues/36402 throws java.lang.RuntimeException: java.lang.ClassNotFoundException: + // catch it and return the error message + catch (RuntimeException exception) { + return exception.getMessage(); + } + } + + private String consumeSse() { + StringBuilder response = new StringBuilder(); + + /* + * Client connects to itself (to server endpoint running on same app), + * because for https://github.com/quarkusio/quarkus/issues/36402 to reproduce client must run on native app. + * Which cannot be done in test code itself. + * This method acts just as a client + */ + WebTarget target = ClientBuilder.newClient().target("http://localhost:" + getQuarkusPort() + "/api/sse/server"); + SseEventSource updateSource = SseEventSource.target(target).build(); + updateSource.register(ev -> { + response.append("event: ").append(ev.getName()).append(" ").append(ev.readData()); + response.append("\n"); + + }, thr -> { + response.append("Error in SSE, message: ").append(thr.getMessage()).append("\n"); + response.append(Arrays.toString(thr.getStackTrace())); + }); + updateSource.open(); + + LockSupport.parkNanos(2_000_000_000L); + return response.toString(); + } + + /** + * Test runner assigns random ports, on which the app should run. + * Parse this port from the CLI and return it. + * If no parameter is specified, return the default (8080) + * + * @return port on which the application is running + */ + private int getQuarkusPort() { + String value = System.getProperty("quarkus.http.port"); + if (value == null || value.isEmpty()) { + return 8080; + } + return Integer.parseInt(value); + } + + @GET + @Path("/server") + @Produces(MediaType.SERVER_SENT_EVENTS) + public void sendSseEvents(@Context SseEventSink eventSink) { + eventSink.send(createEvent("test234", "test")); + LockSupport.parkNanos(1_000_000_000L); + } + + private OutboundSseEvent createEvent(String name, String data) { + return sse.newEventBuilder() + .name(name) + .data(data) + .build(); + } +} diff --git a/http/http-sse/src/test/java/http/sse/HttpSseIT.java b/http/http-advanced/src/test/java/io/quarkus/ts/http/advanced/HttpSseIT.java similarity index 58% rename from http/http-sse/src/test/java/http/sse/HttpSseIT.java rename to http/http-advanced/src/test/java/io/quarkus/ts/http/advanced/HttpSseIT.java index c107bdab5..7924a3f3d 100644 --- a/http/http-sse/src/test/java/http/sse/HttpSseIT.java +++ b/http/http-advanced/src/test/java/io/quarkus/ts/http/advanced/HttpSseIT.java @@ -1,24 +1,29 @@ -package http.sse; - -import static io.restassured.RestAssured.given; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertTrue; +package io.quarkus.ts.http.advanced; +import io.quarkus.test.bootstrap.RestService; +import io.quarkus.test.scenarios.QuarkusScenario; +import io.quarkus.test.services.QuarkusApplication; import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; -import io.quarkus.test.scenarios.QuarkusScenario; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; @QuarkusScenario -@Tag("QQE-257") -// validate issue from https://github.com/quarkusio/quarkus/issues/36402 +@Tag("https://github.com/quarkusio/quarkus/issues/36402") // this test should only fail on native public class HttpSseIT { + + @QuarkusApplication + static RestService app = new RestService() + .withProperty("quarkus.oidc.enabled", "false") + .withProperty("quarkus.keycloak.policy-enforcer.enable", "false") + .withProperty("quarkus.keycloak.devservices.enabled", "false"); private static final String SSE_ERROR_MESSAGE = "java.lang.ClassNotFoundException: Provider for jakarta.ws.rs.sse.SseEventSource.Builder cannot be found"; @Test public void testWorkingSse() { - String response = given().when().get("/sse").thenReturn().body().asString(); + String response = app.given().when().get("/api/sse/client").thenReturn().body().asString(); assertFalse(response.contains(SSE_ERROR_MESSAGE), "SSE failed, https://github.com/quarkusio/quarkus/issues/36402 not fixed"); diff --git a/http/http-sse/pom.xml b/http/http-sse/pom.xml deleted file mode 100644 index 7eea36057..000000000 --- a/http/http-sse/pom.xml +++ /dev/null @@ -1,35 +0,0 @@ - - - 4.0.0 - - io.quarkus.ts.qe - parent - 1.0.0-SNAPSHOT - ../.. - - http-sse - jar - - - io.quarkus - quarkus-picocli - - - io.quarkus - quarkus-resteasy-jsonb - - - io.quarkus - quarkus-rest-client-jsonb - - - - - - org.apache.maven.plugins - maven-compiler-plugin - ${compiler-plugin.version} - - - - diff --git a/http/http-sse/src/main/java/http/sse/MainCommand.java b/http/http-sse/src/main/java/http/sse/MainCommand.java deleted file mode 100644 index c4aad8d51..000000000 --- a/http/http-sse/src/main/java/http/sse/MainCommand.java +++ /dev/null @@ -1,15 +0,0 @@ -package http.sse; - -import io.quarkus.picocli.runtime.annotations.TopCommand; -import io.quarkus.runtime.Quarkus; - -import picocli.CommandLine; - -@TopCommand -@CommandLine.Command(name = "test") -public class MainCommand implements Runnable { - @Override - public void run() { - Quarkus.waitForExit(); - } -} diff --git a/http/http-sse/src/main/java/http/sse/SseClient.java b/http/http-sse/src/main/java/http/sse/SseClient.java deleted file mode 100644 index def0bda45..000000000 --- a/http/http-sse/src/main/java/http/sse/SseClient.java +++ /dev/null @@ -1,71 +0,0 @@ -package http.sse; - -import java.util.Arrays; -import java.util.concurrent.locks.LockSupport; - -import jakarta.annotation.PostConstruct; -import jakarta.annotation.PreDestroy; -import jakarta.enterprise.context.ApplicationScoped; -import jakarta.ws.rs.client.Client; -import jakarta.ws.rs.client.ClientBuilder; -import jakarta.ws.rs.client.WebTarget; -import jakarta.ws.rs.sse.SseEventSource; - -@ApplicationScoped -public class SseClient { - - private Client client; - private SseEventSource updateSource; - - @PostConstruct - void init() { - client = ClientBuilder.newClient(); - } - - @PreDestroy - void close() { - client.close(); - if (updateSource != null) - updateSource.close(); - } - - public String someMethod() { - StringBuilder response = new StringBuilder(); - - WebTarget target = client.target("http://localhost:" + getQuarkusPort() + "/updates"); - updateSource = SseEventSource.target(target).build(); - updateSource.register(ev -> { - response.append("ev.isEmpty() = ").append(ev.isEmpty()); - response.append("\n"); - response.append("event: ").append(ev.getName()).append(" ").append(ev.readData()); - response.append("\n"); - - }, thr -> { - response.append("Error in SSE updates\n"); - response.append(Arrays.toString(thr.getStackTrace())); - // thr.printStackTrace(); - }); - - response.append("SSE opened\n"); - updateSource.open(); - - // LockSupport.parkNanos(7_000_000_000L); - LockSupport.parkNanos(2_000_000_000L); - return response.toString(); - } - - /** - * Test runner assigns random ports, on which the app should run. - * Parse this port from the CLI and return it. - * If no parameter is specified, return the default (8080) - * - * @return port on which the application is running - */ - private int getQuarkusPort() { - String value = System.getProperty("quarkus.http.port"); - if (value == null || value.isEmpty()) { - return 8080; - } - return Integer.parseInt(value); - } -} diff --git a/http/http-sse/src/main/java/http/sse/SseResource.java b/http/http-sse/src/main/java/http/sse/SseResource.java deleted file mode 100644 index dfa660261..000000000 --- a/http/http-sse/src/main/java/http/sse/SseResource.java +++ /dev/null @@ -1,24 +0,0 @@ -package http.sse; - -import jakarta.inject.Inject; -import jakarta.ws.rs.GET; -import jakarta.ws.rs.Path; -import jakarta.ws.rs.Produces; -import jakarta.ws.rs.core.MediaType; - -@Path("/sse") -public class SseResource { - - @Inject - SseClient client; - - @GET - @Produces(MediaType.TEXT_PLAIN) - public String getSse() { - try { - return client.someMethod(); - } catch (RuntimeException exception) { - return exception.getMessage(); - } - } -} diff --git a/http/http-sse/src/main/java/http/sse/UpdatesResource.java b/http/http-sse/src/main/java/http/sse/UpdatesResource.java deleted file mode 100644 index 2f8a366b7..000000000 --- a/http/http-sse/src/main/java/http/sse/UpdatesResource.java +++ /dev/null @@ -1,36 +0,0 @@ -package http.sse; - -import java.util.concurrent.locks.LockSupport; - -import jakarta.enterprise.context.ApplicationScoped; -import jakarta.ws.rs.GET; -import jakarta.ws.rs.Path; -import jakarta.ws.rs.Produces; -import jakarta.ws.rs.core.Context; -import jakarta.ws.rs.core.MediaType; -import jakarta.ws.rs.sse.OutboundSseEvent; -import jakarta.ws.rs.sse.Sse; -import jakarta.ws.rs.sse.SseEventSink; - -@ApplicationScoped -@Path("updates") -@Produces(MediaType.SERVER_SENT_EVENTS) -public class UpdatesResource { - - @Context - Sse sse; - - @GET - public void updates(@Context SseEventSink eventSink) { - eventSink.send(createEvent("test234", "test")); - LockSupport.parkNanos(1_000_000_000L); - } - - private OutboundSseEvent createEvent(String name, String data) { - return sse.newEventBuilder() - .name(name) - .data(data) - .build(); - } - -} diff --git a/http/http-sse/src/main/resources/application.properties b/http/http-sse/src/main/resources/application.properties deleted file mode 100644 index e69de29bb..000000000 From 5e88613240fb580e0e2542e3cc5f8757147c8364 Mon Sep 17 00:00:00 2001 From: Martin Ocenas Date: Wed, 8 Nov 2023 13:58:04 +0100 Subject: [PATCH 3/3] Refactor SSE test into HttpAdvancedIT --- .../quarkus/ts/http/advanced/SseResource.java | 23 +++---------- .../src/main/resources/application.properties | 2 ++ .../ts/http/advanced/BaseHttpAdvancedIT.java | 13 ++++++++ .../quarkus/ts/http/advanced/HttpSseIT.java | 32 ------------------- 4 files changed, 20 insertions(+), 50 deletions(-) delete mode 100644 http/http-advanced/src/test/java/io/quarkus/ts/http/advanced/HttpSseIT.java diff --git a/http/http-advanced/src/main/java/io/quarkus/ts/http/advanced/SseResource.java b/http/http-advanced/src/main/java/io/quarkus/ts/http/advanced/SseResource.java index d513b2860..79b327a45 100644 --- a/http/http-advanced/src/main/java/io/quarkus/ts/http/advanced/SseResource.java +++ b/http/http-advanced/src/main/java/io/quarkus/ts/http/advanced/SseResource.java @@ -15,6 +15,8 @@ import jakarta.ws.rs.sse.SseEventSink; import jakarta.ws.rs.sse.SseEventSource; +import org.eclipse.microprofile.config.ConfigProvider; + @Path("/sse") public class SseResource { @Context @@ -35,6 +37,7 @@ public String sseClient() { private String consumeSse() { StringBuilder response = new StringBuilder(); + int port = ConfigProvider.getConfig().getValue("quarkus.http.port", Integer.class); /* * Client connects to itself (to server endpoint running on same app), @@ -42,7 +45,7 @@ private String consumeSse() { * Which cannot be done in test code itself. * This method acts just as a client */ - WebTarget target = ClientBuilder.newClient().target("http://localhost:" + getQuarkusPort() + "/api/sse/server"); + WebTarget target = ClientBuilder.newClient().target("http://localhost:" + port + "/api/sse/server"); SseEventSource updateSource = SseEventSource.target(target).build(); updateSource.register(ev -> { response.append("event: ").append(ev.getName()).append(" ").append(ev.readData()); @@ -54,31 +57,15 @@ private String consumeSse() { }); updateSource.open(); - LockSupport.parkNanos(2_000_000_000L); + LockSupport.parkNanos(1_000_000_000L); return response.toString(); } - /** - * Test runner assigns random ports, on which the app should run. - * Parse this port from the CLI and return it. - * If no parameter is specified, return the default (8080) - * - * @return port on which the application is running - */ - private int getQuarkusPort() { - String value = System.getProperty("quarkus.http.port"); - if (value == null || value.isEmpty()) { - return 8080; - } - return Integer.parseInt(value); - } - @GET @Path("/server") @Produces(MediaType.SERVER_SENT_EVENTS) public void sendSseEvents(@Context SseEventSink eventSink) { eventSink.send(createEvent("test234", "test")); - LockSupport.parkNanos(1_000_000_000L); } private OutboundSseEvent createEvent(String name, String data) { diff --git a/http/http-advanced/src/main/resources/application.properties b/http/http-advanced/src/main/resources/application.properties index 904607fef..8c2859709 100644 --- a/http/http-advanced/src/main/resources/application.properties +++ b/http/http-advanced/src/main/resources/application.properties @@ -45,6 +45,8 @@ quarkus.keycloak.policy-enforcer.paths.version.enforcement-mode=DISABLED # Application endpoints quarkus.keycloak.policy-enforcer.paths.hello.path=/api/hello/* quarkus.keycloak.policy-enforcer.paths.hello.enforcement-mode=DISABLED +quarkus.keycloak.policy-enforcer.paths.sse.path=/api/sse/* +quarkus.keycloak.policy-enforcer.paths.sse.enforcement-mode=DISABLED quarkus.keycloak.policy-enforcer.paths.details.path=/api/details/* quarkus.keycloak.policy-enforcer.paths.details.enforcement-mode=DISABLED quarkus.keycloak.policy-enforcer.paths.grpc.path=/api/grpc/* diff --git a/http/http-advanced/src/test/java/io/quarkus/ts/http/advanced/BaseHttpAdvancedIT.java b/http/http-advanced/src/test/java/io/quarkus/ts/http/advanced/BaseHttpAdvancedIT.java index 0f943a88d..994232eba 100644 --- a/http/http-advanced/src/test/java/io/quarkus/ts/http/advanced/BaseHttpAdvancedIT.java +++ b/http/http-advanced/src/test/java/io/quarkus/ts/http/advanced/BaseHttpAdvancedIT.java @@ -8,6 +8,8 @@ import static org.hamcrest.Matchers.in; import static org.hamcrest.Matchers.is; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.fail; import java.net.URISyntaxException; @@ -60,6 +62,7 @@ public abstract class BaseHttpAdvancedIT { private static final String PASSWORD = "password"; private static final String KEY_STORE_PATH = "META-INF/resources/server.keystore"; private static final int ASSERT_TIMEOUT_SECONDS = 10; + private static final String SSE_ERROR_MESSAGE = "java.lang.ClassNotFoundException: Provider for jakarta.ws.rs.sse.SseEventSource.Builder cannot be found"; protected abstract RestService getApp(); @@ -242,6 +245,16 @@ public void keepRequestScopeValuesAfterEventPropagation() { "Unexpected requestScope custom context value"); } + @Test + @Tag("https://github.com/quarkusio/quarkus/issues/36402") + public void sseConnectionTest() { + String response = getApp().given().get("/api/sse/client").thenReturn().body().asString(); + + assertFalse(response.contains(SSE_ERROR_MESSAGE), + "SSE failed, https://github.com/quarkusio/quarkus/issues/36402 not fixed"); + assertTrue(response.contains("event: test234 test"), "SSE failed, unknown bug. Response: " + response); + } + protected Protocol getProtocol() { return Protocol.HTTPS; } diff --git a/http/http-advanced/src/test/java/io/quarkus/ts/http/advanced/HttpSseIT.java b/http/http-advanced/src/test/java/io/quarkus/ts/http/advanced/HttpSseIT.java deleted file mode 100644 index 7924a3f3d..000000000 --- a/http/http-advanced/src/test/java/io/quarkus/ts/http/advanced/HttpSseIT.java +++ /dev/null @@ -1,32 +0,0 @@ -package io.quarkus.ts.http.advanced; - -import io.quarkus.test.bootstrap.RestService; -import io.quarkus.test.scenarios.QuarkusScenario; -import io.quarkus.test.services.QuarkusApplication; -import org.junit.jupiter.api.Tag; -import org.junit.jupiter.api.Test; - -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertTrue; - -@QuarkusScenario -@Tag("https://github.com/quarkusio/quarkus/issues/36402") -// this test should only fail on native -public class HttpSseIT { - - @QuarkusApplication - static RestService app = new RestService() - .withProperty("quarkus.oidc.enabled", "false") - .withProperty("quarkus.keycloak.policy-enforcer.enable", "false") - .withProperty("quarkus.keycloak.devservices.enabled", "false"); - private static final String SSE_ERROR_MESSAGE = "java.lang.ClassNotFoundException: Provider for jakarta.ws.rs.sse.SseEventSource.Builder cannot be found"; - - @Test - public void testWorkingSse() { - String response = app.given().when().get("/api/sse/client").thenReturn().body().asString(); - - assertFalse(response.contains(SSE_ERROR_MESSAGE), - "SSE failed, https://github.com/quarkusio/quarkus/issues/36402 not fixed"); - assertTrue(response.contains("event: test234 test"), "SSE failed, unknown bug. Response: " + response); - } -}