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

Commit

Permalink
test model
Browse files Browse the repository at this point in the history
  • Loading branch information
theScrabi committed Oct 8, 2020
1 parent 56842ed commit 161e12f
Show file tree
Hide file tree
Showing 3 changed files with 142 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
*/
package com.owncloud.android.lib.resources

import com.squareup.moshi.Json
import com.squareup.moshi.JsonClass

// Response retrieved by OCS Rest API, used to obtain capabilities, shares and user info among others.
Expand All @@ -41,6 +42,11 @@ data class OCSResponse<T>(
@JsonClass(generateAdapter = true)
data class MetaData(
val status: String,
val statuscode: Int,
val message: String?
@Json(name = "statuscode")
val statusCode: Int,
val message: String?,
@Json(name = "itemsperpage")
val itemsPerPage: String?,
@Json(name = "totalitems")
val totalItems: String?
)
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,6 @@ import com.squareup.moshi.JsonClass
*/
@JsonClass(generateAdapter = true)
data class ShareeOcsResponse(
@Json(name = "data")
val data: ShareeResponseData?,
@Json(name = "meta")
val meta: ShareeMeta?
)

@JsonClass(generateAdapter = true)
data class ShareeResponseData(
@Json(name = "exact")
val exact: ExactSharees?,
@Json(name = "groups")
Expand Down Expand Up @@ -75,17 +67,3 @@ data class ShareeValue(
@Json(name = "shareWith")
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?
)
Original file line number Diff line number Diff line change
@@ -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": ""
}
}
}
"""
}
}

0 comments on commit 161e12f

Please sign in to comment.