1   package org.apache.maven.cvslib;
2   
3   /* ====================================================================
4    *   Licensed to the Apache Software Foundation (ASF) under one or more
5    *   contributor license agreements.  See the NOTICE file distributed with
6    *   this work for additional information regarding copyright ownership.
7    *   The ASF licenses this file to You under the Apache License, Version 2.0
8    *   (the "License"); you may not use this file except in compliance with
9    *   the License.  You may obtain a copy of the License at
10   *
11   *       http://www.apache.org/licenses/LICENSE-2.0
12   *
13   *   Unless required by applicable law or agreed to in writing, software
14   *   distributed under the License is distributed on an "AS IS" BASIS,
15   *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   *   See the License for the specific language governing permissions and
17   *   limitations under the License.
18   * ====================================================================
19   */
20  
21  import java.io.BufferedReader;
22  import java.io.StringReader;
23  
24  import junit.framework.TestCase;
25  
26  
27  /**
28   * Test cases for {@link CvsConnection}
29   * @author 
30   * @version $Id: CvsConnectionTest.java 532339 2007-04-25 12:28:56Z ltheussl $
31   */
32  public class CvsConnectionTest extends TestCase
33  {
34  
35      /** test data */
36      private String testData = ":pserver:user@server:/home/cvs";
37      private String[] testTrueData = {
38      		":pserver:user@server:/home/cvs",
39  			":pserver:user@server:2401/home/cvs"
40      };
41      private String[] testFalseData = {
42      		":ext:user@server:/home/cvs",
43  			":pserver:admin@server:/home/cvs",
44  			":pserver:user@host:/home/cvs",
45  			":pserver:user@server:/home/cvsroot",
46      		":ext:user@server:2401/home/cvs",
47  			":pserver:admin@server:2401/home/cvs",
48  			":pserver:user@host:2401/home/cvs",
49  			":pserver:user@server:2401/home/cvsroot"			
50      };
51  
52      /**
53       * Create a test with the given name
54       * @param testName the name of the test
55       */
56      public CvsConnectionTest(String testName)
57      {
58          super(testName);
59      }
60  
61      /**
62       * Test of compareCvsRoot method
63       * @throws Exception when there is an unexpected problem
64       */
65      public void testCompareTrue() throws Exception
66      {
67      	for (int i=0; i < testTrueData.length; i++) {
68      		assertTrue(CvsConnection.compareCvsRoot(testData, testTrueData[i]));
69      	}
70  
71      }
72  
73      /**
74       * Test of compareCvsRoot method
75       * @throws Exception when there is an unexpected problem
76       */
77      public void testCompareFalse() throws Exception
78      {
79      	for (int i=0; i < testFalseData.length; i++) {
80      		assertFalse(CvsConnection.compareCvsRoot(testData, testFalseData[i]));
81      	}
82  
83      }
84  
85      /**
86       * Test of reading in .cvspass file processes different types of lines properly
87       * @throws Exception when there is an unexpected problem
88       */
89      public void testProcessCvspass() throws Exception 
90  	{
91          String[] expectedResult = {
92          		"A ",
93  			null,
94  			"Axxx ",
95  			"Axxx xxx ",
96      			"A ",
97  			null,
98  			"Axxx ",
99  			"Axxx xxx "			
100         };
101         String[] cvspassData = {
102         		":pserver:user@server:/home/cvs A ",
103 				":ext:user@server:/home/cvs A ",
104 				":pserver:user@server:/home/cvs Axxx ",
105 				":pserver:user@server:/home/cvs Axxx xxx ",
106         		"/1 :pserver:user@server:2401/home/cvs A ",
107 				"/1 :ext:user@server:2401/home/cvs A ",
108 				"/1 :pserver:user@server:2401/home/cvs Axxx ",
109 				"/1 :pserver:user@server:2401/home/cvs Axxx xxx ",				
110         };
111     		
112     		for (int i = 4;i<expectedResult.length;i++){
113     			BufferedReader reader = new BufferedReader(new StringReader(cvspassData[i]));
114 
115     			String password = CvsConnection.processCvspass(testData,reader);
116     			assertEquals(expectedResult[i],password);
117     		}
118 	}
119 
120 
121 }