-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathTestFrontend.java
More file actions
313 lines (309 loc) · 26.2 KB
/
Copy pathTestFrontend.java
File metadata and controls
313 lines (309 loc) · 26.2 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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.io.PrintStream;
import java.io.StringReader;
//--== CS400 File Header Information ==--
//Name: Erhan Wang
//Email: ewang43@wisc.edu
//Team: blue
//Role: Front end developer
//TA: hang
//Lecturer: <name of the team mate's lecturer>
//Notes to Grader: <optional extra notes>
/**
* This class contains a set of tests for the front end of the Movie Mapper project.
*/
public class TestFrontend {
public static void main(String[] args) {
(new TestFrontend()).runTests();
}
/**
* This method calls all of the test methods in the class and ouputs pass / fail
* for each test.
*/
public void runTests() {
System.out.print("Test enter 'x' to exit (WARNING: if 'x' does not exit app, test won't exit and run indefinitely!): ");
if (this.enterXToExit()) {
System.out.println("PASSED");
} else {
System.out.println("FAILED");
}
System.out.print("Test frontend initially lists no movie (WARNING: if 'x' does not exit app, test won't exit and run indefinitely!): ");
if (this.testFrontendInitialOutputNoMovie()) {
System.out.println("PASSED");
} else {
System.out.println("FAILED");
}
System.out.print("Test 'g' load genre selection screen (WARNING: if pressing 'x' twice from the genre selection screen does not exit app, test won't exit and run indefinitely!): ");
if (this.testFrontendGForGenres()) {
System.out.println("PASSED");
} else {
System.out.println("FAILED");
}
System.out.print("Test 'r' load Ratings selection screen (WARNING: if pressing 'x' twice from the rating selection screen does not exit app, test won't exit and run indefinitely!): ");
if (this.testFrontendGForRatings()) {
System.out.println("PASSED");
} else {
System.out.println("FAILED");
}
System.out.print("Test base mode (WARNING: if pressing 'x' once from the year selection screen does not exit app, test won't exit and run indefinitely!): ");
if (this.testFrontendGForBase()) {
System.out.println("PASSED");
} else {
System.out.println("FAILED");
}
}
/**
* This test runs the front end and redirects its output to a string. It then
* passes in 'x' as a command. When the front end exists, the tests succeeds.
* If 'x' does not exist the app, the test will not terminate (it won't fail
* explicitely in this case). The test fails explicitely if the front end is
* not instantiated or if an exception occurs.
* @return true if the test passed, false if it failed
*/
public boolean enterXToExit() {
PrintStream standardOut = System.out;
InputStream standardIn = System.in;
try {
// set the input stream to our input (with an x to test of the program exists)
String input = "x";
InputStream inputStreamSimulator = new ByteArrayInputStream(input.getBytes());
System.setIn(inputStreamSimulator);
ByteArrayOutputStream outputStreamCaptor = new ByteArrayOutputStream();
// set the output to the stream captor to read the output of the front end
System.setOut(new PrintStream(outputStreamCaptor));
// instantiate when front end is implemented
Object frontend = new FrontEnd();
((FrontEnd)frontend).run(new Backend(new StringReader(
"title,original_title,year,genre,duration,country,language,director,writer,production_company,actors,description,avg_vote\n"
+ "The Source of Shadows,The Source of Shadows,2020,Horror,83,USA,English,\"Ryan Bury, Jennifer Bonior\",\"Jennifer Bonior, Trevor Botkin\",Four Thieves Productions,\"Ashleigh Allard, Tom Bonington, Eliane Gagnon, Marissa Kaye Grinestaff, Jenna Heffernan, Joshua Hummel, Janice Kingsley, Chris Labasbas, Jared Laufree, Dominic Lee, Vic May, Sienna Mazzone, Lizzie Mounter, Grace Mumm, Ashley Otis\",\"A series of stories woven together by one of our most primal fears, the fear of the unknown.\",3.5\n"
+ "The Insurrection,The Insurrection,2020,Action,90,USA,English,Rene Perez,Rene Perez,,\"Michael Paré, Wilma Elles, Joseph Camilleri, Rebecca Tarabocchia, Jeanine Harrington, Malorie Glavan, Danner Boyd, Michael Cendejas, Woody Clendenen, Keely Dervin, Aaron Harvey, Tony Jackson, Michael Jarrod, Angelina Karo, Bernie Kelly\",The director of the largest media company wants to expose how left-wing powers use film to control populations.,2.9\n"
+ "Valley Girl,Valley Girl,2020,\"Comedy, Musical, Romance\",102,USA,English,Rachel Lee Goldenberg,\"Amy Talkington, Andrew Lane\",Sneak Preview Productions,\"Jessica Rothe, Josh Whitehouse, Jessie Ennis, Ashleigh Murray, Chloe Bennet, Logan Paul, Mae Whitman, Mario Revolori, Rob Huebel, Judy Greer, Alex Lewis, Alex MacNicoll, Danny Ramirez, Andrew Kai, Allyn Rachel\",\"Set to a new wave '80s soundtrack, a pair of young lovers from different backgrounds defy their parents and friends to stay together. A musical adaptation of the 1983 film.\",5.4\n"
)));
// set the output back to standard out for running the test
System.setOut(standardOut);
// same for standard in
System.setIn(standardIn);
if (frontend == null) {
// test fails
return false;
} else {
// test passed
return true;
}
} catch (Exception e) {
// make sure stdin and stdout are set correctly after we get exception in test
System.setOut(standardOut);
System.setIn(standardIn);
e.printStackTrace();
// test failed
return false;
}
}
/**
* This test runs the front end and redirects its output to a string. It then
* passes in 'x' as a command to exit the app. The test succeeds if the front
* end does not contain any of the three movies (the movie titles are not in
* the string captured from the front end) by default. It fails if any of
* those three titles are present in the string or an exception occurs.
* @return true if the test passed, false if it failed
*/
public boolean testFrontendInitialOutputNoMovie() {
PrintStream standardOut = System.out;
InputStream standardIn = System.in;
try {
// set the input stream to our input (with an x to test of the program exists)
String input = "x";
InputStream inputStreamSimulator = new ByteArrayInputStream(input.getBytes());
System.setIn(inputStreamSimulator);
ByteArrayOutputStream outputStreamCaptor = new ByteArrayOutputStream();
// set the output to the stream captor to read the output of the front end
System.setOut(new PrintStream(outputStreamCaptor));
// instantiate when front end is implemented
Object frontend = new FrontEnd();
((FrontEnd)frontend).run(new Backend(new StringReader(
"title,original_title,year,genre,duration,country,language,director,writer,production_company,actors,description,avg_vote\n"
+ "The Source of Shadows,The Source of Shadows,2020,Horror,83,USA,English,\"Ryan Bury, Jennifer Bonior\",\"Jennifer Bonior, Trevor Botkin\",Four Thieves Productions,\"Ashleigh Allard, Tom Bonington, Eliane Gagnon, Marissa Kaye Grinestaff, Jenna Heffernan, Joshua Hummel, Janice Kingsley, Chris Labasbas, Jared Laufree, Dominic Lee, Vic May, Sienna Mazzone, Lizzie Mounter, Grace Mumm, Ashley Otis\",\"A series of stories woven together by one of our most primal fears, the fear of the unknown.\",3.5\n"
+ "The Insurrection,The Insurrection,2020,Action,90,USA,English,Rene Perez,Rene Perez,,\"Michael Paré, Wilma Elles, Joseph Camilleri, Rebecca Tarabocchia, Jeanine Harrington, Malorie Glavan, Danner Boyd, Michael Cendejas, Woody Clendenen, Keely Dervin, Aaron Harvey, Tony Jackson, Michael Jarrod, Angelina Karo, Bernie Kelly\",The director of the largest media company wants to expose how left-wing powers use film to control populations.,2.9\n"
+ "Valley Girl,Valley Girl,2020,\"Comedy, Musical, Romance\",102,USA,English,Rachel Lee Goldenberg,\"Amy Talkington, Andrew Lane\",Sneak Preview Productions,\"Jessica Rothe, Josh Whitehouse, Jessie Ennis, Ashleigh Murray, Chloe Bennet, Logan Paul, Mae Whitman, Mario Revolori, Rob Huebel, Judy Greer, Alex Lewis, Alex MacNicoll, Danny Ramirez, Andrew Kai, Allyn Rachel\",\"Set to a new wave '80s soundtrack, a pair of young lovers from different backgrounds defy their parents and friends to stay together. A musical adaptation of the 1983 film.\",5.4\n"
)));
// set the output back to standard out for running the test
System.setOut(standardOut);
// same for standard in
System.setIn(standardIn);
String appOutput = outputStreamCaptor.toString();
if (frontend == null || appOutput.contains("The Source of Shadows")|| appOutput.contains("The Insurrection")|| appOutput.contains("Valley Girl")) {
// test failed
return false;
} else {
// test passed
return true;
}
} catch (Exception e) {
// make sure stdin and stdout are set correctly after we get exception in test
System.setOut(standardOut);
System.setIn(standardIn);
e.printStackTrace();
// test failed
return false;
}
}
/**
* This test runs the front end and redirects its output to a string. It then
* passes in 'g' as a command to go to the genre selection mode. It then exists
* the app by pressing 'x' to go back to the main mode and another 'x' to exit.
* The test succeeds if the genre selection screen contains all five genres
* from the data. It fails if any of them are missing, the front end has not
* been instantiated (is null), or there is an exception.
* @return true if the test passed, false if it failed
*/
public boolean testFrontendGForGenres() {
PrintStream standardOut = System.out;
InputStream standardIn = System.in;
try {
// set the input stream to our input (with an g to test of the program lists genres)
String input = "g" + System.lineSeparator() + "x" + System.lineSeparator() + "x";
InputStream inputStreamSimulator = new ByteArrayInputStream(input.getBytes());
System.setIn(inputStreamSimulator);
ByteArrayOutputStream outputStreamCaptor = new ByteArrayOutputStream();
// set the output to the stream captor to read the output of the front end
System.setOut(new PrintStream(outputStreamCaptor));
// instantiate when front end is implemented
Object frontend = new FrontEnd();
((FrontEnd)frontend).run(new Backend(new StringReader(
"title,original_title,year,genre,duration,country,language,director,writer,production_company,actors,description,avg_vote\n"
+ "The Source of Shadows,The Source of Shadows,2020,Horror,83,USA,English,\"Ryan Bury, Jennifer Bonior\",\"Jennifer Bonior, Trevor Botkin\",Four Thieves Productions,\"Ashleigh Allard, Tom Bonington, Eliane Gagnon, Marissa Kaye Grinestaff, Jenna Heffernan, Joshua Hummel, Janice Kingsley, Chris Labasbas, Jared Laufree, Dominic Lee, Vic May, Sienna Mazzone, Lizzie Mounter, Grace Mumm, Ashley Otis\",\"A series of stories woven together by one of our most primal fears, the fear of the unknown.\",3.5\n"
+ "The Insurrection,The Insurrection,2020,Action,90,USA,English,Rene Perez,Rene Perez,,\"Michael Paré, Wilma Elles, Joseph Camilleri, Rebecca Tarabocchia, Jeanine Harrington, Malorie Glavan, Danner Boyd, Michael Cendejas, Woody Clendenen, Keely Dervin, Aaron Harvey, Tony Jackson, Michael Jarrod, Angelina Karo, Bernie Kelly\",The director of the largest media company wants to expose how left-wing powers use film to control populations.,2.9\n"
+ "Valley Girl,Valley Girl,2020,\"Comedy, Musical, Romance\",102,USA,English,Rachel Lee Goldenberg,\"Amy Talkington, Andrew Lane\",Sneak Preview Productions,\"Jessica Rothe, Josh Whitehouse, Jessie Ennis, Ashleigh Murray, Chloe Bennet, Logan Paul, Mae Whitman, Mario Revolori, Rob Huebel, Judy Greer, Alex Lewis, Alex MacNicoll, Danny Ramirez, Andrew Kai, Allyn Rachel\",\"Set to a new wave '80s soundtrack, a pair of young lovers from different backgrounds defy their parents and friends to stay together. A musical adaptation of the 1983 film.\",5.4\n"
)));
// set the output back to standard out for running the test
System.setOut(standardOut);
// same for standard in
System.setIn(standardIn);
// add all tests to this method
String appOutput = outputStreamCaptor.toString();
if (frontend != null && appOutput.contains("Horror")
&& appOutput.contains("Action")
&& appOutput.contains("Comedy")
&& appOutput.contains("Musical")
&& appOutput.contains("Romance")) {
// test passes if all genres from the data are displayed on the screen
return true;
} else {
// test failed
return false;
}
} catch (Exception e) {
// make sure stdin and stdout are set correctly after we get exception in test
System.setOut(standardOut);
System.setIn(standardIn);
e.printStackTrace();
// test failed
return false;
}
}
// TODO: Front End Developer, add at least 2 more tests
/**
* This test runs the front end and redirects its output to a string. It then
* passes in 'r' as a command to go to the Ratings selection mode. It then exists
* the app by pressing 'x' to go back to the main mode and another 'x' to exit.
* The test succeeds if the Ratings selection screen contains all three Ratings
* from the data. It fails if any of them are missing, the front end has not
* been instantiated (is null), or there is an exception.
* @return true if the test passed, false if it failed
*/
public boolean testFrontendGForRatings() {
PrintStream standardOut = System.out;
InputStream standardIn = System.in;
try {
// set the input stream to our input (with an c to test of the program lists countries)
String input = "r" + System.lineSeparator() + "x" + System.lineSeparator() + "x";
InputStream inputStreamSimulator = new ByteArrayInputStream(input.getBytes());
System.setIn(inputStreamSimulator);
ByteArrayOutputStream outputStreamCaptor = new ByteArrayOutputStream();
// set the output to the stream captor to read the output of the front end
System.setOut(new PrintStream(outputStreamCaptor));
// instantiate when front end is implemented
Object frontend = new FrontEnd();
((FrontEnd)frontend).run(new Backend(new StringReader(
"title,original_title,year,genre,duration,country,language,director,writer,production_company,actors,description,avg_vote\n"
+ "The Source of Shadows,The Source of Shadows,2020,Horror,83,USA,English,\"Ryan Bury, Jennifer Bonior\",\"Jennifer Bonior, Trevor Botkin\",Four Thieves Productions,\"Ashleigh Allard, Tom Bonington, Eliane Gagnon, Marissa Kaye Grinestaff, Jenna Heffernan, Joshua Hummel, Janice Kingsley, Chris Labasbas, Jared Laufree, Dominic Lee, Vic May, Sienna Mazzone, Lizzie Mounter, Grace Mumm, Ashley Otis\",\"A series of stories woven together by one of our most primal fears, the fear of the unknown.\",3.5\n"
+ "The Insurrection,The Insurrection,2020,Action,90,USA,English,Rene Perez,Rene Perez,,\"Michael Paré, Wilma Elles, Joseph Camilleri, Rebecca Tarabocchia, Jeanine Harrington, Malorie Glavan, Danner Boyd, Michael Cendejas, Woody Clendenen, Keely Dervin, Aaron Harvey, Tony Jackson, Michael Jarrod, Angelina Karo, Bernie Kelly\",The director of the largest media company wants to expose how left-wing powers use film to control populations.,2.9\n"
+ "Valley Girl,Valley Girl,2020,\"Comedy, Musical, Romance\",102,USA,English,Rachel Lee Goldenberg,\"Amy Talkington, Andrew Lane\",Sneak Preview Productions,\"Jessica Rothe, Josh Whitehouse, Jessie Ennis, Ashleigh Murray, Chloe Bennet, Logan Paul, Mae Whitman, Mario Revolori, Rob Huebel, Judy Greer, Alex Lewis, Alex MacNicoll, Danny Ramirez, Andrew Kai, Allyn Rachel\",\"Set to a new wave '80s soundtrack, a pair of young lovers from different backgrounds defy their parents and friends to stay together. A musical adaptation of the 1983 film.\",5.4\n"
)));
// set the output back to standard out for running the test
System.setOut(standardOut);
// same for standard in
System.setIn(standardIn);
// add all tests to this method
String appOutput = outputStreamCaptor.toString();
if (frontend != null && appOutput.contains("2.9") && appOutput.contains("3.5") && appOutput.contains("5.4")) {
// test passes if all countries from the data are displayed on the screen
return true;
} else {
// test failed
return false;
}
} catch (Exception e) {
// make sure stdin and stdout are set correctly after we get exception in test
System.setOut(standardOut);
System.setIn(standardIn);
e.printStackTrace();
// test failed
return false;
}
}
/**
* This test runs the front end and redirects its output to a string.
* it already in the base mode. It then exists
* the app by pressing 'x' to exit.
* The test succeeds if the year selection screen contains both two years
* from the data. It fails if any of them are missing, the front end has not
* been instantiated (is null), or there is an exception.
* @return true if the test passed, false if it failed
*/
public boolean testFrontendGForBase() {
PrintStream standardOut = System.out;
InputStream standardIn = System.in;
try {
// set the input stream to our input (with null to test of the program base mode)
//String input = "null";
//InputStream inputStreamSimulator = new ByteArrayInputStream(input.getBytes());
//System.setIn(inputStreamSimulator);
ByteArrayOutputStream outputStreamCaptor = new ByteArrayOutputStream();
// set the output to the stream captor to read the output of the front end
System.setOut(new PrintStream(outputStreamCaptor));
// instantiate when front end is implemented
Object frontend = new FrontEnd();
((FrontEnd)frontend).run(new Backend(new StringReader(
"title,original_title,year,genre,duration,country,language,director,writer,production_company,actors,description,avg_vote\n"
+ "The Source of Shadows,The Source of Shadows,2020,Horror,83,USA,English,\"Ryan Bury, Jennifer Bonior\",\"Jennifer Bonior, Trevor Botkin\",Four Thieves Productions,\"Ashleigh Allard, Tom Bonington, Eliane Gagnon, Marissa Kaye Grinestaff, Jenna Heffernan, Joshua Hummel, Janice Kingsley, Chris Labasbas, Jared Laufree, Dominic Lee, Vic May, Sienna Mazzone, Lizzie Mounter, Grace Mumm, Ashley Otis\",\"A series of stories woven together by one of our most primal fears, the fear of the unknown.\",3.5\n"
+ "The Insurrection,The Insurrection,2020,Action,90,USA,English,Rene Perez,Rene Perez,,\"Michael Paré, Wilma Elles, Joseph Camilleri, Rebecca Tarabocchia, Jeanine Harrington, Malorie Glavan, Danner Boyd, Michael Cendejas, Woody Clendenen, Keely Dervin, Aaron Harvey, Tony Jackson, Michael Jarrod, Angelina Karo, Bernie Kelly\",The director of the largest media company wants to expose how left-wing powers use film to control populations.,2.9\n"
+ "Valley Girl,Valley Girl,2020,\"Comedy, Musical, Romance\",102,USA,English,Rachel Lee Goldenberg,\"Amy Talkington, Andrew Lane\",Sneak Preview Productions,\"Jessica Rothe, Josh Whitehouse, Jessie Ennis, Ashleigh Murray, Chloe Bennet, Logan Paul, Mae Whitman, Mario Revolori, Rob Huebel, Judy Greer, Alex Lewis, Alex MacNicoll, Danny Ramirez, Andrew Kai, Allyn Rachel\",\"Set to a new wave '80s soundtrack, a pair of young lovers from different backgrounds defy their parents and friends to stay together. A musical adaptation of the 1983 film.\",5.4\n"
)));
// set the output back to standard out for running the test
System.setOut(standardOut);
// same for standard in
System.setIn(standardIn);
// add all tests to this method
String appOutput = outputStreamCaptor.toString();
if (frontend != null && appOutput.contains("The Source of Shadows,The Source of Shadows,2020,Horror,83,USA,English,\"Ryan Bury, Jennifer Bonior\",\"Jennifer Bonior, Trevor Botkin\",Four Thieves Productions,\"Ashleigh Allard, Tom Bonington, Eliane Gagnon, Marissa Kaye Grinestaff, Jenna Heffernan, Joshua Hummel, Janice Kingsley, Chris Labasbas, Jared Laufree, Dominic Lee, Vic May, Sienna Mazzone, Lizzie Mounter, Grace Mumm, Ashley Otis\",\"A series of stories woven together by one of our most primal fears, the fear of the unknown.\",3.5\n")
&& appOutput.contains("The Insurrection,The Insurrection,2020,Action,90,USA,English,Rene Perez,Rene Perez,,\"Michael Paré, Wilma Elles, Joseph Camilleri, Rebecca Tarabocchia, Jeanine Harrington, Malorie Glavan, Danner Boyd, Michael Cendejas, Woody Clendenen, Keely Dervin, Aaron Harvey, Tony Jackson, Michael Jarrod, Angelina Karo, Bernie Kelly\",The director of the largest media company wants to expose how left-wing powers use film to control populations.,2.9\n")
&& appOutput.contains("Valley Girl,Valley Girl,2020,\"Comedy, Musical, Romance\",102,USA,English,Rachel Lee Goldenberg,\"Amy Talkington, Andrew Lane\",Sneak Preview Productions,\"Jessica Rothe, Josh Whitehouse, Jessie Ennis, Ashleigh Murray, Chloe Bennet, Logan Paul, Mae Whitman, Mario Revolori, Rob Huebel, Judy Greer, Alex Lewis, Alex MacNicoll, Danny Ramirez, Andrew Kai, Allyn Rachel\",\"Set to a new wave '80s soundtrack, a pair of young lovers from different backgrounds defy their parents and friends to stay together. A musical adaptation of the 1983 film.\",5.4\n")) {
// test passes if all movies from the data are displayed on the screen
return true;
} else {
// test failed
return false;
}
} catch (Exception e) {
// make sure stdin and stdout are set correctly after we get exception in test
System.setOut(standardOut);
System.setIn(standardIn);
e.printStackTrace();
// test failed
return false;
}
}
}