Skip to content

Commit 44dc133

Browse files
committed
add tests
Signed-off-by: alperozturk96 <alper_ozturk@proton.me>
1 parent c490776 commit 44dc133

5 files changed

Lines changed: 80 additions & 55 deletions

File tree

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Nextcloud Android Library
3+
*
4+
* SPDX-FileCopyrightText: 2026 Alper Ozturk <alper.ozturk@nextcloud.com>
5+
* SPDX-License-Identifier: MIT
6+
*/
7+
8+
package com.owncloud.android.lib.resources.users
9+
10+
import com.owncloud.android.AbstractIT
11+
import com.owncloud.android.lib.resources.e2ee.DeleteEncryptedFilesRemoteOperation
12+
import junit.framework.TestCase.assertTrue
13+
import org.junit.Test
14+
15+
class DeleteE2ERemoteOperationIT : AbstractIT() {
16+
@Test
17+
fun testDeleteEncryptedFiles() {
18+
val sut = DeleteEncryptedFilesRemoteOperation()
19+
val result = sut.execute(nextcloudClient)
20+
assertTrue(result.isSuccess)
21+
}
22+
23+
@Test
24+
fun testDeletePrivateKey() {
25+
val sut = DeletePrivateKeyRemoteOperation()
26+
val result = sut.execute(nextcloudClient)
27+
assertTrue(result.isSuccess)
28+
}
29+
30+
@Test
31+
fun testDeletePublicKey() {
32+
val sut = DeletePublicKeyRemoteOperation()
33+
val result = sut.execute(nextcloudClient)
34+
assertTrue(result.isSuccess)
35+
}
36+
}

library/src/main/java/com/owncloud/android/lib/resources/assistant/v1/DeleteTaskRemoteOperationV1.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import com.nextcloud.operations.DeleteMethod
1313
import com.owncloud.android.lib.common.operations.RemoteOperation
1414
import com.owncloud.android.lib.common.operations.RemoteOperationResult
1515
import com.owncloud.android.lib.common.utils.Log_OC
16-
import com.owncloud.android.lib.resources.users.DeletePrivateKeyRemoteOperation
1716
import java.io.IOException
1817
import java.net.HttpURLConnection
1918

@@ -42,7 +41,7 @@ class DeleteTaskRemoteOperationV1(
4241
}
4342

4443
companion object {
45-
private val TAG = DeletePrivateKeyRemoteOperation::class.java.simpleName
44+
private val TAG = DeleteTaskRemoteOperationV1::class.java.simpleName
4645
private const val DIRECT_ENDPOINT =
4746
"/ocs/v2.php/textprocessing/task/"
4847
}

library/src/main/java/com/owncloud/android/lib/resources/e2ee/DeleteEncryptedFilesRemoteOperation.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import com.owncloud.android.lib.common.utils.Log_OC
1515
import org.apache.commons.httpclient.HttpStatus
1616

1717
class DeleteEncryptedFilesRemoteOperation : RemoteOperation<Unit>() {
18-
1918
@Deprecated("Deprecated in Java")
2019
@Suppress("Detekt.TooGenericExceptionCaught", "DEPRECATION")
2120
override fun run(client: NextcloudClient): RemoteOperationResult<Unit> {

library/src/main/java/com/owncloud/android/lib/resources/users/DeletePrivateKeyRemoteOperation.kt

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,27 +15,22 @@ import com.owncloud.android.lib.common.utils.Log_OC
1515
import java.io.IOException
1616
import java.net.HttpURLConnection
1717

18-
/**
19-
* Remote operation performing to delete the private key for an user
20-
*/
21-
class DeletePrivateKeyRemoteOperation : RemoteOperation<Void>() {
22-
/**
23-
* @param client Client object
24-
*/
25-
override fun run(client: NextcloudClient): RemoteOperationResult<Void> {
18+
class DeletePrivateKeyRemoteOperation : RemoteOperation<Unit>() {
19+
@Deprecated("Deprecated in Java")
20+
@Suppress("Detekt.TooGenericExceptionCaught", "DEPRECATION")
21+
override fun run(client: NextcloudClient): RemoteOperationResult<Unit> {
2622
var postMethod: DeleteMethod? = null
27-
var result: RemoteOperationResult<Void>
23+
var result: RemoteOperationResult<Unit>
2824
try {
29-
// remote request
3025
postMethod =
3126
DeleteMethod(
3227
client.baseUri.toString() + PRIVATE_KEY_URL,
3328
true
3429
)
3530
val status = client.execute(postMethod)
36-
result = RemoteOperationResult<Void>(status == HttpURLConnection.HTTP_OK, postMethod)
31+
result = RemoteOperationResult<Unit>(status == HttpURLConnection.HTTP_OK, postMethod)
3732
} catch (e: IOException) {
38-
result = RemoteOperationResult<Void>(e)
33+
result = RemoteOperationResult<Unit>(e)
3934
Log_OC.e(TAG, "Deletion of private key failed: " + result.logMessage, result.exception)
4035
} finally {
4136
postMethod?.releaseConnection()

library/src/main/java/com/owncloud/android/lib/resources/users/DeletePublicKeyRemoteOperation.kt

Lines changed: 36 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -5,49 +5,45 @@
55
* SPDX-FileCopyrightText: 2017 Tobias Kaminsky <tobias@kaminsky.me>
66
* SPDX-License-Identifier: MIT
77
*/
8-
package com.owncloud.android.lib.resources.users;
9-
10-
import com.nextcloud.common.NextcloudClient;
11-
import com.nextcloud.operations.DeleteMethod;
12-
import com.owncloud.android.lib.common.operations.RemoteOperation;
13-
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
14-
import com.owncloud.android.lib.common.utils.Log_OC;
15-
16-
import java.net.HttpURLConnection;
17-
18-
19-
/**
20-
* Remote operation performing to delete the public key for an user
21-
*/
22-
23-
public class DeletePublicKeyRemoteOperation extends RemoteOperation<Void> {
24-
25-
private static final String TAG = DeletePublicKeyRemoteOperation.class.getSimpleName();
26-
private static final String PUBLIC_KEY_URL = "/ocs/v2.php/apps/end_to_end_encryption/api/v1/public-key";
27-
28-
/**
29-
* @param client Client object
30-
*/
31-
@Override
32-
public RemoteOperationResult<Void> run(NextcloudClient client) {
33-
DeleteMethod postMethod = null;
34-
RemoteOperationResult<Void> result;
8+
package com.owncloud.android.lib.resources.users
9+
10+
import com.nextcloud.common.NextcloudClient
11+
import com.nextcloud.operations.DeleteMethod
12+
import com.owncloud.android.lib.common.operations.RemoteOperation
13+
import com.owncloud.android.lib.common.operations.RemoteOperationResult
14+
import com.owncloud.android.lib.common.utils.Log_OC
15+
import java.net.HttpURLConnection
16+
17+
class DeletePublicKeyRemoteOperation : RemoteOperation<Unit>() {
18+
@Deprecated("Deprecated in Java")
19+
@Suppress("Detekt.TooGenericExceptionCaught", "DEPRECATION")
20+
override fun run(client: NextcloudClient): RemoteOperationResult<Unit> {
21+
var postMethod: DeleteMethod? = null
22+
var result: RemoteOperationResult<Unit>
3523

3624
try {
37-
// remote request
38-
postMethod = new DeleteMethod(client.getBaseUri() + PUBLIC_KEY_URL, true);
39-
postMethod.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE);
40-
41-
int status = client.execute(postMethod);
42-
43-
result = new RemoteOperationResult<>(status == HttpURLConnection.HTTP_OK, postMethod);
44-
} catch (Exception e) {
45-
result = new RemoteOperationResult<>(e);
46-
Log_OC.e(TAG, "Deletion of public key failed: " + result.getLogMessage(), result.getException());
25+
postMethod = DeleteMethod(client.baseUri.toString() + PUBLIC_KEY_URL, true)
26+
postMethod.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE)
27+
28+
val status = client.execute(postMethod)
29+
30+
result = RemoteOperationResult<Unit>(status == HttpURLConnection.HTTP_OK, postMethod)
31+
} catch (e: Exception) {
32+
result = RemoteOperationResult<Unit>(e)
33+
Log_OC.e(
34+
TAG,
35+
"Deletion of public key failed: " + result.getLogMessage(),
36+
result.exception
37+
)
4738
} finally {
48-
if (postMethod != null)
49-
postMethod.releaseConnection();
39+
postMethod?.releaseConnection()
5040
}
51-
return result;
41+
return result
42+
}
43+
44+
companion object {
45+
private val TAG: String = DeletePublicKeyRemoteOperation::class.java.getSimpleName()
46+
private const val PUBLIC_KEY_URL =
47+
"/ocs/v2.php/apps/end_to_end_encryption/api/v1/public-key"
5248
}
5349
}

0 commit comments

Comments
 (0)