Skip to content

Commit f1f94df

Browse files
committed
cleanup
Signed-off-by: wind57 <[email protected]>
1 parent 09c00d0 commit f1f94df

File tree

3 files changed

+104
-97
lines changed

3 files changed

+104
-97
lines changed

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

Lines changed: 37 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616

1717
package org.springframework.cloud.kubernetes.configserver.it;
1818

19-
import java.util.ArrayList;
20-
import java.util.List;
2119
import java.util.Map;
2220

2321
import io.kubernetes.client.openapi.ApiException;
@@ -31,26 +29,20 @@
3129
import io.kubernetes.client.openapi.models.V1SecretList;
3230
import io.kubernetes.client.openapi.models.V1SecretListBuilder;
3331
import org.junit.jupiter.api.AfterEach;
34-
import org.junit.jupiter.api.BeforeAll;
3532
import org.junit.jupiter.api.Nested;
3633
import org.junit.jupiter.api.Test;
3734

35+
import org.mockito.Mockito;
3836
import org.springframework.boot.test.context.SpringBootTest;
3937
import org.springframework.boot.test.mock.mockito.MockBean;
4038
import org.springframework.boot.test.mock.mockito.SpyBean;
4139
import org.springframework.boot.test.web.server.LocalServerPort;
4240
import org.springframework.cloud.config.environment.Environment;
4341
import org.springframework.cloud.config.environment.PropertySource;
4442
import org.springframework.cloud.config.server.environment.NativeEnvironmentRepository;
45-
import org.springframework.cloud.kubernetes.client.config.KubernetesClientConfigContext;
46-
import org.springframework.cloud.kubernetes.client.config.KubernetesClientConfigMapPropertySource;
4743
import org.springframework.cloud.kubernetes.client.config.KubernetesClientConfigMapsCache;
4844
import org.springframework.cloud.kubernetes.commons.config.Constants;
49-
import org.springframework.cloud.kubernetes.commons.config.NamedConfigMapNormalizedSource;
50-
import org.springframework.cloud.kubernetes.commons.config.NormalizedSource;
5145
import org.springframework.cloud.kubernetes.configserver.KubernetesConfigServerApplication;
52-
import org.springframework.cloud.kubernetes.configserver.KubernetesPropertySourceSupplier;
53-
import org.springframework.core.env.MapPropertySource;
5446
import org.springframework.http.HttpMethod;
5547
import org.springframework.http.ResponseEntity;
5648
import org.springframework.test.context.ActiveProfiles;
@@ -65,22 +57,20 @@
6557
/**
6658
* @author Arjav Dongaonkar
6759
*/
68-
public class CompositeKubernetesIntegrationTests {
69-
70-
private static final List<KubernetesPropertySourceSupplier> KUBERNETES_PROPERTY_SOURCE_SUPPLIER = new ArrayList<>();
60+
class CompositeKubernetesIntegrationTests {
7161

7262
private static V1ConfigMap buildConfigMap(String name, String namespace) {
7363
return new V1ConfigMapBuilder()
7464
.withMetadata(
75-
new V1ObjectMetaBuilder().withName(name).withNamespace(namespace).withResourceVersion("1").build())
65+
new V1ObjectMetaBuilder().withName(name).withNamespace(namespace).build())
7666
.addToData(Constants.APPLICATION_YAML, "dummy:\n property:\n string: \"" + name + "\"\n")
7767
.build();
7868
}
7969

8070
private static V1Secret buildSecret(String name, String namespace) {
8171
return new V1SecretBuilder()
8272
.withMetadata(
83-
new V1ObjectMetaBuilder().withName(name).withResourceVersion("0").withNamespace(namespace).build())
73+
new V1ObjectMetaBuilder().withName(name).withNamespace(namespace).build())
8474
.addToData("password", "p455w0rd".getBytes())
8575
.addToData("username", "user".getBytes())
8676
.build();
@@ -93,22 +83,8 @@ private static V1Secret buildSecret(String name, String namespace) {
9383
.addToItems(buildSecret("gateway", "default"))
9484
.build();
9585

96-
@BeforeAll
97-
public static void before() {
98-
KUBERNETES_PROPERTY_SOURCE_SUPPLIER.add((coreApi, applicationName, namespace, springEnv) -> {
99-
List<MapPropertySource> propertySources = new ArrayList<>();
100-
101-
NormalizedSource defaultSource = new NamedConfigMapNormalizedSource(applicationName, "default", false,
102-
true);
103-
KubernetesClientConfigContext defaultContext = new KubernetesClientConfigContext(coreApi, defaultSource,
104-
"default", springEnv);
105-
propertySources.add(new KubernetesClientConfigMapPropertySource(defaultContext));
106-
return propertySources;
107-
});
108-
}
109-
11086
@AfterEach
111-
public void after() {
87+
void after() {
11288
new KubernetesClientConfigMapsCache().discardAll();
11389
}
11490

@@ -129,12 +105,12 @@ class KubernetesCompositeConfigServerTest {
129105
private CoreV1Api coreV1Api;
130106

131107
@Test
132-
public void contextLoads() throws ApiException {
133-
when(coreV1Api.listNamespacedConfigMap(eq("default"), eq(null), eq(null), eq(null), eq(null), eq(null),
134-
eq(null), eq(null), eq(null), eq(null), eq(null), eq(null)))
108+
void contextLoads() throws ApiException {
109+
when(coreV1Api.listNamespacedConfigMap(
110+
"default", null, null, null, null, null, null, null, null, null, null, null))
135111
.thenReturn(CONFIGMAP_DEFAULT_LIST);
136-
when(coreV1Api.listNamespacedSecret(eq("default"), eq(null), eq(null), eq(null), eq(null), eq(null),
137-
eq(null), eq(null), eq(null), eq(null), eq(null), eq(null)))
112+
when(coreV1Api.listNamespacedSecret(
113+
"default", null, null, null, null, null, null, null, null, null, null, null))
138114
.thenReturn(SECRET_DEFAULT_LIST);
139115

140116
ResponseEntity<Environment> response = new RestTemplate().exchange(
@@ -155,7 +131,6 @@ public void contextLoads() throws ApiException {
155131
properties = { "spring.main.cloud-platform=KUBERNETES", "spring.cloud.kubernetes.client.namespace=default",
156132
"spring.cloud.config.server.composite[0].type=kubernetes",
157133
"spring.cloud.config.server.composite[1].type=native",
158-
"spring.cloud.config.server.composite[1].location=file:./native-config",
159134
"spring.cloud.kubernetes.secrets.enableApi=true" },
160135
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
161136
@ActiveProfiles({ "test", "composite", "kubernetes", "native" })
@@ -171,12 +146,12 @@ class KubernetesSecretsEnabledCompositeConfigServerTest {
171146
private NativeEnvironmentRepository nativeEnvironmentRepository;
172147

173148
@Test
174-
public void contextLoads() throws Exception {
175-
when(coreV1Api.listNamespacedConfigMap(eq("default"), eq(null), eq(null), eq(null), eq(null), eq(null),
176-
eq(null), eq(null), eq(null), eq(null), eq(null), eq(null)))
149+
void contextLoads() throws Exception {
150+
when(coreV1Api.listNamespacedConfigMap(
151+
"default", null, null, null, null, null, null, null, null, null, null, null))
177152
.thenReturn(CONFIGMAP_DEFAULT_LIST);
178-
when(coreV1Api.listNamespacedSecret(eq("default"), eq(null), eq(null), eq(null), eq(null), eq(null),
179-
eq(null), eq(null), eq(null), eq(null), eq(null), eq(null)))
153+
when(coreV1Api.listNamespacedSecret(
154+
"default", null, null, null, null, null, null, null, null, null, null, null))
180155
.thenReturn(SECRET_DEFAULT_LIST);
181156

182157
Environment mockNativeEnvironment = new Environment("gateway", "default");
@@ -206,7 +181,6 @@ public void contextLoads() throws Exception {
206181
properties = { "spring.main.cloud-platform=KUBERNETES", "spring.cloud.kubernetes.client.namespace=default",
207182
"spring.cloud.config.server.composite[0].type=kubernetes",
208183
"spring.cloud.config.server.composite[1].type=native",
209-
"spring.cloud.config.server.composite[1].location=file:./native-config",
210184
"spring.cloud.kubernetes.config.enableApi=false",
211185
"spring.cloud.kubernetes.secrets.enableApi=true" },
212186
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@@ -223,12 +197,12 @@ class KubernetesConfigMapDisabledCompositeConfigServerTest {
223197
private NativeEnvironmentRepository nativeEnvironmentRepository;
224198

225199
@Test
226-
public void contextLoads() throws Exception {
227-
when(coreV1Api.listNamespacedConfigMap(eq("default"), eq(null), eq(null), eq(null), eq(null), eq(null),
228-
eq(null), eq(null), eq(null), eq(null), eq(null), eq(null)))
200+
void contextLoads() throws Exception {
201+
when(coreV1Api.listNamespacedConfigMap(
202+
"default", null, null, null, null, null, null, null, null, null, null, null))
229203
.thenReturn(CONFIGMAP_DEFAULT_LIST);
230-
when(coreV1Api.listNamespacedSecret(eq("default"), eq(null), eq(null), eq(null), eq(null), eq(null),
231-
eq(null), eq(null), eq(null), eq(null), eq(null), eq(null)))
204+
when(coreV1Api.listNamespacedSecret(
205+
"default", null, null, null, null, null, null, null, null, null, null, null))
232206
.thenReturn(SECRET_DEFAULT_LIST);
233207

234208
Environment mockNativeEnvironment = new Environment("gateway", "default");
@@ -256,8 +230,7 @@ public void contextLoads() throws Exception {
256230
@SpringBootTest(classes = { KubernetesConfigServerApplication.class },
257231
properties = { "spring.main.cloud-platform=KUBERNETES", "spring.cloud.kubernetes.client.namespace=default",
258232
"spring.cloud.config.server.composite[0].type=kubernetes",
259-
"spring.cloud.config.server.composite[1].type=native",
260-
"spring.cloud.config.server.composite[1].location=file:./native-config" },
233+
"spring.cloud.config.server.composite[1].type=native" },
261234
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
262235
@ActiveProfiles({ "test", "composite", "kubernetes", "native" })
263236
class KubernetesSecretsDisabledCompositeConfigServerTest {
@@ -272,12 +245,12 @@ class KubernetesSecretsDisabledCompositeConfigServerTest {
272245
private NativeEnvironmentRepository nativeEnvironmentRepository;
273246

274247
@Test
275-
public void contextLoads() throws Exception {
276-
when(coreV1Api.listNamespacedConfigMap(eq("default"), eq(null), eq(null), eq(null), eq(null), eq(null),
277-
eq(null), eq(null), eq(null), eq(null), eq(null), eq(null)))
248+
void contextLoads() throws Exception {
249+
when(coreV1Api.listNamespacedConfigMap(
250+
"default", null, null, null, null, null, null, null, null, null, null, null))
278251
.thenReturn(CONFIGMAP_DEFAULT_LIST);
279-
when(coreV1Api.listNamespacedSecret(eq("default"), eq(null), eq(null), eq(null), eq(null), eq(null),
280-
eq(null), eq(null), eq(null), eq(null), eq(null), eq(null)))
252+
when(coreV1Api.listNamespacedSecret(
253+
"default", null, null, null, null, null, null, null, null, null, null, null))
281254
.thenReturn(SECRET_DEFAULT_LIST);
282255

283256
Environment mockNativeEnvironment = new Environment("gateway", "default");
@@ -306,7 +279,6 @@ public void contextLoads() throws Exception {
306279
@SpringBootTest(classes = { KubernetesConfigServerApplication.class },
307280
properties = { "spring.config.name:compositeconfigserver", "spring.main.cloud-platform=KUBERNETES",
308281
"spring.cloud.kubernetes.client.namespace=default",
309-
"spring.cloud.config.server.native.search-locations=file:./native-config",
310282
"spring.cloud.config.server.native.order=1", "spring.cloud.kubernetes.configserver.order=2",
311283
"spring.cloud.kubernetes.secrets.enableApi=true" },
312284
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@@ -323,12 +295,12 @@ class NativeAndKubernetesConfigServerTest {
323295
private NativeEnvironmentRepository nativeEnvironmentRepository;
324296

325297
@Test
326-
public void contextLoads() throws Exception {
327-
when(coreV1Api.listNamespacedConfigMap(eq("default"), eq(null), eq(null), eq(null), eq(null), eq(null),
328-
eq(null), eq(null), eq(null), eq(null), eq(null), eq(null)))
298+
void contextLoads() throws Exception {
299+
when(coreV1Api.listNamespacedConfigMap(
300+
"default", null, null, null, null, null, null, null, null, null, null, null))
329301
.thenReturn(CONFIGMAP_DEFAULT_LIST);
330-
when(coreV1Api.listNamespacedSecret(eq("default"), eq(null), eq(null), eq(null), eq(null), eq(null),
331-
eq(null), eq(null), eq(null), eq(null), eq(null), eq(null)))
302+
when(coreV1Api.listNamespacedSecret(
303+
"default", null, null, null, null, null, null, null, null, null, null, null))
332304
.thenReturn(SECRET_DEFAULT_LIST);
333305

334306
Environment mockNativeEnvironment = new Environment("gateway", "default");
@@ -340,9 +312,14 @@ public void contextLoads() throws Exception {
340312
ResponseEntity<Environment> response = new RestTemplate().exchange(
341313
"http://localhost:" + this.port + "/gateway/default", HttpMethod.GET, null, Environment.class);
342314

315+
Mockito.verify(coreV1Api, Mockito.times(1)).listNamespacedConfigMap(
316+
"default", null, null, null, null, null, null, null, null, null, null, null);
317+
318+
Mockito.verify(coreV1Api, Mockito.times(1)).listNamespacedSecret(
319+
"default", null, null, null, null, null, null, null, null, null, null, null);
320+
343321
Environment environment = response.getBody();
344322

345-
assert environment != null;
346323
assertThat(3).isEqualTo(environment.getPropertySources().size());
347324
assertThat("nativeProperties").isEqualTo(environment.getPropertySources().get(0).getName());
348325
assertThat(environment.getPropertySources().get(1).getName().contains("configmap.gateway.default.default")

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package org.springframework.cloud.kubernetes.configserver.it;
1818

1919
import com.github.tomakehurst.wiremock.client.WireMock;
20+
import io.kubernetes.client.openapi.ApiClient;
2021
import io.kubernetes.client.util.ClientBuilder;
2122
import org.junit.jupiter.api.AfterEach;
2223
import org.junit.jupiter.api.BeforeEach;
@@ -43,17 +44,13 @@ class ConfigDataConfigServerIntegrationTests extends ConfigServerIntegration {
4344
@BeforeEach
4445
void setup() {
4546
clientUtilsMock = mockStatic(KubernetesClientUtils.class);
46-
clientUtilsMock.when(KubernetesClientUtils::kubernetesApiClient)
47-
.thenReturn(new ClientBuilder().setBasePath(wireMockServer.baseUrl()).build());
47+
ApiClient client = new ClientBuilder().setBasePath(wireMockServer.baseUrl()).build();
48+
clientUtilsMock.when(KubernetesClientUtils::kubernetesApiClient).thenReturn(client);
4849
}
4950

5051
@AfterEach
5152
void teardown() {
5253
clientUtilsMock.close();
53-
}
54-
55-
@AfterEach
56-
void afterEach() {
5754
WireMock.reset();
5855
}
5956

0 commit comments

Comments
 (0)