Only override native default label if config server default label is not null. Fixes #1184 (#1185)

This commit is contained in:
Ryan Baxter
2018-11-12 12:22:22 -05:00
committed by GitHub
parent 5c609f42d9
commit cabc55469b
2 changed files with 54 additions and 1 deletions

View File

@@ -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;
}
}

View File

@@ -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());
}
}