From 52c7dc7ab99b1aadd5a80e6f6dbb769fad190e17 Mon Sep 17 00:00:00 2001 From: Nicolas Filotto Date: Thu, 29 Jun 2023 16:23:59 +0200 Subject: [PATCH] Ref #4894: Make Groovy DSL ITs platform compliant --- integration-tests/groovy-dsl/pom.xml | 55 +----- .../quarkus/dsl/groovy/GroovyDslTest.java | 181 +++++------------- tooling/test-list/pom.xml | 1 - 3 files changed, 51 insertions(+), 186 deletions(-) diff --git a/integration-tests/groovy-dsl/pom.xml b/integration-tests/groovy-dsl/pom.xml index 2e1d62d90421..7760421ef175 100644 --- a/integration-tests/groovy-dsl/pom.xml +++ b/integration-tests/groovy-dsl/pom.xml @@ -30,9 +30,6 @@ Camel Quarkus :: Integration Tests :: Groovy DSL Integration tests for Camel Groovy DSL extension - - ${project.build.directory}/quarkus-app/quarkus-run.jar - org.apache.camel.quarkus @@ -70,18 +67,12 @@ test - org.assertj - assertj-core - test - - - org.apache.camel.quarkus - camel-quarkus-integration-tests-process-executor-support - test + io.rest-assured + rest-assured - org.awaitility - awaitility + org.assertj + assertj-core test @@ -185,7 +176,6 @@ native - ${project.build.directory}/${project.artifactId}-${project.version}-runner @@ -200,43 +190,6 @@ - - - ${quarkus.runner} - - - - - - - - full - - - !quickly - - - - - - - org.apache.maven.plugins - maven-surefire-plugin - - - default-test - - test - - integration-test - - - ${quarkus.runner} - - - - diff --git a/integration-tests/groovy-dsl/src/test/java/org/apache/camel/quarkus/dsl/groovy/GroovyDslTest.java b/integration-tests/groovy-dsl/src/test/java/org/apache/camel/quarkus/dsl/groovy/GroovyDslTest.java index 82ce10720871..6f41d92bba2e 100644 --- a/integration-tests/groovy-dsl/src/test/java/org/apache/camel/quarkus/dsl/groovy/GroovyDslTest.java +++ b/integration-tests/groovy-dsl/src/test/java/org/apache/camel/quarkus/dsl/groovy/GroovyDslTest.java @@ -16,151 +16,64 @@ */ package org.apache.camel.quarkus.dsl.groovy; -import java.util.concurrent.TimeUnit; - +import io.quarkus.test.junit.QuarkusTest; +import io.restassured.RestAssured; import org.apache.camel.dsl.groovy.GroovyRoutesBuilderLoader; -import org.apache.camel.quarkus.test.support.process.QuarkusProcessExecutor; -import org.apache.http.HttpResponse; -import org.apache.http.HttpStatus; -import org.apache.http.client.methods.HttpGet; -import org.apache.http.client.methods.HttpPost; -import org.apache.http.client.methods.HttpUriRequest; -import org.apache.http.entity.ContentType; -import org.apache.http.entity.StringEntity; -import org.apache.http.impl.client.CloseableHttpClient; -import org.apache.http.impl.client.HttpClientBuilder; -import org.apache.http.util.EntityUtils; -import org.awaitility.Awaitility; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.BeforeAll; +import org.hamcrest.CoreMatchers; import org.junit.jupiter.api.Test; -import org.zeroturnaround.exec.StartedProcess; - -import static org.assertj.core.api.Assertions.assertThat; +@QuarkusTest class GroovyDslTest { - private static int port; - private static StartedProcess process; - - @BeforeAll - static void start() throws Exception { - // Need to use an external process to test the extension because of a CL issue that happens only on test mode - // due to the fact that groovy is defined as a parent first artifact - QuarkusProcessExecutor quarkusProcessExecutor = new QuarkusProcessExecutor(); - process = quarkusProcessExecutor.start(); - port = quarkusProcessExecutor.getHttpPort(); - awaitStartup(); - } - - @AfterAll - static void stop() { - if (process != null && process.getProcess().isAlive()) { - process.getProcess().destroy(); - } - } - - private static String toAbsolutePath(String relativePath) { - return String.format("http://localhost:%d/%s", port, relativePath); - } - - private static void awaitStartup() { - Awaitility.await().atMost(10, TimeUnit.SECONDS).pollDelay(1, TimeUnit.SECONDS).until(() -> { - HttpUriRequest request = new HttpGet(toAbsolutePath("/groovy-dsl")); - try (CloseableHttpClient client = HttpClientBuilder.create().build()) { - HttpResponse httpResponse = client.execute(request); - return httpResponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK; - } catch (Exception e) { - return false; - } - }); - } - @Test - void groovyHello() throws Exception { - try (CloseableHttpClient client = HttpClientBuilder.create().build()) { - // Given - HttpPost httpPost = new HttpPost(toAbsolutePath("/groovy-dsl/hello")); - httpPost.setEntity(new StringEntity("John Smith", ContentType.TEXT_PLAIN)); - - // When - HttpResponse httpResponse = client.execute(httpPost); - - // Then - assertThat(httpResponse.getStatusLine().getStatusCode()).isEqualTo(HttpStatus.SC_OK); - assertThat(EntityUtils.toString(httpResponse.getEntity())).isEqualTo("Hello John Smith from Groovy!"); - } + void groovyHello() { + RestAssured.given() + .body("John Smith") + .post("/groovy-dsl/hello") + .then() + .statusCode(200) + .body(CoreMatchers.is("Hello John Smith from Groovy!")); } @Test - void testMainInstanceWithJavaRoutes() throws Exception { - try (CloseableHttpClient client = HttpClientBuilder.create().build()) { - // Given - HttpUriRequest request = new HttpGet(toAbsolutePath("/groovy-dsl/main/groovyRoutesBuilderLoader")); - - // When - HttpResponse httpResponse = client.execute(request); - - // Then - assertThat(httpResponse.getStatusLine().getStatusCode()).isEqualTo(HttpStatus.SC_OK); - assertThat(EntityUtils.toString(httpResponse.getEntity())).isEqualTo(GroovyRoutesBuilderLoader.class.getName()); - - // Given - request = new HttpGet(toAbsolutePath("/groovy-dsl/main/routeBuilders")); - - // When - httpResponse = client.execute(request); - - // Then - assertThat(httpResponse.getStatusLine().getStatusCode()).isEqualTo(HttpStatus.SC_OK); - assertThat(EntityUtils.toString(httpResponse.getEntity())).isEmpty(); - - // Given - request = new HttpGet(toAbsolutePath("/groovy-dsl/main/routes")); - - // When - httpResponse = client.execute(request); - - // Then - assertThat(httpResponse.getStatusLine().getStatusCode()).isEqualTo(HttpStatus.SC_OK); - assertThat(EntityUtils.toString(httpResponse.getEntity())).isEqualTo( - "my-groovy-route,routes-with-components-configuration,routes-with-dataformats-configuration,routes-with-eip-body,routes-with-eip-exchange,routes-with-eip-message,routes-with-eip-process,routes-with-eip-setBody,routes-with-endpoint-dsl,routes-with-error-handler,routes-with-languages-configuration,routes-with-rest,routes-with-rest-dsl-get,routes-with-rest-dsl-post,routes-with-rest-get,routes-with-rest-post"); - - // Given - request = new HttpGet(toAbsolutePath("/groovy-dsl/main/successful/routes")); - - // When - httpResponse = client.execute(request); - - // Then - assertThat(httpResponse.getStatusLine().getStatusCode()).isEqualTo(HttpStatus.SC_OK); - assertThat(EntityUtils.toString(httpResponse.getEntity())).isEqualTo("10"); - } + void testMainInstanceWithJavaRoutes() { + RestAssured.given() + .get("/groovy-dsl/main/groovyRoutesBuilderLoader") + .then() + .statusCode(200) + .body(CoreMatchers.is(GroovyRoutesBuilderLoader.class.getName())); + + RestAssured.given() + .get("/groovy-dsl/main/routeBuilders") + .then() + .statusCode(200) + .body(CoreMatchers.is("")); + + RestAssured.given() + .get("/groovy-dsl/main/routes") + .then() + .statusCode(200) + .body(CoreMatchers.is( + "my-groovy-route,routes-with-components-configuration,routes-with-dataformats-configuration,routes-with-eip-body,routes-with-eip-exchange,routes-with-eip-message,routes-with-eip-process,routes-with-eip-setBody,routes-with-endpoint-dsl,routes-with-error-handler,routes-with-languages-configuration,routes-with-rest,routes-with-rest-dsl-get,routes-with-rest-dsl-post,routes-with-rest-get,routes-with-rest-post")); + RestAssured.given() + .get("/groovy-dsl/main/successful/routes") + .then() + .statusCode(200) + .body(CoreMatchers.is("10")); } @Test - void testRestEndpoints() throws Exception { - try (CloseableHttpClient client = HttpClientBuilder.create().build()) { - // Given - final HttpGet httpGet = new HttpGet(toAbsolutePath("/root/my/path/get")); - - // When - HttpResponse httpResponse = client.execute(httpGet); - - // Then - assertThat(httpResponse.getStatusLine().getStatusCode()).isEqualTo(HttpStatus.SC_OK); - assertThat(EntityUtils.toString(httpResponse.getEntity())).isEqualTo("Hello World"); - - // Given - HttpPost httpPost = new HttpPost(toAbsolutePath("/root/post")); - httpPost.setEntity(new StringEntity("Will", ContentType.TEXT_PLAIN)); - - // When - httpResponse = client.execute(httpPost); - - // Then - assertThat(httpResponse.getStatusLine().getStatusCode()).isEqualTo(HttpStatus.SC_OK); - assertThat(EntityUtils.toString(httpResponse.getEntity())).isEqualTo("Hello Will"); - } + void testRestEndpoints() { + RestAssured.given() + .get("/root/my/path/get") + .then() + .statusCode(200) + .body(CoreMatchers.is("Hello World")); + RestAssured.given() + .body("Will") + .post("/root/post") + .then() + .statusCode(200) + .body(CoreMatchers.is("Hello Will")); } } diff --git a/tooling/test-list/pom.xml b/tooling/test-list/pom.xml index 6fae3b8b4e3e..0ff5740ea4cb 100644 --- a/tooling/test-list/pom.xml +++ b/tooling/test-list/pom.xml @@ -57,7 +57,6 @@ support/**/* support/**/* - groovy-dsl/pom.xml master/pom.xml master-openshift/pom.xml master-file/pom.xml