// Path: keycloak-dropwizard-bearermodule/src/test/java/de/ahus1/lottery/adapter/dropwizard/pages/StartPage.java
// public class StartPage extends Page {
// 
//     @Drone
//     private WebDriver browser;
// 
//     @FindBy(name = "date")
//     private WebElement fieldDate;
// 
//     @FindBy(name = "draw")
//     private WebElement buttonDraw;
// 
//     @Override
//     public void verify() {
//         assertThat(browser.getTitle()).isEqualTo("Lottery Calculator");
//     }
// 
//     public static LoginPage<StartPage> openWithoutLogin(WebDriver webClient, URL url) {
//         webClient.get(url.toString());
//         if (webClient.getCurrentUrl().equals(url.toString())) {
//             // if we end up at the target page, the browser was still logged in
//             webClient.navigate()
//                     .to("http://localhost:8080/auth/realms/test/protocol/openid-connect/logout?redirect_uri=" + url);
//         }
//         LoginPage<StartPage> loginPage = Page.createPage(LoginPage.class, webClient);
//         loginPage.setReturnPage(StartPage.class);
//         return loginPage;
//     }
// 
//     public DrawPage draw(LocalDate date) {
//         fieldDate.sendKeys(date.toString());
//         buttonDraw.click();
//         return createPage(DrawPage.class);
//     }
// }
// 
// Path: keycloak-dropwizard-bearermodule/src/test/java/de/ahus1/lottery/adapter/dropwizard/pages/WhoamiPage.java
// public class WhoamiPage extends Page {
// 
//     @Drone
//     private WebDriver browser;
// 
//     @Override
//     public void verify() {
//         assertThat(browser.getTitle()).isEqualTo("Who Am I");
//     }
// 
//     public static LoginPage<WhoamiPage> openWithoutLogin(WebDriver webClient, URL url) {
//         webClient.get(url.toString());
//         LoginPage<WhoamiPage> loginPage = Page.createPage(LoginPage.class, webClient);
//         loginPage.setReturnPage(WhoamiPage.class);
//         return loginPage;
//     }
// 
// }
// 
// Path: keycloak-dropwizard-bearermodule/src/test/java/de/ahus1/lottery/adapter/dropwizard/state/DrawResourceState.java
// public class DrawResourceState {
//     private final URI baseUrl;
//     private Response response;
//     private String accessToken;
// 
//     public DrawResourceState(URI baseUrl) {
//         this.baseUrl = baseUrl;
//     }
// 
//     public DrawResourceState givenNoToken() {
//         accessToken = null;
//         return this;
//     }
// 
//     public DrawResourceState givenToken(String accessToken) {
//         this.accessToken = accessToken;
//         return this;
//     }
// 
//     public DrawResourceState whenOpened() {
//         Client client = ClientBuilder.newClient();
//         client.property(ClientProperties.FOLLOW_REDIRECTS, false);
//         WebTarget target = client.target(baseUrl).path("/draw");
//         DrawRequest request = new DrawRequest();
//         request.setDate(LocalDate.parse("2015-01-01"));
//         Invocation.Builder builder = target.request();
//         if (accessToken != null) {
//             builder.header("Authorization", "Bearer " + accessToken);
//         }
//         response = builder.post(Entity.entity(request, MediaType.APPLICATION_JSON_TYPE));
//         return this;
//     }
// 
//     public void thenAccessDenied() {
//         assertThat(response.getStatusInfo()).isEqualTo(Response.Status.UNAUTHORIZED);
//     }
// 
//     public void thenForbidden() {
//         assertThat(response.getStatusInfo()).isEqualTo(Response.Status.FORBIDDEN);
//     }
// 
//     public void thenUnauthorized() {
//         assertThat(response.getStatusInfo()).isEqualTo(Response.Status.UNAUTHORIZED);
//     }
// 
//     public void thenRedirectedToLoginScreen() {
//         assertThat(response.getLocation().getPath()).startsWith("/auth/realms");
//     }
// 
// }


import de.ahus1.lottery.adapter.dropwizard.pages.StartPage;
import de.ahus1.lottery.adapter.dropwizard.pages.WhoamiPage;
import de.ahus1.lottery.adapter.dropwizard.state.DrawResourceState;
import io.dropwizard.testing.junit.DropwizardAppRule;
import org.jboss.arquillian.drone.api.annotation.Drone;
import org.jboss.arquillian.junit.Arquillian;
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.openqa.selenium.WebDriver;
import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.time.LocalDate;
package de.ahus1.lottery.adapter.dropwizard;



@RunWith(Arquillian.class)
public class LotteryApplicationTestWithCookieStore {

    @Drone
    private WebDriver browser;

    @ClassRule
    public static final DropwizardAppRule<LotteryConfiguration> RULE =
            new DropwizardAppRule<>(LotteryApplication.class,
                    getConfig()
            );

    private static String getConfig() {
// Path: keycloak-dropwizard-bearermodule/src/test/java/de/ahus1/lottery/adapter/dropwizard/pages/StartPage.java
// public class StartPage extends Page {
// 
//     @Drone
//     private WebDriver browser;
// 
//     @FindBy(name = "date")
//     private WebElement fieldDate;
// 
//     @FindBy(name = "draw")
//     private WebElement buttonDraw;
// 
//     @Override
//     public void verify() {
//         assertThat(browser.getTitle()).isEqualTo("Lottery Calculator");
//     }
// 
//     public static LoginPage<StartPage> openWithoutLogin(WebDriver webClient, URL url) {
//         webClient.get(url.toString());
//         if (webClient.getCurrentUrl().equals(url.toString())) {
//             // if we end up at the target page, the browser was still logged in
//             webClient.navigate()
//                     .to("http://localhost:8080/auth/realms/test/protocol/openid-connect/logout?redirect_uri=" + url);
//         }
//         LoginPage<StartPage> loginPage = Page.createPage(LoginPage.class, webClient);
//         loginPage.setReturnPage(StartPage.class);
//         return loginPage;
//     }
// 
//     public DrawPage draw(LocalDate date) {
//         fieldDate.sendKeys(date.toString());
//         buttonDraw.click();
//         return createPage(DrawPage.class);
//     }
// }
// 
// Path: keycloak-dropwizard-bearermodule/src/test/java/de/ahus1/lottery/adapter/dropwizard/pages/WhoamiPage.java
// public class WhoamiPage extends Page {
// 
//     @Drone
//     private WebDriver browser;
// 
//     @Override
//     public void verify() {
//         assertThat(browser.getTitle()).isEqualTo("Who Am I");
//     }
// 
//     public static LoginPage<WhoamiPage> openWithoutLogin(WebDriver webClient, URL url) {
//         webClient.get(url.toString());
//         LoginPage<WhoamiPage> loginPage = Page.createPage(LoginPage.class, webClient);
//         loginPage.setReturnPage(WhoamiPage.class);
//         return loginPage;
//     }
// 
// }
// 
// Path: keycloak-dropwizard-bearermodule/src/test/java/de/ahus1/lottery/adapter/dropwizard/state/DrawResourceState.java
// public class DrawResourceState {
//     private final URI baseUrl;
//     private Response response;
//     private String accessToken;
// 
//     public DrawResourceState(URI baseUrl) {
//         this.baseUrl = baseUrl;
//     }
// 
//     public DrawResourceState givenNoToken() {
//         accessToken = null;
//         return this;
//     }
// 
//     public DrawResourceState givenToken(String accessToken) {
//         this.accessToken = accessToken;
//         return this;
//     }
// 
//     public DrawResourceState whenOpened() {
//         Client client = ClientBuilder.newClient();
//         client.property(ClientProperties.FOLLOW_REDIRECTS, false);
//         WebTarget target = client.target(baseUrl).path("/draw");
//         DrawRequest request = new DrawRequest();
//         request.setDate(LocalDate.parse("2015-01-01"));
//         Invocation.Builder builder = target.request();
//         if (accessToken != null) {
//             builder.header("Authorization", "Bearer " + accessToken);
//         }
//         response = builder.post(Entity.entity(request, MediaType.APPLICATION_JSON_TYPE));
//         return this;
//     }
// 
//     public void thenAccessDenied() {
//         assertThat(response.getStatusInfo()).isEqualTo(Response.Status.UNAUTHORIZED);
//     }
// 
//     public void thenForbidden() {
//         assertThat(response.getStatusInfo()).isEqualTo(Response.Status.FORBIDDEN);
//     }
// 
//     public void thenUnauthorized() {
//         assertThat(response.getStatusInfo()).isEqualTo(Response.Status.UNAUTHORIZED);
//     }
// 
//     public void thenRedirectedToLoginScreen() {
//         assertThat(response.getLocation().getPath()).startsWith("/auth/realms");
//     }
// 
// }


// Path: keycloak-dropwizard-bearermodule/src/test/java/de/ahus1/lottery/adapter/dropwizard/LotteryApplicationTestWithCookieStore.java
import de.ahus1.lottery.adapter.dropwizard.pages.StartPage;
import de.ahus1.lottery.adapter.dropwizard.pages.WhoamiPage;
import de.ahus1.lottery.adapter.dropwizard.state.DrawResourceState;
import io.dropwizard.testing.junit.DropwizardAppRule;
import org.jboss.arquillian.drone.api.annotation.Drone;
import org.jboss.arquillian.junit.Arquillian;
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.openqa.selenium.WebDriver;
import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.time.LocalDate;

package de.ahus1.lottery.adapter.dropwizard;



@RunWith(Arquillian.class)
public class LotteryApplicationTestWithCookieStore {

    @Drone
    private WebDriver browser;

    @ClassRule
    public static final DropwizardAppRule<LotteryConfiguration> RULE =
            new DropwizardAppRule<>(LotteryApplication.class,
                    getConfig()
            );

    private static String getConfig() {
        File file = new File("config-cookiestore.yml");