1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.vfs2.provider;
18
19 import org.junit.Assert;
20 import org.junit.BeforeClass;
21 import org.junit.Test;
22
23
24
25
26 public class UriParserTestCase {
27
28 private static final String[] schemes = new String[2];
29
30 @BeforeClass
31 public static void setupSchemes() {
32 schemes[0] = "ftp";
33 schemes[1] = "file";
34 }
35
36 @Test
37 public void testColonInFileName() {
38 Assert.assertNull(UriParser.extractScheme("some/path/some:file"));
39 }
40
41 @Test
42 public void testColonInFileNameAndNotSupportedScheme() {
43 Assert.assertNull(UriParser.extractScheme(schemes, "some:file"));
44 }
45
46 @Test
47 public void testColonInFileNameWithPath() {
48 Assert.assertNull(UriParser.extractScheme(schemes, "some/path/some:file"));
49 }
50
51 @Test
52 public void testColonNotFollowedBySlash() {
53 Assert.assertEquals("file", UriParser.extractScheme(schemes, "file:user/subdir/some/path/some:file"));
54 }
55
56 @Test
57 public void testNormalScheme() {
58 Assert.assertEquals("ftp", UriParser.extractScheme(schemes, "ftp://user:pass@host/some/path/some:file"));
59 }
60
61 @Test
62 public void testNormalSchemeWithBuffer() {
63 final StringBuilder buffer = new StringBuilder();
64 UriParser.extractScheme(schemes, "ftp://user:pass@host/some/path/some:file", buffer);
65 Assert.assertEquals("//user:pass@host/some/path/some:file", buffer.toString());
66 }
67
68 @Test
69 public void testOneSlashScheme() {
70 Assert.assertEquals("file", UriParser.extractScheme(schemes, "file:/user:pass@host/some/path/some:file"));
71 }
72
73 @Test
74 public void testOneSlashSchemeWithBuffer() {
75 final StringBuilder buffer = new StringBuilder();
76 UriParser.extractScheme(schemes, "file:/user:pass@host/some/path/some:file", buffer);
77 Assert.assertEquals("/user:pass@host/some/path/some:file", buffer.toString());
78 }
79
80 }