Skip to content

Commit 8cbc0b0

Browse files
Add client reporting
Signed-off-by: tobiasKaminsky <[email protected]>
1 parent a7b0fcd commit 8cbc0b0

File tree

1 file changed

+91
-0
lines changed

1 file changed

+91
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
/* Nextcloud Android Library is available under MIT license
2+
*
3+
* @author Tobias Kaminsky
4+
* Copyright (C) 2023 Tobias Kaminsky
5+
* Copyright (C) 2023 Nextcloud GmbH
6+
*
7+
* Permission is hereby granted, free of charge, to any person obtaining a copy
8+
* of this software and associated documentation files (the "Software"), to deal
9+
* in the Software without restriction, including without limitation the rights
10+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
* copies of the Software, and to permit persons to whom the Software is
12+
* furnished to do so, subject to the following conditions:
13+
*
14+
* The above copyright notice and this permission notice shall be included in
15+
* all copies or substantial portions of the Software.
16+
*
17+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
21+
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
22+
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23+
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
* THE SOFTWARE.
25+
*
26+
*/
27+
28+
package com.owncloud.android.lib.resources.status
29+
30+
import com.owncloud.android.AbstractIT
31+
import org.junit.Assert.assertEquals
32+
import org.junit.Assert.assertTrue
33+
import org.junit.Test
34+
35+
@Suppress("Detekt.MagicNumber")
36+
class SendClientDiagnosticRemoteOperationIT : AbstractIT() {
37+
@Test
38+
@Suppress("Detekt.MaxLineLength", "ktlint:standard:max-line-length")
39+
fun testJSON() {
40+
val problems =
41+
listOf(
42+
Problem("UploadResult.CREDENTIAL_ERROR", 2, 1700152062),
43+
Problem("UploadResult.FOLDER_ERROR", 3, 1400652062)
44+
)
45+
46+
val sut =
47+
SendClientDiagnosticRemoteOperation(
48+
Problem(SendClientDiagnosticRemoteOperation.SYNC_CONFLICTS, 1, 1700652062),
49+
problems,
50+
Problem(SendClientDiagnosticRemoteOperation.VIRUS_DETECTED, 4, 1234234234),
51+
Problem(SendClientDiagnosticRemoteOperation.E2E_ERRORS, 2, 1700612062)
52+
)
53+
assertEquals(
54+
"""{"sync_conflicts": {"count": 1, "oldest": 1700652062}, "problems": {"UploadResult.CREDENTIAL_ERROR": {"count": 2, "oldest": 1700152062}, "UploadResult.FOLDER_ERROR": {"count": 3, "oldest": 1400652062}}, "virus_detected": {"count": 4, "oldest": 1234234234}, "e2e_errors": {"count": 2, "oldest": 1700612062}}""",
55+
sut.generateJSON()
56+
)
57+
}
58+
59+
@Test
60+
fun testEmptyJSON() {
61+
val sut =
62+
SendClientDiagnosticRemoteOperation(
63+
null,
64+
null,
65+
null,
66+
null
67+
)
68+
assertEquals(
69+
"""{"sync_conflicts": {}, "problems": {}, "virus_detected": {}, "e2e_errors": {}}""",
70+
sut.generateJSON()
71+
)
72+
}
73+
74+
@Test
75+
fun sendDiagnostic() {
76+
val problems =
77+
listOf(
78+
Problem("UploadResult.CREDENTIAL_ERROR", 2, 1700152062),
79+
Problem("UploadResult.FOLDER_ERROR", 3, 1400652062)
80+
)
81+
82+
val sut =
83+
SendClientDiagnosticRemoteOperation(
84+
Problem(SendClientDiagnosticRemoteOperation.SYNC_CONFLICTS, 1, 1700652062),
85+
problems,
86+
null,
87+
Problem(SendClientDiagnosticRemoteOperation.E2E_ERRORS, 2, 1700612062)
88+
).execute(nextcloudClient)
89+
assertTrue(sut.isSuccess) // we cannot check anything else
90+
}
91+
}

0 commit comments

Comments
 (0)