Skip to content

Commit

Permalink
chore: Integration test improvements
Browse files Browse the repository at this point in the history
- Update to Citrus 4.5.1
- Automatically purge Http server endpoint after each test
- Remove obsolete workaround to create dump output folders in before suite
- Use general Docker registry mirror
  • Loading branch information
christophd committed Jan 21, 2025
1 parent 97d8a9a commit a5116e7
Show file tree
Hide file tree
Showing 24 changed files with 36 additions and 131 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/integration-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ jobs:
./mvnw clean install -DskipTests -DskipITs
- name: Run Tests
env:
CITRUS_TESTCONTAINERS_LOCALSTACK_IMAGE_NAME: "mirror.gcr.io/localstack/localstack"
CITRUS_TESTCONTAINERS_REGISTRY_MIRROR: "mirror.gcr.io"
CITRUS_TESTCONTAINERS_REGISTRY_MIRROR_ENABLED: "true"
run: |
echo "Install JBang via SDKMAN"
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@

<camel.version>4.9.0</camel.version>

<citrus.version>4.5.0</citrus.version>
<citrus.version>4.5.1</citrus.version>
<cucumber.version>7.20.1</cucumber.version>

<!-- Versions used inside Kamelets (add them also to the dependencyManagement section and the groovy script below) -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,42 +15,41 @@
* limitations under the License.
*/

import java.nio.file.Path;

import org.citrusframework.annotations.CitrusConfiguration;
import org.citrusframework.camel.jbang.CamelJBangSettings;
import org.citrusframework.container.SequenceBeforeSuite;
import org.citrusframework.exceptions.CitrusRuntimeException;
import org.citrusframework.container.SequenceAfterTest;
import org.citrusframework.http.server.HttpServer;
import org.citrusframework.spi.BindToRegistry;
import org.springframework.http.HttpStatus;

import static org.citrusframework.actions.PurgeEndpointAction.Builder.purgeEndpoints;
import static org.citrusframework.http.endpoint.builder.HttpEndpoints.http;
import static org.citrusframework.jbang.actions.JBangAction.Builder.jbang;

@CitrusConfiguration
public class EndpointAutoConfiguration {

private final HttpServer httpServer = http()
.server()
.port(8081)
.defaultStatus(HttpStatus.CREATED)
.timeout(60000L)
.autoStart(true)
.build();

@BindToRegistry
public HttpServer httpServer() {
return http()
.server()
.port(8081)
.defaultStatus(HttpStatus.CREATED)
.timeout(120000L)
.autoStart(true)
.build();
return httpServer;
}

@BindToRegistry
public SequenceBeforeSuite setup() {
// TODO: Workaround - remove when Citrus 4.5.1 is released
return SequenceBeforeSuite.Builder.beforeSuite()
.actions(context -> {
Path workDir = CamelJBangSettings.getWorkDir();
if (!workDir.toFile().exists() && !workDir.toFile().mkdirs()) {
throw new CitrusRuntimeException("Failed to create JBang working directory: %s".formatted(workDir.toAbsolutePath().toString()));
}
})
public SequenceAfterTest afterTest() {
return SequenceAfterTest.Builder.afterTest()
.actions(
// Workaround to stop all Camel JBang integrations after test - remove when Citrus 4.5.2 is released
jbang().app("camel@apache/camel").command("stop"),
// Auto purge Http server endpoint
purgeEndpoints().endpoint(httpServer)
)
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,11 @@
* limitations under the License.
*/


import org.apache.camel.CamelContext
import software.amazon.awssdk.auth.credentials.AwsBasicCredentials
import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider
import software.amazon.awssdk.regions.Region
import software.amazon.awssdk.services.kinesis.KinesisClient

if (context.getReferenceResolver().isResolvable(CamelContext.class)) {
println "Destroying former KINESIS client instance"
context.getReferenceResolver().resolve(CamelContext.class).getRegistry().unbind("amazonKinesisClient")
}

KinesisClient kinesisClient = KinesisClient
.builder()
.endpointOverride(URI.create('${CITRUS_TESTCONTAINERS_LOCALSTACK_SERVICE_URL}'))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,11 @@
* limitations under the License.
*/



import org.apache.camel.CamelContext
import software.amazon.awssdk.auth.credentials.AwsBasicCredentials
import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider
import software.amazon.awssdk.regions.Region
import software.amazon.awssdk.services.s3.S3Client

if (context.getReferenceResolver().isResolvable(CamelContext.class)) {
println "Destroying former S3 client instance"
context.getReferenceResolver().resolve(CamelContext.class).getRegistry().unbind("amazonS3Client")
}

S3Client s3 = S3Client
.builder()
.endpointOverride(URI.create('${CITRUS_TESTCONTAINERS_LOCALSTACK_SERVICE_URL}'))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,6 @@ actions:
http:
url: "${CITRUS_TESTCONTAINERS_LOCALSTACK_SERVICE_URL}"

# Purge Http service
- purge:
endpoints:
- name: "httpServer"

# Create AWS-S3 client
- camel:
createComponent:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,11 @@
* limitations under the License.
*/


import org.apache.camel.CamelContext
import software.amazon.awssdk.auth.credentials.AwsBasicCredentials
import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider
import software.amazon.awssdk.regions.Region
import software.amazon.awssdk.services.sqs.SqsClient

if (context.getReferenceResolver().isResolvable(CamelContext.class)) {
println "Destroying former SQS client instance"
context.getReferenceResolver().resolve(CamelContext.class).getRegistry().unbind("amazonSQSClient")
}

SqsClient sqsClient = SqsClient
.builder()
.endpointOverride(URI.create('${CITRUS_TESTCONTAINERS_LOCALSTACK_SERVICE_URL}'))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Configure endpoints used in tests (e.g. generic Http server)
citrus.java.config=EndpointAutoConfiguration

citrus.file.encoding=UTF-8
Expand All @@ -7,11 +8,22 @@ citrus.type.converter=camel
citrus.mail.marshaller.type=JSON

citrus.cluster.type=local
citrus.camelk.max.attempts=10
citrus.camel.jbang.max.attempts=10

# Camel JBang version (should align with version used in pom.xml)
citrus.camel.jbang.version=4.9.0
# Kamelets version (should point to the next snapshot release version)
citrus.camel.jbang.kamelets.version=4.10.0-SNAPSHOT

# Tests should use local Kamelets
citrus.camel.jbang.kamelets.local.dir=../../../kamelets

# Enable dump of Camel JBang integration output
citrus.camel.jbang.dump.integration.output=true

# Workaround to stop all Camel JBang integrations after test - remove when Citrus 4.5.2 is released
citrus.camel.jbang.auto.remove.resources=false

# Use general registry mirror for Docker images (e.g. Testcontainers)
citrus.testcontainers.registry.mirror=mirror.gcr.io
citrus.testcontainers.registry.mirror.enabled=true
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,6 @@

name: earthquake-to-http-test
actions:
# Purge Http service
- purge:
endpoints:
- name: "httpServer"

# Create Camel JBang integration
- camel:
jbang:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,6 @@ variables:
- name: "jira.password"
value: "secr3t"
actions:
# Purge Http service
- purge:
endpoints:
- name: "httpServer"

# Create Camel JBang integration
- camel:
jbang:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,6 @@ variables:
- name: "jira.password"
value: "secr3t"
actions:
# Purge Http service
- purge:
endpoints:
- name: "httpServer"

# Create Camel JBang integration
- camel:
jbang:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,6 @@ variables:
- name: "jira.jql"
value: "assignee=citrus"
actions:
# Purge Http service
- purge:
endpoints:
- name: "httpServer"

# Create Camel JBang integration
- camel:
jbang:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,6 @@ actions:
start:
redpanda: {}

# Purge Http service
- purge:
endpoints:
- name: "httpServer"

# Create Camel JBang integration
- camel:
jbang:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,6 @@ actions:
start:
redpanda: {}

# Purge Http service
- purge:
endpoints:
- name: "httpServer"

# Create Camel JBang integration
- camel:
jbang:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,6 @@ actions:
start:
redpanda: {}

# Purge Http service
- purge:
endpoints:
- name: "httpServer"

# Create Camel JBang integration
- camel:
jbang:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,6 @@ variables:
- name: "openApiSpec"
value: "citrus:readFile(openapi/openapi.json)"
actions:
# Purge Http service
- purge:
endpoints:
- name: "httpServer"

# Create Camel JBang integration
- camel:
jbang:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,6 @@ variables:
- name: "openApiSpec"
value: "citrus:readFile(openapi/openapi.json)"
actions:
# Purge Http service
- purge:
endpoints:
- name: "httpServer"

# Create Camel JBang integration
- camel:
jbang:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,6 @@ variables:
- name: "timer.source.period"
value: "10000"
actions:
# Purge Http service
- purge:
endpoints:
- name: "httpServer"

# Create Camel JBang integration
- camel:
jbang:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,6 @@ variables:
- name: "slack.message"
value: "Camel rocks!"
actions:
# Purge Http service
- purge:
endpoints:
- name: "httpServer"

# Create Camel JBang integration
- camel:
jbang:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,6 @@ variables:
- name: "timer.message"
value: "Camel rocks!"
actions:
# Purge Http service
- purge:
endpoints:
- name: "httpServer"

# Create Camel JBang integration
- camel:
jbang:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,6 @@ variables:
- name: "timer.message"
value: "Camel rocks!"
actions:
# Purge Http service
- purge:
endpoints:
- name: "httpServer"

# Create Camel JBang integration
- camel:
jbang:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,6 @@ variables:
- name: "uuid"
value: "citrus:randomUUID()"
actions:
# Purge Http service
- purge:
endpoints:
- name: "httpServer"

# Create Camel JBang integration
- camel:
jbang:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,6 @@ variables:
- name: "field.value"
value: "Camel rocks!"
actions:
# Purge Http service
- purge:
endpoints:
- name: "httpServer"

# Create Camel JBang integration
- camel:
jbang:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,6 @@ variables:
- name: "field.name"
value: "subject"
actions:
# Purge Http service
- purge:
endpoints:
- name: "httpServer"

# Create Camel JBang integration
- camel:
jbang:
Expand Down

0 comments on commit a5116e7

Please sign in to comment.