Skip to content

Commit 5c85c0d

Browse files
committed
Move integration tests back into main module.
1 parent a39ddd7 commit 5c85c0d

File tree

5 files changed

+55
-54
lines changed

5 files changed

+55
-54
lines changed

httprpc-test/build.gradle

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ dependencies {
3131
providedCompile 'javax.servlet.jsp:javax.servlet.jsp-api:2.3.1'
3232
implementation 'org.mongodb:mongo-java-driver:3.6.3'
3333
implementation 'mysql:mysql-connector-java:8.0.15'
34-
testCompile 'junit:junit:4.12'
3534
}
3635

3736
compileJava {

httprpc-test/src/test/java/org/httprpc/test/BulkUploadTest.java renamed to httprpc/src/test/java/org/httprpc/BulkUploadTest.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,13 @@
1212
* limitations under the License.
1313
*/
1414

15-
package org.httprpc.test;
15+
package org.httprpc;
1616

1717
import java.io.IOException;
1818
import java.net.URL;
1919
import java.util.Iterator;
2020
import java.util.Map;
2121

22-
import org.httprpc.AbstractTest;
23-
import org.httprpc.WebServiceProxy;
2422
import org.httprpc.io.CSVEncoder;
2523

2624
public class BulkUploadTest extends AbstractTest {
@@ -64,7 +62,7 @@ public static void main(String[] args) throws Exception {
6462
}
6563

6664
private static void testUpload() throws IOException {
67-
testUpload("http://localhost:8080/httprpc-test/bulk-upload/upload", "Upload", 5000);
65+
testUpload("http://localhost:8080/httprpc-test/bulk-upload/upload", "Upload", 500);
6866
testUpload("http://localhost:8080/httprpc-test/bulk-upload/upload-batch", "Upload Batch", 500000);
6967
}
7068

@@ -85,4 +83,4 @@ private static void testUpload(String url, String description, int count) throws
8583

8684
System.out.printf("%s (%d) %.1f\n", description, count, (t1 - t0) / 1000.0);
8785
}
88-
}
86+
}

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

Lines changed: 52 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* limitations under the License.
1313
*/
1414

15-
package org.httprpc.test;
15+
package org.httprpc;
1616

1717
import java.awt.image.BufferedImage;
1818
import java.io.IOException;
@@ -31,10 +31,7 @@
3131

3232
import javax.imageio.ImageIO;
3333

34-
import org.httprpc.*;
3534
import org.httprpc.beans.BeanAdapter;
36-
import org.junit.Assert;
37-
import org.junit.Test;
3835

3936
public class WebServiceProxyTest extends AbstractTest {
4037
public interface TestService {
@@ -84,22 +81,37 @@ public interface TreeNode {
8481
public List<TreeNode> getChildren();
8582
}
8683

87-
private Date date = new Date();
84+
private static Date date = new Date();
8885

89-
private LocalDate localDate = LocalDate.now();
90-
private LocalTime localTime = LocalTime.now();
91-
private LocalDateTime localDateTime = LocalDateTime.now();
86+
private static LocalDate localDate = LocalDate.now();
87+
private static LocalTime localTime = LocalTime.now();
88+
private static LocalDateTime localDateTime = LocalDateTime.now();
9289

9390
private static final int EOF = -1;
9491

95-
@Test
96-
public void testGet() throws Exception {
92+
public static void main(String[] args) throws Exception {
93+
testGet();
94+
testGetFibonnaci();
95+
testURLEncodedPost();
96+
testMultipartPost();
97+
testCustomPost();
98+
testPut();
99+
testDelete();
100+
testUnauthorized();
101+
testError();
102+
testTimeout();
103+
testMath();
104+
testMathService();
105+
testTree();
106+
}
107+
108+
public static void testGet() throws Exception {
97109
TestService testService = WebServiceProxy.adapt(new URL("http://localhost:8080/httprpc-test/test"), TestService.class);
98110

99111
Map<String, ?> result = testService.testGet("héllo+gøodbye", listOf("a", "b", "c"), 123, true,
100112
date, localDate, localTime, localDateTime);
101113

102-
Assert.assertTrue("GET", result.get("string").equals("héllo+gøodbye")
114+
validate("GET", result.get("string").equals("héllo+gøodbye")
103115
&& result.get("strings").equals(listOf("a", "b", "c"))
104116
&& result.get("number").equals(123L)
105117
&& result.get("flag").equals(true)
@@ -109,17 +121,15 @@ public void testGet() throws Exception {
109121
&& result.get("localDateTime").equals(localDateTime.toString()));
110122
}
111123

112-
@Test
113-
public void testGetFibonnaci() throws Exception {
124+
public static void testGetFibonnaci() throws Exception {
114125
TestService testService = WebServiceProxy.adapt(new URL("http://localhost:8080/httprpc-test/test/"), TestService.class);
115126

116127
List<Integer> fibonacci = testService.testGetFibonacci();
117128

118-
Assert.assertTrue("GET (Fibonacci)", fibonacci.equals(listOf(1, 2, 3, 5, 8, 13)));
129+
validate("GET (Fibonacci)", fibonacci.equals(listOf(1, 2, 3, 5, 8, 13)));
119130
}
120131

121-
@Test
122-
public void testURLEncodedPost() throws Exception {
132+
public static void testURLEncodedPost() throws Exception {
123133
WebServiceProxy webServiceProxy = new WebServiceProxy("POST", new URL("http://localhost:8080/httprpc-test/test"));
124134

125135
webServiceProxy.setArguments(mapOf(
@@ -135,7 +145,7 @@ public void testURLEncodedPost() throws Exception {
135145

136146
Map<String, ?> result = webServiceProxy.invoke();
137147

138-
Assert.assertTrue("POST (URL-encoded)", result.get("string").equals("héllo+gøodbye")
148+
validate("POST (URL-encoded)", result.get("string").equals("héllo+gøodbye")
139149
&& result.get("strings").equals(listOf("a", "b", "c"))
140150
&& result.get("number").equals(123L)
141151
&& result.get("flag").equals(true)
@@ -146,8 +156,7 @@ public void testURLEncodedPost() throws Exception {
146156
&& result.get("attachmentInfo").equals(listOf()));
147157
}
148158

149-
@Test
150-
public void testMultipartPost() throws Exception {
159+
public static void testMultipartPost() throws Exception {
151160
URL textTestURL = WebServiceProxyTest.class.getResource("test.txt");
152161
URL imageTestURL = WebServiceProxyTest.class.getResource("test.jpg");
153162

@@ -157,7 +166,7 @@ public void testMultipartPost() throws Exception {
157166
date, localDate, localTime, localDateTime,
158167
listOf(textTestURL, imageTestURL));
159168

160-
Assert.assertTrue("POST (multipart)", response.getString().equals("héllo+gøodbye")
169+
validate("POST (multipart)", response.getString().equals("héllo+gøodbye")
161170
&& response.getStrings().equals(listOf("a", "b", "c"))
162171
&& response.getNumber() == 123
163172
&& response.getFlag() == true
@@ -171,8 +180,7 @@ public void testMultipartPost() throws Exception {
171180
&& response.getAttachmentInfo().get(1).getChecksum() == 1038036);
172181
}
173182

174-
@Test
175-
public void testCustomPost() throws Exception {
183+
public static void testCustomPost() throws Exception {
176184
WebServiceProxy webServiceProxy = new WebServiceProxy("POST", new URL("http://localhost:8080/httprpc-test/test"));
177185

178186
URL imageTestURL = WebServiceProxyTest.class.getResource("test.jpg");
@@ -194,11 +202,10 @@ public void testCustomPost() throws Exception {
194202
return ImageIO.read(inputStream);
195203
});
196204

197-
Assert.assertTrue("POST (custom)", image != null);
205+
validate("POST (custom)", image != null);
198206
}
199207

200-
@Test
201-
public void testPut() throws Exception {
208+
public static void testPut() throws Exception {
202209
WebServiceProxy webServiceProxy = new WebServiceProxy("PUT", new URL("http://localhost:8080/httprpc-test/test"));
203210

204211
URL textTestURL = WebServiceProxyTest.class.getResource("test.txt");
@@ -229,11 +236,10 @@ public void testPut() throws Exception {
229236
return textBuilder.toString();
230237
});
231238

232-
Assert.assertTrue("PUT", text != null);
239+
validate("PUT", text != null);
233240
}
234241

235-
@Test
236-
public void testDelete() throws Exception {
242+
public static void testDelete() throws Exception {
237243
WebServiceProxy webServiceProxy = new WebServiceProxy("DELETE", new URL("http://localhost:8080/httprpc-test/test"));
238244

239245
webServiceProxy.setArguments(mapOf(
@@ -242,11 +248,10 @@ public void testDelete() throws Exception {
242248

243249
webServiceProxy.invoke();
244250

245-
Assert.assertTrue("DELETE", true);
251+
validate("DELETE", true);
246252
}
247253

248-
@Test
249-
public void testUnauthorized() throws Exception {
254+
public static void testUnauthorized() throws Exception {
250255
WebServiceProxy webServiceProxy = new WebServiceProxy("GET", new URL("http://localhost:8080/httprpc-test/test/unauthorized"));
251256

252257
int status;
@@ -258,11 +263,10 @@ public void testUnauthorized() throws Exception {
258263
status = exception.getStatus();
259264
}
260265

261-
Assert.assertTrue("Unauthorized", status == HttpURLConnection.HTTP_FORBIDDEN);
266+
validate("Unauthorized", status == HttpURLConnection.HTTP_FORBIDDEN);
262267
}
263268

264-
@Test
265-
public void testError() throws Exception {
269+
public static void testError() throws Exception {
266270
WebServiceProxy webServiceProxy = new WebServiceProxy("GET", new URL("http://localhost:8080/httprpc-test/test/error"));
267271

268272
boolean error;
@@ -274,11 +278,10 @@ public void testError() throws Exception {
274278
error = true;
275279
}
276280

277-
Assert.assertTrue("Error", error);
281+
validate("Error", error);
278282
}
279283

280-
@Test
281-
public void testTimeout() throws Exception {
284+
public static void testTimeout() throws Exception {
282285
WebServiceProxy webServiceProxy = new WebServiceProxy("GET", new URL("http://localhost:8080/httprpc-test/test"));
283286

284287
webServiceProxy.setConnectTimeout(3000);
@@ -298,11 +301,10 @@ public void testTimeout() throws Exception {
298301
timeout = true;
299302
}
300303

301-
Assert.assertTrue("Timeout", timeout);
304+
validate("Timeout", timeout);
302305
}
303306

304-
@Test
305-
public void testMath() throws Exception {
307+
public static void testMath() throws Exception {
306308
WebServiceProxy webServiceProxy = new WebServiceProxy("GET", new URL("http://localhost:8080/httprpc-test/math/sum"));
307309

308310
HashMap<String, Integer> arguments = new HashMap<>();
@@ -314,25 +316,27 @@ public void testMath() throws Exception {
314316

315317
Number result = webServiceProxy.invoke();
316318

317-
Assert.assertTrue("Math", result.doubleValue() == 6.0);
319+
validate("Math", result.doubleValue() == 6.0);
318320
}
319321

320-
@Test
321-
public void testMathService() throws Exception {
322+
public static void testMathService() throws Exception {
322323
MathService mathService = WebServiceProxy.adapt(new URL("http://localhost:8080/httprpc-test/math/"), MathService.class);
323324

324-
Assert.assertTrue("Math (service)", mathService.getSum(4, 2) == 6.0
325+
validate("Math (service)", mathService.getSum(4, 2) == 6.0
325326
&& mathService.getSum(listOf(1.0, 2.0, 3.0)) == 6.0);
326327
}
327328

328-
@Test
329-
public void testTree() throws Exception {
329+
public static void testTree() throws Exception {
330330
WebServiceProxy webServiceProxy = new WebServiceProxy("GET", new URL("http://localhost:8080/httprpc-test/tree"));
331331

332332
TreeNode root = BeanAdapter.adapt(webServiceProxy.invoke(), TreeNode.class);
333333

334-
Assert.assertTrue("Tree", root.getName().equals("Seasons")
334+
validate("Tree", root.getName().equals("Seasons")
335335
&& root.getChildren().get(0).getName().equals("Winter")
336336
&& root.getChildren().get(0).getChildren().get(0).getName().equals("January"));
337337
}
338-
}
338+
339+
private static void validate(String test, boolean condition) {
340+
System.out.println(test + ": " + (condition ? "OK" : "FAIL"));
341+
}
342+
}
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)