KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > lib > cvsclient > CVSRootTest


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.lib.cvsclient;
21
22 import java.io.*;
23 import junit.framework.*;
24
25
26 /**
27  * Test of CVSRoot class.
28  *
29  * @author Martin Entlicher
30  */

31 public class CVSRootTest extends TestCase {
32
33     /** Creates a new instance of CVSRootTest */
34     public CVSRootTest(String JavaDoc name) {
35         super(name);
36     }
37
38     private void compareRoot(CVSRoot root, String JavaDoc method, String JavaDoc user,
39                              String JavaDoc password, String JavaDoc host, int port, String JavaDoc 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     /**
61      * Test of CVSRoot.parse() method.
62      * It should parse the CVSROOT String of the form
63      * [:method:][[user][:password]@][hostname:[port]]/path/to/repository
64      *
65      * For remote repositories the colon between hostname and path to repository
66      * is optional when port is not specified:
67      * [:method:][[user][:password]@]hostname[:[port]]/path/to/repository
68      */

69     public void testParseCorrectURLS() throws Exception JavaDoc {
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         // #67504
94
root = CVSRoot.parse("c:\\CVSROOT");
95         compareRoot(root, CVSRoot.METHOD_LOCAL, null, null, null, 0, "c:\\CVSROOT");
96         
97         // No last colon:
98
root = CVSRoot.parse("hostname/path/to/repository");
99         compareRoot(root, "server", null, null, "hostname", 0, "/path/to/repository"); //??? ext or server
100
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         // WinCVS, CVS 1.12 has method options
110
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         // CVSNT
117
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"); // #71032
121
compareRoot(root, CVSRoot.METHOD_PSERVER, "mike", null, "javadev.zappmobile.ro", 2401, "/home/cvsroot");
122         
123     }
124     
125     /**
126      * Test of CVSRoot.parse() method.
127      * It should not parse the CVSROOT String if not of the form
128      * [:method:][[user][:password]@][hostname:[port]]/path/to/repository
129      */

130     public void testParseBadURLS() {
131         CVSRoot root;
132         boolean isBad = false;
133         try {
134             root = CVSRoot.parse(":pserver:/path/to/repository");
135         } catch (IllegalArgumentException JavaDoc 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 JavaDoc 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 JavaDoc 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