diff --git a/src/main/resources/templates/login.ftl b/src/main/resources/templates/login.ftl index 37122ac9e08fce3e317727ac0cedeab094ea1d8e..e1547d05360e4c401ead497affb2c70e5de07351 100644 --- a/src/main/resources/templates/login.ftl +++ b/src/main/resources/templates/login.ftl @@ -31,7 +31,7 @@ <table class="${redTextColor} login-message no-border-table"> <tr> <td><i class="material-icons">warning</i></td> - <td>${locale.getString("warning.wrong.password")}</td> + <td id="loginMessage">${locale.getString("warning.wrong.password")}</td> </tr> </table> </div> @@ -44,7 +44,7 @@ <table class="${greenTextColor} login-message no-border-table"> <tr> <td><i class="material-icons">info_outline</i></td> - <td>${locale.getString("logout.success")}</td> + <td id="loginMessage">${locale.getString("logout.success")}</td> </tr> </table> </div> diff --git a/src/test/java/de/deadlocker8/budgetmaster/integration/ImportTest.java b/src/test/java/de/deadlocker8/budgetmaster/integration/ImportTest.java index d3fbdb7741b6b354c12550b80eb0e3626659df8f..ac618f6e2b8ec7a5d14465ed1c39957f79bd8f1d 100644 --- a/src/test/java/de/deadlocker8/budgetmaster/integration/ImportTest.java +++ b/src/test/java/de/deadlocker8/budgetmaster/integration/ImportTest.java @@ -1,6 +1,7 @@ package de.deadlocker8.budgetmaster.integration; import de.deadlocker8.budgetmaster.Main; +import de.deadlocker8.budgetmaster.authentication.UserService; import org.junit.Test; import org.junit.runner.RunWith; import org.openqa.selenium.WebDriver; @@ -11,14 +12,12 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.transaction.annotation.Transactional; import java.io.File; -import java.util.ArrayList; import java.util.Arrays; import java.util.List; @RunWith(SpringJUnit4ClassRunner.class) @SpringBootTest(classes = Main.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) @SeleniumTest -@Transactional public class ImportTest { @SuppressWarnings("SpringJavaInjectionPointsAutowiringInspection") @@ -33,7 +32,7 @@ public class ImportTest { IntegrationTestHelper helper = new IntegrationTestHelper(driver, port); helper.start(); - helper.login(); + helper.login(UserService.DEFAULT_PASSWORD); helper.hideBackupReminder(); String path = getClass().getClassLoader().getResource("SearchDatabase.json").getFile().replace("/", File.separator); diff --git a/src/test/java/de/deadlocker8/budgetmaster/integration/IntegrationTestHelper.java b/src/test/java/de/deadlocker8/budgetmaster/integration/IntegrationTestHelper.java index 3170b91d9d3b38127026fadcc777b35a9e742209..7cd993f5961c56fa3bbbab09139905364e8aa7a4 100644 --- a/src/test/java/de/deadlocker8/budgetmaster/integration/IntegrationTestHelper.java +++ b/src/test/java/de/deadlocker8/budgetmaster/integration/IntegrationTestHelper.java @@ -1,17 +1,14 @@ package de.deadlocker8.budgetmaster.integration; -import de.deadlocker8.budgetmaster.authentication.UserService; import de.thecodelabs.utils.util.Localization; import org.openqa.selenium.By; import org.openqa.selenium.NoSuchElementException; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; -import java.io.File; import java.util.List; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; class IntegrationTestHelper { @@ -36,15 +33,20 @@ class IntegrationTestHelper this.url = BASE_URL + port; } + public String getUrl() + { + return url; + } + void start() { driver.get(url); } - void login() + void login(String password) { WebElement inputPassword = driver.findElement(By.id("login-password")); - inputPassword.sendKeys(UserService.DEFAULT_PASSWORD); + inputPassword.sendKeys(password); WebElement buttonLogin = driver.findElement(By.tagName("button")); buttonLogin.click(); } diff --git a/src/test/java/de/deadlocker8/budgetmaster/integration/LoginControllerTest.java b/src/test/java/de/deadlocker8/budgetmaster/integration/LoginControllerTest.java index e7739548e08df462981f534171874d41153f3852..c8baa9b03467abda57f5134d8f6d1eb72fa18d92 100644 --- a/src/test/java/de/deadlocker8/budgetmaster/integration/LoginControllerTest.java +++ b/src/test/java/de/deadlocker8/budgetmaster/integration/LoginControllerTest.java @@ -1,8 +1,8 @@ package de.deadlocker8.budgetmaster.integration; import de.deadlocker8.budgetmaster.Main; +import de.deadlocker8.budgetmaster.authentication.UserService; import de.thecodelabs.utils.util.Localization; -import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.openqa.selenium.By; @@ -17,29 +17,23 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; @RunWith(SpringJUnit4ClassRunner.class) -@SpringBootTest(classes = Main.class,webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) +@SpringBootTest(classes = Main.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) @SeleniumTest public class LoginControllerTest { @SuppressWarnings("SpringJavaInjectionPointsAutowiringInspection") @Autowired private WebDriver driver; - private final static String BASE_URL = "https://localhost:"; - private String url; @LocalServerPort int port; - @Before - public void before() - { - url = BASE_URL + port; - } - @Test public void getLoginPage() { - driver.get(url); + IntegrationTestHelper helper = new IntegrationTestHelper(driver, port); + helper.start(); + WebElement input = driver.findElement(By.id("login-password")); assertNotNull(input); @@ -49,4 +43,41 @@ public class LoginControllerTest WebElement button = driver.findElement(By.tagName("button")); assertEquals(Localization.getString("login.button"), IntegrationTestHelper.getTextNode(button)); } + + @Test + public void wrongCredentials() + { + IntegrationTestHelper helper = new IntegrationTestHelper(driver, port); + helper.start(); + helper.login("akhjfvbvahsdsa"); + + WebElement label = driver.findElement(By.id("loginMessage")); + assertEquals(Localization.getString("warning.wrong.password"), label.getText()); + } + + @Test + public void successLogin() + { + IntegrationTestHelper helper = new IntegrationTestHelper(driver, port); + helper.start(); + helper.login(UserService.DEFAULT_PASSWORD); + + WebElement label = driver.findElement(By.id("logo-home")); + String expected = helper.getUrl() + "/images/Logo_with_text_medium_res.png"; + assertEquals(expected, label.getAttribute("src")); + } + + @Test + public void logout() + { + IntegrationTestHelper helper = new IntegrationTestHelper(driver, port); + helper.start(); + helper.login(UserService.DEFAULT_PASSWORD); + + WebElement buttonLogout = driver.findElement(By.xpath("//body/ul/li/a[contains(text(), 'Logout')]")); + buttonLogout.click(); + + WebElement label = driver.findElement(By.id("loginMessage")); + assertEquals(Localization.getString("logout.success"), label.getText()); + } } \ No newline at end of file