Skip to content
This repository was archived by the owner on Mar 19, 2024. It is now read-only.

Commit 1c08a94

Browse files
theScrabiabelgardep
authored andcommitted
test model
1 parent 6bdb2ba commit 1c08a94

File tree

3 files changed

+142
-24
lines changed

3 files changed

+142
-24
lines changed

owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/CommonOcsResponse.kt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
*/
2424
package com.owncloud.android.lib.resources
2525

26+
import com.squareup.moshi.Json
2627
import com.squareup.moshi.JsonClass
2728

2829
// Response retrieved by OCS Rest API, used to obtain capabilities, shares and user info among others.
@@ -41,6 +42,11 @@ data class OCSResponse<T>(
4142
@JsonClass(generateAdapter = true)
4243
data class MetaData(
4344
val status: String,
44-
val statuscode: Int,
45-
val message: String?
45+
@Json(name = "statuscode")
46+
val statusCode: Int,
47+
val message: String?,
48+
@Json(name = "itemsperpage")
49+
val itemsPerPage: String?,
50+
@Json(name = "totalitems")
51+
val totalItems: String?
4652
)

owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/responses/ShareeResponse.kt

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,6 @@ import com.squareup.moshi.JsonClass
3232
*/
3333
@JsonClass(generateAdapter = true)
3434
data class ShareeOcsResponse(
35-
@Json(name = "data")
36-
val data: ShareeResponseData?,
37-
@Json(name = "meta")
38-
val meta: ShareeMeta?
39-
)
40-
41-
@JsonClass(generateAdapter = true)
42-
data class ShareeResponseData(
4335
@Json(name = "exact")
4436
val exact: ExactSharees?,
4537
@Json(name = "groups")
@@ -75,17 +67,3 @@ data class ShareeValue(
7567
@Json(name = "shareWith")
7668
val shareWith: String?
7769
)
78-
79-
@JsonClass(generateAdapter = true)
80-
data class ShareeMeta(
81-
@Json(name = "itemsperpage")
82-
val itemsPerPage: Int?,
83-
@Json(name = "message")
84-
val message: String?,
85-
@Json(name = "status")
86-
val status: String?,
87-
@Json(name = "statuscode")
88-
val statusCode: Int?,
89-
@Json(name = "totalitems")
90-
val totalItems: Int?
91-
)
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
package com.owncloud.android.lib
2+
3+
import com.owncloud.android.lib.resources.CommonOcsResponse
4+
import com.owncloud.android.lib.resources.shares.responses.ShareeOcsResponse
5+
import com.squareup.moshi.JsonAdapter
6+
import com.squareup.moshi.Moshi
7+
import com.squareup.moshi.Types
8+
import junit.framework.Assert.assertEquals
9+
import junit.framework.Assert.assertTrue
10+
import org.junit.Assert.assertNotEquals
11+
import org.junit.Before
12+
import org.junit.Test
13+
import java.lang.reflect.Type
14+
15+
class ShareeResponseTest {
16+
17+
var response: CommonOcsResponse<ShareeOcsResponse>? = null
18+
19+
@Before
20+
fun prepare() {
21+
val moshi = Moshi.Builder().build()
22+
val type: Type = Types.newParameterizedType(CommonOcsResponse::class.java, ShareeOcsResponse::class.java)
23+
val adapter: JsonAdapter<CommonOcsResponse<ShareeOcsResponse>> = moshi.adapter(type)
24+
response = adapter.fromJson(EXAMPLE_RESPONSE)
25+
}
26+
27+
@Test
28+
fun `check structure - ok - contains meta`() {
29+
assertEquals("OK", response?.ocs?.meta?.message!!)
30+
assertEquals(200, response?.ocs?.meta?.statusCode!!)
31+
assertEquals("ok", response?.ocs?.meta?.status!!)
32+
assertTrue(response?.ocs?.meta?.itemsPerPage?.isEmpty()!!)
33+
assertTrue(response?.ocs?.meta?.totalItems?.isEmpty()!!)
34+
}
35+
36+
@Test
37+
fun `check structure - ok - contains exact`() {
38+
assertNotEquals(null, response?.ocs?.data?.exact)
39+
}
40+
41+
@Test
42+
fun `check structure - ok - contains groups`() {
43+
assertNotEquals(null, response?.ocs?.data?.groups)
44+
}
45+
46+
@Test
47+
fun `check structure - ok - contains remotes`() {
48+
assertNotEquals(null, response?.ocs?.data?.remotes)
49+
}
50+
51+
@Test
52+
fun `check structure - ok - contains users`() {
53+
assertNotEquals(null, response?.ocs?.data?.users)
54+
}
55+
56+
@Test
57+
fun `check structure - ok - groups contains two items`() {
58+
assertEquals(2, response?.ocs?.data?.groups?.size)
59+
}
60+
61+
@Test
62+
fun `check structure - ok - users contains two items`() {
63+
assertEquals(2, response?.ocs?.data?.users?.size)
64+
}
65+
66+
@Test
67+
fun `check structure - ok - exact_users contains one item`() {
68+
assertEquals(1, response?.ocs?.data?.exact?.users?.size)
69+
}
70+
71+
companion object {
72+
val EXAMPLE_RESPONSE = """
73+
{
74+
"ocs": {
75+
"data": {
76+
"exact": {
77+
"groups": [],
78+
"remotes": [],
79+
"users": [
80+
{
81+
"label": "admin",
82+
"value": {
83+
"shareType": 0,
84+
"shareWith": "admin"
85+
}
86+
}
87+
]
88+
},
89+
"groups": [
90+
{
91+
"label": "group1",
92+
"value": {
93+
"shareType": 1,
94+
"shareWith": "group1"
95+
}
96+
},
97+
{
98+
"label": "group2",
99+
"value": {
100+
"shareType": 1,
101+
"shareWith": "group2"
102+
}
103+
}
104+
],
105+
"remotes": [],
106+
"users": [
107+
{
108+
"label": "user1",
109+
"value": {
110+
"shareType": 0,
111+
"shareWith": "user1"
112+
}
113+
},
114+
{
115+
"label": "user2",
116+
"value": {
117+
"shareType": 0,
118+
"shareWith": "user2"
119+
}
120+
}
121+
]
122+
},
123+
"meta": {
124+
"itemsperpage": "",
125+
"message": "OK",
126+
"status": "ok",
127+
"statuscode": 200,
128+
"totalitems": ""
129+
}
130+
}
131+
}
132+
"""
133+
}
134+
}

0 commit comments

Comments
 (0)