|
|
@@ -21,7 +21,7 @@ import java.io.IOException;
|
|
21
|
21
|
public class ReportServiceTest {
|
|
22
|
22
|
|
|
23
|
23
|
@Test
|
|
24
|
|
- public void deliveryReport() throws Exception {
|
|
|
24
|
+ public void cargoReport() throws Exception {
|
|
25
|
25
|
JSONObject json = readJSON("/report/cargo/ABC");
|
|
26
|
26
|
JSONObject cargo = json.getJSONObject("cargo");
|
|
27
|
27
|
|
|
|
@@ -44,6 +44,29 @@ public class ReportServiceTest {
|
|
44
|
44
|
verifyHandling(handlings.getJSONObject(3), "Load", "Long Beach", "V0200");
|
|
45
|
45
|
}
|
|
46
|
46
|
|
|
|
47
|
+ @Test
|
|
|
48
|
+ public void cargoNotFound() throws Exception {
|
|
|
49
|
+ assertEquals("", readString("/report/cargo/NOSUCH"));
|
|
|
50
|
+ }
|
|
|
51
|
+
|
|
|
52
|
+ @Test
|
|
|
53
|
+ public void voyageReport() throws Exception {
|
|
|
54
|
+ JSONObject json = readJSON("/report/voyage/V0200");
|
|
|
55
|
+ JSONObject voyage = json.getJSONObject("voyage");
|
|
|
56
|
+
|
|
|
57
|
+ assertEquals("V0200", voyage.get("voyageNumber"));
|
|
|
58
|
+ assertEquals("Seattle", voyage.get("nextStop"));
|
|
|
59
|
+ assertEquals("6/7/09 12:45 PM", voyage.get("etaNextStop"));
|
|
|
60
|
+ assertEquals("In transit", voyage.get("currentStatus"));
|
|
|
61
|
+ assertEquals(0, voyage.get("delayedByMinutes"));
|
|
|
62
|
+ assertEquals("6/6/09 2:01 PM", voyage.get("lastUpdatedOn"));
|
|
|
63
|
+ }
|
|
|
64
|
+
|
|
|
65
|
+ @Test
|
|
|
66
|
+ public void voyageNotFound() throws Exception {
|
|
|
67
|
+ assertEquals("", readString("/report/voyage/NOSUCH"));
|
|
|
68
|
+ }
|
|
|
69
|
+
|
|
47
|
70
|
private void verifyHandling(JSONObject handling, String type, String location, String voyage) throws JSONException {
|
|
48
|
71
|
assertEquals(type, handling.get("type"));
|
|
49
|
72
|
assertEquals(location, handling.get("location"));
|
|
|
@@ -54,18 +77,14 @@ public class ReportServiceTest {
|
|
54
|
77
|
}
|
|
55
|
78
|
}
|
|
56
|
79
|
|
|
57
|
|
- @Test
|
|
58
|
|
- public void voyageReport() throws Exception {
|
|
59
|
|
- JSONObject json = readJSON("/report/voyage/V0200");
|
|
60
|
|
- JSONObject voyage = json.getJSONObject("voyage");
|
|
61
|
|
-
|
|
62
|
|
- assertEquals("V0200", voyage.get("voyageNumber"));
|
|
|
80
|
+ private JSONObject readJSON(String path) throws IOException, JSONException {
|
|
|
81
|
+ String jsonString = readString(path);
|
|
|
82
|
+ return new JSONObject(jsonString);
|
|
63
|
83
|
}
|
|
64
|
84
|
|
|
65
|
|
- private JSONObject readJSON(String path) throws IOException, JSONException {
|
|
|
85
|
+ private String readString(String path) throws IOException {
|
|
66
|
86
|
URLConnection urlConnection = new URL("http://localhost:14000" + path).openConnection();
|
|
67
|
|
- String jsonString = IOUtils.toString(urlConnection.getInputStream());
|
|
68
|
|
- return new JSONObject(jsonString);
|
|
|
87
|
+ return IOUtils.toString(urlConnection.getInputStream());
|
|
69
|
88
|
}
|
|
70
|
89
|
|
|
71
|
90
|
}
|