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 4afb3e19e03cca4f5491ea32200950f5b769135d Author: Andrea Cosentino <anco...@gmail.com> AuthorDate: Tue Jul 5 13:43:50 2022 +0200 CAMEL-18257 - Camel-Hashicorp-vault: Support list secrets operation --- .../operations/HashicorpProducerListSecretsIT.java | 93 ++++++++++++++++++++++ 1 file changed, 93 insertions(+) diff --git a/components/camel-hashicorp-vault/src/test/java/org/apache/camel/component/hashicorp/vault/integration/operations/HashicorpProducerListSecretsIT.java b/components/camel-hashicorp-vault/src/test/java/org/apache/camel/component/hashicorp/vault/integration/operations/HashicorpProducerListSecretsIT.java new file mode 100644 index 00000000000..5eafd50b776 --- /dev/null +++ b/components/camel-hashicorp-vault/src/test/java/org/apache/camel/component/hashicorp/vault/integration/operations/HashicorpProducerListSecretsIT.java @@ -0,0 +1,93 @@ +/* + * 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.List; +import java.util.Map; + +import static org.junit.jupiter.api.Assertions.*; + +public class HashicorpProducerListSecretsIT extends HashicorpVaultBase { + + @EndpointInject("mock:result-write") + private MockEndpoint mockWrite; + + @EndpointInject("mock:result-list") + 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("secret", "30"); + exchange.getIn().setBody(map); + } + }); + exchange = template.request("direct:listSecrets", new Processor() { + @Override + public void process(Exchange exchange) { + } + }); + + assertMockEndpointsSatisfied(); + Exchange ret = mockRead.getExchanges().get(0); + assertNotNull(ret); + assertTrue(ret.getMessage().getBody(List.class).contains("test")); + assertEquals(1, ret.getMessage().getBody(List.class).size()); + } + + @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:listSecrets") + .toF("hashicorp-vault://secret?operation=listSecrets&token=RAW(%s)&host=%s&port=%s&scheme=http&secretPath=test", + service.token(), service.host(), service.port()) + .to("mock:result-list"); + } + }; + } +}