package integration;

import hello.Application;
import org.fluentlenium.adapter.FluentTest;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.phantomjs.PhantomJSDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.*;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import static org.assertj.core.api.Assertions.assertThat;

@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = Application.class)
@WebIntegrationTest("server.port:0")
public class GreetingTest extends FluentTest {
    @Value("${local.server.port}")
    private int port;

    private DesiredCapabilities capabilities = DesiredCapabilities.phantomjs();
    private WebDriver driver = new PhantomJSDriver(capabilities);

    @Override
    public WebDriver getDefaultDriver() {
        return driver;
    }

    @Test
    public void testGetIndex() {
        goTo("http://127.0.0.1:" + port + "/greeting?name=Sam");
        assertThat(pageSource()).contains("Hello, Sam!");

        goTo("http://127.0.0.1:" + port + "/greeting?name=Bob");
        assertThat(pageSource()).contains("Hello, Bob!");
    }
}

@@ -1029,16 +1029,17 @@
 test
-GetIndex
+Thymeleaf
 () %7B
@@ -1224,24 +1224,24 @@
 name=Bob%22);%0A
-
         asse
@@ -1291,11 +1291,316 @@
 );%0A    %7D
+%0A%0A    @Test%0A    public void testJavascript() throws InterruptedException %7B%0A        goTo(%22http://127.0.0.1:%22 + port + %22/greeting?name=Sam%22);%0A        Thread.sleep(1000); // There's probably a better way to wait for $(document).ready%0A        assertThat(pageSource()).contains(%22Hello from javascript!%22);%0A    %7D
 %0A%7D%0A

Test confirming spring boot test runner loads external JARs