1+ package servicestack .net .client .tests ;
2+
3+ import android .app .Application ;
4+ import android .test .ApplicationTestCase ;
5+
6+ import net .servicestack .android .AndroidLogProvider ;
7+ import net .servicestack .android .AndroidServiceClient ;
8+ import net .servicestack .client .AsyncResponse ;
9+ import net .servicestack .client .Log ;
10+ import net .servicestack .client .Utils ;
11+
12+ import java .util .concurrent .CountDownLatch ;
13+ import java .util .concurrent .TimeUnit ;
14+
15+ import io .techstacks .dto .*;
16+
17+ public class TechStacksServiceTestsAsync extends ApplicationTestCase <Application > {
18+ public TechStacksServiceTestsAsync () {
19+ super (Application .class );
20+ Log .Instance = new AndroidLogProvider ("ZZZ" );
21+ }
22+
23+ AndroidServiceClient client = new AndroidServiceClient ("http://techstacks.io" );
24+
25+ public void test_Can_GET_TechStacks_Overview () throws InterruptedException {
26+ final CountDownLatch signal = new CountDownLatch (1 );
27+
28+ client .getAsync (new Overview (), new AsyncResponse <OverviewResponse >(){
29+ @ Override
30+ public void success (OverviewResponse response ) {
31+ TechStacksServiceTests .assertOverviewResponse (response );
32+ }
33+
34+ @ Override
35+ public void complete () {
36+ signal .countDown ();
37+ }
38+ });
39+
40+ assertTrue (signal .await (5 , TimeUnit .SECONDS ));
41+ }
42+
43+ public void test_Can_GET_TechStacks_AppOverview_Async () throws InterruptedException {
44+ final CountDownLatch signal = new CountDownLatch (1 );
45+
46+ client .getAsync (new AppOverview (), new AsyncResponse <AppOverviewResponse >(){
47+ @ Override
48+ public void success (AppOverviewResponse r ) {
49+ assertNotNull (r );
50+ assertTrue (r .getTopTechnologies ().size () > 0 );
51+ assertTrue (r .getAllTiers ().size () > 0 );
52+ }
53+
54+ @ Override
55+ public void complete () {
56+ signal .countDown ();
57+ }
58+ });
59+
60+ assertTrue (signal .await (5 , TimeUnit .SECONDS ));
61+ }
62+
63+ public void test_Can_GET_TechStacks_Overview_with_relative_url_Async () throws InterruptedException {
64+ final CountDownLatch signal = new CountDownLatch (1 );
65+
66+ client .getAsync ("/overview" , OverviewResponse .class , new AsyncResponse <OverviewResponse >() {
67+ @ Override
68+ public void success (OverviewResponse response ) {
69+ TechStacksServiceTests .assertOverviewResponse (response );
70+ }
71+
72+ @ Override
73+ public void complete () {
74+ signal .countDown ();
75+ }
76+ });
77+
78+ assertTrue (signal .await (5 , TimeUnit .SECONDS ));
79+ }
80+
81+ public void test_Can_GET_TechStacks_Overview_with_absolute_url_Async () throws InterruptedException {
82+ final CountDownLatch signal = new CountDownLatch (1 );
83+
84+ client .getAsync ("http://techstacks.io/overview" , OverviewResponse .class , new AsyncResponse <OverviewResponse >() {
85+ @ Override
86+ public void success (OverviewResponse response ) {
87+ TechStacksServiceTests .assertOverviewResponse (response );
88+ }
89+
90+ @ Override
91+ public void complete () {
92+ signal .countDown ();
93+ }
94+ });
95+
96+ assertTrue (signal .await (5 , TimeUnit .SECONDS ));
97+ }
98+
99+ public void test_Can_GET_GetTechnology_with_params_Async () throws InterruptedException {
100+ GetTechnology requestDto = new GetTechnology ()
101+ .setSlug ("servicestack" );
102+
103+ final CountDownLatch signal = new CountDownLatch (1 );
104+
105+ client .getAsync (requestDto , new AsyncResponse <GetTechnologyResponse >() {
106+ @ Override
107+ public void success (GetTechnologyResponse response ) {
108+ TechStacksServiceTests .assertGetTechnologyResponse (response );
109+ }
110+
111+ @ Override
112+ public void complete () {
113+ signal .countDown ();
114+ }
115+ });
116+
117+ assertTrue (signal .await (5 , TimeUnit .SECONDS ));
118+ }
119+
120+ public void test_Can_GET_GetTechnology_with_url_Async () throws InterruptedException {
121+ final CountDownLatch signal = new CountDownLatch (1 );
122+
123+ client .getAsync ("/technology/servicestack" , GetTechnologyResponse .class , new AsyncResponse <GetTechnologyResponse >() {
124+ @ Override
125+ public void success (GetTechnologyResponse response ) {
126+ TechStacksServiceTests .assertGetTechnologyResponse (response );
127+ }
128+
129+ @ Override
130+ public void complete () {
131+ signal .countDown ();
132+ }
133+ });
134+
135+ assertTrue (signal .await (5 , TimeUnit .SECONDS ));
136+ }
137+
138+ public void test_Can_call_FindTechnologies_AutoQuery_Service_Async () throws InterruptedException {
139+ FindTechnologies request = new FindTechnologies ()
140+ .setName ("ServiceStack" );
141+
142+ final CountDownLatch signal = new CountDownLatch (1 );
143+
144+ client .getAsync (request , new AsyncResponse <QueryResponse <Technology >>() {
145+ @ Override
146+ public void success (QueryResponse <Technology > response ) {
147+ assertEquals (1 , response .getResults ().size ());
148+
149+ }
150+
151+ @ Override
152+ public void complete () {
153+ signal .countDown ();
154+ }
155+ });
156+
157+ assertTrue (signal .await (5 , TimeUnit .SECONDS ));
158+ }
159+
160+ public void test_Can_call_FindTechnologies_AutoQuery_Implicit_Service () throws InterruptedException {
161+ FindTechnologies request = (FindTechnologies ) new FindTechnologies ()
162+ .setTake (5 );
163+
164+ final CountDownLatch signal = new CountDownLatch (1 );
165+
166+ client .getAsync (request , Utils .createMap ("DescriptionContains" , "framework" ),
167+ new AsyncResponse <QueryResponse <Technology >>() {
168+ @ Override
169+ public void success (QueryResponse <Technology > response ) {
170+ assertEquals (5 , response .getResults ().size ());
171+ }
172+
173+ @ Override
174+ public void complete () {
175+ signal .countDown ();
176+ }
177+ });
178+
179+ assertTrue (signal .await (5 , TimeUnit .SECONDS ));
180+ }
181+ }
0 commit comments