Fix hello-security-explicit checkstyle

This commit is contained in:
Rob Winch 2020-07-10 13:46:27 -05:00
parent 9b76605c2f
commit 67ea8e7438
4 changed files with 50 additions and 29 deletions

View File

@ -22,10 +22,13 @@ import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.web.server.LocalServerPort;
/**
* Integration tests.
*
* @author Michael Simons
*/
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@ -37,27 +40,25 @@ public class HelloSecurityExplicitITests {
private int port;
@BeforeEach
public void setup() {
void setup() {
this.driver = new HtmlUnitDriver();
}
@AfterEach
public void tearDown() {
void tearDown() {
this.driver.quit();
}
@Test
public void login() {
void login() {
final LoginPage loginPage = HomePage.to(this.driver, this.port);
loginPage.assertAt();
HomePage homePage = loginPage.loginForm()
.username("user")
.password("password")
.submit();
HomePage homePage = loginPage.loginForm().username("user").password("password").submit();
homePage.assertAt();
LoginPage logoutSuccess = homePage.logout();
logoutSuccess.assertAt();
}
}

View File

@ -23,16 +23,19 @@ import org.openqa.selenium.support.PageFactory;
import static org.assertj.core.api.Assertions.assertThat;
/**
* The home page.
*
* @author Michael Simons
*/
public class HomePage {
private final WebDriver webDriver;
@FindBy(id = "logout")
private WebElement logout;
public static LoginPage to(WebDriver driver, int port) {
driver.get("http://localhost:" + port +"/");
driver.get("http://localhost:" + port + "/");
return PageFactory.initElements(driver, LoginPage.class);
}
@ -49,4 +52,5 @@ public class HomePage {
this.logout.click();
return PageFactory.initElements(this.webDriver, LogoutConfirmPage.class).logout();
}
}

View File

@ -23,6 +23,8 @@ import org.openqa.selenium.support.PageFactory;
import static org.assertj.core.api.Assertions.assertThat;
/**
* The login page.
*
* @author Michael Simons
*/
public class LoginPage {
@ -46,9 +48,13 @@ public class LoginPage {
}
public static class LoginForm {
private WebDriver webDriver;
private WebElement username;
private WebElement password;
@FindBy(css = "button[type=submit]")
private WebElement submit;
@ -70,5 +76,7 @@ public class LoginPage {
this.submit.click();
return PageFactory.initElements(this.webDriver, HomePage.class);
}
}
}

View File

@ -21,33 +21,41 @@ import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory;
/**
* The log out confirmation page.
* @author Rob Winch
*/
public class LogoutConfirmPage {
private final WebDriver webDriver;
private final WebDriver webDriver;
private final LogoutConfirmPage.LogoutForm logoutForm;
private final LogoutConfirmPage.LogoutForm logoutForm;
public LogoutConfirmPage(WebDriver webDriver) {
this.webDriver = webDriver;
this.logoutForm = PageFactory.initElements(this.webDriver, LogoutForm.class);
}
public LogoutConfirmPage(WebDriver webDriver) {
this.webDriver = webDriver;
this.logoutForm = PageFactory.initElements(this.webDriver, LogoutForm.class);
}
public LoginPage logout() {
return this.logoutForm.logout();
}
public LoginPage logout() {
return this.logoutForm.logout();
}
public static class LogoutForm {
private WebDriver webDriver;
@FindBy(css = "button[type=submit]")
private WebElement submit;
public static class LogoutForm {
public LogoutForm(WebDriver webDriver) {
this.webDriver = webDriver;
}
private WebDriver webDriver;
@FindBy(css = "button[type=submit]")
private WebElement submit;
public LogoutForm(WebDriver webDriver) {
this.webDriver = webDriver;
}
public LoginPage logout() {
this.submit.click();
return PageFactory.initElements(this.webDriver, LoginPage.class);
}
}
public LoginPage logout() {
this.submit.click();
return PageFactory.initElements(this.webDriver, LoginPage.class);
}
}
}