Skip to content

Commit 3a47c5f

Browse files
committed
started work
Signed-off-by: wind57 <[email protected]>
1 parent f0a6a20 commit 3a47c5f

File tree

6 files changed

+170
-3
lines changed

6 files changed

+170
-3
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/*
2+
* Copyright 2013-2025 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.cloud.kubernetes.fabric8.config.array_with_profiles;
18+
19+
import io.fabric8.kubernetes.api.model.ConfigMapBuilder;
20+
import io.fabric8.kubernetes.client.Config;
21+
import io.fabric8.kubernetes.client.KubernetesClient;
22+
import org.junit.jupiter.api.Test;
23+
import org.springframework.beans.factory.annotation.Autowired;
24+
import org.springframework.boot.test.context.SpringBootTest;
25+
import org.springframework.cloud.kubernetes.commons.config.Constants;
26+
import org.springframework.cloud.kubernetes.fabric8.config.TestApplication;
27+
import org.springframework.test.context.ActiveProfiles;
28+
import org.springframework.test.web.reactive.server.WebTestClient;
29+
30+
import java.util.HashMap;
31+
32+
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;
33+
import static org.springframework.cloud.kubernetes.fabric8.config.ConfigMapTestUtil.readResourceFile;
34+
35+
/**
36+
* @author wind57
37+
*/
38+
@SpringBootTest(webEnvironment = RANDOM_PORT, classes = TestApplication.class,
39+
properties = { "spring.application.name=array-with-profiles",
40+
"spring.cloud.kubernetes.reload.enabled=false", "spring.main.cloud-platform=KUBERNETES" })
41+
@ActiveProfiles("dev")
42+
abstract class ArrayWithProfiles {
43+
44+
@Autowired
45+
private WebTestClient webClient;
46+
47+
private static final String APPLICATION_NAME = "array-with-profiles";
48+
49+
static void setUpBeforeClass(KubernetesClient mockClient) {
50+
// Configure the kubernetes master url to point to the mock server
51+
System.setProperty(Config.KUBERNETES_MASTER_SYSTEM_PROPERTY, mockClient.getConfiguration().getMasterUrl());
52+
System.setProperty(Config.KUBERNETES_TRUST_CERT_SYSTEM_PROPERTY, "true");
53+
System.setProperty(Config.KUBERNETES_AUTH_TRYKUBECONFIG_SYSTEM_PROPERTY, "false");
54+
System.setProperty(Config.KUBERNETES_AUTH_TRYSERVICEACCOUNT_SYSTEM_PROPERTY, "false");
55+
System.setProperty(Config.KUBERNETES_NAMESPACE_SYSTEM_PROPERTY, "test");
56+
System.setProperty(Config.KUBERNETES_HTTP2_DISABLE, "true");
57+
58+
HashMap<String, String> data = new HashMap<>();
59+
data.put(Constants.APPLICATION_YML, readResourceFile("array-with-profiles.yaml"));
60+
mockClient.configMaps()
61+
.inNamespace("test")
62+
.resource(new ConfigMapBuilder().withNewMetadata()
63+
.withName(APPLICATION_NAME)
64+
.endMetadata()
65+
.addToData(data)
66+
.build())
67+
.create();
68+
}
69+
70+
@Test
71+
void testItemsEndpoint() {
72+
this.webClient.get()
73+
.uri("/api/items")
74+
.exchange()
75+
.expectStatus()
76+
.isOk()
77+
.expectBody()
78+
.consumeWith(System.out::println);
79+
}
80+
81+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright 2013-2025 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.cloud.kubernetes.fabric8.config.array_with_profiles;
18+
19+
import io.fabric8.kubernetes.client.KubernetesClient;
20+
import io.fabric8.kubernetes.client.server.mock.EnableKubernetesMockClient;
21+
import org.junit.jupiter.api.BeforeAll;
22+
import org.springframework.test.context.TestPropertySource;
23+
24+
/**
25+
* @author wind57
26+
*/
27+
@TestPropertySource(properties = { "spring.cloud.bootstrap.enabled=true" })
28+
@EnableKubernetesMockClient(crud = true, https = false)
29+
class BootstrapArrayWithProfilesTests extends ArrayWithProfiles {
30+
31+
private static KubernetesClient mockClient;
32+
33+
@BeforeAll
34+
public static void setUpBeforeClass() {
35+
setUpBeforeClass(mockClient);
36+
}
37+
}

spring-cloud-kubernetes-fabric8-config/src/test/java/org/springframework/cloud/kubernetes/fabric8/config/config_maps_with_active_profiles/ConfigMapsWithActiveProfilesName.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,6 @@ abstract class ConfigMapsWithActiveProfilesName {
4444

4545
private static final String APPLICATION_NAME = "configmap-with-active-profile-name-example";
4646

47-
@Autowired(required = false)
48-
Config config;
49-
5047
@Autowired
5148
private WebTestClient webClient;
5249

spring-cloud-kubernetes-fabric8-config/src/test/java/org/springframework/cloud/kubernetes/fabric8/config/example/GreetingController.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
import org.springframework.web.bind.annotation.RequestParam;
2222
import org.springframework.web.bind.annotation.RestController;
2323

24+
import java.util.List;
25+
2426
/**
2527
* @author Charles Moulliard
2628
*/
@@ -54,4 +56,9 @@ ResponseMessage bonjour(@RequestParam(value = "name", defaultValue = "World") St
5456
return new ResponseMessage(String.format(this.properties.getBonjour(), name));
5557
}
5658

59+
@RequestMapping("/api/items")
60+
List<String> array() {
61+
return properties.getItems();
62+
}
63+
5764
}

spring-cloud-kubernetes-fabric8-config/src/test/java/org/springframework/cloud/kubernetes/fabric8/config/example/GreetingProperties.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818

1919
import org.springframework.boot.context.properties.ConfigurationProperties;
2020

21+
import java.util.ArrayList;
22+
import java.util.List;
23+
2124
@ConfigurationProperties(prefix = "bean")
2225
class GreetingProperties {
2326

@@ -29,6 +32,8 @@ class GreetingProperties {
2932

3033
private String bonjour = "Bonjour, %s!";
3134

35+
private List<String> items = List.of();
36+
3237
String getGreeting() {
3338
return this.greeting;
3439
}
@@ -61,4 +66,11 @@ void setBonjour(String bonjour) {
6166
this.bonjour = bonjour;
6267
}
6368

69+
List<String> getItems() {
70+
return items;
71+
}
72+
73+
void setItems(List<String> items) {
74+
this.items = items;
75+
}
6476
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
spring:
2+
application:
3+
name: my-spring-config-test-app
4+
main:
5+
cloud-platform: kubernetes
6+
allow-bean-definition-overriding: true
7+
cloud:
8+
kubernetes:
9+
reload:
10+
enabled: true
11+
discovery:
12+
client:
13+
composite-indicator:
14+
enabled: false
15+
bean:
16+
items:
17+
- Item 1
18+
- Item 2
19+
- Item 3
20+
- Item 4
21+
- Item 5
22+
23+
---
24+
spring:
25+
config:
26+
activate:
27+
on-profile: dev
28+
29+
bean:
30+
items:
31+
- Item 6
32+
- Item 7
33+
- Item 8

0 commit comments

Comments
 (0)