|
| 1 | +package net.servicestack.android; |
| 2 | + |
| 3 | +import android.app.Application; |
| 4 | +import android.test.ApplicationTestCase; |
| 5 | + |
| 6 | +import net.servicestack.client.AsyncResult; |
| 7 | +import net.servicestack.client.HttpMethods; |
| 8 | + |
| 9 | +import java.util.concurrent.CountDownLatch; |
| 10 | +import java.util.concurrent.TimeUnit; |
| 11 | + |
| 12 | +import net.servicestack.android.tests.dto.*; |
| 13 | + |
| 14 | +/** |
| 15 | + * Created by mythz on 9/11/2015. |
| 16 | + */ |
| 17 | +public class TestInterfaceMarkerTestsAsync extends ApplicationTestCase<Application> { |
| 18 | + public TestInterfaceMarkerTestsAsync() { |
| 19 | + super(Application.class); |
| 20 | + } |
| 21 | + |
| 22 | + AndroidServiceClient client = new AndroidServiceClient("http://test.servicestack.net"); |
| 23 | + |
| 24 | + public void test_Does_SendDefault_as_POST() throws InterruptedException { |
| 25 | + final CountDownLatch signal = new CountDownLatch(1); |
| 26 | + |
| 27 | + client.sendAsync(new SendDefault().setId(1), |
| 28 | + new AsyncResult<SendVerbResponse>() { |
| 29 | + @Override |
| 30 | + public void success(SendVerbResponse response) { |
| 31 | + assertEquals(1, (int) response.getId()); |
| 32 | + assertEquals(HttpMethods.Post, response.getRequestMethod()); |
| 33 | + assertEquals("/json/reply/SendDefault", response.getPathInfo()); |
| 34 | + } |
| 35 | + |
| 36 | + @Override |
| 37 | + public void complete() { |
| 38 | + signal.countDown(); |
| 39 | + } |
| 40 | + }); |
| 41 | + |
| 42 | + assertTrue(signal.await(5, TimeUnit.SECONDS)); |
| 43 | + } |
| 44 | + |
| 45 | + public void test_Does_SendRestGet_as_GET_using_Predefined_Route() throws InterruptedException { |
| 46 | + final CountDownLatch signal = new CountDownLatch(1); |
| 47 | + |
| 48 | + client.sendAsync(new SendRestGet().setId(1), |
| 49 | + new AsyncResult<SendVerbResponse>() { |
| 50 | + @Override |
| 51 | + public void success(SendVerbResponse response) { |
| 52 | + assertEquals(1, (int) response.getId()); |
| 53 | + assertEquals(HttpMethods.Get, response.getRequestMethod()); |
| 54 | + assertEquals("/json/reply/SendRestGet", response.getPathInfo()); |
| 55 | + } |
| 56 | + |
| 57 | + @Override |
| 58 | + public void complete() { |
| 59 | + signal.countDown(); |
| 60 | + } |
| 61 | + }); |
| 62 | + |
| 63 | + assertTrue(signal.await(5, TimeUnit.SECONDS)); |
| 64 | + } |
| 65 | + |
| 66 | + public void test_Does_SendGet_as_GET() throws InterruptedException { |
| 67 | + final CountDownLatch signal = new CountDownLatch(1); |
| 68 | + |
| 69 | + client.sendAsync(new SendGet().setId(1), |
| 70 | + new AsyncResult<SendVerbResponse>() { |
| 71 | + @Override |
| 72 | + public void success(SendVerbResponse response) { |
| 73 | + assertEquals(1, (int) response.getId()); |
| 74 | + assertEquals(HttpMethods.Get, response.getRequestMethod()); |
| 75 | + assertEquals("/json/reply/SendGet", response.getPathInfo()); |
| 76 | + } |
| 77 | + |
| 78 | + @Override |
| 79 | + public void complete() { |
| 80 | + signal.countDown(); |
| 81 | + } |
| 82 | + }); |
| 83 | + |
| 84 | + assertTrue(signal.await(5, TimeUnit.SECONDS)); |
| 85 | + } |
| 86 | + |
| 87 | + public void test_Does_SendPost_as_POST() throws InterruptedException { |
| 88 | + final CountDownLatch signal = new CountDownLatch(1); |
| 89 | + |
| 90 | + client.sendAsync(new SendPost().setId(1), |
| 91 | + new AsyncResult<SendVerbResponse>() { |
| 92 | + @Override |
| 93 | + public void success(SendVerbResponse response) { |
| 94 | + assertEquals(1, (int) response.getId()); |
| 95 | + assertEquals(HttpMethods.Post, response.getRequestMethod()); |
| 96 | + assertEquals("/json/reply/SendPost", response.getPathInfo()); |
| 97 | + } |
| 98 | + |
| 99 | + @Override |
| 100 | + public void complete() { |
| 101 | + signal.countDown(); |
| 102 | + } |
| 103 | + }); |
| 104 | + |
| 105 | + assertTrue(signal.await(5, TimeUnit.SECONDS)); |
| 106 | + } |
| 107 | + |
| 108 | + public void test_Does_SendPut_as_PUT() throws InterruptedException { |
| 109 | + final CountDownLatch signal = new CountDownLatch(1); |
| 110 | + |
| 111 | + client.sendAsync(new SendPut().setId(1), |
| 112 | + new AsyncResult<SendVerbResponse>() { |
| 113 | + @Override |
| 114 | + public void success(SendVerbResponse response) { |
| 115 | + assertEquals(1, (int) response.getId()); |
| 116 | + assertEquals(HttpMethods.Put, response.getRequestMethod()); |
| 117 | + assertEquals("/json/reply/SendPut", response.getPathInfo()); |
| 118 | + } |
| 119 | + |
| 120 | + @Override |
| 121 | + public void complete() { |
| 122 | + signal.countDown(); |
| 123 | + } |
| 124 | + }); |
| 125 | + |
| 126 | + assertTrue(signal.await(5, TimeUnit.SECONDS)); |
| 127 | + } |
| 128 | +} |
0 commit comments