Removed @Profile for JGitEnvironmentRepository (so it's the default if
no active profile is set). More tests for Subversion Support (based on Git tests).
This commit is contained in:
@@ -42,7 +42,6 @@ public class ConfigServerConfiguration {
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@Profile({ "!native", "!subversion" })
|
||||
protected static class GitRepositoryConfiguration {
|
||||
|
||||
@Autowired
|
||||
|
||||
@@ -17,6 +17,7 @@ package org.springframework.cloud.config.server;
|
||||
|
||||
import org.eclipse.jgit.util.FileUtils;
|
||||
import org.springframework.util.FileSystemUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@@ -73,7 +74,7 @@ public class ConfigServerTestUtils {
|
||||
}
|
||||
local.mkdirs();
|
||||
FileSystemUtils.copyRecursively(sourceDirFile, local);
|
||||
return "file:///" + local.getAbsolutePath();
|
||||
return StringUtils.cleanPath("file:///" + local.getAbsolutePath());
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.cloud.config.Environment;
|
||||
import org.springframework.core.env.ConfigurableEnvironment;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.tmatesoft.svn.core.SVNException;
|
||||
import org.tmatesoft.svn.core.SVNURL;
|
||||
import org.tmatesoft.svn.core.internal.wc.DefaultSVNAuthenticationManager;
|
||||
@@ -91,7 +92,17 @@ public class SVNKitEnvironmentRepository extends AbstractSCMEnvironmentRepositor
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
Assert
|
||||
.state(getUri() != null,
|
||||
"You need to configure a uri for the subversion repository (e.g. 'http://example.com/svn/'");
|
||||
"You need to configure a uri for the subversion repository (e.g. 'http://example.com/svn/')");
|
||||
resolveRelativeFileUri();
|
||||
}
|
||||
|
||||
private void resolveRelativeFileUri() {
|
||||
if (getUri().startsWith("file:///./")) {
|
||||
String path = getUri().substring(8);
|
||||
String absolutePath = new File(path).getAbsolutePath();
|
||||
setUri("file:///" + StringUtils.cleanPath(absolutePath));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public SVNKitEnvironmentRepository(ConfigurableEnvironment environment) {
|
||||
|
||||
@@ -0,0 +1,120 @@
|
||||
/*
|
||||
* Copyright 2013-2014 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 java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
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;
|
||||
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;
|
||||
import org.tmatesoft.svn.core.wc2.SvnCommit;
|
||||
import org.tmatesoft.svn.core.wc2.SvnOperationFactory;
|
||||
import org.tmatesoft.svn.core.wc2.SvnTarget;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* @author Michael Prankl
|
||||
*
|
||||
*/
|
||||
public class SVNKitEnvironmentRepositoryIntegrationTests {
|
||||
|
||||
private ConfigurableApplicationContext context;
|
||||
|
||||
private File workingDir;
|
||||
|
||||
@Before
|
||||
public void init() {
|
||||
workingDir = new File("target/repos/svn-config-repo-update");
|
||||
if (workingDir.exists()) {
|
||||
FileSystemUtils.deleteRecursively(workingDir);
|
||||
}
|
||||
}
|
||||
|
||||
@After
|
||||
public void close() {
|
||||
if (context != null) {
|
||||
context.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void vanilla() 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", "trunk");
|
||||
Environment environment = repository.findOne("bar", "staging", "trunk");
|
||||
assertEquals(2, environment.getPropertySources().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void update() 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", "trunk");
|
||||
Environment environment = repository.findOne("bar", "staging", "trunk");
|
||||
assertEquals("bar", environment.getPropertySources().get(0).getSource().get("foo"));
|
||||
updateRepoForUpdate(uri);
|
||||
environment = repository.findOne("bar", "staging", "trunk");
|
||||
assertEquals("foo", environment.getPropertySources().get(0).getSource().get("foo"));
|
||||
}
|
||||
|
||||
private void updateRepoForUpdate(String uri) throws SVNException, FileNotFoundException,
|
||||
IOException {
|
||||
SvnOperationFactory svnFactory = new SvnOperationFactory();
|
||||
final SvnCheckout checkout = svnFactory.createCheckout();
|
||||
checkout.setSource(SvnTarget.fromURL(SVNURL.parseURIEncoded(uri)));
|
||||
checkout.setSingleTarget(SvnTarget.fromFile(workingDir));
|
||||
checkout.run();
|
||||
|
||||
// update bar.properties
|
||||
File barProps = new File(workingDir, "trunk/bar.properties");
|
||||
StreamUtils.copy("foo: foo", Charset.defaultCharset(), new FileOutputStream(barProps));
|
||||
// commit to repo
|
||||
SvnCommit svnCommit = svnFactory.createCommit();
|
||||
svnCommit.setCommitMessage("update bar.properties");
|
||||
svnCommit.setSingleTarget(SvnTarget.fromFile(barProps));
|
||||
svnCommit.run();
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@Import({ PropertyPlaceholderAutoConfiguration.class, ConfigServerConfiguration.class })
|
||||
protected static class TestConfiguration {
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
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.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;
|
||||
import org.springframework.test.context.ActiveProfiles;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.web.WebAppConfiguration;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@SpringApplicationConfiguration(classes = ConfigServerApplication.class)
|
||||
@IntegrationTest({"server.port:0", "spring.config.name:configserver", "spring.cloud.config.server.svn.uri:file:///./target/repos/svn-config-repo"})
|
||||
@WebAppConfiguration
|
||||
@ActiveProfiles("subversion")
|
||||
public class SubversionConfigServerIntegrationTests {
|
||||
|
||||
@Value("${local.server.port}")
|
||||
private int port;
|
||||
|
||||
@BeforeClass
|
||||
public static void init() throws Exception {
|
||||
ConfigServerTestUtils.prepareLocalSvnRepo("src/test/resources/svn-config-repo",
|
||||
"target/repos/svn-config-repo");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void contextLoads() {
|
||||
Environment environment = new TestRestTemplate().getForObject("http://localhost:"
|
||||
+ port + "/foo/development/", Environment.class);
|
||||
assertFalse(environment.getPropertySources().isEmpty());
|
||||
assertEquals("overrides", environment.getPropertySources().get(0).getName());
|
||||
assertEquals("{spring.cloud.config.enabled=true}", environment
|
||||
.getPropertySources().get(0).getSource().toString());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
spring:
|
||||
cloud:
|
||||
config:
|
||||
server:
|
||||
defaultLabel: trunk
|
||||
overrides:
|
||||
spring:
|
||||
cloud:
|
||||
config:
|
||||
enabled: true
|
||||
Reference in New Issue
Block a user