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
97
|
package org.simpleframework.http.parse;
import junit.framework.TestCase;
import org.simpleframework.http.parse.PathParser;
public class PathParserTest extends TestCase {
private PathParser path;
protected void setUp() {
path = new PathParser();
}
public void testEmpty() {
assertEquals(null, path.getPath());
assertEquals(null, path.getExtension());
assertEquals(null, path.getName());
}
public void testSegments() {
path.parse("/a/b/c/d");
String[] list = path.getSegments();
assertEquals("a", list[0]);
assertEquals("b", list[1]);
assertEquals("c", list[2]);
assertEquals("d", list[3]);
}
public void testSubPath() {
path.parse("/0/1/2/3/4/5/6/index.html");
testSubPath(1);
testSubPath(2);
testSubPath(3);
testSubPath(4);
testSubPath(5);
testSubPath(6);
testSubPath(7);
testSubPath(0,4);
testSubPath(1,2);
testSubPath(2,3);
testSubPath(3,4);
testSubPath(1,3);
testSubPath(1,4);
testSubPath(1,5);
path.parse("/a/b/c/d/e/index.html");
testSubPath(1,2);
testSubPath(2,3);
testSubPath(3,1);
testSubPath(1,3);
}
private void testSubPath(int from) {
System.err.printf("[%s] %s: %s%n", path, from, path.getPath(from));
}
private void testSubPath(int from, int to) {
System.err.printf("[%s] %s, %s: %s%n", path, from, to, path.getPath(from, to));
}
public void testDirectory() {
path.parse("/some/directory/path/index.html");
assertEquals("/some/directory/path/", path.getDirectory());
path.parse("/some/path/README");
assertEquals("/some/path/", path.getDirectory());
}
public void testNormalization() {
path.parse("/path/./../index.html");
assertEquals("/", path.getDirectory());
path.parse("/path/hidden/./index.html");
assertEquals("/path/hidden/", path.getDirectory());
path.parse("/path/README");
assertEquals("/path/", path.getDirectory());
}
public void testString() {
path.parse("/some/path/../path/./to//a/file.txt");
assertEquals("/some/path/to//a/file.txt", path.toString());
}
public void testAIOB(){
path.parse("/admin/ws");
String result = path.getRelative("/admin/ws/");
String expResult = null;
assertEquals(expResult, result);
}
}
|