Skip to content

Commit

Permalink
Move to constants 3.1.x (#1717)
Browse files Browse the repository at this point in the history
* fix

* checkstyle

* checkstyle
  • Loading branch information
wind57 authored Sep 11, 2024
1 parent cc19a5d commit 5f2bf71
Show file tree
Hide file tree
Showing 24 changed files with 78 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@

import org.springframework.cloud.kubernetes.commons.KubernetesNamespaceProvider;
import org.springframework.cloud.kubernetes.commons.config.ConfigMapConfigProperties;
import org.springframework.cloud.kubernetes.commons.config.Constants;
import org.springframework.cloud.kubernetes.commons.config.NamespaceResolutionFailedException;
import org.springframework.cloud.kubernetes.commons.config.RetryProperties;
import org.springframework.core.env.PropertySource;
Expand All @@ -62,7 +63,7 @@ class KubernetesClientConfigMapPropertySourceLocatorTests {
.withNamespace("default")
.withResourceVersion("1")
.build())
.addToData("application.properties",
.addToData(Constants.APPLICATION_PROPERTIES,
"spring.cloud.kubernetes.configuration.watcher.refreshDelay=0\n"
+ "logging.level.org.springframework.cloud.kubernetes=TRACE")
.build());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.junit.jupiter.api.Test;

import org.springframework.cloud.kubernetes.commons.config.ConfigUtils;
import org.springframework.cloud.kubernetes.commons.config.Constants;
import org.springframework.cloud.kubernetes.commons.config.NamedConfigMapNormalizedSource;
import org.springframework.cloud.kubernetes.commons.config.NormalizedSource;
import org.springframework.mock.env.MockEnvironment;
Expand Down Expand Up @@ -59,7 +60,7 @@ class KubernetesClientConfigMapPropertySourceTests {
.withNamespace("default")
.withResourceVersion("1")
.build())
.addToData("application.properties",
.addToData(Constants.APPLICATION_PROPERTIES,
"spring.cloud.kubernetes.configuration.watcher.refreshDelay=0\n"
+ "logging.level.org.springframework.cloud.kubernetes=TRACE")
.build());
Expand All @@ -70,7 +71,7 @@ class KubernetesClientConfigMapPropertySourceTests {
.withNamespace("default")
.withResourceVersion("1")
.build())
.addToData("application.yaml", "dummy:\n property:\n string2: \"a\"\n int2: 1\n bool2: true\n")
.addToData(Constants.APPLICATION_YAML, "dummy:\n property:\n string2: \"a\"\n int2: 1\n bool2: true\n")
.build());

private static WireMockServer wireMockServer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
import org.springframework.cloud.kubernetes.client.config.KubernetesClientConfigMapPropertySource;
import org.springframework.cloud.kubernetes.client.config.KubernetesClientConfigMapPropertySourceLocator;
import org.springframework.cloud.kubernetes.commons.KubernetesNamespaceProvider;
import org.springframework.cloud.kubernetes.commons.config.Constants;
import org.springframework.cloud.kubernetes.commons.config.reload.ConfigReloadProperties;
import org.springframework.cloud.kubernetes.commons.config.reload.ConfigurationUpdateStrategy;
import org.springframework.mock.env.MockPropertySource;
Expand Down Expand Up @@ -99,10 +100,10 @@ void watch() {
Gson gson = builder.create();

Map<String, String> data = new HashMap<>();
data.put("application.properties", "spring.cloud.kubernetes.configuration.watcher.refreshDelay=0\n"
data.put(Constants.APPLICATION_PROPERTIES, "spring.cloud.kubernetes.configuration.watcher.refreshDelay=0\n"
+ "logging.level.org.springframework.cloud.kubernetes=TRACE");
Map<String, String> updateData = new HashMap<>();
updateData.put("application.properties", "spring.cloud.kubernetes.configuration.watcher.refreshDelay=1\n"
updateData.put(Constants.APPLICATION_PROPERTIES, "spring.cloud.kubernetes.configuration.watcher.refreshDelay=1\n"
+ "logging.level.org.springframework.cloud.kubernetes=TRACE");
V1ConfigMap applicationConfig = new V1ConfigMap().kind("ConfigMap")
.metadata(new V1ObjectMeta().namespace("default").name("bar1"))
Expand Down Expand Up @@ -132,7 +133,7 @@ void watch() {
.withBody(new JSON().serialize(new Watch.Response<>(EventType.ADDED.name(),
new V1ConfigMap().kind("ConfigMap")
.metadata(new V1ObjectMeta().namespace("default").name("bar3"))
.putDataItem("application.properties", "debug=true")))))
.putDataItem(Constants.APPLICATION_PROPERTIES, "debug=true")))))
.willSetStateTo("delete"));

stubFor(get(urlMatching("^/api/v1/namespaces/default/configmaps.*")).inScenario("watch")
Expand All @@ -142,7 +143,7 @@ void watch() {
.withBody(new JSON().serialize(new Watch.Response<>(EventType.DELETED.name(),
new V1ConfigMap().kind("ConfigMap")
.metadata(new V1ObjectMeta().namespace("default").name("bar1"))
.putDataItem("application.properties", "debug=true")))))
.putDataItem(Constants.APPLICATION_PROPERTIES, "debug=true")))))
.willSetStateTo("done"));

stubFor(get(urlMatching("^/api/v1/namespaces/default/configmaps.*")).inScenario("watch")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,10 @@ void testWithPrefixSortedName() {
void testMerge() {

StrippedSourceContainer configMapOne = new StrippedSourceContainer(Map.of(), "configmap-one",
Map.of("application.yaml", "propA: A\npropB: B"));
Map.of(Constants.APPLICATION_YAML, "propA: A\npropB: B"));

StrippedSourceContainer configMapOneK8s = new StrippedSourceContainer(Map.of(), "configmap-one-kubernetes",
Map.of("application.yaml", "propA: AA\npropC: C"));
Map.of(Constants.APPLICATION_YAML, "propA: AA\npropC: C"));

LinkedHashSet<String> sourceNames = Stream.of("configmap-one", "configmap-one-kubernetes")
.collect(Collectors.toCollection(LinkedHashSet::new));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ void testSingleNonFileProperty() {
@Test
void testSingleFileProperty() {
Map<String, String> map = new LinkedHashMap<>();
map.put("application.properties", "my-key=from-app");
map.put(Constants.APPLICATION_PROPERTIES, "my-key=from-app");

MockEnvironment mockEnvironment = new MockEnvironment();
Map<String, Object> result = SourceDataEntriesProcessor.processAllEntries(map, mockEnvironment);
Expand All @@ -78,7 +78,7 @@ void testSingleFileProperty() {
void testThree() {

Map<String, String> map = new LinkedHashMap<>();
map.put("application.properties", """
map.put(Constants.APPLICATION_PROPERTIES, """
firstKey=firstFromProperties
secondKey=secondFromProperties""");
map.put("firstKey", "abc");
Expand Down Expand Up @@ -114,7 +114,7 @@ void testThree() {
void testFour() {

Map<String, String> map = new LinkedHashMap<>();
map.put("application.properties", """
map.put(Constants.APPLICATION_PROPERTIES, """
firstKey=firstFromProperties
secondKey=secondFromProperties
thirdKey=thirdFromProperties""");
Expand Down Expand Up @@ -158,7 +158,7 @@ void testFour() {
void testFive() {

Map<String, String> map = new LinkedHashMap<>();
map.put("application.properties", """
map.put(Constants.APPLICATION_PROPERTIES, """
firstKey=firstFromProperties
secondKey=secondFromProperties
thirdKey=thirdFromProperties""");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,28 +66,28 @@ void testTwoNonFileProperties() {
void testSingleFileProperty() {

Map<String, String> k8sSource = new LinkedHashMap<>();
k8sSource.put("application.properties", "key=value");
k8sSource.put(Constants.APPLICATION_PROPERTIES, "key=value");

MockEnvironment mockEnvironment = new MockEnvironment();

List<Map.Entry<String, String>> result = SourceDataEntriesProcessor.sorted(k8sSource, mockEnvironment);
Assertions.assertEquals(result.size(), 1);
Assertions.assertEquals(result.get(0).getKey(), "application.properties");
Assertions.assertEquals(result.get(0).getKey(), Constants.APPLICATION_PROPERTIES);
Assertions.assertEquals(result.get(0).getValue(), "key=value");
}

@Test
void testApplicationAndSimpleProperty() {

Map<String, String> k8sSource = new LinkedHashMap<>();
k8sSource.put("application.properties", "key=value");
k8sSource.put(Constants.APPLICATION_PROPERTIES, "key=value");
k8sSource.put("simple", "other_value");

MockEnvironment mockEnvironment = new MockEnvironment();

List<Map.Entry<String, String>> result = SourceDataEntriesProcessor.sorted(k8sSource, mockEnvironment);
Assertions.assertEquals(result.size(), 2);
Assertions.assertEquals(result.get(0).getKey(), "application.properties");
Assertions.assertEquals(result.get(0).getKey(), Constants.APPLICATION_PROPERTIES);
Assertions.assertEquals(result.get(0).getValue(), "key=value");

Assertions.assertEquals(result.get(1).getKey(), "simple");
Expand All @@ -99,13 +99,13 @@ void testSimplePropertyAndApplication() {

Map<String, String> k8sSource = new LinkedHashMap<>();
k8sSource.put("simple", "other_value");
k8sSource.put("application.properties", "key=value");
k8sSource.put(Constants.APPLICATION_PROPERTIES, "key=value");

MockEnvironment mockEnvironment = new MockEnvironment();

List<Map.Entry<String, String>> result = SourceDataEntriesProcessor.sorted(k8sSource, mockEnvironment);
Assertions.assertEquals(result.size(), 2);
Assertions.assertEquals(result.get(0).getKey(), "application.properties");
Assertions.assertEquals(result.get(0).getKey(), Constants.APPLICATION_PROPERTIES);
Assertions.assertEquals(result.get(0).getValue(), "key=value");

Assertions.assertEquals(result.get(1).getKey(), "simple");
Expand All @@ -117,15 +117,15 @@ void testSimplePropertyAndTwoApplications() {

Map<String, String> k8sSource = new LinkedHashMap<>();
k8sSource.put("simple", "other_value");
k8sSource.put("application.properties", "key=value");
k8sSource.put(Constants.APPLICATION_PROPERTIES, "key=value");
k8sSource.put("application-dev.properties", "key-dev=value-dev");

MockEnvironment mockEnvironment = new MockEnvironment();
mockEnvironment.setActiveProfiles("dev");

List<Map.Entry<String, String>> result = SourceDataEntriesProcessor.sorted(k8sSource, mockEnvironment);
Assertions.assertEquals(result.size(), 3);
Assertions.assertEquals(result.get(0).getKey(), "application.properties");
Assertions.assertEquals(result.get(0).getKey(), Constants.APPLICATION_PROPERTIES);
Assertions.assertEquals(result.get(0).getValue(), "key=value");

Assertions.assertEquals(result.get(1).getKey(), "application-dev.properties");
Expand All @@ -140,7 +140,7 @@ void testSimplePropertyAndTwoApplicationsDoNotIncludeDefaultProfile() {

Map<String, String> k8sSource = new LinkedHashMap<>();
k8sSource.put("simple", "other_value");
k8sSource.put("application.properties", "key=value");
k8sSource.put(Constants.APPLICATION_PROPERTIES, "key=value");
k8sSource.put("application-dev.properties", "key-dev=value-dev");

MockEnvironment mockEnvironment = new MockEnvironment();
Expand All @@ -159,7 +159,7 @@ void testComplex() {
Map<String, String> k8sSource = new LinkedHashMap<>();
k8sSource.put("simple", "other_value");
k8sSource.put("second-simple", "second_other_value");
k8sSource.put("application.properties", "key=value");
k8sSource.put(Constants.APPLICATION_PROPERTIES, "key=value");
k8sSource.put("application-dev.properties", "key-dev=value-dev");
k8sSource.put("application-k8s.properties", "key-k8s=value-k8s");
k8sSource.put("ignored.properties", "key-ignored=value-ignored");
Expand All @@ -169,7 +169,7 @@ void testComplex() {

List<Map.Entry<String, String>> result = SourceDataEntriesProcessor.sorted(k8sSource, mockEnvironment);
Assertions.assertEquals(result.size(), 4);
Assertions.assertEquals(result.get(0).getKey(), "application.properties");
Assertions.assertEquals(result.get(0).getKey(), Constants.APPLICATION_PROPERTIES);
Assertions.assertEquals(result.get(0).getValue(), "key=value");

Assertions.assertEquals(result.get(1).getKey(), "application-k8s.properties");
Expand All @@ -188,7 +188,7 @@ void testComplexWithNonDefaultApplicationName() {
Map<String, String> k8sSource = new LinkedHashMap<>();
k8sSource.put("simple", "other_value");
k8sSource.put("second-simple", "second_other_value");
k8sSource.put("application.properties", "key=value");
k8sSource.put(Constants.APPLICATION_PROPERTIES, "key=value");
k8sSource.put("application-dev.properties", "key-dev=value-dev");
k8sSource.put("application-k8s.properties", "key-k8s=value-k8s");
k8sSource.put("ignored.properties", "key-ignored=value-ignored");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ void twoEntriesOneIsYamlButNotTaken() {
void twoEntriesBothTaken() {

Map.Entry<String, String> one = Map.entry("one", "1");
Map.Entry<String, String> application = Map.entry("application.yaml", "color: \n blue");
Map.Entry<String, String> application = Map.entry(Constants.APPLICATION_YAML, "color: \n blue");
Map<String, String> map = Map.ofEntries(one, application);

Map<String, Object> result = SourceDataEntriesProcessor.processAllEntries(map, new MockEnvironment());
Expand All @@ -127,7 +127,7 @@ void twoEntriesBothTaken() {
void threeEntriesAllTaken() {

Map.Entry<String, String> one = Map.entry("one", "1");
Map.Entry<String, String> application = Map.entry("application.properties", "color=blue");
Map.Entry<String, String> application = Map.entry(Constants.APPLICATION_PROPERTIES, "color=blue");
Map.Entry<String, String> applicationDev = Map.entry("application-dev.properties", "fit=sport");
Map<String, String> map = Map.ofEntries(one, application, applicationDev);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.springframework.cloud.kubernetes.client.config.KubernetesClientConfigMapsCache;
import org.springframework.cloud.kubernetes.client.config.KubernetesClientSecretsPropertySource;
import org.springframework.cloud.kubernetes.commons.config.ConfigUtils;
import org.springframework.cloud.kubernetes.commons.config.Constants;
import org.springframework.cloud.kubernetes.commons.config.NamedConfigMapNormalizedSource;
import org.springframework.cloud.kubernetes.commons.config.NamedSecretNormalizedSource;
import org.springframework.cloud.kubernetes.commons.config.NormalizedSource;
Expand Down Expand Up @@ -74,23 +75,23 @@ class KubernetesEnvironmentRepositoryTests {
private static final V1ConfigMapList CONFIGMAP_DEFAULT_LIST = new V1ConfigMapList()
.addItemsItem(new V1ConfigMapBuilder()
.withMetadata(new V1ObjectMetaBuilder().withName("application").withNamespace(DEFAULT_NAMESPACE).build())
.addToData("application.yaml", VALUE)
.addToData(Constants.APPLICATION_YAML, VALUE)
.build())
.addItemsItem(new V1ConfigMapBuilder()
.withMetadata(new V1ObjectMetaBuilder().withName("stores").withNamespace(DEFAULT_NAMESPACE).build())
.addToData("application.yaml", VALUE)
.addToData(Constants.APPLICATION_YAML, VALUE)
.build())
.addItemsItem(new V1ConfigMapBuilder()
.withMetadata(new V1ObjectMetaBuilder().withName("stores-dev").withNamespace(DEFAULT_NAMESPACE).build())
.addToData("application.yaml",
.addToData(Constants.APPLICATION_YAML,
"dummy:\n property:\n string1: \"a\"\n string2: \"b\"\n int2: 2\n bool2: false\n")
.build());

private static final V1ConfigMapList CONFIGMAP_DEV_LIST = new V1ConfigMapList()
.addItemsItem(new V1ConfigMapBuilder()
.withMetadata(
new V1ObjectMetaBuilder().withName("stores").withNamespace("dev").withResourceVersion("1").build())
.addToData("application.yaml", "dummy:\n property:\n string2: \"dev\"\n int2: 1\n bool2: true\n")
.addToData(Constants.APPLICATION_YAML, "dummy:\n property:\n string2: \"dev\"\n int2: 1\n bool2: true\n")
.build());

private static final V1SecretList SECRET_LIST = new V1SecretListBuilder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.junit.jupiter.api.Test;

import org.springframework.cloud.config.environment.Environment;
import org.springframework.cloud.kubernetes.commons.config.Constants;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.eq;
Expand Down Expand Up @@ -180,7 +181,7 @@ private static V1ConfigMap buildConfigMap(String name, String namespace) {
return new V1ConfigMapBuilder()
.withMetadata(
new V1ObjectMetaBuilder().withName(name).withNamespace(namespace).withResourceVersion("1").build())
.addToData("application.yaml", "dummy:\n property:\n string: \"" + name + "\"\n")
.addToData(Constants.APPLICATION_YAML, "dummy:\n property:\n string: \"" + name + "\"\n")
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
import org.springframework.mock.env.MockEnvironment;

import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.cloud.kubernetes.commons.config.Constants.APPLICATION_PROPERTIES;
import static org.springframework.cloud.kubernetes.commons.config.Constants.APPLICATION_YAML;

/**
* @author Charles Moulliard
Expand Down Expand Up @@ -84,7 +86,7 @@ void testConfigMapFromSingleApplicationProperties() {
ConfigMap configMap = new ConfigMapBuilder().withNewMetadata()
.withName(configMapName)
.endMetadata()
.addToData("application.properties", ConfigMapTestUtil.readResourceFile("application.properties"))
.addToData(APPLICATION_PROPERTIES, ConfigMapTestUtil.readResourceFile(APPLICATION_PROPERTIES))
.build();

mockClient.configMaps().inNamespace("test").resource(configMap).create();
Expand All @@ -104,7 +106,7 @@ void testConfigMapFromSingleApplicationYaml() {
ConfigMap configMap = new ConfigMapBuilder().withNewMetadata()
.withName(configMapName)
.endMetadata()
.addToData("application.yaml", ConfigMapTestUtil.readResourceFile("application.yaml"))
.addToData(APPLICATION_YAML, ConfigMapTestUtil.readResourceFile(APPLICATION_YAML))
.build();

mockClient.configMaps().inNamespace("test").resource(configMap).create();
Expand Down Expand Up @@ -144,7 +146,7 @@ void testConfigMapFromSingleInvalidPropertiesContent() {
ConfigMap configMap = new ConfigMapBuilder().withNewMetadata()
.withName(configMapName)
.endMetadata()
.addToData("application.properties", "somevalue")
.addToData(APPLICATION_PROPERTIES, "somevalue")
.build();

mockClient.configMaps().inNamespace("test").resource(configMap).create();
Expand All @@ -162,7 +164,7 @@ void testConfigMapFromSingleInvalidYamlContent() {
ConfigMap configMap = new ConfigMapBuilder().withNewMetadata()
.withName(configMapName)
.endMetadata()
.addToData("application.yaml", "somevalue")
.addToData(APPLICATION_YAML, "somevalue")
.build();

mockClient.configMaps().inNamespace("test").resource(configMap).create();
Expand All @@ -180,7 +182,7 @@ void testConfigMapFromMultipleApplicationProperties() {
ConfigMap configMap = new ConfigMapBuilder().withNewMetadata()
.withName(configMapName)
.endMetadata()
.addToData("application.properties", ConfigMapTestUtil.readResourceFile("application.properties"))
.addToData(APPLICATION_PROPERTIES, ConfigMapTestUtil.readResourceFile(APPLICATION_PROPERTIES))
.addToData("adhoc.properties", ConfigMapTestUtil.readResourceFile("adhoc.properties"))
.build();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
import org.springframework.cloud.kubernetes.commons.config.reload.ConfigReloadProperties;
import org.springframework.mock.env.MockEnvironment;

import static org.springframework.cloud.kubernetes.commons.config.Constants.APPLICATION_YAML;

/**
* @author wind57
*/
Expand Down Expand Up @@ -91,7 +93,7 @@ void testSecretDataByLabelsSecretFoundWithPropertyFile() {
.inNamespace("spring-k8s")
.resource(new SecretBuilder()
.withMetadata(new ObjectMetaBuilder().withName("my-secret").withLabels(Map.of("color", "pink")).build())
.addToData(Map.of("application.yaml", Base64.getEncoder().encodeToString("key1: value1".getBytes())))
.addToData(Map.of(APPLICATION_YAML, Base64.getEncoder().encodeToString("key1: value1".getBytes())))
.build())
.create();

Expand Down Expand Up @@ -324,7 +326,7 @@ void testConfigMapDataByNameFoundWithPropertyFile() {
client.configMaps()
.inNamespace("spring-k8s")
.resource(new ConfigMapBuilder().withMetadata(new ObjectMetaBuilder().withName("my-config-map").build())
.addToData(Map.of("application.yaml", "key1: value1"))
.addToData(Map.of(APPLICATION_YAML, "key1: value1"))
.build())
.create();

Expand Down
Loading

0 comments on commit 5f2bf71

Please sign in to comment.