From 0c60d82beafeb833c76537e384f1479de763f247 Mon Sep 17 00:00:00 2001 From: "Badr.NassLahsen" Date: Thu, 6 Apr 2023 14:55:33 +0200 Subject: [PATCH] @ConjurPropertySource Not only applied to the properties of a class. Fixes #75 --- .../core/env/ConjurPropertySourceTest.java | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 src/test/java/com/cyberark/conjur/springboot/core/env/ConjurPropertySourceTest.java diff --git a/src/test/java/com/cyberark/conjur/springboot/core/env/ConjurPropertySourceTest.java b/src/test/java/com/cyberark/conjur/springboot/core/env/ConjurPropertySourceTest.java new file mode 100644 index 00000000..dab94101 --- /dev/null +++ b/src/test/java/com/cyberark/conjur/springboot/core/env/ConjurPropertySourceTest.java @@ -0,0 +1,53 @@ +package com.cyberark.conjur.springboot.core.env; + +import com.cyberark.conjur.sdk.ApiException; +import com.cyberark.conjur.sdk.endpoint.SecretsApi; +import com.cyberark.conjur.springboot.annotations.ConjurPropertySource; +import org.junit.jupiter.api.Test; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.context.annotation.Configuration; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; + +/** + * @author bnasslahsen + */ +@SpringBootTest +public class ConjurPropertySourceTest { + + + @MockBean + private SecretsApi secretsApi; + + @Test + public void testGetSecretCallsCount() throws ApiException { + // Verify the number of times the method was called + verify(secretsApi, times(3)).getSecret(any(), any(), + any()); + } + + @SpringBootApplication + static class ConjurPropertySourceTestApp { + + @ConjurPropertySource("db/") + @Configuration + class ConjurPropertySourceConfiguration { + + @Value("${dbpassWord}") + private byte[] dbpassWord; + + @Value("${dbuserName}") + private byte[] dbuserName; + + @Value("${key}") + private byte[] key; + } + } + +}