Skip to content

Commit e100e37

Browse files
committed
Add tests for new HTTP API's
1 parent b4605da commit e100e37

File tree

1 file changed

+48
-2
lines changed

1 file changed

+48
-2
lines changed

src/AndroidClient/client/src/androidTest/java/servicestack/net/client/tests/TestServiceTests.java

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,19 @@
44

55
import android.app.Application;
66
import android.test.ApplicationTestCase;
7-
import android.util.Log;
87

8+
import net.servicestack.android.AndroidLogProvider;
99
import net.servicestack.client.JsonServiceClient;
10+
import net.servicestack.client.Log;
11+
import net.servicestack.client.MimeTypes;
1012
import net.servicestack.client.TimeSpan;
13+
import net.servicestack.client.Utils;
1114

1215
import servicestack.net.client.tests.testdtos.*;
1316

1417
import java.math.BigDecimal;
1518
import java.math.BigInteger;
19+
import java.net.HttpURLConnection;
1620
import java.util.ArrayList;
1721
import java.util.Arrays;
1822
import java.util.Date;
@@ -23,20 +27,62 @@
2327
public class TestServiceTests extends ApplicationTestCase<Application> {
2428
public TestServiceTests() {
2529
super(Application.class);
30+
Log.Instance = new AndroidLogProvider("ZZZ");
2631
}
2732

2833
JsonServiceClient client = new JsonServiceClient("http://test.servicestack.net");
2934
// JsonServiceClient client = new JsonServiceClient("http://10.0.2.2:2020");
3035

36+
public void test_Can_GET_Hello(){
37+
Hello request = new Hello()
38+
.setName("World");
39+
40+
HelloResponse response = client.get(request);
41+
42+
assertEquals("Hello, World!", response.getResult());
43+
}
44+
45+
public void test_Can_GET_Hello_with_CustomPath(){
46+
HelloResponse response = client.get("/hello/World", HelloResponse.class);
47+
48+
assertEquals("Hello, World!", response.getResult());
49+
}
50+
51+
public void test_Can_POST_Hello_with_CustomPath(){
52+
HelloResponse response = client.post("/hello", new Hello().setName("World"), HelloResponse.class);
53+
54+
assertEquals("Hello, World!", response.getResult());
55+
}
56+
57+
public void test_Can_GET_Hello_with_CustomPath_raw(){
58+
HttpURLConnection response = client.get("/hello/World");
59+
String json = Utils.readToEnd(response);
60+
61+
assertEquals("{\"result\":\"Hello, World!\"}", json);
62+
}
63+
64+
public void test_Can_POST_Hello_with_CustomPath_raw(){
65+
HttpURLConnection response = client.post("/hello", Utils.toUtf8Bytes("Name=World"), MimeTypes.FormUrlEncoded);
66+
String json = Utils.readToEnd(response);
67+
68+
assertEquals("{\"result\":\"Hello, World!\"}", json);
69+
}
70+
3171
public void test_Can_POST_test_HelloAllTypes(){
3272
HelloAllTypes request = createHelloAllTypes();
3373
HelloAllTypesResponse response = client.post(request);
3474
assertHelloAllTypesResponse(response, request);
3575
}
3676

77+
public void test_Can_PUT_test_HelloAllTypes(){
78+
HelloAllTypes request = createHelloAllTypes();
79+
HelloAllTypesResponse response = client.put(request);
80+
assertHelloAllTypesResponse(response, request);
81+
}
82+
3783
public void test_Can_Serailize_AllTypes(){
3884
String json = client.getGson().toJson(createAllTypes());
39-
Log.i("ZZZ-json",json);
85+
Log.i(json);
4086
}
4187

4288
/* TEST HELPERS */

0 commit comments

Comments
 (0)