diff --git a/src/main/java/de/deadlocker8/budgetmaster/authentication/UserService.java b/src/main/java/de/deadlocker8/budgetmaster/authentication/UserService.java index e904e2e03850f017b55e4b1d4cd22460ee2dbfb9..c854015d7fb819f6c966f9739be13b50724fd138 100644 --- a/src/main/java/de/deadlocker8/budgetmaster/authentication/UserService.java +++ b/src/main/java/de/deadlocker8/budgetmaster/authentication/UserService.java @@ -12,6 +12,7 @@ import org.springframework.stereotype.Service; public class UserService { private final Logger LOGGER = LoggerFactory.getLogger(this.getClass()); + public static final String DEFAULT_PASSWORD = "BudgetMaster"; @Autowired public UserService(UserRepository userRepository, AccountService accountService) @@ -25,7 +26,7 @@ public class UserService if(userRepository.findAll().size() == 0) { BCryptPasswordEncoder bCryptPasswordEncoder = new BCryptPasswordEncoder(); - String encryptedPassword = bCryptPasswordEncoder.encode("BudgetMaster"); + String encryptedPassword = bCryptPasswordEncoder.encode(DEFAULT_PASSWORD); User user = new User("Default", encryptedPassword); userRepository.save(user); LOGGER.info("Created default user"); diff --git a/src/main/resources/templates/settings/settingsMacros.ftl b/src/main/resources/templates/settings/settingsMacros.ftl index 550e6212bedf45cbb2a077f9beb7c87426e4a657..816778c61648fe4e372739e2419fa80e002a4c4b 100644 --- a/src/main/resources/templates/settings/settingsMacros.ftl +++ b/src/main/resources/templates/settings/settingsMacros.ftl @@ -100,7 +100,7 @@ <div class="file-field input-field"> <div class="btn budgetmaster-blue"> <i class="material-icons">cloud_upload</i> - <input type="file" accept=".json" name="file"> + <input id="inputDatabaseImport" type="file" accept=".json" name="file"> </div> <div class="file-path-wrapper"> <input class="file-path validate" type="text"> diff --git a/src/test/java/de/deadlocker8/budgetmaster/integration/ImportTest.java b/src/test/java/de/deadlocker8/budgetmaster/integration/ImportTest.java new file mode 100644 index 0000000000000000000000000000000000000000..81c7d3509ea7076a9f9e9f998e9e533f329f05f6 --- /dev/null +++ b/src/test/java/de/deadlocker8/budgetmaster/integration/ImportTest.java @@ -0,0 +1,85 @@ +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; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.context.embedded.LocalServerPort; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +import java.io.File; +import java.net.URISyntaxException; +import java.util.List; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +@RunWith(SpringJUnit4ClassRunner.class) +@SpringBootTest(classes = Main.class,webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) +@SeleniumTest +public class ImportTest +{ + @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 requestImport() throws InterruptedException + { + driver.get(url + "/settings/database/requestImport"); + + // login + WebElement inputPassword = driver.findElement(By.id("login-password")); + inputPassword.sendKeys(UserService.DEFAULT_PASSWORD); + WebElement buttonLogin = driver.findElement(By.tagName("button")); + buttonLogin.click(); + + // upload database + WebElement input = driver.findElement(By.id("inputDatabaseImport")); + assertNotNull(input); + + String path = getClass().getClassLoader().getResource("SearchDatabase.json").getFile().replace("/", File.separator); + if(path.startsWith("\\")) + { + path = path.substring(1); + } + input.sendKeys(path); + + WebElement buttonUpload = driver.findElement(By.id("button-confirm-database-import")); + buttonUpload.click(); + + // account matching + WebElement headlineImport = driver.findElement(By.className("headline")); + assertEquals(Localization.getString("info.title.database.import.dialog"), IntegrationTestHelper.getTextNode(headlineImport)); + + List<WebElement> tableRows = driver.findElements(By.cssSelector(".container form table tr")); + assertEquals(2, tableRows.size()); + + WebElement row1 = tableRows.get(0); + WebElement sourceAccount1 = row1.findElement(By.className("account-source")); + assertEquals("DefaultAccount0815", IntegrationTestHelper.getTextNode(sourceAccount1)); + + List<WebElement> destinationAccounts = row1.findElements(By.cssSelector(".account-destination option")); + assertEquals(1, destinationAccounts.size()); + System.out.println(destinationAccounts.get(0).getText()); +// assertEquals("Default Account", IntegrationTestHelper.getTextNode(destinationAccounts.get(0))); + } +} \ No newline at end of file diff --git a/src/test/java/de/deadlocker8/budgetmaster/integration/SeleniumTestExecutionListener.java b/src/test/java/de/deadlocker8/budgetmaster/integration/SeleniumTestExecutionListener.java index 34aac3cbef3a312c448466f97477dfda14a09fbe..b7eabac0960ff4d075b07a8ed5fe74d8dc35eafc 100644 --- a/src/test/java/de/deadlocker8/budgetmaster/integration/SeleniumTestExecutionListener.java +++ b/src/test/java/de/deadlocker8/budgetmaster/integration/SeleniumTestExecutionListener.java @@ -40,7 +40,7 @@ public class SeleniumTestExecutionListener extends AbstractTestExecutionListener { FirefoxOptions options = new FirefoxOptions(); - options.setHeadless(true); +// options.setHeadless(true); webDriver = new FirefoxDriver(options); ConfigurableApplicationContext configurableApplicationContext = (ConfigurableApplicationContext) context; diff --git a/src/test/resources/SearchDatabase.json b/src/test/resources/SearchDatabase.json new file mode 100644 index 0000000000000000000000000000000000000000..cb16a6be6465fae89a5ffdb56b7c57dc794b073c --- /dev/null +++ b/src/test/resources/SearchDatabase.json @@ -0,0 +1,168 @@ +{ + "TYPE": "BUDGETMASTER_DATABASE", + "VERSION": 3, + "categories": [ + { + "ID": 1, + "name": "No Category", + "color": "#FFFFFF", + "type": "NONE" + }, + { + "ID": 2, + "name": "Rest", + "color": "#FFFF00", + "type": "REST" + }, + { + "ID": 97, + "name": "sdfdsf", + "color": "#2e7c2b", + "type": "CUSTOM" + }, + { + "ID": 98, + "name": "12sd", + "color": "#ff3b30", + "type": "CUSTOM" + } + ], + "accounts": [ + { + "ID": 1, + "name": "Placeholder", + "type": "ALL" + }, + { + "ID": 2, + "name": "DefaultAccount0815", + "type": "CUSTOM" + }, + { + "ID": 3, + "name": "sfsdf", + "type": "CUSTOM" + } + ], + "transactions": [ + { + "ID": 97, + "amount": -20000, + "date": "2019-04-24", + "account": { + "ID": 3, + "name": "sfsdf", + "type": "CUSTOM" + }, + "category": { + "ID": 1, + "name": "No Category", + "color": "#FFFFFF", + "type": "NONE" + }, + "name": "Umbuchung", + "description": "", + "tags": [], + "transferAccount": { + "ID": 2, + "name": "DefaultAccount0815", + "type": "CUSTOM" + } + }, + { + "ID": 99, + "amount": -1500, + "date": "2019-05-01", + "account": { + "ID": 2, + "name": "DefaultAccount0815", + "type": "CUSTOM" + }, + "category": { + "ID": 98, + "name": "12sd", + "color": "#ff3b30", + "type": "CUSTOM" + }, + "name": "Test", + "description": "", + "tags": [] + }, + { + "ID": 195, + "amount": -300, + "date": "2019-05-01", + "account": { + "ID": 2, + "name": "DefaultAccount0815", + "type": "CUSTOM" + }, + "category": { + "ID": 1, + "name": "No Category", + "color": "#FFFFFF", + "type": "NONE" + }, + "name": "Transfer dings", + "description": "", + "tags": [], + "transferAccount": { + "ID": 3, + "name": "sfsdf", + "type": "CUSTOM" + } + }, + { + "ID": 199, + "amount": 100, + "date": "2019-05-01", + "account": { + "ID": 2, + "name": "DefaultAccount0815", + "type": "CUSTOM" + }, + "category": { + "ID": 98, + "name": "12sd", + "color": "#ff3b30", + "type": "CUSTOM" + }, + "name": "xxx", + "description": "", + "tags": [] + }, + { + "ID": 227, + "amount": -1500, + "date": "2019-05-01", + "account": { + "ID": 2, + "name": "DefaultAccount0815", + "type": "CUSTOM" + }, + "category": { + "ID": 97, + "name": "sdfdsf", + "color": "#2e7c2b", + "type": "CUSTOM" + }, + "name": "beste", + "description": "Lorem Ipsum", + "tags": [], + "repeatingOption": { + "ID": 161, + "startDate": "2019-05-01", + "modifier": { + "ID": 161, + "quantity": 1, + "localizationKey": "repeating.modifier.days" + }, + "endOption": { + "times": 20, + "ID": 161, + "localizationKey": "repeating.end.key.afterXTimes" + } + } + } + ] +} \ No newline at end of file