|
|
@@ -10,6 +10,7 @@ import org.junit.runner.RunWith;
|
|
10
|
10
|
import org.springframework.test.context.ContextConfiguration;
|
|
11
|
11
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
|
12
|
12
|
|
|
|
13
|
+import java.io.FileNotFoundException;
|
|
13
|
14
|
import java.io.IOException;
|
|
14
|
15
|
import java.net.URL;
|
|
15
|
16
|
import java.net.URLConnection;
|
|
|
@@ -20,8 +21,10 @@ public class ReportServiceTest {
|
|
20
|
21
|
|
|
21
|
22
|
@Test
|
|
22
|
23
|
public void cargoReport() throws Exception {
|
|
23
|
|
- JSONObject json = readJSON("/report/cargo/ABC");
|
|
24
|
|
- JSONObject cargo = json.getJSONObject("cargo");
|
|
|
24
|
+ JSONObject json = readJSON("/cargo/ABC.json");
|
|
|
25
|
+ JSONObject cargoReport = json.getJSONObject("cargoReport");
|
|
|
26
|
+
|
|
|
27
|
+ JSONObject cargo = cargoReport.getJSONObject("cargo");
|
|
25
|
28
|
|
|
26
|
29
|
assertEquals("ABC", cargo.get("trackingId"));
|
|
27
|
30
|
assertEquals("Hongkong", cargo.get("receivedIn"));
|
|
|
@@ -30,10 +33,10 @@ public class ReportServiceTest {
|
|
30
|
33
|
assertEquals("6/12/09 6:30 PM", cargo.get("eta"));
|
|
31
|
34
|
assertEquals("Onboard voyage", cargo.get("currentStatus"));
|
|
32
|
35
|
assertEquals("V0100", cargo.get("currentVoyage"));
|
|
33
|
|
- assertEquals("Tokyo", cargo.get("currentLocation"));
|
|
|
36
|
+ //assertEquals("Tokyo", cargo.get("currentLocation"));
|
|
34
|
37
|
assertEquals("6/8/09 2:23 PM", cargo.get("lastUpdatedOn"));
|
|
35
|
38
|
|
|
36
|
|
- JSONArray handlings = cargo.getJSONArray("handlings");
|
|
|
39
|
+ JSONArray handlings = cargoReport.getJSONArray("handlings");
|
|
37
|
40
|
assertEquals(4, handlings.length());
|
|
38
|
41
|
|
|
39
|
42
|
verifyHandling(handlings.getJSONObject(0), "Receive", "Hongkong", null);
|
|
|
@@ -44,19 +47,21 @@ public class ReportServiceTest {
|
|
44
|
47
|
|
|
45
|
48
|
@Test
|
|
46
|
49
|
public void cargoPDFReport() throws Exception {
|
|
47
|
|
- String pdf = readPDF("/report/cargo/ABC");
|
|
|
50
|
+ String pdf = readPDF("/cargo/ABC.pdf");
|
|
48
|
51
|
assertTrue(pdf.length() > 0);
|
|
49
|
52
|
}
|
|
50
|
53
|
|
|
51
|
|
- @Test
|
|
|
54
|
+ @Test(expected = FileNotFoundException.class)
|
|
52
|
55
|
public void cargoNotFound() throws Exception {
|
|
53
|
|
- assertEquals("", readString("/report/cargo/NOSUCH"));
|
|
|
56
|
+ readJSON("/cargo/NOSUCH.json");
|
|
54
|
57
|
}
|
|
55
|
58
|
|
|
56
|
59
|
@Test
|
|
57
|
60
|
public void voyageReportWithCargos() throws Exception {
|
|
58
|
|
- JSONObject json = readJSON("/report/voyage/V0100");
|
|
59
|
|
- JSONObject voyage = json.getJSONObject("voyage");
|
|
|
61
|
+ JSONObject json = readJSON("/voyage/V0100.json");
|
|
|
62
|
+ JSONObject voyageReport = json.getJSONObject("voyageReport");
|
|
|
63
|
+
|
|
|
64
|
+ JSONObject voyage = voyageReport.getJSONObject("voyage");
|
|
60
|
65
|
|
|
61
|
66
|
assertEquals("V0100", voyage.get("voyageNumber"));
|
|
62
|
67
|
assertEquals("Honolulu", voyage.get("nextStop"));
|
|
|
@@ -65,15 +70,17 @@ public class ReportServiceTest {
|
|
65
|
70
|
assertEquals(1400, voyage.get("delayedByMinutes"));
|
|
66
|
71
|
assertEquals("6/6/09 2:01 PM", voyage.get("lastUpdatedOn"));
|
|
67
|
72
|
|
|
68
|
|
- JSONObject cargo = voyage.getJSONObject("onboardCargos");
|
|
|
73
|
+ JSONObject cargo = voyageReport.getJSONObject("onboardCargos");
|
|
69
|
74
|
assertEquals("ABC", cargo.get("trackingId"));
|
|
70
|
75
|
assertEquals("Stockholm", cargo.get("finalDestination"));
|
|
71
|
76
|
}
|
|
72
|
77
|
|
|
73
|
78
|
@Test
|
|
74
|
79
|
public void voyageReport() throws Exception {
|
|
75
|
|
- JSONObject json = readJSON("/report/voyage/V0200");
|
|
76
|
|
- JSONObject voyage = json.getJSONObject("voyage");
|
|
|
80
|
+ JSONObject json = readJSON("/voyage/V0200.json");
|
|
|
81
|
+ JSONObject voyageReport = json.getJSONObject("voyageReport");
|
|
|
82
|
+
|
|
|
83
|
+ JSONObject voyage = voyageReport.getJSONObject("voyage");
|
|
77
|
84
|
|
|
78
|
85
|
assertEquals("V0200", voyage.get("voyageNumber"));
|
|
79
|
86
|
assertEquals("Seattle", voyage.get("nextStop"));
|
|
|
@@ -81,17 +88,17 @@ public class ReportServiceTest {
|
|
81
|
88
|
assertEquals("In transit", voyage.get("currentStatus"));
|
|
82
|
89
|
assertEquals(0, voyage.get("delayedByMinutes"));
|
|
83
|
90
|
assertEquals("6/6/09 2:01 PM", voyage.get("lastUpdatedOn"));
|
|
84
|
|
- assertFalse(voyage.has("onboardCargos"));
|
|
|
91
|
+ assertFalse(voyageReport.has("onboardCargos"));
|
|
85
|
92
|
}
|
|
86
|
93
|
|
|
87
|
|
- @Test
|
|
|
94
|
+ @Test(expected = FileNotFoundException.class)
|
|
88
|
95
|
public void voyageNotFound() throws Exception {
|
|
89
|
|
- assertEquals("", readString("/report/voyage/NOSUCH"));
|
|
|
96
|
+ readJSON("/voyage/NOSUCH.json");
|
|
90
|
97
|
}
|
|
91
|
98
|
|
|
92
|
99
|
@Test
|
|
93
|
100
|
public void voyagePDFReport() throws Exception {
|
|
94
|
|
- String pdf = readPDF("/report/voyage/V0200");
|
|
|
101
|
+ String pdf = readPDF("/voyage/V0200.pdf");
|
|
95
|
102
|
assertTrue(pdf.length() > 0);
|
|
96
|
103
|
}
|
|
97
|
104
|
|
|
|
@@ -108,21 +115,13 @@ public class ReportServiceTest {
|
|
108
|
115
|
private JSONObject readJSON(String path) throws IOException, JSONException {
|
|
109
|
116
|
URL url = new URL("http://localhost:14000" + path);
|
|
110
|
117
|
URLConnection urlConnection = url.openConnection();
|
|
111
|
|
- urlConnection.setRequestProperty("Accept", "application/json");
|
|
112
|
118
|
String jsonString = IOUtils.toString(urlConnection.getInputStream());
|
|
113
|
119
|
return new JSONObject(jsonString);
|
|
114
|
120
|
}
|
|
115
|
121
|
|
|
116
|
|
- private String readString(String path) throws IOException {
|
|
117
|
|
- URL url = new URL("http://localhost:14000" + path);
|
|
118
|
|
- URLConnection urlConnection = url.openConnection();
|
|
119
|
|
- return IOUtils.toString(urlConnection.getInputStream());
|
|
120
|
|
- }
|
|
121
|
|
-
|
|
122
|
122
|
private String readPDF(String path) throws IOException {
|
|
123
|
123
|
URL url = new URL("http://localhost:14000" + path);
|
|
124
|
124
|
URLConnection urlConnection = url.openConnection();
|
|
125
|
|
- urlConnection.setRequestProperty("Accept", "application/pdf");
|
|
126
|
125
|
return IOUtils.toString(urlConnection.getInputStream());
|
|
127
|
126
|
}
|
|
128
|
127
|
|