diff options
author | Tharre <tharre3@gmail.com> | 2018-05-24 20:28:05 +0200 |
---|---|---|
committer | Tharre <tharre3@gmail.com> | 2018-05-24 20:28:05 +0200 |
commit | f5bc7925a8fbbe247972a6f0e0571cc7e92fbefa (patch) | |
tree | 25c6010b1c96de0302ac618bc3aeee61100655fe /src/test/java/at/ac/tuwien/sepm/assignment/groupphase/employee | |
parent | f7d14a76123911f0bced08356a0c69e61147cb1b (diff) | |
parent | 58f6ea4ad233f4cbb57b57734a5067e0856b6341 (diff) | |
download | sepm-groupproject-f5bc7925a8fbbe247972a6f0e0571cc7e92fbefa.tar.gz sepm-groupproject-f5bc7925a8fbbe247972a6f0e0571cc7e92fbefa.tar.xz sepm-groupproject-f5bc7925a8fbbe247972a6f0e0571cc7e92fbefa.zip |
Merge branch 'develop'v2.0
Diffstat (limited to 'src/test/java/at/ac/tuwien/sepm/assignment/groupphase/employee')
5 files changed, 0 insertions, 380 deletions
diff --git a/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/employee/CreateNewEmployeeApplication.java b/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/employee/CreateNewEmployeeApplication.java deleted file mode 100644 index e9f4801..0000000 --- a/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/employee/CreateNewEmployeeApplication.java +++ /dev/null @@ -1,53 +0,0 @@ -package at.ac.tuwien.sepm.assignment.groupphase.employee; - -import at.ac.tuwien.sepm.assignment.groupphase.util.SpringFXMLLoader; -import java.lang.invoke.MethodHandles; -import javafx.application.Application; -import javafx.scene.Parent; -import javafx.scene.Scene; -import javafx.stage.Stage; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.context.annotation.AnnotationConfigApplicationContext; -import org.springframework.context.annotation.ComponentScan; -import org.springframework.stereotype.Component; - -@Component -@ComponentScan("at.ac.tuwien.sepm.assignment.groupphase") -public final class CreateNewEmployeeApplication extends Application { - - private static final Logger LOG = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); - - public static AnnotationConfigApplicationContext context; - - @Override - public void start(Stage primaryStage) throws Exception { - // setup application - primaryStage.setTitle("Person anlegen"); - primaryStage.setWidth(1366); - primaryStage.setHeight(768); - primaryStage.centerOnScreen(); - primaryStage.setOnCloseRequest(event -> LOG.debug("Application shutdown initiated")); - - context = new AnnotationConfigApplicationContext(CreateNewEmployeeApplication.class); - final var fxmlLoader = context.getBean(SpringFXMLLoader.class); - primaryStage.setScene( - new Scene( - (Parent) - fxmlLoader.load( - getClass() - .getResourceAsStream( - "/fxml/createNewEmployee.fxml")))); - - // show application - primaryStage.show(); - primaryStage.toFront(); - LOG.debug("Application startup complete"); - } - - @Override - public void stop() { - LOG.debug("Stopping application"); - context.close(); - } -} diff --git a/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/employee/CreateNewEmployeeControllerTest.java b/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/employee/CreateNewEmployeeControllerTest.java deleted file mode 100644 index eb1a728..0000000 --- a/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/employee/CreateNewEmployeeControllerTest.java +++ /dev/null @@ -1,85 +0,0 @@ -package at.ac.tuwien.sepm.assignment.groupphase.employee; - -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.when; - -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.service.EmployeeService; -import at.ac.tuwien.sepm.assignment.groupphase.exception.InvalidEmployeeException; -import at.ac.tuwien.sepm.assignment.groupphase.exception.ServiceException; -import at.ac.tuwien.sepm.assignment.groupphase.util.Helper; -import at.ac.tuwien.sepm.assignment.groupphase.util.HighDpiAwareApplicationTest; -import javafx.scene.control.DialogPane; -import javafx.scene.input.MouseButton; -import javafx.stage.Stage; -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.testfx.api.FxToolkit; -import org.testfx.robot.Motion; - -public class CreateNewEmployeeControllerTest extends HighDpiAwareApplicationTest { - - private EmployeeService employeeService; - - @Before - public void setup() throws Exception { - // TODO: check if testfx can be run in headless mode on Jenkins - FxToolkit.registerPrimaryStage(); - FxToolkit.setupApplication(CreateNewEmployeeApplication.class); - employeeService = CreateNewEmployeeApplication.context.getBean(EmployeeService.class); - } - - @After - public void cleanup() throws Exception { - FxToolkit.cleanupStages(); - } - - @Test - public void testClickAddValidEmployee() throws InvalidEmployeeException, ServiceException { - - when(employeeService.add(any())).thenReturn(1L); - - clickOn("#inputName", Motion.DIRECT, MouseButton.PRIMARY); - write("Name"); - clickOn("#btnCreate", Motion.DIRECT, MouseButton.PRIMARY); - - Stage alertDialog = Helper.getTopModalStage(robotContext()); - Assert.assertNotNull(alertDialog); - - DialogPane dialogPane = (DialogPane) alertDialog.getScene().getRoot(); - Assert.assertEquals("Erfolgreich angelegt", dialogPane.getHeaderText()); - } - - @Test - public void testClickAddInvalidEmployee() throws InvalidEmployeeException, ServiceException { - - when(employeeService.add(any())).thenThrow(InvalidEmployeeException.class); - - moveTo("#inputName"); - clickOn("#btnCreate", Motion.DIRECT, MouseButton.PRIMARY); - - Stage alertDialog = Helper.getTopModalStage(robotContext()); - Assert.assertNotNull(alertDialog); - - DialogPane dialogPane = (DialogPane) alertDialog.getScene().getRoot(); - Assert.assertEquals("Ungültige Eingabe", dialogPane.getHeaderText()); - } - - @Test - public void testClickAddEmployeeWithServiceException() - throws InvalidEmployeeException, ServiceException { - - when(employeeService.add(any())).thenThrow(ServiceException.class); - - clickOn("#inputName", Motion.DIRECT, MouseButton.PRIMARY); - write("Test"); - clickOn("#btnCreate", Motion.DIRECT, MouseButton.PRIMARY); - - Stage alertDialog = Helper.getTopModalStage(robotContext()); - Assert.assertNotNull(alertDialog); - - DialogPane dialogPane = (DialogPane) alertDialog.getScene().getRoot(); - Assert.assertEquals("Speicherfehler", dialogPane.getHeaderText()); - } -} diff --git a/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/employee/EmployeePersistenceTest.java b/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/employee/EmployeePersistenceTest.java deleted file mode 100644 index f8fe0f3..0000000 --- a/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/employee/EmployeePersistenceTest.java +++ /dev/null @@ -1,155 +0,0 @@ -package at.ac.tuwien.sepm.assignment.groupphase.employee; - -import static junit.framework.TestCase.fail; - -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dao.EmployeeDAO; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dao.EmployeeDatabaseDao; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Employee; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Employee.EducationLevel; -import at.ac.tuwien.sepm.assignment.groupphase.exception.PersistenceException; -import at.ac.tuwien.sepm.assignment.groupphase.util.JDBCConnectionManager; -import java.nio.charset.Charset; -import java.sql.SQLException; -import java.time.LocalDate; -import java.time.format.DateTimeFormatter; -import java.util.List; -import org.dbunit.IDatabaseTester; -import org.dbunit.JdbcDatabaseTester; -import org.dbunit.dataset.DataSetException; -import org.dbunit.dataset.IDataSet; -import org.dbunit.dataset.xml.FlatXmlDataSetBuilder; -import org.dbunit.operation.DatabaseOperation; -import org.h2.tools.RunScript; -import org.junit.Assert; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -public class EmployeePersistenceTest { - - private static final String JDBC_DRIVER = org.h2.Driver.class.getName(); - private static final String JDBC_URL = "jdbc:h2:mem:test;DB_CLOSE_DELAY=-1"; - private static final String USER = ""; - private static final String PASSWORD = ""; - - private EmployeeDAO employeePersistence; - - public EmployeePersistenceTest() throws PersistenceException { - employeePersistence = new EmployeeDatabaseDao(new JDBCConnectionManager(JDBC_URL)); - } - - @BeforeClass - public static void createSchema() throws SQLException { - RunScript.execute( - JDBC_URL, - USER, - PASSWORD, - "classpath:sql/database.sql", - Charset.forName("UTF8"), - false); - } - - @Before - public void importDataSet() throws Exception { - IDataSet dataSet = readDataSet(); - cleanlyInsert(dataSet); - } - - private IDataSet readDataSet() throws DataSetException { - return new FlatXmlDataSetBuilder() - .build( - getClass() - .getClassLoader() - .getResourceAsStream("employeeServiceTestData.xml")); - } - - private void cleanlyInsert(IDataSet dataSet) throws Exception { - IDatabaseTester databaseTester = - new JdbcDatabaseTester(JDBC_DRIVER, JDBC_URL, USER, PASSWORD); - - databaseTester.setSetUpOperation(DatabaseOperation.CLEAN_INSERT); - databaseTester.setDataSet(dataSet); - databaseTester.onSetup(); - } - - @Test - public void testListEmployees() { - - try { - List<Employee> employees = employeePersistence.list(); - - Employee empOne = - Employee.builder() - .id(1) - .name("Adam") - .birthday( - LocalDate.parse( - "10.10.2010", - DateTimeFormatter.ofPattern("dd.MM.yyyy"))) - .educationLevel(EducationLevel.RS) - .isDriver(true) - .isPilot(false) - .build(); - - Employee empTwo = - Employee.builder() - .id(2) - .name("Max") - .birthday( - LocalDate.parse( - "11.11.1990", - DateTimeFormatter.ofPattern("dd.MM.yyyy"))) - .educationLevel(EducationLevel.NFS) - .isDriver(false) - .isPilot(false) - .build(); - - Employee empThree = - Employee.builder() - .id(3) - .name("Lisa") - .birthday( - LocalDate.parse( - "16.10.1999", - DateTimeFormatter.ofPattern("dd.MM.yyyy"))) - .educationLevel(EducationLevel.NKI) - .isDriver(true) - .isPilot(false) - .build(); - - Assert.assertTrue(employees.contains(empOne)); - Assert.assertTrue(employees.contains(empTwo)); - Assert.assertTrue(employees.contains(empThree)); - Assert.assertEquals(3, employees.size()); - - } catch (PersistenceException e) { - fail(); - } - } - - @Test - public void testEmployeeListNoElement() { - - try { - List<Employee> employees = employeePersistence.list(); - - Employee empOne = - Employee.builder() - .id(10) - .name("Adam") - .birthday( - LocalDate.parse( - "10.10.2010", - DateTimeFormatter.ofPattern("dd.MM.yyyy"))) - .educationLevel(EducationLevel.RS) - .isDriver(true) - .isPilot(false) - .build(); - - Assert.assertFalse(employees.contains(empOne)); - - } catch (PersistenceException e) { - fail(); - } - } -} diff --git a/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/employee/EmployeeServiceTest.java b/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/employee/EmployeeServiceTest.java deleted file mode 100644 index 47328b3..0000000 --- a/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/employee/EmployeeServiceTest.java +++ /dev/null @@ -1,68 +0,0 @@ -package at.ac.tuwien.sepm.assignment.groupphase.employee; - -import static junit.framework.TestCase.fail; -import static org.hamcrest.CoreMatchers.is; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dao.EmployeeDAO; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dao.EmployeeDatabaseDao; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Employee; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Employee.EducationLevel; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.service.EmployeeService; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.service.EmployeeServiceImpl; -import at.ac.tuwien.sepm.assignment.groupphase.exception.InvalidEmployeeException; -import at.ac.tuwien.sepm.assignment.groupphase.exception.PersistenceException; -import at.ac.tuwien.sepm.assignment.groupphase.exception.ServiceException; -import java.time.LocalDate; -import org.junit.Assert; -import org.junit.Test; - -public class EmployeeServiceTest { - - private final EmployeeDAO employeePersistence = mock(EmployeeDatabaseDao.class); - private final EmployeeService employeeService = new EmployeeServiceImpl(employeePersistence); - - public EmployeeServiceTest() throws PersistenceException { - when(employeePersistence.add(any())).thenReturn(1L); - } - - @Test - public void testAddValidEmployee() { - - Employee employee = - Employee.builder() - .name("Testperson") - .birthday(LocalDate.MIN) - .educationLevel(EducationLevel.NA) - .isDriver(true) - .isPilot(false) - .build(); - - try { - Assert.assertThat(employeeService.add(employee), is(1L)); - } catch (InvalidEmployeeException | ServiceException e) { - fail(); - } - } - - @Test(expected = InvalidEmployeeException.class) - public void testAddInvalidEmployee() throws InvalidEmployeeException { - - Employee employee = - Employee.builder() - .name("") - .birthday(LocalDate.MIN) - .educationLevel(EducationLevel.NA) - .isDriver(true) - .isPilot(false) - .build(); - - try { - employeeService.add(employee); - } catch (ServiceException e) { - fail(); - } - } -} diff --git a/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/employee/EmployeeServiceTestConfiguration.java b/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/employee/EmployeeServiceTestConfiguration.java deleted file mode 100644 index 3668ef4..0000000 --- a/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/employee/EmployeeServiceTestConfiguration.java +++ /dev/null @@ -1,19 +0,0 @@ -package at.ac.tuwien.sepm.assignment.groupphase.employee; - -import static org.mockito.Mockito.mock; - -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.service.EmployeeService; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.service.EmployeeServiceImpl; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Primary; - -@Configuration -public class EmployeeServiceTestConfiguration { - - @Bean - @Primary - public EmployeeService employeeService() { - return mock(EmployeeServiceImpl.class); - } -} |