1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.vfs2.provider.local;
18
19 import org.apache.commons.vfs2.AbstractProviderTestCase;
20 import org.apache.commons.vfs2.FileName;
21 import org.apache.commons.vfs2.FileObject;
22 import org.apache.commons.vfs2.FileSystemException;
23 import org.apache.commons.vfs2.impl.DefaultFileSystemManager;
24 import org.junit.Assert;
25 import org.junit.Test;
26
27
28
29
30
31
32 public class WindowsFileNameTests extends AbstractProviderTestCase {
33
34 @Test
35 public void testWindowsFilenameParserError() throws Exception {
36
37 try {
38 final String FILE = "file://////";
39 final DefaultFileSystemManager manager = getManager();
40 Assert.assertNotNull("Unexpected null manager for test " + this, manager);
41 final FileObject fo = manager.resolveFile(FILE);
42 fail("Windows File Parser should not allow " + FILE + " " + fo);
43 } catch (FileSystemException ex) {
44 assertEquals("Exception code", "vfs.provider/invalid-absolute-uri.error", ex.getCode());
45 ex = (FileSystemException) ex.getCause();
46 assertEquals("Exception code", "vfs.provider.local/not-absolute-file-name.error", ex.getCode());
47 }
48 }
49
50 @Test
51 public void testWindowsFilenameUNCStartError() throws Exception {
52 try {
53 final String FILE = "file://///";
54 final DefaultFileSystemManager manager = getManager();
55 Assert.assertNotNull("Unexpected null manager for test " + this, manager);
56 final FileObject fo = manager.resolveFile(FILE);
57 fail("Windows File Parser should not allow " + FILE + " " + fo);
58 } catch (FileSystemException ex) {
59 assertEquals("Exception code", "vfs.provider/invalid-absolute-uri.error", ex.getCode());
60 ex = (FileSystemException) ex.getCause();
61 assertEquals("Exception code", "vfs.provider.local/missing-share-name.error", ex.getCode());
62 }
63 }
64
65 @Test
66 public void testWindowsRoots() throws Exception {
67
68 final String[] tests = new String[] { "file:///C:/", "file://C:/", "file:/C:/", "file:C:/" };
69
70 for (final String name : tests) {
71 final DefaultFileSystemManager manager = getManager();
72 Assert.assertNotNull("Unexpected null manager for test " + this, manager);
73 final FileName fn = manager.resolveFile(name).getName();
74
75
76 assertSame(WindowsFileName.class, fn.getClass());
77
78
79 assertEquals("file:///C:/", fn.toString());
80 assertEquals("/", fn.getPath());
81 assertEquals("/", fn.getPathDecoded());
82 assertEquals("file:///C:/", fn.getRootURI());
83 assertEquals("file:///C:/", fn.getFriendlyURI());
84
85 assertEquals("file:///C:/", fn.getRoot().toString());
86
87 assertEquals("", fn.getExtension());
88 assertEquals("", fn.getBaseName());
89 }
90 }
91
92 @Test
93 public void testWindowsWrongRoots() throws Exception {
94 final String[] tests = new String[] { "file:///C:", "file://C:", "file:/C:", "file:C:" };
95
96 for (final String name : tests) {
97 try {
98 final DefaultFileSystemManager manager = getManager();
99 Assert.assertNotNull("Unexpected null manager for test " + this, manager);
100 final FileName fn = manager.resolveFile(name).getName();
101 fail("should not accept root " + name);
102 } catch (final FileSystemException ex) {
103 assertEquals("vfs.provider/invalid-absolute-uri.error", ex.getCode());
104 assertTrue(ex.toString().indexOf(name) >= 0);
105 }
106 }
107 }
108 }