|
4 | 4 |
|
5 | 5 | import android.app.Application; |
6 | 6 | import android.test.ApplicationTestCase; |
7 | | -import android.util.Log; |
8 | 7 |
|
| 8 | +import net.servicestack.android.AndroidLogProvider; |
9 | 9 | import net.servicestack.client.JsonServiceClient; |
| 10 | +import net.servicestack.client.Log; |
| 11 | +import net.servicestack.client.MimeTypes; |
10 | 12 | import net.servicestack.client.TimeSpan; |
| 13 | +import net.servicestack.client.Utils; |
11 | 14 |
|
12 | 15 | import servicestack.net.client.tests.testdtos.*; |
13 | 16 |
|
14 | 17 | import java.math.BigDecimal; |
15 | 18 | import java.math.BigInteger; |
| 19 | +import java.net.HttpURLConnection; |
16 | 20 | import java.util.ArrayList; |
17 | 21 | import java.util.Arrays; |
18 | 22 | import java.util.Date; |
|
23 | 27 | public class TestServiceTests extends ApplicationTestCase<Application> { |
24 | 28 | public TestServiceTests() { |
25 | 29 | super(Application.class); |
| 30 | + Log.Instance = new AndroidLogProvider("ZZZ"); |
26 | 31 | } |
27 | 32 |
|
28 | 33 | JsonServiceClient client = new JsonServiceClient("http://test.servicestack.net"); |
29 | 34 | // JsonServiceClient client = new JsonServiceClient("http://10.0.2.2:2020"); |
30 | 35 |
|
| 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 | + |
31 | 71 | public void test_Can_POST_test_HelloAllTypes(){ |
32 | 72 | HelloAllTypes request = createHelloAllTypes(); |
33 | 73 | HelloAllTypesResponse response = client.post(request); |
34 | 74 | assertHelloAllTypesResponse(response, request); |
35 | 75 | } |
36 | 76 |
|
| 77 | + public void test_Can_PUT_test_HelloAllTypes(){ |
| 78 | + HelloAllTypes request = createHelloAllTypes(); |
| 79 | + HelloAllTypesResponse response = client.put(request); |
| 80 | + assertHelloAllTypesResponse(response, request); |
| 81 | + } |
| 82 | + |
37 | 83 | public void test_Can_Serailize_AllTypes(){ |
38 | 84 | String json = client.getGson().toJson(createAllTypes()); |
39 | | - Log.i("ZZZ-json",json); |
| 85 | + Log.i(json); |
40 | 86 | } |
41 | 87 |
|
42 | 88 | /* TEST HELPERS */ |
|
0 commit comments