Skip to content

Commit

Permalink
chore(e2e): Add AWS SQS Kamelet tests (#2026)
Browse files Browse the repository at this point in the history
  • Loading branch information
christophd committed May 10, 2024
1 parent 5b96031 commit 1d0f4f1
Show file tree
Hide file tree
Showing 19 changed files with 517 additions and 8 deletions.
6 changes: 6 additions & 0 deletions tests/camel-kamelets-itest/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,12 @@
<version>${camel.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-aws2-sqs</artifactId>
<version>${camel.version}</version>
<scope>test</scope>
</dependency>

<!-- Citrus -->
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,11 @@ Feature: AWS Kinesis - Sink
And Camel K integration aws-kinesis-source-pipe is running
And Camel K integration aws-kinesis-source-pipe should print Started aws-kinesis-source-pipe
# Publish event
Given variable aws.kinesis.streamData is "Camel rocks!"
Given Camel exchange message header CamelAwsKinesisPartitionKey="${aws.kinesis.partitionKey}"
Given send Camel exchange to("aws2-kinesis://${aws.kinesis.streamName}?amazonKinesisClient=#amazonKinesisClient") with body: Camel rocks!
Given send Camel exchange to("aws2-kinesis://${aws.kinesis.streamName}?amazonKinesisClient=#amazonKinesisClient") with body: ${aws.kinesis.streamData}
# Verify event
And Camel K integration aws-kinesis-source-pipe should print Camel rocks!
Then Camel K integration aws-kinesis-source-pipe should print ${aws.kinesis.streamData}

Scenario: Remove resources
# Remove Camel K binding
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
package aws.s3
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
Expand All @@ -16,6 +15,8 @@ package aws.s3
* limitations under the License.
*/

package aws.s3

import software.amazon.awssdk.auth.credentials.AwsBasicCredentials
import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider
import software.amazon.awssdk.regions.Region
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ Feature: AWS S3 Source - secret based config
# Create Kubernetes secret
Given create Kubernetes secret aws-s3-source-credentials
| aws-s3-credentials.properties | citrus:encodeBase64(citrus:readFile(aws-s3-credentials.properties)) |
Given create labels on Kubernetes secret aws-s3-source-credentials
| camel.apache.org/kamelet | aws-s3-source |
| camel.apache.org/kamelet.configuration | aws-s3-credentials |

Scenario: Verify AWS-S3 Kamelet to log binding
# Create AWS-S3 client
Given New Camel context
Given load to Camel registry amazonS3Client.groovy
# Create binding
Given create labels on Kubernetes secret aws-s3-source-credentials
| camel.apache.org/kamelet | aws-s3-source |
| camel.apache.org/kamelet.configuration | aws-s3-credentials |
Given load Camel K integration aws-s3-to-log-secret-based.groovy
Then Camel K integration aws-s3-to-log-secret-based should be running
# Verify Kamelet source
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ spec:
- ref:
kind: Kamelet
apiVersion: camel.apache.org/v1
name: log-sink
name: log-action
properties:
showHeaders: true
sink:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ config:
- knative-channel-to-log.yaml
cucumber:
tags:
- "not @ignored and not @knative"
- "not @ignored"
- "not @knative"
settings:
loggers:
- name: INTEGRATION_STATUS
Expand Down
76 changes: 76 additions & 0 deletions tests/camel-kamelets-itest/src/test/resources/aws/sqs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# AWS SQS Kamelet test

This test verifies the AWS SQS Kamelet source defined in [aws-sqs-source.kamelet.yaml](aws-sqs-source.kamelet.yaml)

## Objectives

The test verifies the AWS SQS Kamelet source by creating a Camel K integration that uses the Kamelet and listens for messages on the
AWS SQS channel.

The test uses a [LocalStack Testcontainers](https://www.testcontainers.org/modules/localstack/) instance to start a local AWS SQS service for mocking reasons.
The Kamelet and the test interact with the local AWS SQS service for validation of functionality.

### Test Kamelet source

The test performs the following high level steps for configs - URI, secret and property based:

*Preparation*
- Start the AWS SQS service as LocalStack container
- Overwrite the Kamelet with the latest source
- Prepare the Camel AWS SQS client

*Scenario*
- Create the Kamelet in the current namespace in the cluster
- Create the Camel K integration that uses the Kamelet source to consume data from AWS SQS service
- Wait for the Camel K integration to start and listen for AWS SQS messages
- Create a new message in the AWS SQS queue
- Verify that the integration has received the message event

*Cleanup*
- Stop the LocalStack container
- Delete the Camel K integration
- Delete the secret from the current namespacce

## Installation

The test assumes that you have access to a Kubernetes cluster and that the Camel K operator as well as the YAKS operator is installed
and running.

You can review the installation steps for the operators in the documentation:

- [Install Camel K operator](https://camel.apache.org/camel-k/latest/installation/installation.html)
- [Install YAKS operator](https://github.com/citrusframework/yaks#installation)

## Run the tests

To run tests with URI based configuration:

```shell script
$ yaks test aws-sqs-source-uri-conf.feature
```

To run tests with secret based configuration:

```shell script
$ yaks test aws-sqs-source-secret-conf.feature
```

To run tests with property based configuration:

```shell script
$ yaks test aws-sqs-source-property-conf.feature
```

To run tests with URI binding:

```shell script
$ yaks test aws-sqs-uri-pipe.feature
```

To run tests with binding to Knative channel:

```shell script
$ yaks test aws-sqs-knative-channel.feature
```

You will be provided with the test log output and the test results.
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package aws.sqs

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

SqsClient sqsClient = SqsClient
.builder()
.endpointOverride(URI.create("${YAKS_TESTCONTAINERS_LOCALSTACK_SQS_LOCAL_URL}"))
.credentialsProvider(StaticCredentialsProvider.create(
AwsBasicCredentials.create(
"${YAKS_TESTCONTAINERS_LOCALSTACK_ACCESS_KEY}",
"${YAKS_TESTCONTAINERS_LOCALSTACK_SECRET_KEY}")
))
.region(Region.of("${YAKS_TESTCONTAINERS_LOCALSTACK_REGION}"))
.build()

sqsClient.createQueue(s -> s.queueName("${aws.sqs.queueName}"))

return sqsClient
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Please add your AWS SQS account credentials
camel.kamelet.aws-sqs-source.aws-sqs-credentials.queueNameOrArn=${aws.sqs.queueName}
camel.kamelet.aws-sqs-source.aws-sqs-credentials.overrideEndpoint=true
camel.kamelet.aws-sqs-source.aws-sqs-credentials.uriEndpointOverride=${YAKS_TESTCONTAINERS_LOCALSTACK_SQS_URL}
camel.kamelet.aws-sqs-source.aws-sqs-credentials.secretKey=${YAKS_TESTCONTAINERS_LOCALSTACK_SECRET_KEY}
camel.kamelet.aws-sqs-source.aws-sqs-credentials.accessKey=${YAKS_TESTCONTAINERS_LOCALSTACK_ACCESS_KEY}
camel.kamelet.aws-sqs-source.aws-sqs-credentials.region=${YAKS_TESTCONTAINERS_LOCALSTACK_REGION}
camel.kamelet.aws-sqs-source.aws-sqs-credentials.deleteAfterRead=true
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
@knative
Feature: AWS SQS Kamelet - binding to InMemoryChannel

Background:
Given variables
| aws.sqs.queueName | myqueue |

Scenario: Create infrastructure
# Start LocalStack container
Given Enable service SQS
Given start LocalStack container
# Create Knative broker and channel
Given create Knative broker default
And Knative broker default is running
And create Knative channel messages

Scenario: Verify AWS-SQS Kamelet to InMemoryChannel binding
# Create AWS-SQS client
Given load to Camel registry amazonSQSClient.groovy
# Create binding
Given load Pipe aws-sqs-to-knative-channel.yaml
Given load Pipe knative-channel-to-log.yaml
Then Pipe aws-sqs-to-knative-channel is available
And Pipe knative-channel-to-log should be available
And Camel K integration aws-sqs-to-knative-channel is running
And Camel K integration knative-channel-to-log is running
And Camel K integration aws-sqs-to-knative-channel should print Started aws-sqs-to-knative-channel
And Camel K integration knative-channel-to-log should print Installed features
# Verify Kamelet source
Given variable aws.sqs.message is "Hello from SQS Kamelet"
And send Camel exchange to("aws2-sqs:${aws.sqs.queueName}?amazonSQSClient=#amazonSQSClient") with body: ${aws.sqs.message}
Then Camel K integration knative-channel-to-log should print ${aws.sqs.message}

Scenario: Remove resources
# Remove Camel K resources
Given delete Pipe aws-sqs-to-knative-channel
Given delete Pipe knative-channel-to-log
# Remove Knative resources
Given delete Knative broker default
Given delete Knative channel messages
# Stop LocalStack container
Given stop LocalStack container
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
Feature: AWS SQS Kamelet - property based config

Background:
Given variables
| aws.sqs.queueName | myqueue |

Scenario: Create infrastructure
# Start LocalStack container
Given Enable service SQS
Given start LocalStack container

Scenario: Verify AWS-SQS events
# Create AWS-SQS client
Given load to Camel registry amazonSQSClient.groovy
# Create binding
Given Camel K integration property file aws-sqs-credentials.properties
Given create Camel K integration aws-sqs-to-log-prop-based.groovy
"""
from("kamelet:aws-sqs-source/aws-sqs-credentials")
.to("log:info")
"""
Then Camel K integration aws-sqs-to-log-prop-based should be running
# Verify Kamelet source
Given variable aws.sqs.message is "Hello from SQS Kamelet"
And send Camel exchange to("aws2-sqs:${aws.sqs.queueName}?amazonSQSClient=#amazonSQSClient") with body: ${aws.sqs.message}
Then Camel K integration aws-sqs-to-log-prop-based should print ${aws.sqs.message}

Scenario: Remove resources
# Remove Camel K resources
Given delete Camel K integration aws-sqs-to-log-prop-based
# Stop LocalStack container
Given stop LocalStack container
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
@ignored
Feature: AWS SQS Kamelet - secret based config

Background:
Given variables
| aws.sqs.queueName | myqueue |

Scenario: Create infrastructure
# Start LocalStack container
Given Enable service SQS
Given start LocalStack container
# Create Kubernetes secret
Given create Kubernetes secret aws-sqs-source-credentials
| aws-sqs-credentials.properties | citrus:encodeBase64(citrus:readFile(aws-sqs-credentials.properties)) |
Given create labels on Kubernetes secret aws-sqs-source-credentials
| camel.apache.org/kamelet | aws-sqs-source |
| camel.apache.org/kamelet.configuration | aws-sqs-credentials |

Scenario: Verify AWS-SQS events
# Create AWS-SQS client
Given load to Camel registry amazonSQSClient.groovy
# Create binding
Given load Camel K integration aws-sqs-to-log-secret-based.groovy
Then Camel K integration aws-sqs-to-log-secret-based should be running
# Verify Kamelet source
Given variable aws.sqs.message is "Hello from SQS Kamelet"
And send Camel exchange to("aws2-sqs:${aws.sqs.queueName}?amazonSQSClient=#amazonSQSClient") with body: ${aws.sqs.message}
Then Camel K integration aws-sqs-to-log-secret-based should print ${aws.sqs.message}

Scenario: Remove resources
# Remove Camel K resources
Given delete Camel K integration aws-sqs-to-log-secret-based
# Remove Kubernetes secret
Given delete Kubernetes secret aws-sqs-source-credentials
# Stop LocalStack container
Given stop LocalStack container
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
Feature: AWS SQS Kamelet - URI based config

Background:
Given variables
| aws.sqs.queueName | myqueue |

Scenario: Create infrastructure
# Start LocalStack container
Given Enable service SQS
Given start LocalStack container

Scenario: Verify AWS-SQS events
# Create AWS-SQS client
Given load to Camel registry amazonSQSClient.groovy
# Create binding
Given load Camel K integration aws-sqs-to-log-uri-based.groovy
Then Camel K integration aws-sqs-to-log-uri-based should be running
# Verify Kamelet source
Given variable aws.sqs.message is "Hello from SQS Kamelet"
And send Camel exchange to("aws2-sqs:${aws.sqs.queueName}?amazonSQSClient=#amazonSQSClient") with body: ${aws.sqs.message}
Then Camel K integration aws-sqs-to-log-uri-based should print ${aws.sqs.message}

Scenario: Remove resources
# Remove Camel K resources
Given delete Camel K integration aws-sqs-to-log-uri-based
# Stop LocalStack container
Given stop LocalStack container
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# ---------------------------------------------------------------------------
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ---------------------------------------------------------------------------

apiVersion: camel.apache.org/v1
kind: Pipe
metadata:
name: aws-sqs-to-knative-channel
spec:
source:
ref:
kind: Kamelet
apiVersion: camel.apache.org/v1
name: aws-sqs-source
properties:
queueNameOrArn: ${aws.sqs.queueName}
overrideEndpoint: true
uriEndpointOverride: ${YAKS_TESTCONTAINERS_LOCALSTACK_SQS_URL}
accessKey: ${YAKS_TESTCONTAINERS_LOCALSTACK_ACCESS_KEY}
secretKey: ${YAKS_TESTCONTAINERS_LOCALSTACK_SECRET_KEY}
region: ${YAKS_TESTCONTAINERS_LOCALSTACK_REGION}
steps:
- ref:
kind: Kamelet
apiVersion: camel.apache.org/v1
name: log-action
properties:
showHeaders: true
sink:
ref:
kind: InMemoryChannel
apiVersion: messaging.knative.dev/v1
name: messages
Loading

0 comments on commit 1d0f4f1

Please sign in to comment.