From cabc55469b49a0d1c852b3437ad99f947610f3f2 Mon Sep 17 00:00:00 2001 From: Ryan Baxter Date: Mon, 12 Nov 2018 12:22:22 -0500 Subject: [PATCH] Only override native default label if config server default label is not null. Fixes #1184 (#1185) --- .../NativeEnvironmentRepositoryFactory.java | 4 +- ...ativeEnvironmentRepositoryFactoryTest.java | 51 +++++++++++++++++++ 2 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/NativeEnvironmentRepositoryFactoryTest.java diff --git a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/NativeEnvironmentRepositoryFactory.java b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/NativeEnvironmentRepositoryFactory.java index d8daa2b5..42ea7e8e 100644 --- a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/NativeEnvironmentRepositoryFactory.java +++ b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/NativeEnvironmentRepositoryFactory.java @@ -34,7 +34,9 @@ public class NativeEnvironmentRepositoryFactory implements EnvironmentRepository @Override public NativeEnvironmentRepository build(NativeEnvironmentProperties environmentProperties) { NativeEnvironmentRepository repository = new NativeEnvironmentRepository(environment, environmentProperties); - repository.setDefaultLabel(properties.getDefaultLabel()); + if(properties.getDefaultLabel() != null) { + repository.setDefaultLabel(properties.getDefaultLabel()); + } return repository; } } diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/NativeEnvironmentRepositoryFactoryTest.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/NativeEnvironmentRepositoryFactoryTest.java new file mode 100644 index 00000000..3c7ce758 --- /dev/null +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/NativeEnvironmentRepositoryFactoryTest.java @@ -0,0 +1,51 @@ +/* + * Copyright 2018 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.cloud.config.server.environment; + +import org.junit.Test; +import org.springframework.cloud.config.server.config.ConfigServerProperties; +import org.springframework.core.env.StandardEnvironment; + +import static org.junit.Assert.assertEquals; + + +/** + * @author Ryan Baxter + */ +public class NativeEnvironmentRepositoryFactoryTest { + + @Test + public void testDefaultLabel() { + ConfigServerProperties props = new ConfigServerProperties(); + props.setDefaultLabel("mylabel"); + NativeEnvironmentRepositoryFactory factory = new NativeEnvironmentRepositoryFactory(new StandardEnvironment(), props); + NativeEnvironmentProperties environmentProperties = new NativeEnvironmentProperties(); + NativeEnvironmentRepository repo = factory.build(environmentProperties); + assertEquals("mylabel", repo.getDefaultLabel()); + + factory = new NativeEnvironmentRepositoryFactory(new StandardEnvironment(), props); + environmentProperties = new NativeEnvironmentProperties(); + environmentProperties.setDefaultLabel("mynewlabel"); + repo = factory.build(environmentProperties); + assertEquals("mylabel", repo.getDefaultLabel()); + + factory = new NativeEnvironmentRepositoryFactory(new StandardEnvironment(), new ConfigServerProperties()); + environmentProperties = new NativeEnvironmentProperties(); + environmentProperties.setDefaultLabel("mynewlabel"); + repo = factory.build(environmentProperties); + assertEquals("mynewlabel", repo.getDefaultLabel()); + } +} \ No newline at end of file