diff --git a/gradle.properties b/gradle.properties index 946d709d..53ae0ae4 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,3 +1,3 @@ android.enableJetifier=true android.useAndroidX=true -org.gradle.jvmargs=-Xmx1536M \ No newline at end of file +org.gradle.jvmargs=-Xmx1536M diff --git a/owncloudComLibrary/build.gradle b/owncloudComLibrary/build.gradle index 6db1f790..5537f94e 100644 --- a/owncloudComLibrary/build.gradle +++ b/owncloudComLibrary/build.gradle @@ -14,6 +14,8 @@ dependencies { exclude module: "kotlin-reflect" } kapt "com.squareup.moshi:moshi-kotlin-codegen:$moshiVersion" + + testImplementation 'junit:junit:4.13' } android { diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/response/CommonOcsResponse.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/CommonOcsResponse.kt similarity index 86% rename from owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/response/CommonOcsResponse.kt rename to owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/CommonOcsResponse.kt index d8402eb9..7a37dc82 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/response/CommonOcsResponse.kt +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/CommonOcsResponse.kt @@ -21,8 +21,9 @@ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -package com.owncloud.android.lib.resources.response +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. @@ -41,6 +42,11 @@ data class OCSResponse( @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? ) diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/GetRemoteShareesOperation.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/GetRemoteShareesOperation.kt index e3432b5b..546bf05b 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/GetRemoteShareesOperation.kt +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/GetRemoteShareesOperation.kt @@ -1,5 +1,6 @@ /* ownCloud Android Library is available under MIT license * + * @author Christian Schabesberger * @author masensio * @author David A. Velasco * @author David González Verdugo @@ -28,16 +29,21 @@ package com.owncloud.android.lib.resources.shares +import android.net.Uri import com.owncloud.android.lib.common.OwnCloudClient import com.owncloud.android.lib.common.http.HttpConstants import com.owncloud.android.lib.common.http.methods.nonwebdav.GetMethod import com.owncloud.android.lib.common.operations.RemoteOperation import com.owncloud.android.lib.common.operations.RemoteOperationResult import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode.OK -import org.json.JSONObject +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 timber.log.Timber +import java.lang.reflect.Type import java.net.URL -import java.util.ArrayList /** * Created by masensio on 08/10/2015. @@ -65,6 +71,7 @@ import java.util.ArrayList * Status codes: * 100 - successful * + * @author Christian Schabesberger * @author masensio * @author David A. Velasco * @author David González Verdugo @@ -78,80 +85,66 @@ class GetRemoteShareesOperation * @param perPage maximum number of results in a single page */ (private val searchString: String, private val page: Int, private val perPage: Int) : - RemoteOperation>() { + RemoteOperation() { - override fun run(client: OwnCloudClient): RemoteOperationResult> { - var result: RemoteOperationResult> + private fun buildRequestUri(baseUri: Uri) = + baseUri.buildUpon() + .appendEncodedPath(OCS_ROUTE) + .appendQueryParameter(PARAM_FORMAT, VALUE_FORMAT) + .appendQueryParameter(PARAM_ITEM_TYPE, VALUE_ITEM_TYPE) + .appendQueryParameter(PARAM_SEARCH, searchString) + .appendQueryParameter(PARAM_PAGE, page.toString()) + .appendQueryParameter(PARAM_PER_PAGE, perPage.toString()) + .build() - try { - val requestUri = client.baseUri - val uriBuilder = requestUri.buildUpon() - .appendEncodedPath(OCS_ROUTE) - .appendQueryParameter(PARAM_FORMAT, VALUE_FORMAT) - .appendQueryParameter(PARAM_ITEM_TYPE, VALUE_ITEM_TYPE) - .appendQueryParameter(PARAM_SEARCH, searchString) - .appendQueryParameter(PARAM_PAGE, page.toString()) - .appendQueryParameter(PARAM_PER_PAGE, perPage.toString()) + private fun parseResponse(response: String): ShareeOcsResponse? { + val moshi = Moshi.Builder().build() + val type: Type = Types.newParameterizedType(CommonOcsResponse::class.java, ShareeOcsResponse::class.java) + val adapter: JsonAdapter> = moshi.adapter(type) + return adapter.fromJson(response)!!.ocs.data + } - val getMethod = GetMethod(URL(uriBuilder.build().toString())) + private fun onResultUnsuccessful( + method: GetMethod, + response: String?, + status: Int + ): RemoteOperationResult { + Timber.e("Failed response while getting users/groups from the server ") + if (response != null) { + Timber.e("*** status code: $status; response message: $response") + } else { + Timber.e("*** status code: $status") + } + return RemoteOperationResult(method) + } - getMethod.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE) + private fun onRequestSuccessful(response: String?): RemoteOperationResult { + val result = RemoteOperationResult(OK) + Timber.d("Successful response: $response") + result.data = parseResponse(response!!) + Timber.d("*** Get Users or groups completed ") + return result + } + override fun run(client: OwnCloudClient): RemoteOperationResult { + val requestUri = buildRequestUri(client.baseUri) + + val getMethod = GetMethod(URL(requestUri.toString())) + getMethod.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE) + + return try { val status = client.executeHttpMethod(getMethod) val response = getMethod.getResponseBodyAsString() - if (isSuccess(status)) { - Timber.d("Successful response: $response") - - // Parse the response - val respJSON = JSONObject(response) - val respOCS = respJSON.getJSONObject(NODE_OCS) - val respData = respOCS.getJSONObject(NODE_DATA) - val respExact = respData.getJSONObject(NODE_EXACT) - val respExactUsers = respExact.getJSONArray(NODE_USERS) - val respExactGroups = respExact.getJSONArray(NODE_GROUPS) - val respExactRemotes = respExact.getJSONArray(NODE_REMOTES) - val respPartialUsers = respData.getJSONArray(NODE_USERS) - val respPartialGroups = respData.getJSONArray(NODE_GROUPS) - val respPartialRemotes = respData.getJSONArray(NODE_REMOTES) - val jsonResults = arrayOf( - respExactUsers, - respExactGroups, - respExactRemotes, - respPartialUsers, - respPartialGroups, - respPartialRemotes - ) - - val data = ArrayList() // For result data - for (i in 0..5) { - for (j in 0 until jsonResults[i].length()) { - val jsonResult = jsonResults[i].getJSONObject(j) - data.add(jsonResult) - Timber.d("*** Added item: ${jsonResult.getString(PROPERTY_LABEL)}") - } - } - - result = RemoteOperationResult(OK) - result.data = data - - Timber.d("*** Get Users or groups completed ") - + if (!isSuccess(status)) { + onResultUnsuccessful(getMethod, response, status) } else { - result = RemoteOperationResult(getMethod) - Timber.e("Failed response while getting users/groups from the server ") - if (response != null) { - Timber.e("*** status code: $status; response message: $response") - } else { - Timber.e("*** status code: $status") - } + onRequestSuccessful(response) } } catch (e: Exception) { - result = RemoteOperationResult(e) Timber.e(e, "Exception while getting users/groups") + RemoteOperationResult(e) } - - return result } private fun isSuccess(status: Int) = status == HttpConstants.HTTP_OK @@ -171,18 +164,5 @@ class GetRemoteShareesOperation // Arguments - constant values private const val VALUE_FORMAT = "json" private const val VALUE_ITEM_TYPE = "file" // to get the server search for users / groups - - // JSON Node names - private const val NODE_OCS = "ocs" - private const val NODE_DATA = "data" - private const val NODE_EXACT = "exact" - private const val NODE_USERS = "users" - private const val NODE_GROUPS = "groups" - private const val NODE_REMOTES = "remotes" - const val NODE_VALUE = "value" - const val PROPERTY_LABEL = "label" - const val PROPERTY_SHARE_TYPE = "shareType" - const val PROPERTY_SHARE_WITH = "shareWith" - const val PROPERTY_SHARE_WITH_ADDITIONAL_INFO = "shareWithAdditionalInfo" } } diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/RemoteShare.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/RemoteShare.kt index 20bb1ae9..21e3835b 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/RemoteShare.kt +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/RemoteShare.kt @@ -24,7 +24,6 @@ package com.owncloud.android.lib.resources.shares -import com.owncloud.android.lib.resources.files.FileUtils import java.io.File /** @@ -106,17 +105,6 @@ enum class ShareType constructor(val value: Int) { FEDERATED(6); companion object { - fun fromValue(value: Int): ShareType? { - return when (value) { - -1 -> UNKNOWN - 0 -> USER - 1 -> GROUP - 3 -> PUBLIC_LINK - 4 -> EMAIL - 5 -> CONTACT - 6 -> FEDERATED - else -> null - } - } + fun fromValue(value: Int) = values().firstOrNull { it.value == value } } } diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/responses/ShareeResponse.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/responses/ShareeResponse.kt new file mode 100644 index 00000000..0cd0162a --- /dev/null +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/responses/ShareeResponse.kt @@ -0,0 +1,72 @@ +/* ownCloud Android Library is available under MIT license + * + * Copyright (C) 2020 ownCloud GmbH. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package com.owncloud.android.lib.resources.shares.responses + +import com.squareup.moshi.Json +import com.squareup.moshi.JsonClass + +/** + * This was modeled according to the documentation: + * https://doc.owncloud.com/server/developer_manual/core/apis/ocs-recipient-api.html#get-shares-recipients + */ +@JsonClass(generateAdapter = true) +data class ShareeOcsResponse( + val exact: ExactSharees?, + val groups: List, + val remotes: List, + val users: List +) { + fun getFlatRepresentationWithoutExact() = ArrayList().apply { + addAll(users) + addAll(remotes) + addAll(groups) + } +} + +@JsonClass(generateAdapter = true) +data class ExactSharees( + val groups: List, + val remotes: List, + val users: List +) { + fun getFlatRepresentation() = ArrayList().apply { + addAll(users) + addAll(remotes) + addAll(groups) + } +} + +@JsonClass(generateAdapter = true) +data class ShareeItem( + val label: String, + val value: ShareeValue +) + +@JsonClass(generateAdapter = true) +data class ShareeValue( + val shareType: Int, + val shareWith: String, + @Json(name = "shareWithAdditionalInfo") + val additionalInfo: String? +) diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/services/ShareeService.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/services/ShareeService.kt index ab6d9e83..95983ec5 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/services/ShareeService.kt +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/services/ShareeService.kt @@ -1,6 +1,7 @@ /** * ownCloud Android client application * + * @author Christian Schabesberger * @author David González Verdugo * * Copyright (C) 2020 ownCloud GmbH. @@ -22,13 +23,12 @@ package com.owncloud.android.lib.resources.shares.services import com.owncloud.android.lib.common.operations.RemoteOperationResult import com.owncloud.android.lib.resources.Service -import org.json.JSONObject -import java.util.ArrayList +import com.owncloud.android.lib.resources.shares.responses.ShareeOcsResponse interface ShareeService : Service { fun getSharees( searchString: String, page: Int, perPage: Int - ): RemoteOperationResult> + ): RemoteOperationResult } diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/services/implementation/OCShareeService.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/services/implementation/OCShareeService.kt index 370ef34b..9cb014f3 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/services/implementation/OCShareeService.kt +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/services/implementation/OCShareeService.kt @@ -23,9 +23,8 @@ package com.owncloud.android.lib.resources.shares.services.implementation import com.owncloud.android.lib.common.OwnCloudClient import com.owncloud.android.lib.common.operations.RemoteOperationResult import com.owncloud.android.lib.resources.shares.GetRemoteShareesOperation +import com.owncloud.android.lib.resources.shares.responses.ShareeOcsResponse import com.owncloud.android.lib.resources.shares.services.ShareeService -import org.json.JSONObject -import java.util.ArrayList class OCShareeService(override val client: OwnCloudClient) : ShareeService { @@ -33,7 +32,7 @@ class OCShareeService(override val client: OwnCloudClient) : searchString: String, page: Int, perPage: Int - ): RemoteOperationResult> = + ): RemoteOperationResult = GetRemoteShareesOperation( searchString, page, diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/GetRemoteCapabilitiesOperation.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/GetRemoteCapabilitiesOperation.kt index f9f164eb..806440be 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/GetRemoteCapabilitiesOperation.kt +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/GetRemoteCapabilitiesOperation.kt @@ -34,8 +34,8 @@ import com.owncloud.android.lib.common.http.methods.nonwebdav.GetMethod import com.owncloud.android.lib.common.operations.RemoteOperation import com.owncloud.android.lib.common.operations.RemoteOperationResult import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode.OK -import com.owncloud.android.lib.resources.response.CapabilityResponse -import com.owncloud.android.lib.resources.response.CommonOcsResponse +import com.owncloud.android.lib.resources.status.responses.CapabilityResponse +import com.owncloud.android.lib.resources.CommonOcsResponse import com.squareup.moshi.JsonAdapter import com.squareup.moshi.Moshi import com.squareup.moshi.Types diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/response/CapabilityResponse.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/responses/CapabilityResponse.kt similarity index 99% rename from owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/response/CapabilityResponse.kt rename to owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/responses/CapabilityResponse.kt index 49efaea9..dea2431e 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/response/CapabilityResponse.kt +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/responses/CapabilityResponse.kt @@ -22,7 +22,7 @@ * THE SOFTWARE. * */ -package com.owncloud.android.lib.resources.response +package com.owncloud.android.lib.resources.status.responses import com.owncloud.android.lib.resources.status.RemoteCapability import com.owncloud.android.lib.resources.status.RemoteCapability.CapabilityBooleanType diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/users/GetRemoteUserInfoOperation.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/users/GetRemoteUserInfoOperation.kt index 53600d29..d1f2a43c 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/users/GetRemoteUserInfoOperation.kt +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/users/GetRemoteUserInfoOperation.kt @@ -29,8 +29,8 @@ import com.owncloud.android.lib.common.http.methods.nonwebdav.GetMethod import com.owncloud.android.lib.common.operations.RemoteOperation import com.owncloud.android.lib.common.operations.RemoteOperationResult import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode -import com.owncloud.android.lib.resources.response.CommonOcsResponse -import com.owncloud.android.lib.resources.response.UserInfoResponse +import com.owncloud.android.lib.resources.CommonOcsResponse +import com.owncloud.android.lib.resources.users.responses.UserInfoResponse import com.squareup.moshi.JsonAdapter import com.squareup.moshi.Moshi import com.squareup.moshi.Types diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/response/UserInfoResponse.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/users/responses/UserInfoResponse.kt similarity index 96% rename from owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/response/UserInfoResponse.kt rename to owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/users/responses/UserInfoResponse.kt index 1ff3b94e..0371e50f 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/response/UserInfoResponse.kt +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/users/responses/UserInfoResponse.kt @@ -21,7 +21,7 @@ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -package com.owncloud.android.lib.resources.response +package com.owncloud.android.lib.resources.users.responses import com.owncloud.android.lib.resources.users.RemoteUserInfo import com.squareup.moshi.Json diff --git a/owncloudComLibrary/src/test/java/com/owncloud/android/lib/resources/shares/responses/ShareeResponseTest.kt b/owncloudComLibrary/src/test/java/com/owncloud/android/lib/resources/shares/responses/ShareeResponseTest.kt new file mode 100644 index 00000000..ee88839d --- /dev/null +++ b/owncloudComLibrary/src/test/java/com/owncloud/android/lib/resources/shares/responses/ShareeResponseTest.kt @@ -0,0 +1,93 @@ +/* ownCloud Android Library is available under MIT license + * Copyright (C) 2020 ownCloud GmbH. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + */ + +package com.owncloud.android.lib.resources.shares.responses + +import com.owncloud.android.lib.resources.CommonOcsResponse +import com.squareup.moshi.JsonAdapter +import com.squareup.moshi.Moshi +import com.squareup.moshi.Types +import org.junit.Assert.assertNull +import org.junit.Assert.assertEquals +import org.junit.Assert.assertTrue +import org.junit.Before +import org.junit.Test +import java.io.File +import java.lang.reflect.Type + +class ShareeResponseTest { + + lateinit var adapter: JsonAdapter> + + private fun loadResponses(fileName: String) = + adapter.fromJson(File(fileName).readText()) + + @Before + fun prepare() { + val moshi = Moshi.Builder().build() + val type: Type = Types.newParameterizedType(CommonOcsResponse::class.java, ShareeOcsResponse::class.java) + adapter = moshi.adapter(type) + } + + @Test + fun `check structure - ok - contains meta`() { + val response = loadResponses(EXAMPLE_RESPONSE_JSON)!! + 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 `example response - ok - correct sturcture`() { + val response = loadResponses(EXAMPLE_RESPONSE_JSON)!! + assertEquals(2, response.ocs.data.groups.size) + assertEquals(0, response.ocs.data.remotes.size) + assertEquals(2, response.ocs.data.users.size) + assertEquals(0, response.ocs.data.exact?.groups?.size) + assertEquals(0, response.ocs.data.exact?.remotes?.size) + assertEquals(1, response.ocs.data.exact?.users?.size) + assertEquals("user1@user1.com", response.ocs.data.users.get(0).value.additionalInfo) + assertNull(response.ocs.data.users[1].value.additionalInfo) + } + + @Test + fun `check empty response - ok - parsing ok`() { + val response = loadResponses(EMPTY_RESPONSE_JSON)!! + assertTrue(response.ocs.data.exact?.groups?.isEmpty()!!) + assertTrue(response.ocs.data.exact?.remotes?.isEmpty()!!) + assertTrue(response.ocs.data.exact?.users?.isEmpty()!!) + assertTrue(response.ocs.data.groups.isEmpty()) + assertTrue(response.ocs.data.remotes.isEmpty()) + assertTrue(response.ocs.data.users.isEmpty()) + } + + companion object { + val RESOURCES_PATH = + "src/test/responses/com.owncloud.android.lib.resources.sharees.responses" + val EXAMPLE_RESPONSE_JSON = "$RESOURCES_PATH/example_sharee_response.json" + val EMPTY_RESPONSE_JSON = "$RESOURCES_PATH/empty_sharee_response.json" + } +} \ No newline at end of file diff --git a/owncloudComLibrary/src/test/responses/com.owncloud.android.lib.resources.sharees.responses/empty_sharee_response.json b/owncloudComLibrary/src/test/responses/com.owncloud.android.lib.resources.sharees.responses/empty_sharee_response.json new file mode 100644 index 00000000..b74338d2 --- /dev/null +++ b/owncloudComLibrary/src/test/responses/com.owncloud.android.lib.resources.sharees.responses/empty_sharee_response.json @@ -0,0 +1,21 @@ +{ + "ocs": { + "meta": { + "status": "ok", + "statuscode": 100, + "message": "OK", + "totalitems": "", + "itemsperpage": "" + }, + "data": { + "exact": { + "users": [], + "groups": [], + "remotes": [] + }, + "users": [], + "groups": [], + "remotes": [] + } + } +} \ No newline at end of file diff --git a/owncloudComLibrary/src/test/responses/com.owncloud.android.lib.resources.sharees.responses/example_sharee_response.json b/owncloudComLibrary/src/test/responses/com.owncloud.android.lib.resources.sharees.responses/example_sharee_response.json new file mode 100644 index 00000000..fe988811 --- /dev/null +++ b/owncloudComLibrary/src/test/responses/com.owncloud.android.lib.resources.sharees.responses/example_sharee_response.json @@ -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": "" + } + } +} \ No newline at end of file