Skip to content

Commit

Permalink
Ref #4894: Make Groovy DSL ITs platform compliant
Browse files Browse the repository at this point in the history
  • Loading branch information
essobedo committed Jun 30, 2023
1 parent 6d0c8df commit 52c7dc7
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 186 deletions.
55 changes: 4 additions & 51 deletions integration-tests/groovy-dsl/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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>
Expand Down Expand Up @@ -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>
Expand All @@ -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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
}
}
1 change: 0 additions & 1 deletion tooling/test-list/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down

0 comments on commit 52c7dc7

Please sign in to comment.