aboutsummaryrefslogtreecommitdiffstats
path: root/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/missioncontrol/controller
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/java/at/ac/tuwien/sepm/assignment/groupphase/missioncontrol/controller')
-rw-r--r--src/test/java/at/ac/tuwien/sepm/assignment/groupphase/missioncontrol/controller/CreateNewEmployeeControllerTest.java87
-rw-r--r--src/test/java/at/ac/tuwien/sepm/assignment/groupphase/missioncontrol/controller/CreateNewVehicleControllerTest.java81
-rw-r--r--src/test/java/at/ac/tuwien/sepm/assignment/groupphase/missioncontrol/controller/GuiTestApplication.java101
-rw-r--r--src/test/java/at/ac/tuwien/sepm/assignment/groupphase/missioncontrol/controller/RegistrationControllerTest.java22
4 files changed, 291 insertions, 0 deletions
diff --git a/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/missioncontrol/controller/CreateNewEmployeeControllerTest.java b/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/missioncontrol/controller/CreateNewEmployeeControllerTest.java
new file mode 100644
index 0000000..ccd37b4
--- /dev/null
+++ b/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/missioncontrol/controller/CreateNewEmployeeControllerTest.java
@@ -0,0 +1,87 @@
+package at.ac.tuwien.sepm.assignment.groupphase.missioncontrol.controller;
+
+import static at.ac.tuwien.sepm.assignment.groupphase.missioncontrol.controller.Helper.ALERT_TITLE_SERVICE_EXCEPTION;
+import static at.ac.tuwien.sepm.assignment.groupphase.missioncontrol.controller.Helper.ALERT_TITLE_SUCCESS;
+import static at.ac.tuwien.sepm.assignment.groupphase.missioncontrol.controller.Helper.ALERT_TITLE_VALIDATION_ERROR;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.when;
+
+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.missioncontrol.service.EmployeeService;
+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 {
+ FxToolkit.registerPrimaryStage();
+ FxToolkit.setupApplication(GuiTestApplication.class, "createNewEmployee.fxml");
+ employeeService = GuiTestApplication.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(ALERT_TITLE_SUCCESS, 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(ALERT_TITLE_VALIDATION_ERROR, 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(ALERT_TITLE_SERVICE_EXCEPTION, dialogPane.getHeaderText());
+ }
+}
diff --git a/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/missioncontrol/controller/CreateNewVehicleControllerTest.java b/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/missioncontrol/controller/CreateNewVehicleControllerTest.java
new file mode 100644
index 0000000..4906d64
--- /dev/null
+++ b/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/missioncontrol/controller/CreateNewVehicleControllerTest.java
@@ -0,0 +1,81 @@
+package at.ac.tuwien.sepm.assignment.groupphase.missioncontrol.controller;
+
+import static at.ac.tuwien.sepm.assignment.groupphase.missioncontrol.controller.Helper.ALERT_TITLE_SERVICE_EXCEPTION;
+import static at.ac.tuwien.sepm.assignment.groupphase.missioncontrol.controller.Helper.ALERT_TITLE_SUCCESS;
+import static at.ac.tuwien.sepm.assignment.groupphase.missioncontrol.controller.Helper.ALERT_TITLE_VALIDATION_ERROR;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.when;
+
+import at.ac.tuwien.sepm.assignment.groupphase.exception.InvalidVehicleException;
+import at.ac.tuwien.sepm.assignment.groupphase.exception.ServiceException;
+import at.ac.tuwien.sepm.assignment.groupphase.missioncontrol.service.VehicleService;
+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 CreateNewVehicleControllerTest extends HighDpiAwareApplicationTest {
+
+ private VehicleService vehicleService;
+
+ @Before
+ public void setup() throws Exception {
+ FxToolkit.registerPrimaryStage();
+ FxToolkit.setupApplication(GuiTestApplication.class, "createCar.fxml");
+ vehicleService = GuiTestApplication.context.getBean(VehicleService.class);
+ }
+
+ @After
+ public void cleanup() throws Exception {
+ FxToolkit.cleanupStages();
+ }
+
+ @Test
+ public void testClickAddValidVehicle() throws ServiceException, InvalidVehicleException {
+
+ when(vehicleService.add(any())).thenReturn(1L);
+
+ clickOn("#btnCreate", Motion.DIRECT, MouseButton.PRIMARY);
+
+ Stage alertDialog = Helper.getTopModalStage(robotContext());
+ Assert.assertNotNull(alertDialog);
+
+ DialogPane dialogPane = (DialogPane) alertDialog.getScene().getRoot();
+ Assert.assertEquals(ALERT_TITLE_SUCCESS, dialogPane.getHeaderText());
+ }
+
+ @Test
+ public void testClickInvalidVehicleEx() throws ServiceException, InvalidVehicleException {
+
+ when(vehicleService.add(any())).thenThrow(InvalidVehicleException.class);
+
+ clickOn("#btnCreate", Motion.DIRECT, MouseButton.PRIMARY);
+
+ Stage alertDialog = Helper.getTopModalStage(robotContext());
+ Assert.assertNotNull(alertDialog);
+
+ DialogPane dialogPane = (DialogPane) alertDialog.getScene().getRoot();
+ Assert.assertEquals(ALERT_TITLE_VALIDATION_ERROR, dialogPane.getHeaderText());
+ }
+
+ @Test
+ public void testClickInvalidServiceEx() throws ServiceException, InvalidVehicleException {
+
+ when(vehicleService.add(any())).thenThrow(ServiceException.class);
+
+ clickOn("#btnCreate", Motion.DIRECT, MouseButton.PRIMARY);
+
+ Stage alertDialog = Helper.getTopModalStage(robotContext());
+ Assert.assertNotNull(alertDialog);
+
+ DialogPane dialogPane = (DialogPane) alertDialog.getScene().getRoot();
+ Assert.assertEquals(ALERT_TITLE_SERVICE_EXCEPTION, dialogPane.getHeaderText());
+ }
+}
diff --git a/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/missioncontrol/controller/GuiTestApplication.java b/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/missioncontrol/controller/GuiTestApplication.java
new file mode 100644
index 0000000..968141e
--- /dev/null
+++ b/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/missioncontrol/controller/GuiTestApplication.java
@@ -0,0 +1,101 @@
+package at.ac.tuwien.sepm.assignment.groupphase.missioncontrol.controller;
+
+import static org.mockito.Mockito.mock;
+
+import at.ac.tuwien.sepm.assignment.groupphase.missioncontrol.service.EmployeeService;
+import at.ac.tuwien.sepm.assignment.groupphase.missioncontrol.service.EmployeeServiceImpl;
+import at.ac.tuwien.sepm.assignment.groupphase.missioncontrol.service.OperationService;
+import at.ac.tuwien.sepm.assignment.groupphase.missioncontrol.service.OperationServiceImpl;
+import at.ac.tuwien.sepm.assignment.groupphase.missioncontrol.service.RegistrationService;
+import at.ac.tuwien.sepm.assignment.groupphase.missioncontrol.service.RegistrationServiceImpl;
+import at.ac.tuwien.sepm.assignment.groupphase.missioncontrol.service.VehicleService;
+import at.ac.tuwien.sepm.assignment.groupphase.missioncontrol.service.VehicleServiceImpl;
+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.Bean;
+import org.springframework.context.annotation.ComponentScan;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Primary;
+import org.springframework.stereotype.Component;
+
+@Component
+@ComponentScan("at.ac.tuwien.sepm.assignment.groupphase")
+public class GuiTestApplication extends Application {
+
+ private static final Logger LOG = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
+
+ public static AnnotationConfigApplicationContext context;
+
+ @Configuration
+ public static class ContextConfiguration {
+
+ @Bean
+ @Primary
+ public EmployeeService employeeService() {
+ return mock(EmployeeServiceImpl.class);
+ }
+
+ @Bean
+ @Primary
+ public VehicleService vehicleService() {
+ return mock(VehicleServiceImpl.class);
+ }
+
+ @Bean
+ @Primary
+ public OperationService operationService() {
+ return mock(OperationServiceImpl.class);
+ }
+
+ @Bean
+ @Primary
+ public RegistrationService registrationService() {
+ return mock(RegistrationServiceImpl.class);
+ }
+ }
+
+ @Override
+ public void start(Stage primaryStage) throws Exception {
+ // setup application
+ primaryStage.setTitle("Test window");
+ primaryStage.setWidth(1366);
+ primaryStage.setHeight(768);
+ primaryStage.centerOnScreen();
+ primaryStage.setOnCloseRequest(event -> LOG.debug("Application shutdown initiated"));
+
+ if (getParameters().getRaw().size() < 1) {
+ throw new UnsupportedOperationException("FXML file not set");
+ }
+
+ context = new AnnotationConfigApplicationContext(GuiTestApplication.class);
+ final var fxmlLoader = context.getBean(SpringFXMLLoader.class);
+ primaryStage.setScene(
+ new Scene(
+ (Parent)
+ fxmlLoader.load(
+ getClass()
+ .getResourceAsStream(
+ "/fxml/"
+ + getParameters()
+ .getRaw()
+ .get(0)))));
+
+ // 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/missioncontrol/controller/RegistrationControllerTest.java b/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/missioncontrol/controller/RegistrationControllerTest.java
new file mode 100644
index 0000000..97fb0e7
--- /dev/null
+++ b/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/missioncontrol/controller/RegistrationControllerTest.java
@@ -0,0 +1,22 @@
+package at.ac.tuwien.sepm.assignment.groupphase.missioncontrol.controller;
+
+import at.ac.tuwien.sepm.assignment.groupphase.util.HighDpiAwareApplicationTest;
+import org.junit.After;
+import org.junit.Before;
+import org.testfx.api.FxToolkit;
+
+public class RegistrationControllerTest extends HighDpiAwareApplicationTest {
+
+ @Before
+ public void setup() throws Exception {
+ FxToolkit.registerPrimaryStage();
+ FxToolkit.setupApplication(GuiTestApplication.class, "RegistrationWindow.fxml");
+ }
+
+ @After
+ public void cleanup() throws Exception {
+ FxToolkit.cleanupStages();
+ }
+
+ // TODO: implement GUI Tests
+}