Skip to content

Commit b57e447

Browse files
test case for new constructor
1 parent cceb805 commit b57e447

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

spring-cloud-kubernetes-controllers/spring-cloud-kubernetes-configserver/src/test/java/org/springframework/cloud/kubernetes/configserver/KubernetesEnvironmentRepositoryTests.java

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,48 @@ public void testApplicationCase() throws ApiException {
190190
});
191191
}
192192

193+
@Test
194+
public void testApplicationCaseWithNewConstructor() throws ApiException {
195+
CoreV1Api coreApi = mock(CoreV1Api.class);
196+
KubernetesConfigServerProperties properties = mock(KubernetesConfigServerProperties.class);
197+
when(properties.getOrder()).thenReturn(0);
198+
199+
when(coreApi.listNamespacedConfigMap(eq("default"), eq(null), eq(null), eq(null), eq(null), eq(null), eq(null),
200+
eq(null), eq(null), eq(null), eq(null), eq(null)))
201+
.thenReturn(CONFIGMAP_DEFAULT_LIST);
202+
when(coreApi.listNamespacedSecret(eq("default"), eq(null), eq(null), eq(null), eq(null), eq(null), eq(null),
203+
eq(null), eq(null), eq(null), eq(null), eq(null)))
204+
.thenReturn(SECRET_LIST);
205+
when(coreApi.listNamespacedConfigMap(eq("dev"), eq(null), eq(null), eq(null), eq(null), eq(null), eq(null),
206+
eq(null), eq(null), eq(null), eq(null), eq(null)))
207+
.thenReturn(CONFIGMAP_DEV_LIST);
208+
209+
KubernetesEnvironmentRepository environmentRepository = new KubernetesEnvironmentRepository(coreApi,
210+
KUBERNETES_PROPERTY_SOURCE_SUPPLIER, "default", properties);
211+
212+
Environment environment = environmentRepository.findOne("application", "", "");
213+
214+
assertThat(environment.getPropertySources().size()).isEqualTo(2);
215+
environment.getPropertySources().forEach(propertySource -> {
216+
assertThat(propertySource.getName().equals("configmap.application.default")
217+
|| propertySource.getName().equals("secret.application.default"))
218+
.isTrue();
219+
if (propertySource.getName().equals("configmap.application.default")) {
220+
assertThat(propertySource.getSource().size()).isEqualTo(3);
221+
assertThat(propertySource.getSource().get("dummy.property.int2")).isEqualTo(1);
222+
assertThat(propertySource.getSource().get("dummy.property.bool2")).isEqualTo(true);
223+
assertThat(propertySource.getSource().get("dummy.property.string2")).isEqualTo("a");
224+
}
225+
if (propertySource.getName().equals("secrets.application.default")) {
226+
assertThat(propertySource.getSource().size()).isEqualTo(2);
227+
assertThat(propertySource.getSource().get("username")).isEqualTo("user");
228+
assertThat(propertySource.getSource().get("password")).isEqualTo("p455w0rd");
229+
}
230+
});
231+
232+
assertThat(environmentRepository.getOrder()).isEqualTo(0);
233+
}
234+
193235
@Test
194236
public void testStoresCase() throws ApiException {
195237
CoreV1Api coreApi = mock(CoreV1Api.class);

0 commit comments

Comments
 (0)