Make server tests work offline
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
info:
|
||||
foo: bar
|
||||
raw: true
|
||||
@@ -0,0 +1 @@
|
||||
foo: bar
|
||||
@@ -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
|
||||
@@ -0,0 +1 @@
|
||||
ref: refs/heads/raw
|
||||
@@ -0,0 +1,5 @@
|
||||
[core]
|
||||
repositoryformatversion = 0
|
||||
filemode = true
|
||||
logallrefupdates = true
|
||||
[branch "raw"]
|
||||
@@ -0,0 +1,3 @@
|
||||
1 1
|
||||
7df4a26d5437d9d4090cd5809967f870444cde8f 9f01fb972bc9617e4ea59f5c8ee3ceb5ff515cd0 9f01fb972bc9617e4ea59f5c8ee3ceb5ff515cd0
|
||||
1
|
||||
Binary file not shown.
@@ -0,0 +1 @@
|
||||
0000000000000000000000000000000000000000 7df4a26d5437d9d4090cd5809967f870444cde8f Dave Syer <dsyer@gopivotal.com> 1406860717 -0700
|
||||
@@ -0,0 +1 @@
|
||||
0000000000000000000000000000000000000000 9f01fb972bc9617e4ea59f5c8ee3ceb5ff515cd0 Dave Syer <dsyer@gopivotal.com> 1406860776 -0700 branch: Created from 9f01fb972bc9617e4ea59f5c8ee3ceb5ff515cd0
|
||||
@@ -0,0 +1 @@
|
||||
0000000000000000000000000000000000000000 7df4a26d5437d9d4090cd5809967f870444cde8f Dave Syer <dsyer@gopivotal.com> 1406860717 -0700
|
||||
Binary file not shown.
Binary file not shown.
@@ -0,0 +1 @@
|
||||
9f01fb972bc9617e4ea59f5c8ee3ceb5ff515cd0
|
||||
@@ -0,0 +1 @@
|
||||
7df4a26d5437d9d4090cd5809967f870444cde8f
|
||||
@@ -0,0 +1 @@
|
||||
7df4a26d5437d9d4090cd5809967f870444cde8f
|
||||
Reference in New Issue
Block a user