|
19 | 19 | import java.util.Arrays; |
20 | 20 | import java.util.List; |
21 | 21 |
|
| 22 | +import java.util.Arrays; |
| 23 | +import java.util.Collections; |
| 24 | +import java.util.List; |
| 25 | + |
22 | 26 | import org.junit.Before; |
23 | 27 | import org.junit.Test; |
24 | | - |
25 | 28 | import org.springframework.boot.DefaultBootstrapContext; |
26 | 29 | import org.springframework.boot.context.config.ConfigDataLocation; |
27 | 30 | import org.springframework.boot.context.config.ConfigDataLocationResolverContext; |
28 | 31 | import org.springframework.boot.context.config.Profiles; |
29 | 32 | import org.springframework.boot.context.properties.bind.Binder; |
30 | 33 |
|
| 34 | +import java.util.Arrays; |
| 35 | +import java.util.Collections; |
| 36 | +import java.util.List; |
| 37 | + |
31 | 38 | import static org.assertj.core.api.Assertions.assertThat; |
32 | 39 | import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; |
33 | 40 | import static org.mockito.Mockito.mock; |
@@ -89,6 +96,36 @@ public void shouldDiscoverContextualLocations() { |
89 | 96 |
|
90 | 97 | assertThat(locations).hasSize(1); |
91 | 98 | assertThat(locations.get(0)).hasToString("VaultConfigLocation [path='my/context/path', optional=false]"); |
| 99 | + assertThat(locations.get(0).getSecretBackendMetadata().getPropertyTransformer() |
| 100 | + .transformProperties(Collections.singletonMap("key", "value"))).containsEntry("key", "value"); |
| 101 | + } |
| 102 | + |
| 103 | + @Test |
| 104 | + public void shouldDiscoverContextualLocationsWithPrefix() { |
| 105 | + |
| 106 | + VaultConfigDataLocationResolver resolver = new VaultConfigDataLocationResolver(); |
| 107 | + |
| 108 | + List<VaultConfigLocation> locations = resolver.resolveProfileSpecific(this.contextMock, |
| 109 | + ConfigDataLocation.of("vault://my/context/path?prefix=myPrefix"), this.profilesMock); |
| 110 | + |
| 111 | + assertThat(locations).hasSize(1); |
| 112 | + assertThat(locations.get(0)).hasToString("VaultConfigLocation [path='my/context/path', optional=false]"); |
| 113 | + assertThat(locations.get(0).getSecretBackendMetadata().getPropertyTransformer() |
| 114 | + .transformProperties(Collections.singletonMap("key", "value"))).containsEntry("myPrefix.key", "value"); |
| 115 | + } |
| 116 | + |
| 117 | + @Test |
| 118 | + public void shouldNotPrefixWhenPrefixIsEmpty() { |
| 119 | + |
| 120 | + VaultConfigDataLocationResolver resolver = new VaultConfigDataLocationResolver(); |
| 121 | + |
| 122 | + List<VaultConfigLocation> locations = resolver.resolveProfileSpecific(this.contextMock, |
| 123 | + ConfigDataLocation.of("vault://my/context/path?prefix="), this.profilesMock); |
| 124 | + |
| 125 | + assertThat(locations).hasSize(1); |
| 126 | + assertThat(locations.get(0)).hasToString("VaultConfigLocation [path='my/context/path', optional=false]"); |
| 127 | + assertThat(locations.get(0).getSecretBackendMetadata().getPropertyTransformer() |
| 128 | + .transformProperties(Collections.singletonMap("key", "value"))).containsEntry("key", "value"); |
92 | 129 | } |
93 | 130 |
|
94 | 131 | } |
0 commit comments