View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
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  }