1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
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());
}
}
|