1 19 20 package org.netbeans.lib.cvsclient; 21 22 import java.io.*; 23 import junit.framework.*; 24 25 26 31 public class CVSRootTest extends TestCase { 32 33 34 public CVSRootTest(String name) { 35 super(name); 36 } 37 38 private void compareRoot(CVSRoot root, String method, String user, 39 String password, String host, int port, String repository) { 40 if (!(method == root.getMethod())) { 41 fail("Bad connection method is parsed: '"+root.getMethod()+"', expected was '"+method+"'"); 42 } 43 if (user != null && !user.equals(root.getUserName())) { 44 fail("Bad user name is parsed: '"+root.getUserName()+"', expected was '"+user+"'"); 45 } 46 if (password != null && !password.equals(root.getPassword())) { 47 fail("Bad password is parsed: '"+root.getPassword()+"', expected was '"+password+"'"); 48 } 49 if (host != null && !host.equals(root.getHostName())) { 50 fail("Bad host name is parsed: '"+root.getHostName()+"', expected was '"+host+"'"); 51 } 52 if (port != root.getPort()) { 53 fail("Bad port is parsed: '"+root.getPort()+"', expected was '"+port+"'"); 54 } 55 if (!repository.equals(root.getRepository())) { 56 fail("Bad repository is parsed: '"+root.getRepository()+"', expected was '"+repository+"'"); 57 } 58 } 59 60 69 public void testParseCorrectURLS() throws Exception { 70 CVSRoot root = CVSRoot.parse("/path/to/repository"); 71 compareRoot(root, CVSRoot.METHOD_LOCAL, null, null, null, 0, "/path/to/repository"); 72 root = CVSRoot.parse(":local:/path/to/repository"); 73 compareRoot(root, CVSRoot.METHOD_LOCAL, null, null, null, 0, "/path/to/repository"); 74 root = CVSRoot.parse(":local:user@hostname:/path/to/repository"); 75 compareRoot(root, CVSRoot.METHOD_LOCAL, null, null, null, 0, "user@hostname:/path/to/repository"); 76 root = CVSRoot.parse("hostname:/path/to/repository"); 77 compareRoot(root, "ext", null, null, "hostname", 0, "/path/to/repository"); 78 root = CVSRoot.parse("hostname:/path:/to/repository"); 79 compareRoot(root, "ext", null, null, "hostname", 0, "/path:/to/repository"); 80 root = CVSRoot.parse(":server:hostname:/path/to/repository"); 81 compareRoot(root, CVSRoot.METHOD_SERVER, null, null, "hostname", 0, "/path/to/repository"); 82 root = CVSRoot.parse(":pserver:hostname:/path/to/repository"); 83 compareRoot(root, CVSRoot.METHOD_PSERVER, null, null, "hostname", 0, "/path/to/repository"); 84 root = CVSRoot.parse(":pserver:user@hostname:/path/to/repository"); 85 compareRoot(root, CVSRoot.METHOD_PSERVER, "user", null, "hostname", 0, "/path/to/repository"); 86 root = CVSRoot.parse(":pserver:user:password@hostname:/path/to/repository"); 87 compareRoot(root, CVSRoot.METHOD_PSERVER, "user", "password", "hostname", 0, "/path/to/repository"); 88 root = CVSRoot.parse(":pserver:hostname:2403/path/to/repository"); 89 compareRoot(root, CVSRoot.METHOD_PSERVER, null, null, "hostname", 2403, "/path/to/repository"); 90 root = CVSRoot.parse(":pserver:user:password@hostname:2403/path/to/repository"); 91 compareRoot(root, CVSRoot.METHOD_PSERVER, "user", "password", "hostname", 2403, "/path/to/repository"); 92 93 root = CVSRoot.parse("c:\\CVSROOT"); 95 compareRoot(root, CVSRoot.METHOD_LOCAL, null, null, null, 0, "c:\\CVSROOT"); 96 97 root = CVSRoot.parse("hostname/path/to/repository"); 99 compareRoot(root, "server", null, null, "hostname", 0, "/path/to/repository"); root = CVSRoot.parse(":server:hostname/path/to/repository"); 101 compareRoot(root, CVSRoot.METHOD_SERVER, null, null, "hostname", 0, "/path/to/repository"); 102 root = CVSRoot.parse(":pserver:hostname/path/to/repository"); 103 compareRoot(root, CVSRoot.METHOD_PSERVER, null, null, "hostname", 0, "/path/to/repository"); 104 root = CVSRoot.parse(":pserver:user@hostname/path/to/repository"); 105 compareRoot(root, CVSRoot.METHOD_PSERVER, "user", null, "hostname", 0, "/path/to/repository"); 106 root = CVSRoot.parse(":pserver:user:password@hostname/path/to/repository"); 107 compareRoot(root, CVSRoot.METHOD_PSERVER, "user", "password", "hostname", 0, "/path/to/repository"); 108 109 root = CVSRoot.parse(":pserver;hostname=host;username=user:/path/to/repository"); 111 compareRoot(root, CVSRoot.METHOD_PSERVER, "user", null, "host", 0, "/path/to/repository"); 112 113 root = CVSRoot.parse(":pserver;username=SCR_Roland;hostname=mainsrv:/Software"); 114 compareRoot(root, CVSRoot.METHOD_PSERVER, "SCR_Roland", null, "mainsrv", 0, "/Software"); 115 116 root = CVSRoot.parse(":ssh;ver=2:username@cvs.sf.net:/cvsroot/xoops"); 118 compareRoot(root, CVSRoot.METHOD_EXT, "username", null, "cvs.sf.net", 0, "/cvsroot/xoops"); 119 120 root = CVSRoot.parse(":pserver:mike@javadev.zappmobile.ro:2401:/home/cvsroot"); compareRoot(root, CVSRoot.METHOD_PSERVER, "mike", null, "javadev.zappmobile.ro", 2401, "/home/cvsroot"); 122 123 } 124 125 130 public void testParseBadURLS() { 131 CVSRoot root; 132 boolean isBad = false; 133 try { 134 root = CVSRoot.parse(":pserver:/path/to/repository"); 135 } catch (IllegalArgumentException iaex) { 136 isBad = true; 137 } 138 if (!isBad) fail("CVSROOT ':pserver:/path/to/repository' is not considered as bad."); 139 isBad = false; 140 try { 141 root = CVSRoot.parse(":somethig that does not end with a colon"); 142 } catch (IllegalArgumentException iaex) { 143 isBad = true; 144 } 145 if (!isBad) fail("CVSROOT ':somethig that does not end with a colon' is not considered as bad."); 146 isBad = false; 147 try { 148 root = CVSRoot.parse("somethig that does not have neither slash, nor a colon"); 149 } catch (IllegalArgumentException iaex) { 150 isBad = true; 151 } 152 if (!isBad) fail("CVSROOT 'somethig that does not have neither slash, nor a colon' is not considered as bad."); 153 } 154 155 156 } 157 | Popular Tags |