formatting corrections on test-container tests

This commit is contained in:
Bahtiyar Kaba 2018-06-14 14:55:32 +03:00 committed by José Carlos Valero Sánchez
parent 4931f31d91
commit 8fd641b074
3 changed files with 27 additions and 14 deletions

View File

@ -13,17 +13,22 @@ import org.junit.Test;
import org.testcontainers.containers.DockerComposeContainer;
public class DockerComposeContainerTests {
@ClassRule
public static DockerComposeContainer compose = new DockerComposeContainer(new File("src/test/resources/test-compose.yml"))
.withExposedService("simpleWebServer_1", 80);
@ClassRule
public static DockerComposeContainer compose =
new DockerComposeContainer(
new File("src/test/resources/test-compose.yml"))
.withExposedService("simpleWebServer_1", 80);
@Test
public void when() throws Exception {
String address ="http://" + compose.getServiceHost("simpleWebServer_1", 80)+ ":"+ compose.getServicePort("simpleWebServer_1", 80);
public void givenSimpleWebServerContainer_whenGetReuqest_thenReturnsResponse()
throws Exception {
String address = "http://" + compose.getServiceHost("simpleWebServer_1", 80)
+ ":" + compose.getServicePort("simpleWebServer_1", 80);
String response = simpleGetRequest(address);
assertEquals(response, "Hello World!");
}
private String simpleGetRequest(String address) throws Exception {
URL url = new URL(address);
HttpURLConnection con = (HttpURLConnection) url.openConnection();

View File

@ -15,15 +15,20 @@ import org.testcontainers.containers.GenericContainer;
@Testable
public class GenericContainerTests {
@ClassRule
public static GenericContainer simpleWebServer = new GenericContainer("alpine:3.2")
public static GenericContainer simpleWebServer =
new GenericContainer("alpine:3.2")
.withExposedPorts(80)
.withCommand("/bin/sh", "-c", "while true; do echo "
+ "\"HTTP/1.1 200 OK\n\nHello World!\" | nc -l -p 80; done");
.withCommand("/bin/sh", "-c", "while true; do echo "
+ "\"HTTP/1.1 200 OK\n\nHello World!\" | nc -l -p 80; done");
@Test
public void givenSimpleWebServerContainer_whenGetReuqest_thenReturnsResponse() throws Exception {
String address = "http://" + simpleWebServer.getContainerIpAddress() + ":" + simpleWebServer.getMappedPort(80);
public void givenSimpleWebServerContainer_whenGetReuqest_thenReturnsResponse()
throws Exception {
String address = "http://"
+ simpleWebServer.getContainerIpAddress()
+ ":" + simpleWebServer.getMappedPort(80);
String response = simpleGetRequest(address);
assertEquals(response, "Hello World!");
}
@ -32,7 +37,8 @@ public class GenericContainerTests {
HttpURLConnection con = (HttpURLConnection) url.openConnection();
con.setRequestMethod("GET");
BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
BufferedReader in = new BufferedReader(
new InputStreamReader(con.getInputStream()));
String inputLine;
StringBuffer content = new StringBuffer();
while ((inputLine = in.readLine()) != null) {

View File

@ -14,7 +14,9 @@ import org.testcontainers.containers.GenericContainer;
public class WebDriverContainerTests {
@Rule
public BrowserWebDriverContainer chrome = new BrowserWebDriverContainer().withDesiredCapabilities(DesiredCapabilities.chrome());
public BrowserWebDriverContainer chrome
= new BrowserWebDriverContainer()
.withDesiredCapabilities(DesiredCapabilities.chrome());
@Test
public void whenNavigatedToPage_thenHeadingIsInThePage() {