* Tests parsing a URI into its parts.
*/
public void testParseUri() throws Exception
{
// Simple name
SmbFileName name = (SmbFileName) SmbFileNameParser.getInstance().parseUri(null, null, "smb://hostname/share/file");
assertEquals("smb", name.getScheme());
assertNull(name.getUserName());
assertNull(name.getPassword());
assertEquals("hostname", name.getHostName());
assertEquals(139, name.getPort());
assertEquals(name.getDefaultPort(), name.getPort());
assertEquals("share", name.getShare());
assertEquals("/file", name.getPath());
assertEquals("smb://hostname/share/", name.getRootURI());
assertEquals("smb://hostname/share/file", name.getURI());
// Name with port
name = (SmbFileName) SmbFileNameParser.getInstance().parseUri(null, null, "smb://hostname:9090/share/file");
assertEquals("smb", name.getScheme());
assertNull(name.getUserName());
assertNull(name.getPassword());
assertEquals("hostname", name.getHostName());
assertEquals(9090, name.getPort());
assertEquals("share", name.getShare());
assertEquals("/file", name.getPath());
assertEquals("smb://hostname:9090/share/", name.getRootURI());
assertEquals("smb://hostname:9090/share/file", name.getURI());
// Name with no path
name = (SmbFileName) SmbFileNameParser.getInstance().parseUri(null, null, "smb://hostname/share");
assertEquals("smb", name.getScheme());
assertNull(name.getUserName());
assertNull(name.getPassword());
assertEquals("hostname", name.getHostName());
assertEquals(139, name.getPort());
assertEquals("share", name.getShare());
assertEquals("/", name.getPath());
assertEquals("smb://hostname/share/", name.getRootURI());
assertEquals("smb://hostname/share/", name.getURI());
// Name with username
name = (SmbFileName) SmbFileNameParser.getInstance().parseUri(null, null, "smb://user@hostname/share/file");
assertEquals("smb", name.getScheme());
assertEquals("user", name.getUserName());
assertNull(name.getPassword());
assertEquals("hostname", name.getHostName());
assertEquals(139, name.getPort());
assertEquals("share", name.getShare());
assertEquals("/file", name.getPath());
assertEquals("smb://user@hostname/share/", name.getRootURI());
assertEquals("smb://user@hostname/share/file", name.getURI());
// Name with extension
name = (SmbFileName) SmbFileNameParser.getInstance().parseUri(null, null, "smb://user@hostname/share/file.txt");
assertEquals("smb", name.getScheme());
assertEquals("user", name.getUserName());
assertNull(name.getPassword());
assertEquals("hostname", name.getHostName());
assertEquals(139, name.getPort());
assertEquals("share", name.getShare());
assertEquals("/file.txt", name.getPath());
assertEquals("file.txt", name.getBaseName());
assertEquals("txt", name.getExtension());
assertEquals("smb://user@hostname/share/", name.getRootURI());
assertEquals("smb://user@hostname/share/file.txt", name.getURI());
// Name look likes extension, but isnt
name = (SmbFileName) SmbFileNameParser.getInstance().parseUri(null, null, "smb://user@hostname/share/.bashrc");
assertEquals("smb", name.getScheme());
assertEquals("user", name.getUserName());
assertNull(name.getPassword());
assertEquals("hostname", name.getHostName());
assertEquals(139, name.getPort());
assertEquals("share", name.getShare());
assertEquals("/.bashrc", name.getPath());
assertEquals(".bashrc", name.getBaseName());
assertEquals("", name.getExtension());
assertEquals("smb://user@hostname/share/", name.getRootURI());
assertEquals("smb://user@hostname/share/.bashrc", name.getURI());
}