Use 'trunk' as default label for Subversion repositories
This commit adds a getDefaultLabel() method to the EnvironmentRepository interface. SvnKitEnvironmentRepository returns 'trunk', while all other implementations return 'master'. ConfigServerMvcConfiguration and ConfigServerBootstrapConfiguration will utilize labels configured on the client and server before falling back to the repository's default label. Resolves #107
This commit is contained in:
@@ -27,7 +27,7 @@ import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
*
|
||||
* @author Roy Clarkson
|
||||
*/
|
||||
public class EnvironmentControllerIntegrationTests {
|
||||
|
||||
@@ -36,6 +36,7 @@ public class EnvironmentControllerIntegrationTests {
|
||||
|
||||
@Before
|
||||
public void init() {
|
||||
Mockito.when(repository.getDefaultLabel()).thenReturn("master");
|
||||
mvc = MockMvcBuilders.standaloneSetup(
|
||||
new EnvironmentController(repository, new EncryptionController()))
|
||||
.build();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2013-2014 the original author or authors.
|
||||
* Copyright 2013-2015 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.
|
||||
@@ -15,18 +15,17 @@
|
||||
*/
|
||||
package org.springframework.cloud.config.server;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import org.springframework.cloud.config.environment.Environment;
|
||||
import org.springframework.cloud.config.environment.PropertySource;
|
||||
import org.springframework.http.MediaType;
|
||||
@@ -35,9 +34,12 @@ import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
|
||||
import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
|
||||
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
*
|
||||
* @author Roy Clarkson
|
||||
*/
|
||||
public class EnvironmentControllerTests {
|
||||
|
||||
@@ -46,11 +48,16 @@ public class EnvironmentControllerTests {
|
||||
|
||||
private EnvironmentRepository repository = Mockito.mock(EnvironmentRepository.class);
|
||||
|
||||
private EnvironmentController controller = new EnvironmentController(repository,
|
||||
new EncryptionController());
|
||||
private EnvironmentController controller;
|
||||
|
||||
private Environment environment = new Environment("foo", "master");
|
||||
|
||||
@Before
|
||||
public void init() {
|
||||
Mockito.when(repository.getDefaultLabel()).thenReturn("master");
|
||||
this.controller = new EnvironmentController(repository, new EncryptionController());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void vanillaYaml() throws Exception {
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
@@ -223,7 +230,7 @@ public class EnvironmentControllerTests {
|
||||
map.put("a.b.c", "d");
|
||||
environment.add(new PropertySource("one", map));
|
||||
Mockito.when(repository.findOne("foo", "bar", "master")).thenReturn(environment);
|
||||
assertEquals("{foo=bar}", controller.master("foo", "bar").getPropertySources()
|
||||
assertEquals("{foo=bar}", controller.defaultLabel("foo", "bar").getPropertySources()
|
||||
.get(0).getSource().toString());
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2013-2014 the original author or authors.
|
||||
* Copyright 2013-2015 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.
|
||||
@@ -16,9 +16,6 @@
|
||||
|
||||
package org.springframework.cloud.config.server;
|
||||
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
@@ -29,6 +26,7 @@ import org.eclipse.jgit.util.FileUtils;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration;
|
||||
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||
import org.springframework.cloud.config.environment.Environment;
|
||||
@@ -38,9 +36,12 @@ import org.springframework.context.annotation.Import;
|
||||
import org.springframework.util.ResourceUtils;
|
||||
import org.springframework.util.StreamUtils;
|
||||
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
*
|
||||
* @author Roy Clarkson
|
||||
*/
|
||||
public class JGitEnvironmentRepositoryIntegrationTests {
|
||||
|
||||
@@ -112,6 +113,24 @@ public class JGitEnvironmentRepositoryIntegrationTests {
|
||||
assertEquals(2, environment.getPropertySources().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void defaultLabel() throws Exception {
|
||||
String uri = ConfigServerTestUtils.prepareLocalRepo();
|
||||
context = new SpringApplicationBuilder(TestConfiguration.class).web(false)
|
||||
.properties("spring.cloud.config.server.git.uri:" + uri).run();
|
||||
EnvironmentRepository repository = context.getBean(EnvironmentRepository.class);
|
||||
assertEquals("master", repository.getDefaultLabel());
|
||||
}
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
public void invalidLabel() throws IOException {
|
||||
String uri = ConfigServerTestUtils.prepareLocalRepo();
|
||||
context = new SpringApplicationBuilder(TestConfiguration.class).web(false)
|
||||
.properties("spring.cloud.config.server.git.uri:" + uri).run();
|
||||
EnvironmentRepository repository = context.getBean(EnvironmentRepository.class);
|
||||
repository.findOne("bar", "staging", "unknownlabel");
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@Import({ PropertyPlaceholderAutoConfiguration.class, ConfigServerConfiguration.class })
|
||||
protected static class TestConfiguration {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2013-2014 the original author or authors.
|
||||
* Copyright 2013-2015 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.
|
||||
@@ -25,17 +25,6 @@ import java.nio.charset.Charset;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration;
|
||||
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||
import org.springframework.cloud.config.environment.Environment;
|
||||
import org.springframework.cloud.config.server.ConfigServerConfiguration;
|
||||
import org.springframework.cloud.config.server.ConfigServerTestUtils;
|
||||
import org.springframework.cloud.config.server.EnvironmentRepository;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.util.FileSystemUtils;
|
||||
import org.springframework.util.StreamUtils;
|
||||
import org.tmatesoft.svn.core.SVNException;
|
||||
import org.tmatesoft.svn.core.SVNURL;
|
||||
import org.tmatesoft.svn.core.wc2.SvnCheckout;
|
||||
@@ -43,11 +32,20 @@ import org.tmatesoft.svn.core.wc2.SvnCommit;
|
||||
import org.tmatesoft.svn.core.wc2.SvnOperationFactory;
|
||||
import org.tmatesoft.svn.core.wc2.SvnTarget;
|
||||
|
||||
import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration;
|
||||
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||
import org.springframework.cloud.config.environment.Environment;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.util.FileSystemUtils;
|
||||
import org.springframework.util.StreamUtils;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* @author Michael Prankl
|
||||
*
|
||||
* @author Roy Clarkson
|
||||
*/
|
||||
public class SVNKitEnvironmentRepositoryIntegrationTests {
|
||||
|
||||
@@ -120,6 +118,30 @@ public class SVNKitEnvironmentRepositoryIntegrationTests {
|
||||
svnCommit.run();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void defaultLabel() throws Exception {
|
||||
String uri = ConfigServerTestUtils.prepareLocalSvnRepo(
|
||||
"src/test/resources/svn-config-repo", "target/config");
|
||||
context = new SpringApplicationBuilder(TestConfiguration.class).web(false)
|
||||
.profiles("subversion")
|
||||
.run("--spring.cloud.config.server.svn.uri=" + uri);
|
||||
EnvironmentRepository repository = context.getBean(EnvironmentRepository.class);
|
||||
assertEquals("trunk", repository.getDefaultLabel());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void invalidLabel() throws Exception {
|
||||
String uri = ConfigServerTestUtils.prepareLocalSvnRepo(
|
||||
"src/test/resources/svn-config-repo", "target/config");
|
||||
context = new SpringApplicationBuilder(TestConfiguration.class).web(false)
|
||||
.profiles("subversion")
|
||||
.run("--spring.cloud.config.server.svn.uri=" + uri);
|
||||
EnvironmentRepository repository = context.getBean(EnvironmentRepository.class);
|
||||
repository.findOne("bar", "staging", "unknownlabel");
|
||||
Environment environment = repository.findOne("bar", "staging", "unknownlabel");
|
||||
assertEquals(0, environment.getPropertySources().size());
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@Import({ PropertyPlaceholderAutoConfiguration.class, ConfigServerConfiguration.class })
|
||||
protected static class TestConfiguration {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2013-2014 the original author or authors.
|
||||
* Copyright 2013-2015 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.
|
||||
@@ -21,17 +21,16 @@ import java.io.File;
|
||||
import org.eclipse.jgit.util.FileUtils;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.cloud.config.environment.Environment;
|
||||
import org.springframework.cloud.config.server.ConfigServerTestUtils;
|
||||
import org.springframework.cloud.config.server.SvnKitEnvironmentRepository;
|
||||
import org.springframework.core.env.StandardEnvironment;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* @author Michael Prankl
|
||||
*
|
||||
* @author Roy Clarkson
|
||||
*/
|
||||
public class SVNKitEnvironmentRepositoryTests {
|
||||
|
||||
@@ -92,4 +91,10 @@ public class SVNKitEnvironmentRepositoryTests {
|
||||
.contains("application.yml"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void invalidLabel() {
|
||||
Environment environment = repository.findOne("bar", "staging", "unknownlabel");
|
||||
assertEquals(0, environment.getPropertySources().size());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,15 +1,31 @@
|
||||
/*
|
||||
* Copyright 2013-2015 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;
|
||||
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.test.IntegrationTest;
|
||||
import org.springframework.boot.test.SpringApplicationConfiguration;
|
||||
import org.springframework.boot.test.TestRestTemplate;
|
||||
import org.springframework.cloud.config.environment.Environment;
|
||||
import org.springframework.cloud.config.server.ConfigServerApplication;
|
||||
import org.springframework.cloud.config.server.ConfigServerTestUtils;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.test.context.ActiveProfiles;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.web.WebAppConfiguration;
|
||||
@@ -17,6 +33,11 @@ import org.springframework.test.context.web.WebAppConfiguration;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
|
||||
/**
|
||||
* @author Michael Prankl
|
||||
* @author Dave Syer
|
||||
* @author Roy Clarkson
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@SpringApplicationConfiguration(classes = ConfigServerApplication.class)
|
||||
@IntegrationTest({ "server.port:0", "spring.config.name:configserver",
|
||||
@@ -28,6 +49,9 @@ public class SubversionConfigServerIntegrationTests {
|
||||
@Value("${local.server.port}")
|
||||
private int port;
|
||||
|
||||
@Autowired
|
||||
private ApplicationContext context;
|
||||
|
||||
@BeforeClass
|
||||
public static void init() throws Exception {
|
||||
ConfigServerTestUtils.prepareLocalSvnRepo("src/test/resources/svn-config-repo",
|
||||
@@ -44,4 +68,10 @@ public class SubversionConfigServerIntegrationTests {
|
||||
.getPropertySources().get(0).getSource().toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void defaultLabel() throws Exception {
|
||||
EnvironmentRepository repository = context.getBean(EnvironmentRepository.class);
|
||||
assertEquals("trunk", repository.getDefaultLabel());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user