1+ // Copyright (c) 2015 ServiceStack LLC. All rights reserved.
2+
3+ package test.servicestack.net.kotlin.techstacks
4+
5+ import android.app.Application
6+ import android.test.ApplicationTestCase
7+ import junit.framework.Assert
8+ import net.servicestack.android.AndroidLogProvider
9+ import net.servicestack.android.AndroidServiceClient
10+ import net.servicestack.client.AsyncSuccess
11+ import net.servicestack.client.Log
12+ import java.util.concurrent.CountDownLatch
13+ import java.util.concurrent.TimeUnit
14+
15+ class TechStacksServiceTestsAsync : ApplicationTestCase <Application >(Application : :class.java) {
16+ init {
17+ Log .Instance = AndroidLogProvider (" ZZZ" )
18+ }
19+
20+ internal var client = AndroidServiceClient (" http://techstacks.io" )
21+
22+ @Throws(InterruptedException ::class )
23+ fun test_Can_GET_TechStacks_Overview () {
24+ val signal = CountDownLatch (1 )
25+
26+ client.getAsync<OverviewResponse >(Overview (), AsyncSuccess <OverviewResponse > {
27+ assertOverviewResponse(it)
28+ signal.countDown()
29+ })
30+
31+ Assert .assertTrue(signal.await(5 , TimeUnit .SECONDS ))
32+ }
33+
34+ @Throws(InterruptedException ::class )
35+ fun test_Can_GET_TechStacks_AppOverview_Async () {
36+ val signal = CountDownLatch (1 )
37+
38+ client.getAsync<AppOverviewResponse >(AppOverview (), AsyncSuccess <AppOverviewResponse > {
39+ Assert .assertNotNull(it)
40+ Assert .assertTrue(it.TopTechnologies .size > 0 )
41+ Assert .assertTrue(it.AllTiers .size > 0 )
42+ signal.countDown()
43+ })
44+
45+ Assert .assertTrue(signal.await(5 , TimeUnit .SECONDS ))
46+ }
47+
48+ @Throws(InterruptedException ::class )
49+ fun test_Can_GET_TechStacks_Overview_with_relative_url_Async () {
50+ val signal = CountDownLatch (1 )
51+
52+ client.getAsync(" /overview" , OverviewResponse ::class .java, AsyncSuccess <OverviewResponse > {
53+ assertOverviewResponse(it)
54+ signal.countDown()
55+ })
56+
57+ Assert .assertTrue(signal.await(5 , TimeUnit .SECONDS ))
58+ }
59+
60+ @Throws(InterruptedException ::class )
61+ fun test_Can_GET_TechStacks_Overview_with_absolute_url_Async () {
62+ val signal = CountDownLatch (1 )
63+
64+ client.getAsync(" http://techstacks.io/overview" , OverviewResponse ::class .java, AsyncSuccess <OverviewResponse > {
65+ assertOverviewResponse(it)
66+ signal.countDown()
67+ })
68+
69+ Assert .assertTrue(signal.await(5 , TimeUnit .SECONDS ))
70+ }
71+
72+ @Throws(InterruptedException ::class )
73+ fun test_Can_GET_GetTechnology_with_params_Async () {
74+ val requestDto = GetTechnology ()
75+ requestDto.Slug = " servicestack"
76+
77+ val signal = CountDownLatch (1 )
78+
79+ client.getAsync<GetTechnologyResponse >(requestDto, AsyncSuccess <GetTechnologyResponse > {
80+ assertGetTechnologyResponse(it)
81+ signal.countDown()
82+ })
83+
84+ Assert .assertTrue(signal.await(5 , TimeUnit .SECONDS ))
85+ }
86+
87+ @Throws(InterruptedException ::class )
88+ fun test_Can_GET_GetTechnology_with_url_Async () {
89+ val signal = CountDownLatch (1 )
90+
91+ client.getAsync(" /technology/servicestack" , GetTechnologyResponse ::class .java, AsyncSuccess <GetTechnologyResponse > {
92+ assertGetTechnologyResponse(it)
93+ signal.countDown()
94+ })
95+
96+ Assert .assertTrue(signal.await(5 , TimeUnit .SECONDS ))
97+ }
98+
99+ @Throws(InterruptedException ::class )
100+ fun test_Can_call_FindTechnologies_AutoQuery_Service_Async () {
101+ val request = FindTechnologies ()
102+ request.Name = " ServiceStack"
103+
104+ val signal = CountDownLatch (1 )
105+
106+ client.getAsync<QueryResponse <Technology >>(request, AsyncSuccess <QueryResponse <Technology >> {
107+ Assert .assertEquals(1 , it.Results .size)
108+ signal.countDown()
109+ })
110+
111+ Assert .assertTrue(signal.await(5 , TimeUnit .SECONDS ))
112+ }
113+
114+ @Throws(InterruptedException ::class )
115+ fun test_Can_call_FindTechnologies_AutoQuery_Implicit_Service () {
116+ val request = FindTechnologies ()
117+ request.Take = 5
118+
119+ val signal = CountDownLatch (1 )
120+
121+ client.getAsync<QueryResponse <Technology >>(request, hashMapOf(Pair (" DescriptionContains" , " framework" )),
122+ AsyncSuccess <QueryResponse <Technology >> {
123+ Assert .assertEquals(5 , it.Results .size)
124+ signal.countDown()
125+ })
126+
127+ Assert .assertTrue(signal.await(5 , TimeUnit .SECONDS ))
128+ }
129+
130+ companion object {
131+
132+ fun assertOverviewResponse (r : OverviewResponse ) {
133+ Assert .assertNotNull(r)
134+ Assert .assertTrue(r.TopUsers .size > 0 )
135+ Assert .assertTrue(r.TopTechnologies .size > 0 )
136+ Assert .assertTrue(r.LatestTechStacks .size > 0 )
137+ Assert .assertTrue(r.LatestTechStacks [0 ].TechnologyChoices .size > 0 )
138+ Assert .assertTrue(r.TopTechnologiesByTier .size > 0 )
139+ }
140+
141+ fun assertGetTechnologyResponse (r : GetTechnologyResponse ) {
142+ Assert .assertNotNull(r)
143+ Assert .assertEquals(" ServiceStack" , r.Technology ?.Name )
144+ Assert .assertTrue(r.TechnologyStacks .size > 0 )
145+ }
146+ }
147+ }
0 commit comments