This is an automated email from the ASF dual-hosted git repository. cdeppisch pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/camel-kamelets.git
The following commit(s) were added to refs/heads/main by this push: new 97219422 chore: Improve AWS DDB E2E tests 97219422 is described below commit 97219422a16428e0b59e55ae5a639ac8d71f98d6 Author: Christoph Deppisch <cdeppi...@redhat.com> AuthorDate: Mon May 13 16:50:26 2024 +0200 chore: Improve AWS DDB E2E tests - Test PutItem, UpdateItem, DeleteItem AWS DDB sink in one feature file - Avoids too many restarts of LocalStack Testcontainers instance - Use getItem operation to verify entries in DDB --- .../aws/ddb/aws-ddb-sink-deleteItem.feature | 61 ----------- .../resources/aws/ddb/aws-ddb-sink-putItem.feature | 60 ----------- .../aws/ddb/aws-ddb-sink-updateItem.feature | 64 ------------ .../test/resources/aws/ddb/aws-ddb-sink.feature | 111 +++++++++++++++++++++ ...urce-getItem.feature => aws-ddb-source.feature} | 2 +- .../src/test/resources/aws/ddb/getItem.groovy | 33 ++++++ .../src/test/resources/aws/ddb/yaks-config.yaml | 1 + 7 files changed, 146 insertions(+), 186 deletions(-) diff --git a/tests/camel-kamelets-itest/src/test/resources/aws/ddb/aws-ddb-sink-deleteItem.feature b/tests/camel-kamelets-itest/src/test/resources/aws/ddb/aws-ddb-sink-deleteItem.feature deleted file mode 100644 index e1a731b7..00000000 --- a/tests/camel-kamelets-itest/src/test/resources/aws/ddb/aws-ddb-sink-deleteItem.feature +++ /dev/null @@ -1,61 +0,0 @@ -# --------------------------------------------------------------------------- -# 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. -# --------------------------------------------------------------------------- - -Feature: AWS DDB Sink - DeleteItem - - Background: - Given variables - | timer.source.period | 10000 | - | aws.ddb.streams | false | - | aws.ddb.operation | DeleteItem | - | aws.ddb.tableName | movies | - | aws.ddb.item.id | 1 | - | aws.ddb.item.year | 1985 | - | aws.ddb.item.title | Back to the future | - | aws.ddb.json.data | {"id": ${aws.ddb.item.id}} | - - Scenario: Create infrastructure - # Start LocalStack container - Given Enable service DYNAMODB - Given start LocalStack container - - Scenario: Verify AWS-DDB Kamelet sink binding - # Create AWS-DDB client - Given load to Camel registry amazonDDBClient.groovy - Given run script putItem.groovy - Given variables - | maxRetryAttempts | 20 | - | aws.ddb.items | [[year:AttributeValue(N=${aws.ddb.item.year}), id:AttributeValue(N=${aws.ddb.item.id}), title:AttributeValue(S=${aws.ddb.item.title})]] | - # Create item on AWS-DDB - Then apply actions verifyItems.groovy - - # Create binding - When load Pipe aws-ddb-sink-pipe.yaml - And Pipe aws-ddb-sink-pipe is available - And Camel K integration aws-ddb-sink-pipe is running - And Camel K integration aws-ddb-sink-pipe should print Started aws-ddb-sink-pipe - # Verify Kamelet sink - Given variables - | maxRetryAttempts | 20 | - | aws.ddb.items | [] | - Then apply actions verifyItems.groovy - - Scenario: Remove resources - # Remove Camel K resources - Given delete Pipe aws-ddb-sink-pipe - # Stop LocalStack container - Given stop LocalStack container diff --git a/tests/camel-kamelets-itest/src/test/resources/aws/ddb/aws-ddb-sink-putItem.feature b/tests/camel-kamelets-itest/src/test/resources/aws/ddb/aws-ddb-sink-putItem.feature deleted file mode 100644 index a3261236..00000000 --- a/tests/camel-kamelets-itest/src/test/resources/aws/ddb/aws-ddb-sink-putItem.feature +++ /dev/null @@ -1,60 +0,0 @@ -# --------------------------------------------------------------------------- -# 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. -# --------------------------------------------------------------------------- - -Feature: AWS DDB Sink - PutItem - - Background: - Given variables - | timer.source.period | 10000 | - | aws.ddb.streams | false | - | aws.ddb.operation | PutItem | - | aws.ddb.tableName | movies | - | aws.ddb.item.id | 1 | - | aws.ddb.item.year | 1977 | - | aws.ddb.item.title | Star Wars IV | - | aws.ddb.json.data | { "id":${aws.ddb.item.id}, "year":${aws.ddb.item.year}, "title":"${aws.ddb.item.title}" } | - - Scenario: Create infrastructure - # Start LocalStack container - Given Enable service DYNAMODB - Given start LocalStack container - - Scenario: Verify AWS-DDB Kamelet sink binding - Given variables - | maxRetryAttempts | 20 | - | aws.ddb.items | [] | - # Create AWS-DDB client - Given load to Camel registry amazonDDBClient.groovy - # Verify empty items on AWS-DDB - Then apply actions verifyItems.groovy - - # Create binding - When load Pipe aws-ddb-sink-pipe.yaml - And Pipe aws-ddb-sink-pipe is available - And Camel K integration aws-ddb-sink-pipe is running - And Camel K integration aws-ddb-sink-pipe should print Started aws-ddb-sink-pipe - # Verify Kamelet sink - Given variables - | maxRetryAttempts | 20 | - | aws.ddb.items | [[year:AttributeValue(N=${aws.ddb.item.year}), id:AttributeValue(N=${aws.ddb.item.id}), title:AttributeValue(S=${aws.ddb.item.title})]] | - Then apply actions verifyItems.groovy - - Scenario: Remove resources - # Remove Camel K binding - Given delete Pipe aws-ddb-sink-pipe - # Stop LocalStack container - Given stop LocalStack container diff --git a/tests/camel-kamelets-itest/src/test/resources/aws/ddb/aws-ddb-sink-updateItem.feature b/tests/camel-kamelets-itest/src/test/resources/aws/ddb/aws-ddb-sink-updateItem.feature deleted file mode 100644 index 02b07d93..00000000 --- a/tests/camel-kamelets-itest/src/test/resources/aws/ddb/aws-ddb-sink-updateItem.feature +++ /dev/null @@ -1,64 +0,0 @@ -# --------------------------------------------------------------------------- -# 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. -# --------------------------------------------------------------------------- - -Feature: AWS DDB Sink - UpdateItem - - Background: - Given variables - | timer.source.period | 10000 | - | aws.ddb.streams | false | - | aws.ddb.operation | UpdateItem | - | aws.ddb.tableName | movies | - | aws.ddb.item.id | 1 | - | aws.ddb.item.year | 1933 | - | aws.ddb.item.title | King Kong | - | aws.ddb.item.title.new | King Kong - Historical | - | aws.ddb.item.directors | ["Merian C. Cooper", "Ernest B. Schoedsack"] | - | aws.ddb.json.data | { "key": {"id": ${aws.ddb.item.id}}, "item": {"title": "${aws.ddb.item.title.new}", "year": ${aws.ddb.item.year}, "directors": ${aws.ddb.item.directors}} } | - - Scenario: Create infrastructure - # Start LocalStack container - Given Enable service DYNAMODB - Given start LocalStack container - - Scenario: Verify AWS-DDB Kamelet sink binding - # Create AWS-DDB client - Given load to Camel registry amazonDDBClient.groovy - # Create item on AWS-DDB - Given run script putItem.groovy - Given variables - | maxRetryAttempts | 20 | - | aws.ddb.items | [[year:AttributeValue(N=${aws.ddb.item.year}), id:AttributeValue(N=${aws.ddb.item.id}), title:AttributeValue(S=${aws.ddb.item.title})]] | - Then apply actions verifyItems.groovy - - # Create binding - When load Pipe aws-ddb-sink-pipe.yaml - And Pipe aws-ddb-sink-pipe is available - And Camel K integration aws-ddb-sink-pipe is running - And Camel K integration aws-ddb-sink-pipe should print Started aws-ddb-sink-pipe - # Verify Kamelet sink - Given variables - | maxRetryAttempts | 200 | - | aws.ddb.item.directors | [Ernest B. Schoedsack, Merian C. Cooper] | - | aws.ddb.items | [[year:AttributeValue(N=${aws.ddb.item.year}), directors:AttributeValue(SS=${aws.ddb.item.directors}), id:AttributeValue(N=${aws.ddb.item.id}), title:AttributeValue(S=${aws.ddb.item.title.new})]] | - Then apply actions verifyItems.groovy - - Scenario: Remove resources - # Remove Camel K resources - Given delete Pipe aws-ddb-sink-pipe - # Stop LocalStack container - Given stop LocalStack container diff --git a/tests/camel-kamelets-itest/src/test/resources/aws/ddb/aws-ddb-sink.feature b/tests/camel-kamelets-itest/src/test/resources/aws/ddb/aws-ddb-sink.feature new file mode 100644 index 00000000..acf300dc --- /dev/null +++ b/tests/camel-kamelets-itest/src/test/resources/aws/ddb/aws-ddb-sink.feature @@ -0,0 +1,111 @@ +# --------------------------------------------------------------------------- +# 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. +# --------------------------------------------------------------------------- + +Feature: AWS DDB Sink + + Background: + Given variables + | maxRetryAttempts | 20 | + | timer.source.period | 10000 | + | aws.ddb.streams | false | + | aws.ddb.tableName | movies | + + Scenario: Create infrastructure + # Start LocalStack container + Given Enable service DYNAMODB + Given start LocalStack container + + Scenario: Create AWS DDB client + # Create AWS-DDB client + Given load to Camel registry amazonDDBClient.groovy + # Verify empty AWS-DDB + Given variables + | aws.ddb.items | [] | + Then apply actions verifyItems.groovy + + Scenario: DeleteItem + Given variables + | aws.ddb.operation | DeleteItem | + | aws.ddb.item.id | yaks:randomNumber(4) | + | aws.ddb.item.year | 1985 | + | aws.ddb.item.title | Back to the future | + | aws.ddb.json.data | {"id": ${aws.ddb.item.id}} | + Given run script putItem.groovy + Given variables + | aws.ddb.items | [[year:AttributeValue(N=${aws.ddb.item.year}), id:AttributeValue(N=${aws.ddb.item.id}), title:AttributeValue(S=${aws.ddb.item.title})]] | + # Create item on AWS-DDB + Then apply actions verifyItems.groovy + # Create binding + When load Pipe aws-ddb-sink-pipe.yaml + And Pipe aws-ddb-sink-pipe is available + And Camel K integration aws-ddb-sink-pipe is running + And Camel K integration aws-ddb-sink-pipe should print Started aws-ddb-sink-pipe + # Verify Kamelet sink + Given variables + | aws.ddb.items | [] | + Then apply actions verifyItems.groovy + # Remove Camel K resources + Given delete Pipe aws-ddb-sink-pipe + + Scenario: PutItem + Given variables + | aws.ddb.operation | PutItem | + | aws.ddb.item.id | yaks:randomNumber(4) | + | aws.ddb.item.year | 1977 | + | aws.ddb.item.title | Star Wars IV | + | aws.ddb.json.data | { "id":${aws.ddb.item.id}, "year":${aws.ddb.item.year}, "title":"${aws.ddb.item.title}" } | + When load Pipe aws-ddb-sink-pipe.yaml + And Pipe aws-ddb-sink-pipe is available + And Camel K integration aws-ddb-sink-pipe is running + And Camel K integration aws-ddb-sink-pipe should print Started aws-ddb-sink-pipe + # Verify Kamelet sink + Given variables + | aws.ddb.item | [year:AttributeValue(N=${aws.ddb.item.year}), id:AttributeValue(N=${aws.ddb.item.id}), title:AttributeValue(S=${aws.ddb.item.title})] | + Then apply actions getItem.groovy + # Remove Camel K binding + Given delete Pipe aws-ddb-sink-pipe + + Scenario: UpdateItem + Given variables + | aws.ddb.operation | UpdateItem | + | aws.ddb.item.id | yaks:randomNumber(4) | + | aws.ddb.item.year | 1933 | + | aws.ddb.item.title | King Kong | + | aws.ddb.item.title.new | King Kong - Historical | + | aws.ddb.item.directors | ["Merian C. Cooper", "Ernest B. Schoedsack"] | + | aws.ddb.json.data | { "key": {"id": ${aws.ddb.item.id}}, "item": {"title": "${aws.ddb.item.title.new}", "year": ${aws.ddb.item.year}, "directors": ${aws.ddb.item.directors}} } | + Given run script putItem.groovy + Given variables + | aws.ddb.item | [year:AttributeValue(N=${aws.ddb.item.year}), id:AttributeValue(N=${aws.ddb.item.id}), title:AttributeValue(S=${aws.ddb.item.title})] | + Then apply actions getItem.groovy + # Create binding + When load Pipe aws-ddb-sink-pipe.yaml + And Pipe aws-ddb-sink-pipe is available + And Camel K integration aws-ddb-sink-pipe is running + And Camel K integration aws-ddb-sink-pipe should print Started aws-ddb-sink-pipe + # Verify Kamelet sink + Given variables + | maxRetryAttempts | 200 | + | aws.ddb.item.directors | [Ernest B. Schoedsack, Merian C. Cooper] | + | aws.ddb.item | [year:AttributeValue(N=${aws.ddb.item.year}), directors:AttributeValue(SS=${aws.ddb.item.directors}), id:AttributeValue(N=${aws.ddb.item.id}), title:AttributeValue(S=${aws.ddb.item.title.new})] | + Then apply actions getItem.groovy + # Remove Camel K resources + Given delete Pipe aws-ddb-sink-pipe + + Scenario: Remove resources + # Stop LocalStack container + Given stop LocalStack container diff --git a/tests/camel-kamelets-itest/src/test/resources/aws/ddb/aws-ddb-source-getItem.feature b/tests/camel-kamelets-itest/src/test/resources/aws/ddb/aws-ddb-source.feature similarity index 98% rename from tests/camel-kamelets-itest/src/test/resources/aws/ddb/aws-ddb-source-getItem.feature rename to tests/camel-kamelets-itest/src/test/resources/aws/ddb/aws-ddb-source.feature index 8f8b51c4..8a43b0fa 100644 --- a/tests/camel-kamelets-itest/src/test/resources/aws/ddb/aws-ddb-source-getItem.feature +++ b/tests/camel-kamelets-itest/src/test/resources/aws/ddb/aws-ddb-source.feature @@ -15,7 +15,7 @@ # limitations under the License. # --------------------------------------------------------------------------- -Feature: AWS DDB Source - GetItem +Feature: AWS DDB Source Background: Given variables diff --git a/tests/camel-kamelets-itest/src/test/resources/aws/ddb/getItem.groovy b/tests/camel-kamelets-itest/src/test/resources/aws/ddb/getItem.groovy new file mode 100644 index 00000000..c9c46811 --- /dev/null +++ b/tests/camel-kamelets-itest/src/test/resources/aws/ddb/getItem.groovy @@ -0,0 +1,33 @@ +/* + * 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.ddb + +$(repeatOnError() + .until('i > ${maxRetryAttempts}') + .actions(new org.citrusframework.TestAction() { + @Override + void execute(org.citrusframework.context.TestContext context) { + try { + assert context.getVariable('aws.ddb.item').equals(amazonDDBClient.getItem(b -> b.tableName(context.getVariable('aws.ddb.tableName')) + .key(Collections.singletonMap("id", software.amazon.awssdk.services.dynamodb.model.AttributeValue.builder().n(context.getVariable('aws.ddb.item.id')).build())))?.item()?.toString()) + } catch (AssertionError e) { + throw new org.citrusframework.exceptions.CitrusRuntimeException("AWS DDB item verification failed", e) + } + } + }) +) diff --git a/tests/camel-kamelets-itest/src/test/resources/aws/ddb/yaks-config.yaml b/tests/camel-kamelets-itest/src/test/resources/aws/ddb/yaks-config.yaml index 38c2609b..c3c2a998 100644 --- a/tests/camel-kamelets-itest/src/test/resources/aws/ddb/yaks-config.yaml +++ b/tests/camel-kamelets-itest/src/test/resources/aws/ddb/yaks-config.yaml @@ -35,6 +35,7 @@ config: - name: CITRUS_TYPE_CONVERTER value: camel resources: + - getItem.groovy - putItem.groovy - verifyItems.groovy - amazonDDBClient.groovy