You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2022/04/21 05:14:33 UTC
[camel-spring-boot] branch main updated: CAMEL-17982 Add tests in camel-aws2-kinesis (#534)
This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-spring-boot.git
The following commit(s) were added to refs/heads/main by this push:
new e371746a5e6 CAMEL-17982 Add tests in camel-aws2-kinesis (#534)
e371746a5e6 is described below
commit e371746a5e6631c4a6e831cca650a77175410cd5
Author: JiriOndrusek <on...@gmail.com>
AuthorDate: Thu Apr 21 07:14:28 2022 +0200
CAMEL-17982 Add tests in camel-aws2-kinesis (#534)
---
.../camel-aws2-kinesis-starter/pom.xml | 8 ++
.../camel/component/aws2/kinesis/BaseKinesis.java | 59 +++++++++
.../aws2/kinesis/KinesisComponentTest.java | 134 +++++++++++++++++++++
3 files changed, 201 insertions(+)
diff --git a/components-starter/camel-aws2-kinesis-starter/pom.xml b/components-starter/camel-aws2-kinesis-starter/pom.xml
index 58ab0716066..55e6a63926b 100644
--- a/components-starter/camel-aws2-kinesis-starter/pom.xml
+++ b/components-starter/camel-aws2-kinesis-starter/pom.xml
@@ -47,6 +47,14 @@
</exclusions>
<!--END OF GENERATED CODE-->
</dependency>
+ <!-- test infra -->
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-test-infra-aws-v2</artifactId>
+ <version>${camel-version}</version>
+ <type>test-jar</type>
+ <scope>test</scope>
+ </dependency>
<!--START OF GENERATED CODE-->
<dependency>
<groupId>org.apache.camel.springboot</groupId>
diff --git a/components-starter/camel-aws2-kinesis-starter/src/test/java/org/apache/camel/component/aws2/kinesis/BaseKinesis.java b/components-starter/camel-aws2-kinesis-starter/src/test/java/org/apache/camel/component/aws2/kinesis/BaseKinesis.java
new file mode 100644
index 00000000000..8e9a8a375e7
--- /dev/null
+++ b/components-starter/camel-aws2-kinesis-starter/src/test/java/org/apache/camel/component/aws2/kinesis/BaseKinesis.java
@@ -0,0 +1,59 @@
+/*
+ * 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 org.apache.camel.component.aws2.kinesis;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.test.infra.aws2.clients.AWSSDKClientUtils;
+import org.junit.jupiter.api.extension.RegisterExtension;
+import org.apache.camel.test.infra.aws.common.services.AWSService;
+import org.apache.camel.test.infra.aws2.services.AWSServiceFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import software.amazon.awssdk.services.cloudwatch.CloudWatchClient;
+import software.amazon.awssdk.services.kinesis.KinesisClient;
+
+public class BaseKinesis {
+
+ @Autowired
+ protected CamelContext context;
+
+ @Autowired
+ protected ProducerTemplate template;
+
+ @RegisterExtension
+ public static AWSService service = AWSServiceFactory.createKinesisService();
+
+ protected void assertMockEndpointsSatisfied() throws InterruptedException {
+ MockEndpoint.assertIsSatisfied(this.context);
+ }
+
+ // *************************************
+ // Config
+ // *************************************
+
+ @Configuration
+ public static class TestConfiguration {
+
+ @Bean
+ public KinesisClient kinesisClient() {
+ return AWSSDKClientUtils.newKinesisClient();
+ }
+ }
+}
diff --git a/components-starter/camel-aws2-kinesis-starter/src/test/java/org/apache/camel/component/aws2/kinesis/KinesisComponentTest.java b/components-starter/camel-aws2-kinesis-starter/src/test/java/org/apache/camel/component/aws2/kinesis/KinesisComponentTest.java
new file mode 100644
index 00000000000..c606bb08bc1
--- /dev/null
+++ b/components-starter/camel-aws2-kinesis-starter/src/test/java/org/apache/camel/component/aws2/kinesis/KinesisComponentTest.java
@@ -0,0 +1,134 @@
+/*
+ * 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 org.apache.camel.component.aws2.kinesis;
+
+import org.apache.camel.EndpointInject;
+import org.apache.camel.Exchange;
+import org.apache.camel.ExchangePattern;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.spring.boot.CamelAutoConfiguration;
+import org.apache.camel.test.infra.aws2.clients.AWSSDKClientUtils;
+import org.apache.camel.test.spring.junit5.CamelSpringBootTest;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.test.annotation.DirtiesContext;
+import software.amazon.awssdk.services.cloudwatch.CloudWatchClient;
+import software.amazon.awssdk.services.cloudwatch.model.ListMetricsRequest;
+import software.amazon.awssdk.services.cloudwatch.model.ListMetricsResponse;
+import software.amazon.awssdk.services.kinesis.KinesisClient;
+import software.amazon.awssdk.services.kinesis.model.CreateStreamRequest;
+import software.amazon.awssdk.services.kinesis.model.Record;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
+//Based on CwComponentIT
+@DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_CLASS)
+@CamelSpringBootTest
+@SpringBootTest(
+ classes = {
+ CamelAutoConfiguration.class,
+ KinesisComponentTest.class,
+ KinesisComponentTest.TestConfiguration.class
+ }
+)
+public class KinesisComponentTest extends BaseKinesis {
+
+ @EndpointInject("mock:result")
+ private MockEndpoint result;
+
+ private static KinesisClient client;
+
+ @BeforeAll
+ static void setUp() {
+ client = AWSSDKClientUtils.newKinesisClient();
+ client.createStream(
+ CreateStreamRequest.builder()
+ .shardCount(1)
+ .streamName("kinesis1")
+ .build());
+ }
+
+ @AfterAll
+ static void clean() {
+ if(client != null) {
+ client.close();
+ }
+ }
+
+
+ @Test
+ public void send() throws Exception {
+ result.expectedMessageCount(2);
+
+ template.send("direct:start", ExchangePattern.InOnly, new Processor() {
+ public void process(Exchange exchange) {
+ exchange.getIn().setHeader(Kinesis2Constants.PARTITION_KEY, "partition-1");
+ exchange.getIn().setBody("Kinesis Event 1.");
+ }
+ });
+
+ template.send("direct:start", ExchangePattern.InOut, new Processor() {
+ public void process(Exchange exchange) {
+ exchange.getIn().setHeader(Kinesis2Constants.PARTITION_KEY, "partition-1");
+ exchange.getIn().setBody("Kinesis Event 2.");
+ }
+ });
+
+ assertMockEndpointsSatisfied();
+
+ assertResultExchange(result.getExchanges().get(0), "Kinesis Event 1.", "partition-1");
+ assertResultExchange(result.getExchanges().get(1), "Kinesis Event 2.", "partition-1");
+ }
+
+ private void assertResultExchange(Exchange resultExchange, String data, String partition) {
+ assertEquals(data,resultExchange.getIn().getBody(String.class));
+ assertEquals(partition, resultExchange.getIn().getHeader(Kinesis2Constants.PARTITION_KEY));
+ assertNotNull(resultExchange.getIn().getHeader(Kinesis2Constants.APPROX_ARRIVAL_TIME));
+ assertNotNull(resultExchange.getIn().getHeader(Kinesis2Constants.SEQUENCE_NUMBER));
+ }
+
+ // *************************************
+ // Config
+ // *************************************
+
+ @Configuration
+ public class TestConfiguration extends BaseKinesis.TestConfiguration {
+ @Bean
+ public RouteBuilder routeBuilder() {
+ return new RouteBuilder() {
+ @Override
+ public void configure() {
+ String kinesisEndpointUri = "aws2-kinesis://kinesis1";
+
+ from("direct:start").to(kinesisEndpointUri);
+ from(kinesisEndpointUri).to("mock:result");
+ }
+ };
+ }
+ }
+}