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

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


The following commit(s) were added to refs/heads/main by this push:
     new 792a600df48 Enable automated property function test
792a600df48 is described below

commit 792a600df486879657033dd31b9e45843ff6b327
Author: Croway <[email protected]>
AuthorDate: Mon Oct 7 15:56:42 2024 +0200

    Enable automated property function test
---
 .../HashicorpVaultPropertiesSourceNoEnvTestIT.java | 67 ++++++++++++++++++----
 1 file changed, 56 insertions(+), 11 deletions(-)

diff --git 
a/components/camel-hashicorp-vault/src/test/java/org/apache/camel/component/hashicorp/vault/integration/HashicorpVaultPropertiesSourceNoEnvTestIT.java
 
b/components/camel-hashicorp-vault/src/test/java/org/apache/camel/component/hashicorp/vault/integration/HashicorpVaultPropertiesSourceNoEnvTestIT.java
index 246c172491b..c4d9117c138 100644
--- 
a/components/camel-hashicorp-vault/src/test/java/org/apache/camel/component/hashicorp/vault/integration/HashicorpVaultPropertiesSourceNoEnvTestIT.java
+++ 
b/components/camel-hashicorp-vault/src/test/java/org/apache/camel/component/hashicorp/vault/integration/HashicorpVaultPropertiesSourceNoEnvTestIT.java
@@ -16,28 +16,73 @@
  */
 package org.apache.camel.component.hashicorp.vault.integration;
 
+import java.util.Map;
+
 import org.apache.camel.FailedToCreateRouteException;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
+import 
org.apache.camel.test.infra.hashicorp.vault.services.HashicorpServiceFactory;
+import 
org.apache.camel.test.infra.hashicorp.vault.services.HashicorpVaultService;
 import org.apache.camel.test.junit5.CamelTestSupport;
+import org.junit.jupiter.api.BeforeAll;
 import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.condition.EnabledIfSystemProperties;
-import org.junit.jupiter.api.condition.EnabledIfSystemProperty;
+import org.junit.jupiter.api.extension.RegisterExtension;
+import org.springframework.vault.authentication.TokenAuthentication;
+import org.springframework.vault.client.VaultEndpoint;
+import org.springframework.vault.core.VaultKeyValueOperations;
+import org.springframework.vault.core.VaultKeyValueOperationsSupport;
+import org.springframework.vault.core.VaultTemplate;
+import org.springframework.vault.support.VaultMount;
 
 import static org.junit.jupiter.api.Assertions.assertThrows;
 
-// Must be manually tested. Provide your own accessKey and secretKey using 
-Dcamel.vault.hashicorp.token, -Dcamel.vault.hashicorp.host, 
-Dcamel.vault.hashicorp.port and -Dcamel.vault.hashicorp.scheme
-@EnabledIfSystemProperties({
-        @EnabledIfSystemProperty(named = "camel.vault.hashicorp.token", 
matches = ".*",
-                                 disabledReason = "Token not provided"),
-        @EnabledIfSystemProperty(named = "camel.vault.hashicorp.host", matches 
= ".*", disabledReason = "Host not provided"),
-        @EnabledIfSystemProperty(named = "camel.vault.hashicorp.port", matches 
= ".*", disabledReason = "Port not provided"),
-        @EnabledIfSystemProperty(named = "camel.vault.hashicorp.scheme", 
matches = ".*", disabledReason = "Scheme not provided")
-})
 public class HashicorpVaultPropertiesSourceNoEnvTestIT extends 
CamelTestSupport {
 
+    @RegisterExtension
+    public static HashicorpVaultService service = 
HashicorpServiceFactory.createService();
+
+    @BeforeAll
+    public static void init() {
+        System.setProperty("camel.vault.hashicorp.token", service.token());
+        System.setProperty("camel.vault.hashicorp.host", service.host());
+        System.setProperty("camel.vault.hashicorp.port", 
String.valueOf(service.port()));
+        System.setProperty("camel.vault.hashicorp.scheme", "http");
+
+        VaultEndpoint vaultEndpoint = new VaultEndpoint();
+        vaultEndpoint.setHost(service.host());
+        vaultEndpoint.setPort(service.port());
+        vaultEndpoint.setScheme("http");
+
+        VaultTemplate client = new VaultTemplate(
+                vaultEndpoint,
+                new TokenAuthentication(service.token()));
+
+        VaultKeyValueOperations vaultKeyValueOperations
+                = client.opsForKeyValue("secret", 
VaultKeyValueOperationsSupport.KeyValueBackend.versioned());
+
+        vaultKeyValueOperations.put("hello", Map.of(
+                "id", "21",
+                "password", "password",
+                "username", "admin"));
+        vaultKeyValueOperations.put("production/secrets/hello", Map.of(
+                "id", "21"));
+
+        client.opsForSys().mount("secretengine1", VaultMount.create("kv"));
+        client.opsForSys().mount("secretengine2", VaultMount.create("kv"));
+
+        vaultKeyValueOperations
+                = client.opsForKeyValue("secretengine1", 
VaultKeyValueOperationsSupport.KeyValueBackend.versioned());
+        vaultKeyValueOperations.put("hello", Map.of(
+                "id", "21"));
+
+        vaultKeyValueOperations
+                = client.opsForKeyValue("secretengine2", 
VaultKeyValueOperationsSupport.KeyValueBackend.versioned());
+        vaultKeyValueOperations.put("hello", Map.of(
+                "id", "21"));
+    }
+
     @Test
-    public void testFunctio() throws Exception {
+    public void testFunction() throws Exception {
         
context.getVaultConfiguration().hashicorp().setToken(System.getProperty("camel.vault.hashicorp.token"));
         
context.getVaultConfiguration().hashicorp().setHost(System.getProperty("camel.vault.hashicorp.host"));
         
context.getVaultConfiguration().hashicorp().setPort(System.getProperty("camel.vault.hashicorp.port"));

Reply via email to