1 16 package org.apache.commons.vfs.provider.smb.test; 17 18 import org.apache.commons.AbstractVfsTestCase; 19 import org.apache.commons.vfs.FileSystemException; 20 import org.apache.commons.vfs.provider.smb.SmbFileName; 21 import org.apache.commons.vfs.provider.smb.SmbFileNameParser; 22 23 28 public class FileNameTestCase 29 extends AbstractVfsTestCase 30 { 31 34 public void testParseUri() throws Exception 35 { 36 SmbFileName name = (SmbFileName) SmbFileNameParser.getInstance().parseUri(null, null, "smb://hostname/share/file"); 38 assertEquals("smb", name.getScheme()); 39 assertNull(name.getUserName()); 40 assertNull(name.getPassword()); 41 assertEquals("hostname", name.getHostName()); 42 assertEquals(139, name.getPort()); 43 assertEquals(name.getDefaultPort(), name.getPort()); 44 assertEquals("share", name.getShare()); 45 assertEquals("/file", name.getPath()); 46 assertEquals("smb://hostname/share/", name.getRootURI()); 47 assertEquals("smb://hostname/share/file", name.getURI()); 48 49 name = (SmbFileName) SmbFileNameParser.getInstance().parseUri(null, null, "smb://hostname:9090/share/file"); 51 assertEquals("smb", name.getScheme()); 52 assertNull(name.getUserName()); 53 assertNull(name.getPassword()); 54 assertEquals("hostname", name.getHostName()); 55 assertEquals(9090, name.getPort()); 56 assertEquals("share", name.getShare()); 57 assertEquals("/file", name.getPath()); 58 assertEquals("smb://hostname:9090/share/", name.getRootURI()); 59 assertEquals("smb://hostname:9090/share/file", name.getURI()); 60 61 name = (SmbFileName) SmbFileNameParser.getInstance().parseUri(null, null, "smb://hostname/share"); 63 assertEquals("smb", name.getScheme()); 64 assertNull(name.getUserName()); 65 assertNull(name.getPassword()); 66 assertEquals("hostname", name.getHostName()); 67 assertEquals(139, name.getPort()); 68 assertEquals("share", name.getShare()); 69 assertEquals("/", name.getPath()); 70 assertEquals("smb://hostname/share/", name.getRootURI()); 71 assertEquals("smb://hostname/share/", name.getURI()); 72 73 name = (SmbFileName) SmbFileNameParser.getInstance().parseUri(null, null, "smb://user@hostname/share/file"); 75 assertEquals("smb", name.getScheme()); 76 assertEquals("user", name.getUserName()); 77 assertNull(name.getPassword()); 78 assertEquals("hostname", name.getHostName()); 79 assertEquals(139, name.getPort()); 80 assertEquals("share", name.getShare()); 81 assertEquals("/file", name.getPath()); 82 assertEquals("smb://user@hostname/share/", name.getRootURI()); 83 assertEquals("smb://user@hostname/share/file", name.getURI()); 84 85 name = (SmbFileName) SmbFileNameParser.getInstance().parseUri(null, null, "smb://user@hostname/share/file.txt"); 87 assertEquals("smb", name.getScheme()); 88 assertEquals("user", name.getUserName()); 89 assertNull(name.getPassword()); 90 assertEquals("hostname", name.getHostName()); 91 assertEquals(139, name.getPort()); 92 assertEquals("share", name.getShare()); 93 assertEquals("/file.txt", name.getPath()); 94 assertEquals("file.txt", name.getBaseName()); 95 assertEquals("txt", name.getExtension()); 96 assertEquals("smb://user@hostname/share/", name.getRootURI()); 97 assertEquals("smb://user@hostname/share/file.txt", name.getURI()); 98 99 name = (SmbFileName) SmbFileNameParser.getInstance().parseUri(null, null, "smb://user@hostname/share/.bashrc"); 101 assertEquals("smb", name.getScheme()); 102 assertEquals("user", name.getUserName()); 103 assertNull(name.getPassword()); 104 assertEquals("hostname", name.getHostName()); 105 assertEquals(139, name.getPort()); 106 assertEquals("share", name.getShare()); 107 assertEquals("/.bashrc", name.getPath()); 108 assertEquals(".bashrc", name.getBaseName()); 109 assertEquals("", name.getExtension()); 110 assertEquals("smb://user@hostname/share/", name.getRootURI()); 111 assertEquals("smb://user@hostname/share/.bashrc", name.getURI()); 112 } 113 114 117 public void testBadlyFormedUri() throws Exception 118 { 119 testBadlyFormedUri("smb:", "vfs.provider/missing-double-slashes.error"); 121 testBadlyFormedUri("smb:/", "vfs.provider/missing-double-slashes.error"); 122 testBadlyFormedUri("smb:a", "vfs.provider/missing-double-slashes.error"); 123 124 testBadlyFormedUri("smb://", "vfs.provider/missing-hostname.error"); 126 testBadlyFormedUri("smb://:21/share", "vfs.provider/missing-hostname.error"); 127 testBadlyFormedUri("smb:///share", "vfs.provider/missing-hostname.error"); 128 129 testBadlyFormedUri("smb://host:", "vfs.provider/missing-port.error"); 131 testBadlyFormedUri("smb://host:/share", "vfs.provider/missing-port.error"); 132 testBadlyFormedUri("smb://host:port/share/file", "vfs.provider/missing-port.error"); 133 134 testBadlyFormedUri("smb://host:90a", "vfs.provider/missing-hostname-path-sep.error"); 136 testBadlyFormedUri("smb://host?a", "vfs.provider/missing-hostname-path-sep.error"); 137 138 testBadlyFormedUri("smb://host", "vfs.provider.smb/missing-share-name.error"); 140 testBadlyFormedUri("smb://host/", "vfs.provider.smb/missing-share-name.error"); 141 testBadlyFormedUri("smb://host:9090/", "vfs.provider.smb/missing-share-name.error"); 142 } 143 144 147 private void testBadlyFormedUri(final String uri, final String errorMsg) 148 { 149 try 150 { 151 SmbFileNameParser.getInstance().parseUri(null, null, uri); 152 fail(); 153 } 154 catch (final FileSystemException e) 155 { 156 assertSameMessage(errorMsg, uri, e); 157 } 158 } 159 } 160 | Popular Tags |