You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ac...@apache.org on 2020/09/29 07:01:34 UTC
[camel] 02/02: Camel-AWS2-KMS: Added localstack test for createKey
operation
This is an automated email from the ASF dual-hosted git repository.
acosentino pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git
commit d925cdac2e2523084ea3155af525bd6f9223f592
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Tue Sep 29 09:00:45 2020 +0200
Camel-AWS2-KMS: Added localstack test for createKey operation
---
.../aws2/kms/localstack/Aws2KmsBaseTest.java | 76 ++++++++++++++++++++++
.../kms/localstack/KmsCreateKeyLocalstackTest.java | 68 +++++++++++++++++++
2 files changed, 144 insertions(+)
diff --git a/components/camel-aws2-kms/src/test/java/org/apache/camel/component/aws2/kms/localstack/Aws2KmsBaseTest.java b/components/camel-aws2-kms/src/test/java/org/apache/camel/component/aws2/kms/localstack/Aws2KmsBaseTest.java
new file mode 100644
index 0000000..31d4c81
--- /dev/null
+++ b/components/camel-aws2-kms/src/test/java/org/apache/camel/component/aws2/kms/localstack/Aws2KmsBaseTest.java
@@ -0,0 +1,76 @@
+/*
+ * 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.kms.localstack;
+
+import java.net.URI;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.component.aws2.kms.KMS2Component;
+import org.apache.camel.test.testcontainers.junit5.ContainerAwareTestSupport;
+import org.apache.camel.test.testcontainers.junit5.Wait;
+import org.junit.jupiter.api.TestInstance;
+import org.testcontainers.containers.GenericContainer;
+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.kms.KmsClient;
+
+@TestInstance(TestInstance.Lifecycle.PER_CLASS)
+public class Aws2KmsBaseTest extends ContainerAwareTestSupport {
+
+ public static final String CONTAINER_IMAGE = "localstack/localstack:0.11.5";
+ public static final String CONTAINER_NAME = "eventbridge";
+
+ @Override
+ protected GenericContainer<?> createContainer() {
+ return localstackContainer();
+ }
+
+ public static GenericContainer localstackContainer() {
+ return new GenericContainer(CONTAINER_IMAGE)
+ .withNetworkAliases(CONTAINER_NAME)
+ .withEnv("SERVICES", "kms")
+ .withExposedPorts(4566)
+ .waitingFor(Wait.forListeningPort())
+ .waitingFor(Wait.forLogMessageContaining("Ready.", 1));
+ }
+
+ public String getEventbridgeUrl() {
+ return String.format(
+ "%s:%d",
+ getContainerHost(CONTAINER_NAME),
+ getContainerPort(CONTAINER_NAME, 4566));
+ }
+
+ public KmsClient getKmsClient() {
+ KmsClient eventbridgeClient = KmsClient
+ .builder()
+ .endpointOverride(URI.create("http://" + getEventbridgeUrl()))
+ .credentialsProvider(StaticCredentialsProvider.create(AwsBasicCredentials.create("xxx", "yyy")))
+ .region(Region.EU_WEST_1)
+ .build();
+ return eventbridgeClient;
+ }
+
+ @Override
+ protected CamelContext createCamelContext() throws Exception {
+ CamelContext context = super.createCamelContext();
+ KMS2Component kmsComponent = context.getComponent("aws2-kms", KMS2Component.class);
+ kmsComponent.getConfiguration().setKmsClient(getKmsClient());
+ return context;
+ }
+}
diff --git a/components/camel-aws2-kms/src/test/java/org/apache/camel/component/aws2/kms/localstack/KmsCreateKeyLocalstackTest.java b/components/camel-aws2-kms/src/test/java/org/apache/camel/component/aws2/kms/localstack/KmsCreateKeyLocalstackTest.java
new file mode 100644
index 0000000..71da566
--- /dev/null
+++ b/components/camel-aws2-kms/src/test/java/org/apache/camel/component/aws2/kms/localstack/KmsCreateKeyLocalstackTest.java
@@ -0,0 +1,68 @@
+/*
+ * 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.kms.localstack;
+
+import org.apache.camel.EndpointInject;
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.aws2.kms.KMS2Constants;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.junit.jupiter.api.Test;
+import software.amazon.awssdk.services.kms.model.CreateKeyResponse;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+public class KmsCreateKeyLocalstackTest extends Aws2KmsBaseTest {
+
+ @EndpointInject
+ private ProducerTemplate template;
+
+ @EndpointInject("mock:result")
+ private MockEndpoint result;
+
+ @Test
+ public void sendIn() throws Exception {
+ result.expectedMessageCount(1);
+
+ template.send("direct:createKey", new Processor() {
+
+ @Override
+ public void process(Exchange exchange) throws Exception {
+ exchange.getIn().setHeader(KMS2Constants.OPERATION, "createKey");
+ }
+ });
+
+ assertMockEndpointsSatisfied();
+ assertEquals(1, result.getExchanges().size());
+ assertNotNull(result.getExchanges().get(0).getIn().getBody(CreateKeyResponse.class).keyMetadata().keyId());
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ String awsEndpoint
+ = "aws2-kms://default?operation=createKey";
+ from("direct:createKey").to(awsEndpoint).to("mock:result");
+ }
+ };
+ }
+}