-
Notifications
You must be signed in to change notification settings - Fork 96
Expand file tree
/
Copy pathExceptionParserIT.java
More file actions
96 lines (74 loc) · 3.4 KB
/
ExceptionParserIT.java
File metadata and controls
96 lines (74 loc) · 3.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/*
* Nextcloud Android Library
*
* SPDX-FileCopyrightText: 2018-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2018-2022 Tobias Kaminsky <tobias@kaminsky.me>
* SPDX-License-Identifier: MIT
*/
package com.owncloud.android;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import com.owncloud.android.lib.common.operations.ExceptionParser;
import org.junit.Test;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
/**
* Created by tobi on 3/21/18.
*/
public class ExceptionParserIT {
@Test
public void testVirusException() throws IOException {
String virusException = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" +
"<d:error xmlns:d=\"DAV:\" xmlns:s=\"http://sabredav.org/ns\">\n" +
" <s:exception>OCA\\DAV\\Connector\\Sabre\\Exception\\UnsupportedMediaType" +
"</s:exception>\n" +
" <s:message>Virus Eicar-Test-Signature is detected in the file. " +
"Upload cannot be completed.</s:message>\n" +
"</d:error>";
InputStream is = new ByteArrayInputStream(virusException.getBytes());
ExceptionParser xmlParser = new ExceptionParser(is);
assertTrue(xmlParser.isVirusException());
assertFalse(xmlParser.isInvalidCharacterException());
}
@Test
public void testInvalidCharacterException() throws IOException {
String virusException = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" +
"<d:error xmlns:d=\"DAV:\" xmlns:s=\"http://sabredav.org/ns\">\n" +
" <s:exception>OC\\Connector\\Sabre\\Exception\\InvalidPath</s:exception>\n" +
" <s:message>Wrong Path</s:message>\n" +
"</d:error>";
InputStream is = new ByteArrayInputStream(virusException.getBytes());
ExceptionParser xmlParser = new ExceptionParser(is);
assertTrue(xmlParser.isInvalidCharacterException());
assertFalse(xmlParser.isVirusException());
}
@Test
public void testInvalidCharacterUploadException() throws IOException {
String virusException = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" +
"<d:error xmlns:d=\"DAV:\" xmlns:s=\"http://sabredav.org/ns\">\n" +
" <s:exception>OCP\\Files\\InvalidPathException</s:exception>\n" +
" <s:message>Wrong Path</s:message>\n" +
"</d:error>";
InputStream is = new ByteArrayInputStream(virusException.getBytes());
ExceptionParser xmlParser = new ExceptionParser(is);
assertTrue(xmlParser.isInvalidCharacterException());
assertFalse(xmlParser.isVirusException());
}
@Test
public void testEmptyString() throws IOException {
String emptyString = "";
InputStream is = new ByteArrayInputStream(emptyString.getBytes());
ExceptionParser xmlParser = new ExceptionParser(is);
assertFalse(xmlParser.isVirusException());
assertFalse(xmlParser.isInvalidCharacterException());
}
@Test
public void testString() throws IOException {
String emptyString = "";
InputStream is = new ByteArrayInputStream(emptyString.getBytes());
ExceptionParser xmlParser = new ExceptionParser(is);
assertFalse(xmlParser.isVirusException());
assertFalse(xmlParser.isInvalidCharacterException());
}
}