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

@@ -1,8 +1,9 @@
package sample;
import static org.junit.Assert.assertEquals;
import java.io.IOException;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -12,6 +13,7 @@ import org.springframework.boot.context.embedded.EmbeddedWebApplicationContext;
import org.springframework.boot.test.IntegrationTest;
import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.boot.test.TestRestTemplate;
import org.springframework.cloud.config.server.ConfigServerTestUtils;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;
@@ -28,22 +30,25 @@ public class ApplicationTests {
private int port;
@BeforeClass
public static void startConfigServer() {
public static void startConfigServer() throws IOException {
String repo = ConfigServerTestUtils.prepareLocalRepo();
ConfigurableApplicationContext context = SpringApplication.run(
org.springframework.cloud.config.server.ConfigServerApplication.class,
"--server.port=" + configPort, "--spring.config.name=server");
configPort = ((EmbeddedWebApplicationContext) context).getEmbeddedServletContainer().getPort();
"--server.port=" + configPort, "--spring.config.name=server",
"--spring.cloud.config.server.uri=" + repo);
configPort = ((EmbeddedWebApplicationContext) context)
.getEmbeddedServletContainer().getPort();
System.setProperty("config.port", "" + configPort);
}
@Test
public void contextLoads() {
String foo = new TestRestTemplate().getForObject("http://localhost:" + port
+ "/env/foo", String.class);
+ "/env/info.foo", String.class);
assertEquals("bar", foo);
}
public static void main(String[] args) {
public static void main(String[] args) throws IOException {
configPort = 8888;
startConfigServer();
SpringApplication.run(Application.class, args);

View File

@@ -0,0 +1,3 @@
info:
foo: bar
raw: true

View File

@@ -0,0 +1 @@
foo: bar

View File

@@ -0,0 +1,2 @@
7df4a26d5437d9d4090cd5809967f870444cde8f not-for-merge branch 'raw' of dsyer@localhost:/home/dsyer/dev/platform/config/spring-platform-config-server/target/test-classes/config-repo
7df4a26d5437d9d4090cd5809967f870444cde8f not-for-merge tag 'foo' of dsyer@localhost:/home/dsyer/dev/platform/config/spring-platform-config-server/target/test-classes/config-repo

View File

@@ -0,0 +1 @@
ref: refs/heads/raw

View File

@@ -0,0 +1,5 @@
[core]
repositoryformatversion = 0
filemode = true
logallrefupdates = true
[branch "raw"]

View File

@@ -0,0 +1,3 @@
1 1
7df4a26d5437d9d4090cd5809967f870444cde8f 9f01fb972bc9617e4ea59f5c8ee3ceb5ff515cd0 9f01fb972bc9617e4ea59f5c8ee3ceb5ff515cd0
1

View File

@@ -0,0 +1 @@
0000000000000000000000000000000000000000 7df4a26d5437d9d4090cd5809967f870444cde8f Dave Syer <dsyer@gopivotal.com> 1406860717 -0700

View File

@@ -0,0 +1 @@
0000000000000000000000000000000000000000 9f01fb972bc9617e4ea59f5c8ee3ceb5ff515cd0 Dave Syer <dsyer@gopivotal.com> 1406860776 -0700 branch: Created from 9f01fb972bc9617e4ea59f5c8ee3ceb5ff515cd0

View File

@@ -0,0 +1 @@
0000000000000000000000000000000000000000 7df4a26d5437d9d4090cd5809967f870444cde8f Dave Syer <dsyer@gopivotal.com> 1406860717 -0700

View File

@@ -0,0 +1 @@
9f01fb972bc9617e4ea59f5c8ee3ceb5ff515cd0

View File

@@ -0,0 +1 @@
7df4a26d5437d9d4090cd5809967f870444cde8f

View File

@@ -0,0 +1 @@
7df4a26d5437d9d4090cd5809967f870444cde8f