-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFrontendDeveloperTests.java
More file actions
221 lines (195 loc) · 8.29 KB
/
Copy pathFrontendDeveloperTests.java
File metadata and controls
221 lines (195 loc) · 8.29 KB
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
import org.junit.jupiter.api.Test;
import org.testfx.framework.junit5.ApplicationTest;
import javafx.scene.Node;
import java.io.IOException;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.concurrent.TimeUnit;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.CheckBox;
import javafx.scene.control.Label;
import javafx.scene.layout.Pane;
import javafx.stage.Stage;
/**
* Contains methods to test the functionality of FrontendImplementation
* NOTE: Every method is called as a result of the setup() method, and so methods will
* not be called within the tests themselves
*/
public class FrontendDeveloperTests extends ApplicationTest{
/**
* This method launches the JavaFX application that you would like to test
* BeforeEach of your @Test methods are run. Copy and paste this into your
* own Test class, and change the SampleApp.class reference to instead
* refer to your own application class that extends Application.
*/
@BeforeEach
public void setup() throws Exception {
FrontendImplementation.setBackend(new BackendPlaceholder(new GraphPlaceholder()));
ApplicationTest.launch(FrontendImplementation.class); // CHANGE THIS TO IMPLEMENTATION LATER!
}
/**
* Test createAboutAndQuitControls and tests the use of times and via locations together
*/
@Test
public void Test1() {
// get components for createAboutAndQuitControls
Button about = lookup("#about").query();
Label aboutLabel = lookup("#aboutlabel").query();
Button quit = lookup("#quit").query();
Assertions.assertEquals(about.getText(), "About");
Assertions.assertEquals(quit.getText(), "Quit");
// Tests that the about button correctly displays the controls if clicked
Assertions.assertEquals(aboutLabel.getText(),"");
clickOn("#about");
Assertions.assertTrue(aboutLabel.getText().contains("Controls:"));
// gets the path label
Label first = lookup("#path").query();
clickOn("#useviabox");
clickOn("#ttbox");
clickOn("#findbutton");
// verifies that the output is what is expected
Assertions.assertTrue(first.getText().contains("146"));
Assertions.assertTrue(first.getText().contains("Radio Hall"));
}
/**
* Test createShortestPathControls and createPathListDisplay
*/
@Test
public void Test2() {
// Tests for createShortestPathControls
// Looks up the components of the createShortestPathControls method
Label first = lookup("#pathstartselector").query();
Label second = lookup("#pathendselector").query();
Button third = lookup("#findbutton").query();
// Tests the functionality of the components from createShortestPathControls
Assertions.assertTrue(first.getText().contains("Path Start Selector:"));
Assertions.assertTrue(second.getText().contains("Path End Selector:"));
Assertions.assertEquals(third.getText(),"Submit/Find Button");
// Tests for createPathListDisplay
clickOn("#findbutton");
// looks up the fourth label where results should be
Label fourth = lookup("#path").query();
// tests the functionality of the button and label
Assertions.assertTrue(fourth.getText().contains("Union South"));
//Assertions.assertTrue(fourth.getText().contains("Results List (with travel times):"));
}
/**
* Tests createTravelTimesBox
*/
@Test
public void Test3() {
// gets the components of createTravelTimeBox
CheckBox first = lookup("#ttbox").query();
Label second = lookup("#path").query();
// (WILL FAIL FOR NOW!)
// Tests that checking the box correctly adds the Results list with travel times
clickOn("#findbutton");
Assertions.assertTrue(!(second.getText().contains("Results List (with travel times):")));
clickOn("#ttbox");
clickOn("#findbutton");
Assertions.assertTrue(second.getText().contains("Results List (with travel times):"));
}
/**
* Test createOptionalLocationControls
*/
@Test
public void Test4() {
// get components for createOptionalLocationControls
CheckBox first = lookup("#useviabox").query();
Label second = lookup("#locationselector").query();
Label third = lookup("#path").query();
clickOn("#useviabox");
clickOn("#findbutton");
// test the functionality of the components
Assertions.assertTrue(second.getText().contains("Via Location (optional):"));
Assertions.assertEquals(first.getText(), "Use Above Location in Path");
Assertions.assertTrue(third.getText().contains("Radio Hall"));
}
// integration tests
/**
* Tests finding the shortest path without time and without via location
*/
@Test
public void IntegrationTest1() {
// check to backend implementation and interface
BackendInterface backend = new Backend(new DijkstraGraph<String,Double>());
try {
// will need to change inside of VM
backend.loadGraphData("campus.dot");
} catch (IOException e) {}
FrontendImplementation.setBackend(backend);
Label path = lookup("#path").query();
// clicks on the path start text box and writes Union South
write("Union South");
// clicks on the path end text box and writes AOS Sciences
clickOn("#endtext").write("Atmospheric, Oceanic and Space Sciences");
// generates the shortest path
clickOn("#findbutton");
// verifies that the requires location appear in the Label
Assertions.assertTrue(path.getText().contains("Union South"));
Assertions.assertTrue(path.getText().contains("Atmospheric, Oceanic and Space Sciences"));
}
/**
* Tests finding the shortest path using time and via location
*/
@Test
public void IntegrationTest2() {
// check to backend implementation and interface
BackendInterface backend = new Backend(new DijkstraGraph<String,Double>());
try {
backend.loadGraphData("campus.dot");
} catch (IOException e) {}
FrontendImplementation.setBackend(backend);
Label path = lookup("#path").query();
// clicks on the path start text box and writes Union South
write("Union South");
// clicks on the via location selector and writes Computer Sciences
clickOn("#viatext").write("Computer Sciences and Statistics");
// clicks on the path end text box and writes AOS Sciences
clickOn("#endtext").write("Atmospheric, Oceanic and Space Sciences");
// sets the app to use both optional features
clickOn("#useviabox");
clickOn("#ttbox");
// generates the shortest path
clickOn("#findbutton");
// verifies that the requires location appear in the Label
Assertions.assertTrue(path.getText().contains("Union South"));
Assertions.assertTrue(path.getText().contains("Computer Sciences and Statistics"));
Assertions.assertTrue(path.getText().contains("Atmospheric, Oceanic and Space Sciences"));
Assertions.assertTrue(path.getText().contains("sec"));
Assertions.assertTrue(path.getText().contains("min"));
}
// partner tests
/**
* Test findShortestPath
*/
@Test
public void PartnerTest1() {
// creates backend object with full implementations
Backend backend = new Backend(new DijkstraGraph<String,Double>());
try {
backend.loadGraphData("campus.dot");
} catch (IOException e) {}
// gets results from find shortest path
LinkedList<String> path = (LinkedList<String>) backend.findShortestPath("Memorial Union", "Union South");
Assertions.assertTrue(path.contains("Memorial Union"));
Assertions.assertTrue(path.contains("Union South"));
}
/**
* Test getTravelTimesOnPath
*/
@Test
public void PartnerTest2() {
// creates backend object with full implementations
Backend backend = new Backend(new DijkstraGraph<String,Double>());
try {
backend.loadGraphData("campus.dot");
} catch (IOException e) {}
ArrayList<Double> path = (ArrayList<Double>) backend.getTravelTimesOnPath("Memorial Union", "Science Hall");
Assertions.assertTrue(path.contains(105.8));
}
}