1   package org.apache.maven.util;
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 junit.framework.TestCase;
22  
23  public class RepositoryTest
24      extends TestCase
25  {
26      public void testGetScmConnectionSeparatorColon()
27      {
28          String con = "scm:cvs:pserver:anoncvs@cvs.apache.org:/home/cvspublic:module";
29          String separator = RepositoryUtils.getSCMConnectionSeparator( con );
30          assertEquals( "Wrong SCM connection separator", ":", separator );
31      }
32  
33      public void testGetScmConnectionSeparatorVerticalBar()
34      {
35          String con = "scm:cvs|pserver|anoncvs@cvs.apache.org|/home/cvspublic|module";
36          String separator = RepositoryUtils.getSCMConnectionSeparator( con );
37          assertEquals( "Wrong SCM connection separator", "|", separator );
38      }
39  
40      public void testSplitScmConnectionCvsPserver()
41      {
42          String con = "scm:cvs:pserver:anoncvs@cvs.apache.org:/home/cvspublic:module";
43          String[] tokens = RepositoryUtils.splitSCMConnection(con);
44          assertEquals("Wrong number of tokens split", 6, tokens.length);
45      }
46  
47      public void testSplitScmConnectionEmptyPassword()
48      {
49          String con = "scm:cvs:pserver:anoncvs:@cvs.apache.org:/cvs/root:module";
50          String[] tokens = RepositoryUtils.splitSCMConnection(con);
51          assertEquals("Empty password should be ignored", "anoncvs@cvs.apache.org", tokens[3]);
52      }
53  
54      public void testSplitScmConnectionCvsLocal5Tokens()
55      {
56          String con = "scm:cvs:local:/cvs/root:module";
57          String[] tokens = RepositoryUtils.splitSCMConnection(con);
58          assertEquals("Wrong number of tokens split", 6, tokens.length);
59      }
60  
61      public void testSplitScmConnectionCvsLocal6Tokens3rdEmpty()
62      {
63          String con = "scm:cvs:local::/cvs/root:module";
64          String[] tokens = RepositoryUtils.splitSCMConnection(con);
65          assertEquals("Wrong number of tokens split", 6, tokens.length);
66      }
67  
68      public void testSplitScmConnectionCvsLocal6Tokens3rdLocal()
69      {
70          String con = "scm:cvs:local:local:/cvs/root:module";
71          String[] tokens = RepositoryUtils.splitSCMConnection(con);
72          assertEquals("Wrong number of tokens split", 6, tokens.length);
73      }
74  
75      public void testSplitScmConnectionCvsLocal4Tokens()
76      {
77          String con = "scm:cvs:local:/cvs/root";
78          try
79          {
80              RepositoryUtils.splitSCMConnection(con);
81              fail("Should throw an exception splitting " + con);
82          }
83          catch ( IllegalArgumentException expected )
84          {
85              assertTrue( true );
86          }
87      }
88  
89      public void testSplitScmConnectionCvsPserver5Tokens()
90      {
91          String con = "scm:cvs:pserver:user@host:/cvs/root";
92          try
93          {
94              RepositoryUtils.splitSCMConnection(con);
95              fail("Should throw an exception splitting " + con);
96          }
97          catch ( IllegalArgumentException expected )
98          {
99              assertTrue( true );
100         }
101     }
102 
103     public void testSplitScmConnectionCvsLocal6TokensNonEmpty3rd()
104     {
105         String con = "scm:cvs:local:foo:/cvs/root:module";
106         try
107         {
108             RepositoryUtils.splitSCMConnection(con);
109             fail("Should throw an exception splitting " + con);
110         }
111         catch ( IllegalArgumentException expected )
112         {
113             assertTrue( true );
114         }
115     }
116 
117     public void testSplitScmConnectionSvn()
118     {
119         String con = "scm:svn|http://svn.apache.org/repos";
120         String[] tokens = RepositoryUtils.splitSCMConnection(con);
121         assertEquals("Wrong number of tokens split", 3, tokens.length);
122     }
123 }