Account for different base directories depending on test environment
Fixes gh-62, fixes gh-68
This commit is contained in:
@@ -1,9 +1,5 @@
|
||||
package sample;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
@@ -19,22 +15,27 @@ import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.web.WebAppConfiguration;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@SpringApplicationConfiguration(classes = Application.class)
|
||||
@IntegrationTest("server.port:0")
|
||||
import java.io.IOException;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
@RunWith ( SpringJUnit4ClassRunner.class )
|
||||
@SpringApplicationConfiguration ( classes = Application.class )
|
||||
@IntegrationTest ( "server.port:0" )
|
||||
@WebAppConfiguration
|
||||
public class ApplicationTests {
|
||||
|
||||
private static int configPort = 0;
|
||||
|
||||
@Value("${local.server.port}")
|
||||
@Value ( "${local.server.port}" )
|
||||
private int port;
|
||||
|
||||
private static ConfigurableApplicationContext server;
|
||||
|
||||
@BeforeClass
|
||||
public static void startConfigServer() throws IOException {
|
||||
String repo = ConfigServerTestUtils.prepareLocalRepo();
|
||||
String baseDir = ConfigServerTestUtils.getBaseDirectory("spring-cloud-config-sample");
|
||||
String repo = ConfigServerTestUtils.prepareLocalRepo(baseDir, "target/repos", "config-repo", "target/config");
|
||||
server = SpringApplication.run(
|
||||
org.springframework.cloud.config.server.ConfigServerApplication.class,
|
||||
"--server.port=" + configPort, "--spring.config.name=server",
|
||||
@@ -43,11 +44,11 @@ public class ApplicationTests {
|
||||
.getEmbeddedServletContainer().getPort();
|
||||
System.setProperty("config.port", "" + configPort);
|
||||
}
|
||||
|
||||
|
||||
@AfterClass
|
||||
public static void close() {
|
||||
System.clearProperty("config.port");
|
||||
if (server!=null) {
|
||||
if (server != null) {
|
||||
server.close();
|
||||
}
|
||||
}
|
||||
@@ -55,7 +56,7 @@ public class ApplicationTests {
|
||||
@Test
|
||||
public void contextLoads() {
|
||||
String foo = new TestRestTemplate().getForObject("http://localhost:" + port
|
||||
+ "/env/info.foo", String.class);
|
||||
+ "/env/info.foo", String.class);
|
||||
assertEquals("bar", foo);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user