Make server tests work offline

This commit is contained in:
Dave Syer
2014-10-25 18:20:19 +01:00
parent 19cd6be001
commit 09bdb001d7
20 changed files with 121 additions and 35 deletions

View File

@@ -2,6 +2,9 @@ package org.springframework.cloud.config.server;
import static org.junit.Assert.assertFalse;
import java.io.IOException;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Value;
@@ -15,13 +18,18 @@ import org.springframework.test.context.web.WebAppConfiguration;
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = ConfigServerApplication.class)
@IntegrationTest({"server.port:0", "spring.config.name:configserver"})
@IntegrationTest({"server.port:0", "spring.config.name:configserver", "spring.cloud.config.server.uri:file:./target/test-classes/config-repo"})
@WebAppConfiguration
@ActiveProfiles("test")
public class ApplicationTests {
@Value("${local.server.port}")
private int port;
@BeforeClass
public static void init() throws IOException{
ConfigServerTestUtils.prepareLocalRepo();
}
@Test
public void contextLoads() {

View File

@@ -21,16 +21,11 @@ import static org.junit.Assert.assertTrue;
import java.io.File;
import org.eclipse.jgit.transport.JschConfigSessionFactory;
import org.eclipse.jgit.transport.OpenSshConfig.Host;
import org.eclipse.jgit.transport.SshSessionFactory;
import org.eclipse.jgit.util.FileUtils;
import org.junit.Before;
import org.junit.Test;
import org.springframework.core.env.StandardEnvironment;
import org.springframework.cloud.config.Environment;
import com.jcraft.jsch.Session;
import org.springframework.core.env.StandardEnvironment;
/**
* @author Dave Syer
@@ -42,27 +37,12 @@ public class JGitEnvironmentRepositoryTests {
private JGitEnvironmentRepository repository = new JGitEnvironmentRepository(
environment);
private File basedir = new File("target/config-repo");
private File basedir = new File("target/config");
@Before
public void init() throws Exception {
SshSessionFactory.setInstance(new JschConfigSessionFactory() {
@Override
protected void configure(Host hc, Session session) {
session.setConfig("StrictHostKeyChecking", "no");
}
});
File dotGit = new File("target/test-classes/config-repo/.git");
File git = new File("target/test-classes/config-repo/git");
if (git.exists()) {
if (dotGit.exists()) {
FileUtils.delete(dotGit, FileUtils.RECURSIVE);
}
}
git.renameTo(dotGit);
repository
.setUri(environment
.resolvePlaceholders("file:./target/test-classes/config-repo"));
String uri = ConfigServerTestUtils.prepareLocalRepo();
repository.setUri(uri);
if (basedir.exists()) {
FileUtils.delete(basedir, FileUtils.RECURSIVE);
}