diff --git a/spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/KubernetesClientConfigMapPropertySourceLocatorTests.java b/spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/KubernetesClientConfigMapPropertySourceLocatorTests.java index c668480e..b4e6031d 100644 --- a/spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/KubernetesClientConfigMapPropertySourceLocatorTests.java +++ b/spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/KubernetesClientConfigMapPropertySourceLocatorTests.java @@ -16,7 +16,7 @@ package org.springframework.cloud.kubernetes.client.config; -import java.util.ArrayList; +import java.util.Collections; import java.util.List; import com.github.tomakehurst.wiremock.WireMockServer; @@ -95,7 +95,7 @@ class KubernetesClientConfigMapPropertySourceLocatorTests { configMapConfigProperties.setName("bootstrap-640"); KubernetesClientProperties kubernetesClientProperties = new KubernetesClientProperties(); kubernetesClientProperties.setNamespace("default"); - PropertySource propertySource = new KubernetesClientConfigMapPropertySourceLocator(api, + PropertySource propertySource = new KubernetesClientConfigMapPropertySourceLocator(api, configMapConfigProperties, kubernetesClientProperties).locate(new MockEnvironment()); assertThat(propertySource.containsProperty("spring.cloud.kubernetes.configuration.watcher.refreshDelay")) .isTrue(); @@ -108,15 +108,14 @@ class KubernetesClientConfigMapPropertySourceLocatorTests { .willReturn(aResponse().withStatus(200).withBody(new JSON().serialize(PROPERTIES_CONFIGMAP_LIST)))); ConfigMapConfigProperties configMapConfigProperties = new ConfigMapConfigProperties(); configMapConfigProperties.setName("fake-name"); - ConfigMapConfigProperties.Source source1 = new ConfigMapConfigProperties.Source(); - source1.setName("bootstrap-640"); - source1.setNamespace("default"); - List sources = new ArrayList<>(); - sources.add(source1); + ConfigMapConfigProperties.Source source = new ConfigMapConfigProperties.Source(); + source.setName("bootstrap-640"); + source.setNamespace("default"); + List sources = Collections.singletonList(source); configMapConfigProperties.setSources(sources); KubernetesClientProperties kubernetesClientProperties = new KubernetesClientProperties(); kubernetesClientProperties.setNamespace("dev"); - PropertySource propertySource = new KubernetesClientConfigMapPropertySourceLocator(api, + PropertySource propertySource = new KubernetesClientConfigMapPropertySourceLocator(api, configMapConfigProperties, kubernetesClientProperties).locate(new MockEnvironment()); assertThat(propertySource.containsProperty("spring.cloud.kubernetes.configuration.watcher.refreshDelay")) .isTrue(); diff --git a/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/config/ConfigMapConfigProperties.java b/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/config/ConfigMapConfigProperties.java index 29577822..e8755fde 100644 --- a/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/config/ConfigMapConfigProperties.java +++ b/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/config/ConfigMapConfigProperties.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2019 the original author or authors. + * Copyright 2013-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,6 +18,7 @@ package org.springframework.cloud.kubernetes.commons.config; import java.util.Collections; import java.util.List; +import java.util.Objects; import java.util.stream.Collectors; import org.springframework.boot.context.properties.ConfigurationProperties; @@ -132,6 +133,23 @@ public class ConfigMapConfigProperties extends AbstractConfigProperties { return new NormalizedSource(normalizedName, normalizedNamespace); } + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + Source other = (Source) o; + return Objects.equals(this.name, other.name) && Objects.equals(this.namespace, other.namespace); + } + + @Override + public int hashCode() { + return Objects.hash(name, namespace); + } + } public static class NormalizedSource { @@ -158,6 +176,23 @@ public class ConfigMapConfigProperties extends AbstractConfigProperties { return "{ config-map name : '" + name + "', namespace : '" + namespace + "' }"; } + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + NormalizedSource other = (NormalizedSource) o; + return Objects.equals(this.name, other.name) && Objects.equals(this.namespace, other.namespace); + } + + @Override + public int hashCode() { + return Objects.hash(name, namespace); + } + } } diff --git a/spring-cloud-kubernetes-fabric8-config/src/test/java/org/springframework/cloud/kubernetes/fabric8/config/MultipleConfigMapsTests.java b/spring-cloud-kubernetes-fabric8-config/src/test/java/org/springframework/cloud/kubernetes/fabric8/config/MultipleConfigMapsTests.java index ae067c16..d0cdda56 100644 --- a/spring-cloud-kubernetes-fabric8-config/src/test/java/org/springframework/cloud/kubernetes/fabric8/config/MultipleConfigMapsTests.java +++ b/spring-cloud-kubernetes-fabric8-config/src/test/java/org/springframework/cloud/kubernetes/fabric8/config/MultipleConfigMapsTests.java @@ -85,7 +85,7 @@ public class MultipleConfigMapsTests { .addToData(data).done(); } - // the last confimap defined in 'multiplecms.yml' has the highest priority, so + // the last configmap defined in 'multiplecms.yml' has the highest priority, so // the common property defined in all configmaps is taken from the last one defined @Test public void testCommonMessage() {