This is an automated email from the ASF dual-hosted git repository.

acosentino pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 080b5c9e97f99187545c5e89f888359694f9061a
Author: Andrea Cosentino <anco...@gmail.com>
AuthorDate: Tue Jul 5 11:32:55 2022 +0200

    CAMEL-18256 - Camel-Hashicorp-vault: Support Versioning of secret while 
reading
---
 ...ashicorpProducerCreateMultiVersionSecretIT.java | 94 +++++++++++++++++++++
 ...ashicorpProducerReadMultiVersionedSecretIT.java | 95 ++++++++++++++++++++++
 2 files changed, 189 insertions(+)

diff --git 
a/components/camel-hashicorp-vault/src/test/java/org/apache/camel/component/hashicorp/vault/integration/operations/HashicorpProducerCreateMultiVersionSecretIT.java
 
b/components/camel-hashicorp-vault/src/test/java/org/apache/camel/component/hashicorp/vault/integration/operations/HashicorpProducerCreateMultiVersionSecretIT.java
new file mode 100644
index 00000000000..cc25cfd0338
--- /dev/null
+++ 
b/components/camel-hashicorp-vault/src/test/java/org/apache/camel/component/hashicorp/vault/integration/operations/HashicorpProducerCreateMultiVersionSecretIT.java
@@ -0,0 +1,94 @@
+/*
+ * 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.hashicorp.vault.integration.operations;
+
+import org.apache.camel.EndpointInject;
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.hashicorp.vault.HashicorpVaultConstants;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.junit.jupiter.api.Test;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
+public class HashicorpProducerCreateMultiVersionSecretIT extends 
HashicorpVaultBase {
+
+    @EndpointInject("mock:result-write")
+    private MockEndpoint mockWrite;
+
+    @EndpointInject("mock:result-read")
+    private MockEndpoint mockRead;
+
+    @Test
+    public void createSecretTest() throws InterruptedException {
+
+        mockWrite.expectedMessageCount(2);
+        mockRead.expectedMessageCount(1);
+        Exchange exchange = template.request("direct:createSecret", new 
Processor() {
+            @Override
+            public void process(Exchange exchange) {
+                HashMap map = new HashMap();
+                map.put("integer", "30");
+                exchange.getIn().setBody(map);
+            }
+        });
+        exchange = template.request("direct:createSecret", new Processor() {
+            @Override
+            public void process(Exchange exchange) {
+                HashMap map = new HashMap();
+                map.put("integer", "31");
+                exchange.getIn().setBody(map);
+            }
+        });
+        exchange = template.request("direct:readSecret", new Processor() {
+            @Override
+            public void process(Exchange exchange) {
+                
exchange.getMessage().setHeader(HashicorpVaultConstants.SECRET_PATH, "test");
+            }
+        });
+
+        assertMockEndpointsSatisfied();
+        Exchange ret = mockRead.getExchanges().get(0);
+        assertNotNull(ret);
+        assertEquals(((Map) 
ret.getMessage().getBody(Map.class).get("data")).get("integer"), "31");
+        assertEquals(((Map) 
ret.getMessage().getBody(Map.class).get("metadata")).get("version"), 2);
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() {
+        return new RouteBuilder() {
+            @Override
+            public void configure() {
+                from("direct:createSecret")
+                        
.toF("hashicorp-vault://secret?operation=createSecret&token=RAW(%s)&host=%s&port=%s&scheme=http&secretPath=test",
+                                service.token(), service.host(), 
service.port())
+                        .to("mock:result-write");
+
+                from("direct:readSecret")
+                        
.toF("hashicorp-vault://secret?operation=getSecret&token=RAW(%s)&host=%s&port=%s&scheme=http",
+                                service.token(), service.host(), 
service.port())
+                        .to("mock:result-read");
+            }
+        };
+    }
+}
diff --git 
a/components/camel-hashicorp-vault/src/test/java/org/apache/camel/component/hashicorp/vault/integration/operations/HashicorpProducerReadMultiVersionedSecretIT.java
 
b/components/camel-hashicorp-vault/src/test/java/org/apache/camel/component/hashicorp/vault/integration/operations/HashicorpProducerReadMultiVersionedSecretIT.java
new file mode 100644
index 00000000000..a7bf9b23228
--- /dev/null
+++ 
b/components/camel-hashicorp-vault/src/test/java/org/apache/camel/component/hashicorp/vault/integration/operations/HashicorpProducerReadMultiVersionedSecretIT.java
@@ -0,0 +1,95 @@
+/*
+ * 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.hashicorp.vault.integration.operations;
+
+import org.apache.camel.EndpointInject;
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.hashicorp.vault.HashicorpVaultConstants;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.junit.jupiter.api.Test;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
+public class HashicorpProducerReadMultiVersionedSecretIT extends 
HashicorpVaultBase {
+
+    @EndpointInject("mock:result-write")
+    private MockEndpoint mockWrite;
+
+    @EndpointInject("mock:result-read")
+    private MockEndpoint mockRead;
+
+    @Test
+    public void createSecretTest() throws InterruptedException {
+
+        mockWrite.expectedMessageCount(2);
+        mockRead.expectedMessageCount(1);
+        Exchange exchange = template.request("direct:createSecret", new 
Processor() {
+            @Override
+            public void process(Exchange exchange) {
+                HashMap map = new HashMap();
+                map.put("integer", "30");
+                exchange.getIn().setBody(map);
+            }
+        });
+        exchange = template.request("direct:createSecret", new Processor() {
+            @Override
+            public void process(Exchange exchange) {
+                HashMap map = new HashMap();
+                map.put("integer", "31");
+                exchange.getIn().setBody(map);
+            }
+        });
+        exchange = template.request("direct:readSecret", new Processor() {
+            @Override
+            public void process(Exchange exchange) {
+                
exchange.getMessage().setHeader(HashicorpVaultConstants.SECRET_PATH, "test");
+                
exchange.getMessage().setHeader(HashicorpVaultConstants.SECRET_VERSION, "1");
+            }
+        });
+
+        assertMockEndpointsSatisfied();
+        Exchange ret = mockRead.getExchanges().get(0);
+        assertNotNull(ret);
+        assertEquals(((Map) 
ret.getMessage().getBody(Map.class).get("data")).get("integer"), "30");
+        assertEquals(((Map) 
ret.getMessage().getBody(Map.class).get("metadata")).get("version"), 1);
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() {
+        return new RouteBuilder() {
+            @Override
+            public void configure() {
+                from("direct:createSecret")
+                        
.toF("hashicorp-vault://secret?operation=createSecret&token=RAW(%s)&host=%s&port=%s&scheme=http&secretPath=test",
+                                service.token(), service.host(), 
service.port())
+                        .to("mock:result-write");
+
+                from("direct:readSecret")
+                        
.toF("hashicorp-vault://secret?operation=getSecret&token=RAW(%s)&host=%s&port=%s&scheme=http",
+                                service.token(), service.host(), 
service.port())
+                        .to("mock:result-read");
+            }
+        };
+    }
+}

Reply via email to