mirror of
https://github.com/owncloud/android-library.git
synced 2025-06-07 16:06:08 +00:00
move response json to resource folder
This commit is contained in:
parent
76c55c9a9c
commit
6ec1bd2bb2
@ -41,12 +41,9 @@ import com.owncloud.android.lib.resources.shares.responses.ShareeOcsResponse
|
|||||||
import com.squareup.moshi.JsonAdapter
|
import com.squareup.moshi.JsonAdapter
|
||||||
import com.squareup.moshi.Moshi
|
import com.squareup.moshi.Moshi
|
||||||
import com.squareup.moshi.Types
|
import com.squareup.moshi.Types
|
||||||
import org.json.JSONArray
|
|
||||||
import org.json.JSONObject
|
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
import java.lang.reflect.Type
|
import java.lang.reflect.Type
|
||||||
import java.net.URL
|
import java.net.URL
|
||||||
import java.util.ArrayList
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by masensio on 08/10/2015.
|
* Created by masensio on 08/10/2015.
|
||||||
|
@ -24,7 +24,6 @@
|
|||||||
|
|
||||||
package com.owncloud.android.lib.resources.shares
|
package com.owncloud.android.lib.resources.shares
|
||||||
|
|
||||||
import com.owncloud.android.lib.resources.files.FileUtils
|
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -25,8 +25,6 @@ import com.owncloud.android.lib.common.operations.RemoteOperationResult
|
|||||||
import com.owncloud.android.lib.resources.shares.GetRemoteShareesOperation
|
import com.owncloud.android.lib.resources.shares.GetRemoteShareesOperation
|
||||||
import com.owncloud.android.lib.resources.shares.responses.ShareeOcsResponse
|
import com.owncloud.android.lib.resources.shares.responses.ShareeOcsResponse
|
||||||
import com.owncloud.android.lib.resources.shares.services.ShareeService
|
import com.owncloud.android.lib.resources.shares.services.ShareeService
|
||||||
import org.json.JSONObject
|
|
||||||
import java.util.ArrayList
|
|
||||||
|
|
||||||
class OCShareeService(override val client: OwnCloudClient) :
|
class OCShareeService(override val client: OwnCloudClient) :
|
||||||
ShareeService {
|
ShareeService {
|
||||||
|
@ -29,140 +29,94 @@ import com.squareup.moshi.JsonAdapter
|
|||||||
import com.squareup.moshi.Moshi
|
import com.squareup.moshi.Moshi
|
||||||
import com.squareup.moshi.Types
|
import com.squareup.moshi.Types
|
||||||
import org.junit.Assert.assertEquals
|
import org.junit.Assert.assertEquals
|
||||||
import org.junit.Assert.assertTrue
|
|
||||||
import org.junit.Assert.assertNotEquals
|
import org.junit.Assert.assertNotEquals
|
||||||
|
import org.junit.Assert.assertTrue
|
||||||
import org.junit.Before
|
import org.junit.Before
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
|
import java.io.File
|
||||||
import java.lang.reflect.Type
|
import java.lang.reflect.Type
|
||||||
|
|
||||||
class ShareeResponseTest {
|
class ShareeResponseTest {
|
||||||
|
|
||||||
var response: CommonOcsResponse<ShareeOcsResponse>? = null
|
lateinit var response: CommonOcsResponse<ShareeOcsResponse>
|
||||||
|
|
||||||
|
private fun loadResponses(fileName: String, adapter: JsonAdapter<CommonOcsResponse<ShareeOcsResponse>>) =
|
||||||
|
adapter.fromJson(File(fileName).readText())
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
fun prepare() {
|
fun prepare() {
|
||||||
val moshi = Moshi.Builder().build()
|
val moshi = Moshi.Builder().build()
|
||||||
val type: Type = Types.newParameterizedType(CommonOcsResponse::class.java, ShareeOcsResponse::class.java)
|
val type: Type = Types.newParameterizedType(CommonOcsResponse::class.java, ShareeOcsResponse::class.java)
|
||||||
val adapter: JsonAdapter<CommonOcsResponse<ShareeOcsResponse>> = moshi.adapter(type)
|
val adapter: JsonAdapter<CommonOcsResponse<ShareeOcsResponse>> = moshi.adapter(type)
|
||||||
response = adapter.fromJson(EXAMPLE_RESPONSE)
|
response = loadResponses(EXAMPLE_RESPONSE_JSON, adapter)!!
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `check structure - ok - contains meta`() {
|
fun `check structure - ok - contains meta`() {
|
||||||
assertEquals("OK", response?.ocs?.meta?.message!!)
|
assertEquals("OK", response.ocs.meta.message!!)
|
||||||
assertEquals(200, response?.ocs?.meta?.statusCode!!)
|
assertEquals(200, response.ocs.meta.statusCode!!)
|
||||||
assertEquals("ok", response?.ocs?.meta?.status!!)
|
assertEquals("ok", response.ocs.meta.status!!)
|
||||||
assertTrue(response?.ocs?.meta?.itemsPerPage?.isEmpty()!!)
|
assertTrue(response.ocs.meta.itemsPerPage?.isEmpty()!!)
|
||||||
assertTrue(response?.ocs?.meta?.totalItems?.isEmpty()!!)
|
assertTrue(response.ocs.meta.totalItems?.isEmpty()!!)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `check structure - ok - contains exact`() {
|
fun `check structure - ok - contains exact`() {
|
||||||
assertNotEquals(null, response?.ocs?.data?.exact)
|
assertNotEquals(null, response.ocs.data.exact)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `check structure - ok - contains groups`() {
|
fun `check structure - ok - contains groups`() {
|
||||||
assertNotEquals(null, response?.ocs?.data?.groups)
|
assertNotEquals(null, response.ocs.data.groups)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `check structure - ok - contains remotes`() {
|
fun `check structure - ok - contains remotes`() {
|
||||||
assertNotEquals(null, response?.ocs?.data?.remotes)
|
assertNotEquals(null, response.ocs.data.remotes)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `check structure - ok - contains users`() {
|
fun `check structure - ok - contains users`() {
|
||||||
assertNotEquals(null, response?.ocs?.data?.users)
|
assertNotEquals(null, response.ocs.data.users)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `check structure - ok - groups contains two items`() {
|
fun `check structure - ok - groups contains two items`() {
|
||||||
assertEquals(2, response?.ocs?.data?.groups?.size)
|
assertEquals(2, response.ocs.data.groups.size)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `check structure - ok - users contains two items`() {
|
fun `check structure - ok - users contains two items`() {
|
||||||
assertEquals(2, response?.ocs?.data?.users?.size)
|
assertEquals(2, response.ocs.data.users.size)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `check structure - ok - exact_users contains one item`() {
|
fun `check structure - ok - exact_users contains one item`() {
|
||||||
assertEquals(1, response?.ocs?.data?.exact?.users?.size)
|
assertEquals(1, response.ocs.data.exact?.users?.size)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `check structure - ok - user1 contains additional data`() {
|
fun `check structure - ok - user1 contains additional data`() {
|
||||||
assertEquals("user1@user1.com", response?.ocs?.data?.users?.get(0)?.value?.additionalInfo)
|
assertEquals("user1@user1.com", response.ocs.data.users.get(0).value.additionalInfo)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `check structure - ok - user2 does not contain additional data`() {
|
fun `check structure - ok - user2 does not contain additional data`() {
|
||||||
assertEquals(null, response!!.ocs.data.users!![1].value!!.additionalInfo)
|
assertEquals(null, response.ocs.data.users[1].value.additionalInfo)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `check empty response - ok - parsing ok`() {
|
||||||
|
val moshi = Moshi.Builder().build()
|
||||||
|
val type: Type = Types.newParameterizedType(CommonOcsResponse::class.java, ShareeOcsResponse::class.java)
|
||||||
|
val adapter: JsonAdapter<CommonOcsResponse<ShareeOcsResponse>> = moshi.adapter(type)
|
||||||
|
loadResponses(EMPTY_RESPONSE_JSON, adapter)!!
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
val EXAMPLE_RESPONSE = """
|
val RESOURCES_PATH =
|
||||||
{
|
"/home/schabi/Projects/owncloud-android/owncloud-android-library/owncloudComLibrary/src/test/resources/com.owncloud.android.lib.resources.sharees.responses"
|
||||||
"ocs": {
|
val EXAMPLE_RESPONSE_JSON = "$RESOURCES_PATH/example_sharee_response.json"
|
||||||
"data": {
|
val EMPTY_RESPONSE_JSON = "$RESOURCES_PATH/empty_sharee_response.json"
|
||||||
"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",
|
|
||||||
"shareWithAdditionalInfo": "user1@user1.com"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"label": "user2",
|
|
||||||
"value": {
|
|
||||||
"shareType": 0,
|
|
||||||
"shareWith": "user2"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"meta": {
|
|
||||||
"itemsperpage": "",
|
|
||||||
"message": "OK",
|
|
||||||
"status": "ok",
|
|
||||||
"statuscode": 200,
|
|
||||||
"totalitems": ""
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
"""
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -0,0 +1,21 @@
|
|||||||
|
{
|
||||||
|
"ocs": {
|
||||||
|
"meta": {
|
||||||
|
"status": "ok",
|
||||||
|
"statuscode": 100,
|
||||||
|
"message": "OK",
|
||||||
|
"totalitems": "",
|
||||||
|
"itemsperpage": ""
|
||||||
|
},
|
||||||
|
"data": {
|
||||||
|
"exact": {
|
||||||
|
"users": [],
|
||||||
|
"groups": [],
|
||||||
|
"remotes": []
|
||||||
|
},
|
||||||
|
"users": [],
|
||||||
|
"groups": [],
|
||||||
|
"remotes": []
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,60 @@
|
|||||||
|
{
|
||||||
|
"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",
|
||||||
|
"shareWithAdditionalInfo": "user1@user1.com"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"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