Skip to content

Commit c5d167c

Browse files
committed
Port remaining Async Android tests to Kotlin
1 parent 97b015e commit c5d167c

File tree

8 files changed

+588
-39
lines changed

8 files changed

+588
-39
lines changed

src/AndroidClient/kotlin/kotlin.iml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" />
7878
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/jniLibs" />
7979
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/lint" />
80+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/pre-dexed" />
8081
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/res" />
8182
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/rs" />
8283
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/symbols" />

src/AndroidClient/kotlin/src/androidTest/java/test/servicestack/net/kotlin/techstacks/TechStacksServiceTests.kt

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
1+
// Copyright (c) 2015 ServiceStack LLC. All rights reserved.
2+
13
package test.servicestack.net.kotlin.techstacks
24

5+
import junit.framework.Assert
36
import junit.framework.TestCase
4-
57
import net.servicestack.client.JsonServiceClient
68
import net.servicestack.client.Utils
7-
8-
import java.io.FileInputStream
99
import java.io.IOException
10-
import java.util.ArrayList
11-
12-
import junit.framework.Assert
1310

1411
class TechStacksServiceTests : TestCase() {
1512

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
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+
}

src/AndroidClient/kotlin/src/androidTest/java/test/servicestack/net/kotlin/test/JsonServiceClientTests.kt

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,10 @@ import junit.framework.Assert
66
import junit.framework.TestCase
77
import net.servicestack.client.ConnectionFilter
88
import net.servicestack.client.JsonServiceClient
9-
109
import net.servicestack.client.WebServiceException
11-
12-
import java.net.HttpURLConnection
13-
import java.util.Calendar
14-
import java.util.Date
15-
1610
import test.servicestack.net.kotlin.test.EchoTypes
1711
import test.servicestack.net.kotlin.test.Hello
18-
import test.servicestack.net.kotlin.test.HelloResponse
12+
import java.util.*
1913

2014
class JsonServiceClientTests : TestCase() {
2115
//10.0.2.2 = loopback

src/AndroidClient/kotlin/src/androidTest/java/test/servicestack/net/kotlin/test/TestInterfaceMarkerTests.kt

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
1+
// Copyright (c) 2015 ServiceStack LLC. All rights reserved.
2+
13
package test.servicestack.net.kotlin.test
24

35
import junit.framework.Assert
46
import junit.framework.TestCase
5-
67
import net.servicestack.client.HttpMethods
78
import net.servicestack.client.JsonServiceClient
89

9-
import test.servicestack.net.kotlin.test.*
10-
11-
/**
12-
* Created by mythz on 9/11/2015.
13-
*/
1410
class TestInterfaceMarkerTests : TestCase() {
1511

1612
internal var client = JsonServiceClient("http://test.servicestack.net")
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
// Copyright (c) 2015 ServiceStack LLC. All rights reserved.
2+
3+
package test.servicestack.net.kotlin.test
4+
5+
import android.app.Application
6+
import android.test.ApplicationTestCase
7+
import junit.framework.Assert
8+
import net.servicestack.android.AndroidServiceClient
9+
import net.servicestack.client.AsyncSuccess
10+
import net.servicestack.client.HttpMethods
11+
import java.util.concurrent.CountDownLatch
12+
import java.util.concurrent.TimeUnit
13+
14+
class TestInterfaceMarkerTestsAsync : ApplicationTestCase<Application>(Application::class.java) {
15+
16+
internal var client = AndroidServiceClient("http://test.servicestack.net")
17+
18+
@Throws(InterruptedException::class)
19+
fun test_Does_SendDefault_as_POST() {
20+
val signal = CountDownLatch(1)
21+
22+
var request = SendDefault()
23+
request.id = 1
24+
25+
client.sendAsync<SendVerbResponse>(request, AsyncSuccess<SendVerbResponse> {
26+
Assert.assertEquals(1, it.id)
27+
Assert.assertEquals(HttpMethods.Post, it.requestMethod)
28+
Assert.assertEquals("/json/reply/SendDefault", it.pathInfo)
29+
signal.countDown()
30+
})
31+
32+
Assert.assertTrue(signal.await(5, TimeUnit.SECONDS))
33+
}
34+
35+
@Throws(InterruptedException::class)
36+
fun test_Does_SendRestGet_as_GET_using_Predefined_Route() {
37+
val signal = CountDownLatch(1)
38+
39+
var request = SendRestGet()
40+
request.id = 1
41+
client.sendAsync<SendVerbResponse>(request,AsyncSuccess<SendVerbResponse> {
42+
Assert.assertEquals(1, it.id!!)
43+
Assert.assertEquals(HttpMethods.Get, it?.requestMethod)
44+
Assert.assertEquals("/json/reply/SendRestGet", it?.pathInfo)
45+
signal.countDown()
46+
})
47+
48+
Assert.assertTrue(signal.await(5, TimeUnit.SECONDS))
49+
}
50+
51+
@Throws(InterruptedException::class)
52+
fun test_Does_SendGet_as_GET() {
53+
val signal = CountDownLatch(1)
54+
55+
var request = SendGet()
56+
request.id = 1
57+
client.sendAsync<SendVerbResponse>(request,AsyncSuccess<SendVerbResponse> {
58+
Assert.assertEquals(1, it.id!!)
59+
Assert.assertEquals(HttpMethods.Get, it.requestMethod!!)
60+
Assert.assertEquals("/json/reply/SendGet", it.pathInfo!!)
61+
signal.countDown()
62+
})
63+
64+
Assert.assertTrue(signal.await(500, TimeUnit.SECONDS))
65+
}
66+
67+
@Throws(InterruptedException::class)
68+
fun test_Does_SendPost_as_POST() {
69+
val signal = CountDownLatch(1)
70+
71+
var request = SendPost()
72+
request.id = 1
73+
client.sendAsync<SendVerbResponse>(request,AsyncSuccess<SendVerbResponse> {
74+
Assert.assertEquals(1, it.id!!)
75+
Assert.assertEquals(HttpMethods.Post, it.requestMethod)
76+
Assert.assertEquals("/json/reply/SendPost", it.pathInfo)
77+
signal.countDown()
78+
})
79+
80+
Assert.assertTrue(signal.await(5, TimeUnit.SECONDS))
81+
}
82+
83+
@Throws(InterruptedException::class)
84+
fun test_Does_SendPut_as_PUT() {
85+
val signal = CountDownLatch(1)
86+
87+
var request = SendPut()
88+
request.id = 1
89+
client.sendAsync<SendVerbResponse>(request,AsyncSuccess<SendVerbResponse> {
90+
Assert.assertEquals(1, it.id!!)
91+
Assert.assertEquals(HttpMethods.Put, it.requestMethod)
92+
Assert.assertEquals("/json/reply/SendPut", it.pathInfo)
93+
signal.countDown()
94+
})
95+
96+
Assert.assertTrue(signal.await(5, TimeUnit.SECONDS))
97+
}
98+
}

src/AndroidClient/kotlin/src/androidTest/java/test/servicestack/net/kotlin/test/TestServiceTests.kt

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,13 @@
22

33
package test.servicestack.net.kotlin.test
44

5+
import junit.framework.Assert
56
import junit.framework.TestCase
6-
7-
import net.servicestack.client.ConnectionFilter
8-
import net.servicestack.client.ExceptionFilter
9-
import net.servicestack.client.HttpMethods
10-
import net.servicestack.client.JsonServiceClient
11-
import net.servicestack.client.Log
12-
import net.servicestack.client.MimeTypes
13-
import net.servicestack.client.ResponseStatus
14-
import net.servicestack.client.TimeSpan
15-
import net.servicestack.client.Utils
16-
import net.servicestack.client.WebServiceException
17-
7+
import net.servicestack.client.*
8+
import test.servicestack.net.kotlin.techstacks.LockTechStack
189
import java.math.BigDecimal
1910
import java.math.BigInteger
20-
import java.net.HttpURLConnection
21-
import java.util.ArrayList
22-
import java.util.Date
23-
import java.util.HashMap
24-
import java.util.UUID
25-
26-
import junit.framework.Assert
27-
import test.servicestack.net.kotlin.techstacks.LockTechStack
11+
import java.util.*
2812

2913
class TestServiceTests : TestCase() {
3014

0 commit comments

Comments
 (0)