2727
2828import org .springframework .cloud .bootstrap .config .BootstrapPropertySource ;
2929import org .springframework .cloud .kubernetes .commons .config .MountConfigMapPropertySource ;
30+ import org .springframework .cloud .kubernetes .commons .config .SecretsPropertySource ;
31+ import org .springframework .cloud .kubernetes .commons .config .SourceData ;
3032import org .springframework .core .env .CompositePropertySource ;
3133import org .springframework .core .env .EnumerablePropertySource ;
3234import org .springframework .core .env .MapPropertySource ;
@@ -127,8 +129,8 @@ void testFindPropertySources() {
127129 MockEnvironment environment = new MockEnvironment ();
128130 MutablePropertySources propertySources = environment .getPropertySources ();
129131 propertySources .addFirst (new OneComposite ());
130- propertySources .addFirst (new PlainPropertySource ("plain" ));
131- propertySources .addFirst (new OneBootstrap (new EnumerablePropertySource <>("enumerable" ) {
132+ propertySources .addFirst (new PlainPropertySource <> ("plain" ));
133+ propertySources .addFirst (new OneBootstrap <> (new EnumerablePropertySource <>("enumerable" ) {
132134 @ Override
133135 public String [] getPropertyNames () {
134136 return new String [0 ];
@@ -143,11 +145,35 @@ public Object getProperty(String name) {
143145
144146 List <? extends PropertySource > result = ConfigReloadUtil .findPropertySources (PlainPropertySource .class ,
145147 environment );
146- Assertions .assertEquals (4 , result .size ());
148+ Assertions .assertEquals (3 , result .size ());
147149 Assertions .assertEquals ("b" , result .get (0 ).getProperty ("a" ));
148150 Assertions .assertEquals ("plain" , result .get (1 ).getProperty ("" ));
149- Assertions .assertEquals ("from-bootstrap" , result .get (2 ).getProperty ("" ));
150- Assertions .assertEquals ("from-inner-two-composite" , result .get (3 ).getProperty ("" ));
151+ Assertions .assertEquals ("from-inner-two-composite" , result .get (2 ).getProperty ("" ));
152+ }
153+
154+ @ Test
155+ void testSecretsPropertySource () {
156+ MockEnvironment environment = new MockEnvironment ();
157+ MutablePropertySources propertySources = environment .getPropertySources ();
158+ propertySources .addFirst (new SecretsPropertySource (new SourceData ("secret" , Map .of ("a" , "b" ))));
159+
160+ List <? extends PropertySource > result = ConfigReloadUtil .findPropertySources (PlainPropertySource .class ,
161+ environment );
162+ assertThat (result .size ()).isEqualTo (1 );
163+ assertThat (result .get (0 ).getProperty ("a" )).isEqualTo ("b" );
164+ }
165+
166+ @ Test
167+ void testBootstrapSecretsPropertySource () {
168+ MockEnvironment environment = new MockEnvironment ();
169+ MutablePropertySources propertySources = environment .getPropertySources ();
170+ propertySources
171+ .addFirst (new OneBootstrap <>(new SecretsPropertySource (new SourceData ("secret" , Map .of ("a" , "b" )))));
172+
173+ List <? extends PropertySource > result = ConfigReloadUtil .findPropertySources (PlainPropertySource .class ,
174+ environment );
175+ assertThat (result .size ()).isEqualTo (1 );
176+ assertThat (result .get (0 ).getProperty ("a" )).isEqualTo ("b" );
151177 }
152178
153179 private static final class OneComposite extends CompositePropertySource {
@@ -171,12 +197,12 @@ private TwoComposite() {
171197
172198 @ Override
173199 public Collection <PropertySource <?>> getPropertySources () {
174- return List .of (new PlainPropertySource ("from-inner-two-composite" ));
200+ return List .of (new PlainPropertySource <> ("from-inner-two-composite" ));
175201 }
176202
177203 }
178204
179- private static final class PlainPropertySource extends PropertySource <String > {
205+ private static final class PlainPropertySource < T > extends PropertySource <T > {
180206
181207 private PlainPropertySource (String name ) {
182208 super (name );
@@ -189,15 +215,18 @@ public Object getProperty(String name) {
189215
190216 }
191217
192- private static final class OneBootstrap extends BootstrapPropertySource <String > {
218+ private static final class OneBootstrap <T > extends BootstrapPropertySource <T > {
219+
220+ private final EnumerablePropertySource <T > delegate ;
193221
194- private OneBootstrap (EnumerablePropertySource <String > delegate ) {
222+ private OneBootstrap (EnumerablePropertySource <T > delegate ) {
195223 super (delegate );
224+ this .delegate = delegate ;
196225 }
197226
198227 @ Override
199- public PropertySource <String > getDelegate () {
200- return new PlainPropertySource ( "from-bootstrap" ) ;
228+ public PropertySource <T > getDelegate () {
229+ return delegate ;
201230 }
202231
203232 }
0 commit comments