Skip to content

Commit 216ff72

Browse files
committed
Update tests.
1 parent 1ea4995 commit 216ff72

File tree

3 files changed

+32
-154
lines changed

3 files changed

+32
-154
lines changed

httprpc-test/src/main/java/org/httprpc/test/TestService.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import org.httprpc.ResourcePath;
2121
import org.httprpc.WebService;
2222
import org.httprpc.beans.BeanAdapter;
23+
import org.httprpc.beans.Key;
2324

2425
import javax.servlet.annotation.MultipartConfig;
2526
import javax.servlet.annotation.WebServlet;
@@ -45,6 +46,7 @@
4546
import java.util.List;
4647
import java.util.Map;
4748
import java.util.NoSuchElementException;
49+
import java.util.UUID;
4850

4951
import static org.httprpc.util.Collections.entry;
5052
import static org.httprpc.util.Collections.listOf;
@@ -64,6 +66,8 @@ public interface Response {
6466
LocalDate getLocalDate();
6567
LocalTime getLocalTime();
6668
LocalDateTime getLocalDateTime();
69+
@Key("uuid")
70+
UUID getUUID();
6771
List<AttachmentInfo> getAttachmentInfo();
6872
}
6973

@@ -116,7 +120,8 @@ public interface Body {
116120

117121
@RequestMethod("GET")
118122
public Map<String, ?> testGet(String string, List<String> strings, int number, boolean flag, DayOfWeek dayOfWeek,
119-
Date date, Instant instant, LocalDate localDate, LocalTime localTime, LocalDateTime localDateTime) {
123+
Date date, Instant instant, LocalDate localDate, LocalTime localTime, LocalDateTime localDateTime,
124+
UUID uuid) {
120125
return mapOf(
121126
entry("string", string),
122127
entry("strings", strings),
@@ -127,7 +132,8 @@ public interface Body {
127132
entry("instant", instant),
128133
entry("localDate", localDate),
129134
entry("localTime", localTime),
130-
entry("localDateTime", localDateTime)
135+
entry("localDateTime", localDateTime),
136+
entry("uuid", uuid)
131137
);
132138
}
133139

@@ -227,7 +233,7 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response) t
227233
@RequestMethod("POST")
228234
public Response testPost(String string, List<String> strings, int number, boolean flag, DayOfWeek dayOfWeek,
229235
Date date, Instant instant, LocalDate localDate, LocalTime localTime, LocalDateTime localDateTime,
230-
List<URL> attachments) throws IOException {
236+
UUID uuid, List<URL> attachments) throws IOException {
231237
List<Map<String, ?>> attachmentInfo = new LinkedList<>();
232238

233239
for (URL attachment : attachments) {
@@ -260,6 +266,7 @@ public Response testPost(String string, List<String> strings, int number, boolea
260266
entry("localDate", localDate),
261267
entry("localTime", localTime),
262268
entry("localDateTime", localDateTime),
269+
entry("uuid", uuid),
263270
entry("attachmentInfo", attachmentInfo)
264271
), Response.class);
265272
}

httprpc-test/src/main/webapp/index.jsp

Lines changed: 9 additions & 146 deletions
Original file line numberDiff line numberDiff line change
@@ -7,170 +7,33 @@
77

88
<body>
99

10-
<a href="${pageContext.request.contextPath}/math?api">Math (API)</a><br/>
10+
<a href="${pageContext.request.contextPath}/math?api">Math API</a><br/>
1111
<br/>
1212
<a href="${pageContext.request.contextPath}/math/sum?a=2&b=4">Sum</a><br/>
1313
<a href="${pageContext.request.contextPath}/math/sum?values=1&values=2&values=3">Sum Values</a><br/>
1414

1515
<hr/>
1616

17-
<a href="${pageContext.request.contextPath}/echo?api">Echo (API)</a><br/>
17+
<a href="${pageContext.request.contextPath}/echo?api">Echo API</a><br/>
1818
<br/>
1919
<a href="${pageContext.request.contextPath}/echo?value=héllo">Echo</a><br/>
2020

2121
<hr/>
2222

23-
<a href="${pageContext.request.contextPath}/catalog?api">Catalog (API)</a><br/>
23+
<a href="${pageContext.request.contextPath}/catalog?api">Catalog API</a><br/>
24+
<a href="${pageContext.request.contextPath}/upload?api">Upload API</a><br/>
25+
<a href="${pageContext.request.contextPath}/tree?api">Tree API</a><br/>
26+
<a href="${pageContext.request.contextPath}/test?api">Test API</a><br/>
2427

2528
<hr/>
2629

27-
<a href="${pageContext.request.contextPath}/upload?api">Upload (API)</a><br/>
28-
<br/>
29-
30-
<form action="${pageContext.request.contextPath}/upload" method="post" enctype="multipart/form-data">
31-
<table>
32-
<tr>
33-
<td>File</td><td><input type="file" name="file"/></td>
34-
</tr>
35-
<tr>
36-
<td colspan="2"><input type="submit" value="Upload"/></td>
37-
</tr>
38-
</table>
39-
</form>
40-
41-
<hr/>
42-
43-
<form action="${pageContext.request.contextPath}/upload" method="post" enctype="multipart/form-data">
44-
<table>
45-
<tr>
46-
<td>Files</td><td><input type="file" name="files" multiple/></td>
47-
</tr>
48-
<tr>
49-
<td colspan="2"><input type="submit" value="Upload"/></td>
50-
</tr>
51-
</table>
52-
</form>
53-
54-
<hr>
55-
56-
<a href="${pageContext.request.contextPath}/tree?api">Tree (API)</a><br/>
57-
<br/>
58-
<a href="${pageContext.request.contextPath}/tree">Tree</a><br/>
59-
60-
<hr>
61-
62-
<a href="${pageContext.request.contextPath}/test?api">Test (API)</a><br/>
63-
<br/>
64-
<a href="${pageContext.request.contextPath}/test?string=héllo&strings=a&strings=b&strings=c&number=123&flag=true&dayOfWeek=MONDAY&date=0&instant=1970-01-01T00:00:00.001Z&localDate=2018-06-28&localTime=10:45&localDateTime=2018-06-28T10:45">GET</a><br/>
65-
<a href="${pageContext.request.contextPath}/test/a/123/b/héllo/c/456/d/göodbye">GET (Keys)</a><br/>
66-
<a href="${pageContext.request.contextPath}/test/fibonacci?count=8">GET (Fibonacci)</a><br/>
67-
68-
<hr/>
69-
70-
<form action="${pageContext.request.contextPath}/test" method="post" enctype="application/x-www-form-urlencoded">
71-
<table>
72-
<tr>
73-
<td>String</td><td><input name="string" value="héllo"/></td>
74-
</tr>
75-
<tr>
76-
<td>Strings</td>
77-
<td>
78-
<select multiple name="strings">
79-
<option value="a" selected>a</option>
80-
<option value="b" selected>b</option>
81-
<option value="c" selected>c</option>
82-
</select>
83-
</td>
84-
</tr>
85-
<tr>
86-
<td>Number</td><td><input name="number" value="123"/></td>
87-
</tr>
88-
<tr>
89-
<td>Flag</td><td><input name="flag" value="true"/></td>
90-
</tr>
91-
<tr>
92-
<td>Day of Week</td><td><input name="dayOfWeek" value="MONDAY"/></td>
93-
</tr>
94-
<tr>
95-
<td>Date</td><td><input name="date" value="0"/></td>
96-
</tr>
97-
<tr>
98-
<td>Instant</td><td><input name="instant" value="1970-01-01T00:00:00.001Z"/></td>
99-
</tr>
100-
<tr>
101-
<td>Local Date</td><td><input name="localDate" value="2018-06-28"/></td>
102-
</tr>
103-
<tr>
104-
<td>Local Time</td><td><input name="localTime" value="10:45"/></td>
105-
</tr>
106-
<tr>
107-
<td>Local Date/Time</td><td><input name="localDateTime" value="2018-06-28T10:45"/></td>
108-
</tr>
109-
<tr>
110-
<td colspan="2"><input type="submit"/></td>
111-
</tr>
112-
</table>
113-
</form>
114-
115-
<hr/>
116-
117-
<form action="${pageContext.request.contextPath}/test" method="post" enctype="multipart/form-data">
118-
<table>
119-
<tr>
120-
<td>String</td><td><input name="string" value="héllo"/></td>
121-
</tr>
122-
<tr>
123-
<td>Strings</td>
124-
<td>
125-
<select multiple name="strings">
126-
<option value="a" selected>a</option>
127-
<option value="b" selected>b</option>
128-
<option value="c" selected>c</option>
129-
</select>
130-
</td>
131-
</tr>
132-
<tr>
133-
<td>Number</td><td><input name="number" value="123"/></td>
134-
</tr>
135-
<tr>
136-
<td>Flag</td><td><input name="flag" value="true"/></td>
137-
</tr>
138-
<tr>
139-
<td>Day of Week</td><td><input name="dayOfWeek" value="MONDAY"/></td>
140-
</tr>
141-
<tr>
142-
<td>Date</td><td><input name="date" value="0"/></td>
143-
</tr>
144-
<tr>
145-
<td>Instant</td><td><input name="instant" value="1970-01-01T00:00:00.001Z"/></td>
146-
</tr>
147-
<tr>
148-
<td>Local Date</td><td><input name="localDate" value="2018-06-28"/></td>
149-
</tr>
150-
<tr>
151-
<td>Local Time</td><td><input name="localTime" value="10:45"/></td>
152-
</tr>
153-
<tr>
154-
<td>Local Date/Time</td><td><input name="localDateTime" value="2018-06-28T10:45"/></td>
155-
</tr>
156-
<tr>
157-
<td>Attachments</td><td><input type="file" name="attachments" multiple/></td>
158-
</tr>
159-
<tr>
160-
<td colspan="2"><input type="submit"/></td>
161-
</tr>
162-
</table>
163-
</form>
164-
165-
<hr/>
166-
167-
<a href="${pageContext.request.contextPath}/system-info?api">System Info (API)</a><br/>
30+
<a href="${pageContext.request.contextPath}/system-info?api">System Info API</a><br/>
16831
<br/>
16932
<a href="${pageContext.request.contextPath}/system-info">System Info</a><br/>
17033

17134
<hr/>
17235

173-
<a href="${pageContext.request.contextPath}/pets?api">Pets (API)</a><br/>
36+
<a href="${pageContext.request.contextPath}/pets?api">Pets API</a><br/>
17437
<br/>
17538
<a href="${pageContext.request.contextPath}/pets?owner=Gwen">Pets (JSON)</a><br/>
17639
<a href="${pageContext.request.contextPath}/pets?owner=Gwen&format=csv">Pets (CSV)</a><br/>
@@ -180,7 +43,7 @@
18043

18144
<hr/>
18245

183-
<a href="${pageContext.request.contextPath}/employees?api">Employees (API)</a><br/>
46+
<a href="${pageContext.request.contextPath}/employees?api">Employees API</a><br/>
18447

18548
</body>
18649
</html>

httprpc-test/src/test/java/org/httprpc/WebServiceProxyTest.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import java.util.Date;
3838
import java.util.List;
3939
import java.util.Map;
40+
import java.util.UUID;
4041

4142
import static org.httprpc.util.Collections.entry;
4243
import static org.httprpc.util.Collections.listOf;
@@ -60,6 +61,8 @@ public interface Response {
6061
LocalDate getLocalDate();
6162
LocalTime getLocalTime();
6263
LocalDateTime getLocalDateTime();
64+
@Key("uuid")
65+
UUID getUUID();
6366
List<AttachmentInfo> getAttachmentInfo();
6467
}
6568

@@ -143,13 +146,12 @@ public static class CustomException extends IOException {
143146
private URL baseURL;
144147

145148
private DayOfWeek dayOfWeek = DayOfWeek.MONDAY;
146-
147149
private Date date = new Date();
148150
private Instant instant = Instant.ofEpochMilli(1);
149-
150151
private LocalDate localDate = LocalDate.now();
151152
private LocalTime localTime = LocalTime.now();
152153
private LocalDateTime localDateTime = LocalDateTime.now();
154+
private UUID uuid = UUID.randomUUID();
153155

154156
private static final int EOF = -1;
155157

@@ -169,7 +171,8 @@ public void testGet() throws IOException {
169171
entry("date", date),
170172
entry("localDate", localDate),
171173
entry("localTime", localTime),
172-
entry("localDateTime", localDateTime)
174+
entry("localDateTime", localDateTime),
175+
entry("uuid", uuid)
173176
)).invoke();
174177

175178
assertEquals(mapOf(
@@ -182,7 +185,8 @@ public void testGet() throws IOException {
182185
entry("instant", instant.toString()),
183186
entry("localDate", localDate.toString()),
184187
entry("localTime", localTime.toString()),
185-
entry("localDateTime", localDateTime.toString())
188+
entry("localDateTime", localDateTime.toString()),
189+
entry("uuid", uuid.toString())
186190
), result);
187191
}
188192

@@ -229,7 +233,8 @@ public void testURLEncodedPost() throws IOException {
229233
entry("instant", instant),
230234
entry("localDate", localDate),
231235
entry("localTime", localTime),
232-
entry("localDateTime", localDateTime)
236+
entry("localDateTime", localDateTime),
237+
entry("uuid", uuid)
233238
)).invoke();
234239

235240
assertEquals(mapOf(
@@ -243,6 +248,7 @@ public void testURLEncodedPost() throws IOException {
243248
entry("localDate", localDate.toString()),
244249
entry("localTime", localTime.toString()),
245250
entry("localDateTime", localDateTime.toString()),
251+
entry("uuid", uuid.toString()),
246252
entry("attachmentInfo", listOf())
247253
), result);
248254
}
@@ -263,6 +269,7 @@ public void testMultipartPost() throws IOException {
263269
entry("localDate", localDate),
264270
entry("localTime", localTime),
265271
entry("localDateTime", localDateTime),
272+
entry("uuid", uuid),
266273
entry("attachments", listOf(textTestURL, imageTestURL))
267274
)).invoke(Response.class);
268275

@@ -278,6 +285,7 @@ public void testMultipartPost() throws IOException {
278285
&& response.getLocalDate().equals(localDate)
279286
&& response.getLocalTime().equals(localTime)
280287
&& response.getLocalDateTime().equals(localDateTime)
288+
&& response.getUUID().equals(uuid)
281289
&& response.getAttachmentInfo().get(0).getBytes() == 26
282290
&& response.getAttachmentInfo().get(0).getChecksum() == 2412
283291
&& response.getAttachmentInfo().get(1).getBytes() == 10392

0 commit comments

Comments
 (0)