-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAPITest.java
More file actions
435 lines (296 loc) · 12 KB
/
Copy pathAPITest.java
File metadata and controls
435 lines (296 loc) · 12 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
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
package org.transitime;
/*-
* #%L
* transitimeWebappRegression
* %%
* Copyright (C) 2017 Sean Óg Crudden
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/gpl-3.0.html>.
* #L%
*/
import org.testng.annotations.Test;
import java.util.List;
import java.util.concurrent.TimeUnit;
import org.json.JSONArray;
import org.json.JSONObject;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.Select;
import org.testng.Assert;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.AfterTest;
/**
* @author Sean Óg Crudden
* Test the API end points.
*
*/
public class APITest {
private WebDriver driver;
private String baseUrl="http://127.0.0.1:8080/web";
/**
* This goes to the API screen and selects "Agencies" and then reads the json result to check there is at least one agency.
* @throws InterruptedException
*/
@Test
public void getAgencies() {
driver.get(baseUrl);
String title = driver.getTitle();
Assert.assertTrue(title.contains("Agencies"));
driver.findElement(By.partialLinkText("API")).click();
driver.findElement(By.partialLinkText("Agencies")).click();
driver.findElement(By.id("submit")).click();;
String jsonResult=driver.findElement(By.tagName("body")).getText();
JSONObject objResult = new JSONObject(jsonResult);
JSONArray agencies = objResult.getJSONArray("agency");
Assert.assertTrue(agencies.length()>0);
}
/**
* This goes to the API screen and selects "Routes" and then reads the json result to check there is at least one route.
* @throws InterruptedException
*/
@Test
public void getRouteInfo() {
driver.get(baseUrl);
String title = driver.getTitle();
Assert.assertTrue(title.contains("Agencies"));
driver.findElement(By.partialLinkText("API")).click();
driver.findElement(By.partialLinkText("Routes")).click();
driver.findElement(By.id("submit")).click();;
String jsonResult=driver.findElement(By.tagName("body")).getText();
JSONObject objResult = new JSONObject(jsonResult);
JSONArray routes = objResult.getJSONArray("routes");
Assert.assertTrue(routes.length()>0);
}
/**
* This goes to the API screen and selects "Vehicles" and then reads the json result to check there is at least one vehicle.
* @throws InterruptedException
*/
@Test
public void getVehicleInfo() {
driver.get(baseUrl);
String title = driver.getTitle();
Assert.assertTrue(title.contains("Agencies"));
driver.findElement(By.partialLinkText("API")).click();
driver.findElement(By.partialLinkText("Vehicles")).click();
driver.findElement(By.id("submit")).click();;
String jsonResult=driver.findElement(By.tagName("body")).getText();
JSONObject objResult = new JSONObject(jsonResult);
JSONArray vehicles = objResult.getJSONArray("vehicles");
Assert.assertTrue(vehicles.length()>0);
}
/**
* This goes to the API screen and selects "Vehicle Configurations" and then reads the json result to check there is at least one vehicles configuration.
* @throws InterruptedException
*/
@Test
public void getVehicleConfigurationInfo() {
driver.get(baseUrl);
String title = driver.getTitle();
Assert.assertTrue(title.contains("Agencies"));
driver.findElement(By.partialLinkText("API")).click();
driver.findElement(By.partialLinkText("Vehicle Configurations")).click();
driver.findElement(By.id("submit")).click();;
String jsonResult=driver.findElement(By.tagName("body")).getText();
JSONObject objResult = new JSONObject(jsonResult);
JSONArray vehicleConfigurations = objResult.getJSONArray("vehicleConfig");
Assert.assertTrue(vehicleConfigurations.length()>0);
}
/**
* This goes to the API screen and selects "Blocks" and then reads the json result to check there is at least one block configuration.
* @throws InterruptedException
*/
@Test
public void getBlockInfo() {
driver.get(baseUrl);
String title = driver.getTitle();
Assert.assertTrue(title.contains("Agencies"));
driver.findElement(By.partialLinkText("API")).click();
driver.findElement(By.partialLinkText("Block")).click();
driver.findElement(By.id("submit")).click();;
String jsonResult=driver.findElement(By.tagName("body")).getText();
JSONObject objResult = new JSONObject(jsonResult);
JSONArray blocks = objResult.getJSONArray("block");
Assert.assertTrue(blocks.length()>0);
}
/**
* This goes to the API screen and selects "Block details" and then reads the json result to check there is at least one block.
* @throws InterruptedException
*/
@Test
public void getBlockDetails() {
driver.get(baseUrl);
String title = driver.getTitle();
Assert.assertTrue(title.contains("Agencies"));
driver.findElement(By.partialLinkText("API")).click();
driver.findElement(By.partialLinkText("Block Details")).click();
driver.findElement(By.id("submit")).click();;
String jsonResult=driver.findElement(By.tagName("body")).getText();
JSONObject objResult = new JSONObject(jsonResult);
JSONArray blocks = objResult.getJSONArray("block");
Assert.assertTrue(blocks.length()>0);
}
/**
* This goes to the API screen and selects "Service ID" and then reads the json result to check there is at least one service id configuration.
* @throws InterruptedException
*/
@Test
public void getServiceInfo() {
driver.get(baseUrl);
String title = driver.getTitle();
Assert.assertTrue(title.contains("Agencies"));
driver.findElement(By.partialLinkText("API")).click();
driver.findElement(By.partialLinkText("Service IDs")).click();
driver.findElement(By.id("submit")).click();;
String jsonResult=driver.findElement(By.tagName("body")).getText();
JSONObject objResult = new JSONObject(jsonResult);
JSONArray ids = objResult.getJSONArray("ids");
Assert.assertTrue(ids.length()>0);
}
/**
* This goes to the API screen and selects "GTFS-Realtime trip updates" and then reads the json result to check there is at least one update.
* @throws InterruptedException
*/
@Test
public void getGTFSRealtimeUpdateDetails() {
driver.get(baseUrl);
String title = driver.getTitle();
Assert.assertTrue(title.contains("Agencies"));
driver.findElement(By.partialLinkText("API")).click();
driver.findElement(By.partialLinkText("GTFS-realtime Trip Updates")).click();
//select second option to be human readable format
driver.findElements(By.name("format")).get(1).click();
driver.findElement(By.id("submit")).click();
String text = driver.findElement(By.tagName("body")).getText();
Assert.assertTrue(text.contains("header"));
}
/**
* This goes to the API screen and selects "GTFS-Realtime vehicle positions" and then reads the json result to check there is at least one vehicle position.
* @throws InterruptedException
*/
@Test
public void getGTFSRealtimeVehiclePositions() {
driver.get(baseUrl);
String title = driver.getTitle();
Assert.assertTrue(title.contains("Agencies"));
driver.findElement(By.partialLinkText("API")).click();
driver.findElement(By.partialLinkText("GTFS-realtime Vehicle Positions")).click();
//select second option to be human readable format
driver.findElements(By.name("format")).get(1).click();
driver.findElement(By.id("submit")).click();
String text = driver.findElement(By.tagName("body")).getText();
Assert.assertTrue(text.contains("entity"));
}
/**
* This goes to the API screen and selects "SIRI Vehicle Monitoring" and then reads the json result to check there is ServiceDelivery.
* @throws InterruptedException
*/
@Test
public void getSIRIVehicleMonitoring() {
driver.get(baseUrl);
String title = driver.getTitle();
Assert.assertTrue(title.contains("Agencies"));
driver.findElement(By.partialLinkText("API")).click();
driver.findElement(By.partialLinkText("SIRI Vehicle Monitoring")).click();
driver.findElement(By.id("submit")).click();;
String jsonResult=driver.findElement(By.tagName("body")).getText();
JSONObject objResult = new JSONObject(jsonResult);
JSONObject objServiceDelivery = objResult.getJSONObject("ServiceDelivery");
String responseTimestamp = objServiceDelivery.getString("ResponseTimestamp");
Assert.assertTrue(responseTimestamp != null);
}
/**
* This goes to the API screen and selects "Schedule for Route, stops horizontal" and then reads the json result to check there is at least one schedule.
* @throws InterruptedException
*/
@Test
public void getScheduleForRouteHorizontal() {
driver.get(baseUrl);
String title = driver.getTitle();
Assert.assertTrue(title.contains("Agencies"));
driver.findElement(By.partialLinkText("API")).click();
driver.findElement(By.partialLinkText("Schedule for Route, stops horizontal")).click();
driver.findElement(By.id("submit")).click();;
String jsonResult=driver.findElement(By.tagName("body")).getText();
JSONObject objResult = new JSONObject(jsonResult);
JSONArray vehicles = objResult.getJSONArray("schedule");
Assert.assertTrue(vehicles.length()>0);
}
/**
* This goes to the API screen and selects "Schedule for Route, stops vertical" and then reads the json result to check there is at least one schedule.
* @throws InterruptedException
*/
@Test
public void getScheduleForRouteVertical() {
driver.get(baseUrl);
String title = driver.getTitle();
Assert.assertTrue(title.contains("Agencies"));
driver.findElement(By.partialLinkText("API")).click();
driver.findElement(By.partialLinkText("Schedule for Route, stops vertical")).click();
driver.findElement(By.id("submit")).click();;
String jsonResult=driver.findElement(By.tagName("body")).getText();
JSONObject objResult = new JSONObject(jsonResult);
JSONArray schedules = objResult.getJSONArray("schedule");
Assert.assertTrue(schedules.length()>0);
}
/**
* This goes to the API screen and selects "Vehicles" and then reads the json result to check there is at least one vehicle.
* @throws InterruptedException
*/
@Test
public void getVehicleDetails() {
driver.get(baseUrl);
String title = driver.getTitle();
Assert.assertTrue(title.contains("Agencies"));
driver.findElement(By.partialLinkText("API")).click();
driver.findElement(By.partialLinkText("Vehicles")).click();
driver.findElement(By.id("submit")).click();;
String jsonResult=driver.findElement(By.tagName("body")).getText();
JSONObject objResult = new JSONObject(jsonResult);
JSONArray vehicles = objResult.getJSONArray("vehicles");
Assert.assertTrue(vehicles.length()>0);
}
/**
* This goes to the API screen and selects "Route Details" and then reads the json result to check there is at least one route.
* @throws InterruptedException
*/
@Test
public void getRouteDetails() {
driver.get(baseUrl);
String title = driver.getTitle();
Assert.assertTrue(title.contains("Agencies"));
driver.findElement(By.partialLinkText("API")).click();
driver.findElement(By.partialLinkText("Route Details")).click();
driver.findElement(By.id("submit")).click();;
String jsonResult=driver.findElement(By.tagName("body")).getText();
JSONObject objResult = new JSONObject(jsonResult);
JSONArray routes = objResult.getJSONArray("routes");
Assert.assertTrue(routes.length()>0);
}
@BeforeTest
public void beforeTest() {
driver = new ChromeDriver();
driver.manage().timeouts().pageLoadTimeout(10, TimeUnit.SECONDS);
if(System.getProperty("baseurl")!=null&&System.getProperty("baseurl").length()>0)
{
this.baseUrl=System.getProperty("baseurl");
}
}
@AfterTest
public void afterTest() {
driver.quit();
}
}