Skip to content

Commit 66293e7

Browse files
surinder-tsysAndyScherzinger
authored andcommitted
Test case added.
1 parent 82963c6 commit 66293e7

File tree

1 file changed

+118
-0
lines changed

1 file changed

+118
-0
lines changed
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
/* Nextcloud Android Library is available under MIT license
2+
*
3+
* @author TSI-mc
4+
* Copyright (C) 2023 TSI-mc
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.download_limit
29+
30+
import org.junit.Assert.*
31+
import org.junit.Test
32+
33+
class DownloadLimitXMLParserIT {
34+
35+
@Test
36+
fun parseSuccessResponseWithValues(){
37+
val xml = """<?xml version="1.0"?>
38+
<ocs>
39+
<meta>
40+
<status>ok</status>
41+
<statuscode>200</statuscode>
42+
<message>OK</message>
43+
</meta>
44+
<data>
45+
<limit>5</limit>
46+
<count>1</count>
47+
</data>
48+
</ocs>
49+
"""
50+
51+
val remoteOperationResult = DownloadLimitXMLParser().parse(true, xml)
52+
53+
assertTrue(remoteOperationResult.isSuccess)
54+
assertEquals(5, remoteOperationResult.resultData.limit)
55+
assertEquals(1, remoteOperationResult.resultData.count)
56+
}
57+
58+
59+
@Test
60+
fun parseSuccessResponseWithNoValues(){
61+
val xml = """<?xml version="1.0"?>
62+
<ocs>
63+
<meta>
64+
<status>ok</status>
65+
<statuscode>200</statuscode>
66+
<message>OK</message>
67+
</meta>
68+
<data>
69+
<limit/>
70+
<count/>
71+
</data>
72+
</ocs>
73+
"""
74+
75+
val remoteOperationResult = DownloadLimitXMLParser().parse(true, xml)
76+
77+
assertTrue(remoteOperationResult.isSuccess)
78+
assertEquals(0, remoteOperationResult.resultData.limit)
79+
assertEquals(0, remoteOperationResult.resultData.count)
80+
}
81+
82+
@Test
83+
fun parseSuccessResponseForUpdateDeleteOperations(){
84+
val xml = """<?xml version="1.0"?>
85+
<ocs>
86+
<meta>
87+
<status>ok</status>
88+
<statuscode>200</statuscode>
89+
<message>OK</message>
90+
</meta>
91+
<data/>
92+
</ocs>
93+
"""
94+
95+
val remoteOperationResult = DownloadLimitXMLParser().parse(true, xml)
96+
97+
assertTrue(remoteOperationResult.isSuccess)
98+
}
99+
100+
@Test
101+
fun parseFailResponse(){
102+
val xml = """<?xml version="1.0"?>
103+
<ocs>
104+
<meta>
105+
<status>ok</status>
106+
<statuscode>403</statuscode>
107+
<message>OK</message>
108+
</meta>
109+
<data/>
110+
</ocs>
111+
"""
112+
113+
val remoteOperationResult = DownloadLimitXMLParser().parse(true, xml)
114+
115+
assertFalse(remoteOperationResult.isSuccess)
116+
}
117+
118+
}

0 commit comments

Comments
 (0)