mirror of
https://github.com/owncloud/android-library.git
synced 2025-06-07 16:06:08 +00:00
test model
This commit is contained in:
parent
6bdb2badca
commit
1c08a942d1
@ -23,6 +23,7 @@
|
|||||||
*/
|
*/
|
||||||
package com.owncloud.android.lib.resources
|
package com.owncloud.android.lib.resources
|
||||||
|
|
||||||
|
import com.squareup.moshi.Json
|
||||||
import com.squareup.moshi.JsonClass
|
import com.squareup.moshi.JsonClass
|
||||||
|
|
||||||
// Response retrieved by OCS Rest API, used to obtain capabilities, shares and user info among others.
|
// Response retrieved by OCS Rest API, used to obtain capabilities, shares and user info among others.
|
||||||
@ -41,6 +42,11 @@ data class OCSResponse<T>(
|
|||||||
@JsonClass(generateAdapter = true)
|
@JsonClass(generateAdapter = true)
|
||||||
data class MetaData(
|
data class MetaData(
|
||||||
val status: String,
|
val status: String,
|
||||||
val statuscode: Int,
|
@Json(name = "statuscode")
|
||||||
val message: String?
|
val statusCode: Int,
|
||||||
|
val message: String?,
|
||||||
|
@Json(name = "itemsperpage")
|
||||||
|
val itemsPerPage: String?,
|
||||||
|
@Json(name = "totalitems")
|
||||||
|
val totalItems: String?
|
||||||
)
|
)
|
||||||
|
@ -32,14 +32,6 @@ import com.squareup.moshi.JsonClass
|
|||||||
*/
|
*/
|
||||||
@JsonClass(generateAdapter = true)
|
@JsonClass(generateAdapter = true)
|
||||||
data class ShareeOcsResponse(
|
data class ShareeOcsResponse(
|
||||||
@Json(name = "data")
|
|
||||||
val data: ShareeResponseData?,
|
|
||||||
@Json(name = "meta")
|
|
||||||
val meta: ShareeMeta?
|
|
||||||
)
|
|
||||||
|
|
||||||
@JsonClass(generateAdapter = true)
|
|
||||||
data class ShareeResponseData(
|
|
||||||
@Json(name = "exact")
|
@Json(name = "exact")
|
||||||
val exact: ExactSharees?,
|
val exact: ExactSharees?,
|
||||||
@Json(name = "groups")
|
@Json(name = "groups")
|
||||||
@ -75,17 +67,3 @@ data class ShareeValue(
|
|||||||
@Json(name = "shareWith")
|
@Json(name = "shareWith")
|
||||||
val shareWith: String?
|
val shareWith: String?
|
||||||
)
|
)
|
||||||
|
|
||||||
@JsonClass(generateAdapter = true)
|
|
||||||
data class ShareeMeta(
|
|
||||||
@Json(name = "itemsperpage")
|
|
||||||
val itemsPerPage: Int?,
|
|
||||||
@Json(name = "message")
|
|
||||||
val message: String?,
|
|
||||||
@Json(name = "status")
|
|
||||||
val status: String?,
|
|
||||||
@Json(name = "statuscode")
|
|
||||||
val statusCode: Int?,
|
|
||||||
@Json(name = "totalitems")
|
|
||||||
val totalItems: Int?
|
|
||||||
)
|
|
||||||
|
@ -0,0 +1,134 @@
|
|||||||
|
package com.owncloud.android.lib
|
||||||
|
|
||||||
|
import com.owncloud.android.lib.resources.CommonOcsResponse
|
||||||
|
import com.owncloud.android.lib.resources.shares.responses.ShareeOcsResponse
|
||||||
|
import com.squareup.moshi.JsonAdapter
|
||||||
|
import com.squareup.moshi.Moshi
|
||||||
|
import com.squareup.moshi.Types
|
||||||
|
import junit.framework.Assert.assertEquals
|
||||||
|
import junit.framework.Assert.assertTrue
|
||||||
|
import org.junit.Assert.assertNotEquals
|
||||||
|
import org.junit.Before
|
||||||
|
import org.junit.Test
|
||||||
|
import java.lang.reflect.Type
|
||||||
|
|
||||||
|
class ShareeResponseTest {
|
||||||
|
|
||||||
|
var response: CommonOcsResponse<ShareeOcsResponse>? = null
|
||||||
|
|
||||||
|
@Before
|
||||||
|
fun prepare() {
|
||||||
|
val moshi = Moshi.Builder().build()
|
||||||
|
val type: Type = Types.newParameterizedType(CommonOcsResponse::class.java, ShareeOcsResponse::class.java)
|
||||||
|
val adapter: JsonAdapter<CommonOcsResponse<ShareeOcsResponse>> = moshi.adapter(type)
|
||||||
|
response = adapter.fromJson(EXAMPLE_RESPONSE)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `check structure - ok - contains meta`() {
|
||||||
|
assertEquals("OK", response?.ocs?.meta?.message!!)
|
||||||
|
assertEquals(200, response?.ocs?.meta?.statusCode!!)
|
||||||
|
assertEquals("ok", response?.ocs?.meta?.status!!)
|
||||||
|
assertTrue(response?.ocs?.meta?.itemsPerPage?.isEmpty()!!)
|
||||||
|
assertTrue(response?.ocs?.meta?.totalItems?.isEmpty()!!)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `check structure - ok - contains exact`() {
|
||||||
|
assertNotEquals(null, response?.ocs?.data?.exact)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `check structure - ok - contains groups`() {
|
||||||
|
assertNotEquals(null, response?.ocs?.data?.groups)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `check structure - ok - contains remotes`() {
|
||||||
|
assertNotEquals(null, response?.ocs?.data?.remotes)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `check structure - ok - contains users`() {
|
||||||
|
assertNotEquals(null, response?.ocs?.data?.users)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `check structure - ok - groups contains two items`() {
|
||||||
|
assertEquals(2, response?.ocs?.data?.groups?.size)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `check structure - ok - users contains two items`() {
|
||||||
|
assertEquals(2, response?.ocs?.data?.users?.size)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `check structure - ok - exact_users contains one item`() {
|
||||||
|
assertEquals(1, response?.ocs?.data?.exact?.users?.size)
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
val EXAMPLE_RESPONSE = """
|
||||||
|
{
|
||||||
|
"ocs": {
|
||||||
|
"data": {
|
||||||
|
"exact": {
|
||||||
|
"groups": [],
|
||||||
|
"remotes": [],
|
||||||
|
"users": [
|
||||||
|
{
|
||||||
|
"label": "admin",
|
||||||
|
"value": {
|
||||||
|
"shareType": 0,
|
||||||
|
"shareWith": "admin"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"groups": [
|
||||||
|
{
|
||||||
|
"label": "group1",
|
||||||
|
"value": {
|
||||||
|
"shareType": 1,
|
||||||
|
"shareWith": "group1"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "group2",
|
||||||
|
"value": {
|
||||||
|
"shareType": 1,
|
||||||
|
"shareWith": "group2"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"remotes": [],
|
||||||
|
"users": [
|
||||||
|
{
|
||||||
|
"label": "user1",
|
||||||
|
"value": {
|
||||||
|
"shareType": 0,
|
||||||
|
"shareWith": "user1"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "user2",
|
||||||
|
"value": {
|
||||||
|
"shareType": 0,
|
||||||
|
"shareWith": "user2"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"meta": {
|
||||||
|
"itemsperpage": "",
|
||||||
|
"message": "OK",
|
||||||
|
"status": "ok",
|
||||||
|
"statuscode": 200,
|
||||||
|
"totalitems": ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user