You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by nf...@apache.org on 2023/06/30 08:27:35 UTC

[camel-quarkus] 04/04: Ref #4894: Make Groovy DSL ITs platform compliant

This is an automated email from the ASF dual-hosted git repository.

nfilotto pushed a commit to branch 4894/make-groovy-dsl-its-platform-compliant
in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git

commit 52c7dc7ab99b1aadd5a80e6f6dbb769fad190e17
Author: Nicolas Filotto <nf...@talend.com>
AuthorDate: Thu Jun 29 16:23:59 2023 +0200

    Ref #4894: Make Groovy DSL ITs platform compliant
---
 integration-tests/groovy-dsl/pom.xml               |  55 +------
 .../camel/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 2e1d62d904..7760421ef1 100644
--- a/integration-tests/groovy-dsl/pom.xml
+++ b/integration-tests/groovy-dsl/pom.xml
@@ -30,9 +30,6 @@
     <name>Camel Quarkus :: Integration Tests :: Groovy DSL</name>
     <description>Integration tests for Camel Groovy DSL extension</description>
 
-    <properties>
-        <quarkus.runner>${project.build.directory}/quarkus-app/quarkus-run.jar</quarkus.runner>
-    </properties>
     <dependencies>
         <dependency>
             <groupId>org.apache.camel.quarkus</groupId>
@@ -70,18 +67,12 @@
             <scope>test</scope>
         </dependency>
         <dependency>
-            <groupId>org.assertj</groupId>
-            <artifactId>assertj-core</artifactId>
-            <scope>test</scope>
-        </dependency>
-        <dependency>
-            <groupId>org.apache.camel.quarkus</groupId>
-            <artifactId>camel-quarkus-integration-tests-process-executor-support</artifactId>
-            <scope>test</scope>
+            <groupId>io.rest-assured</groupId>
+            <artifactId>rest-assured</artifactId>
         </dependency>
         <dependency>
-            <groupId>org.awaitility</groupId>
-            <artifactId>awaitility</artifactId>
+            <groupId>org.assertj</groupId>
+            <artifactId>assertj-core</artifactId>
             <scope>test</scope>
         </dependency>
     </dependencies>
@@ -185,7 +176,6 @@
             </activation>
             <properties>
                 <quarkus.package.type>native</quarkus.package.type>
-                <quarkus.runner>${project.build.directory}/${project.artifactId}-${project.version}-runner</quarkus.runner>
             </properties>
             <build>
                 <plugins>
@@ -200,43 +190,6 @@
                                 </goals>
                             </execution>
                         </executions>
-                        <configuration>
-                            <systemProperties>
-                                <quarkus.runner>${quarkus.runner}</quarkus.runner>
-                            </systemProperties>
-                        </configuration>
-                    </plugin>
-                </plugins>
-            </build>
-        </profile>
-        <profile>
-            <id>full</id>
-            <activation>
-                <property>
-                    <name>!quickly</name>
-                </property>
-            </activation>
-            <build>
-                <plugins>
-                    <plugin>
-                        <!-- Move surefire:test to integration-test phase to be able to run
-                             java -jar target/*runner.jar from a test -->
-                        <groupId>org.apache.maven.plugins</groupId>
-                        <artifactId>maven-surefire-plugin</artifactId>
-                        <executions>
-                            <execution>
-                                <id>default-test</id>
-                                <goals>
-                                    <goal>test</goal>
-                                </goals>
-                                <phase>integration-test</phase>
-                                <configuration>
-                                    <systemProperties>
-                                        <quarkus.runner>${quarkus.runner}</quarkus.runner>
-                                    </systemProperties>
-                                </configuration>
-                            </execution>
-                        </executions>
                     </plugin>
                 </plugins>
             </build>
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 82ce107208..6f41d92bba 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 6fae3b8b4e..0ff5740ea4 100644
--- a/tooling/test-list/pom.xml
+++ b/tooling/test-list/pom.xml
@@ -57,7 +57,6 @@
                             <excludes>
                                 <exclude>support/**/*</exclude>
                                 <exclude>support/**/*</exclude>
-                                <exclude>groovy-dsl/pom.xml</exclude><!-- See https://github.com/apache/camel-quarkus/issues/4894 -->
                                 <exclude>master/pom.xml</exclude>
                                 <exclude>master-openshift/pom.xml</exclude>
                                 <exclude>master-file/pom.xml</exclude>