1   package org.apache.maven.xdoc.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  /**
24   * ScmUtil Test class.
25   *
26   * @author <a href="mailto:ltheussl@apache.org">Lukas Theussl</a>
27   */
28  public class ScmUtilTest extends TestCase
29  {
30      private final ScmUtil scmUtil = new ScmUtil();
31      private final String cvs1 =
32          "scm:cvs|pserver|username@localhost|C:/repositories|module_name";
33      private final String cvs2 =
34          "scm:cvs:ext:username@cvs.apache.org:/cvs/root:module";
35      private final String cvs3 =
36          "scm:cvs:pserver:anoncvs:@cvs.apache.org:/cvs/root:module";
37      private final String svn = "scm:svn:http://svn.apache.org/svn/root/module";
38      private final String perforce1 =
39          "scm:perforce:john_doe@somehost:21:path_to_repository";
40      private final String perforce2 = "scm:perforce://depot/modules/myproject";
41      private final String starteam1 =
42          "scm:starteam:john_doe:secret_password@myhost:23456/project/view/folder";
43      private final String starteam2 =
44          "scm:starteam:john_doe@myhost:23456/project/view/folder";
45      private final String clearcase =
46          "scm:clearcase:my_module_view://myserver/clearcase/configspecs/my_module.txt";
47      private final String invalid = "";
48  
49      public void testSCMConnectionSeparator()
50      {
51          assertEquals( scmUtil.getSCMConnectionSeparator( cvs1 ), "|" );
52          assertEquals( scmUtil.getSCMConnectionSeparator( cvs2 ), ":" );
53          assertEquals( scmUtil.getSCMConnectionSeparator( cvs3 ), ":" );
54          assertEquals( scmUtil.getSCMConnectionSeparator( svn ), ":" );
55      }
56  
57      public void testScmType()
58      {
59          assertEquals( scmUtil.getScmType( cvs1 ), "cvs" );
60          assertEquals( scmUtil.getScmType( cvs2 ), "cvs" );
61          assertEquals( scmUtil.getScmType( cvs3 ), "cvs" );
62          assertEquals( scmUtil.getScmType( svn ), "svn" );
63          assertNull( scmUtil.getScmType( invalid ) );
64      }
65  
66      public void testCvsModule()
67      {
68          assertEquals( scmUtil.getCvsModule( cvs1 ), "module_name" );
69          assertEquals( scmUtil.getCvsModule( cvs2 ), "module" );
70          assertEquals( scmUtil.getCvsModule( cvs3 ), "module" );
71          assertNull( scmUtil.getCvsModule( invalid ) );
72      }
73  
74      public void testCvsConnection()
75      {
76          assertEquals( scmUtil.getCvsConnection( cvs1, "" ),
77              "scm:cvs|pserver|username|@localhost|C:/repositories|module_name" );
78          assertEquals( scmUtil.getCvsConnection( cvs1, "john_doe" ),
79              "scm:cvs|pserver|john_doe@localhost|C:/repositories|module_name" );
80          assertEquals( scmUtil.getCvsConnection( cvs2, "" ),
81              "scm:cvs:ext:username:@cvs.apache.org:/cvs/root:module" );
82          assertEquals( scmUtil.getCvsConnection( cvs2, "john_doe" ),
83              "scm:cvs:ext:john_doe@cvs.apache.org:/cvs/root:module" );
84          assertEquals( scmUtil.getCvsConnection( cvs3, "" ),
85              "scm:cvs:pserver:anoncvs:@cvs.apache.org:/cvs/root:module" );
86          assertEquals( scmUtil.getCvsConnection( cvs3, "john_doe" ),
87              "scm:cvs:pserver:john_doe@cvs.apache.org:/cvs/root:module" );
88          assertEquals( scmUtil.getCvsConnection( svn, "" ), "" );
89      }
90  
91      public void testDeveloperAccessPerforce()
92      {
93          assertEquals( scmUtil.developerAccessPerforce( perforce1 ),
94              "p4 -H somehost -p 21 -u username -P password path_to_repository\np4 submit -c \"A comment\"" );
95          assertEquals( scmUtil.developerAccessPerforce( perforce2 ),
96              "p4 -u username -P password //depot/modules/myproject\np4 submit -c \"A comment\"" );
97      }
98  
99  //    TODO: FIXME: why does this fail with a NoClassDefFoundError?
100 /*
101     public void testDeveloperAccessStarteam()
102     {
103         assertEquals( scmUtil.developerAccessStarteam( starteam1 ),
104             "stcmd co -x -nologo -stop -p username:password@myhost:23456/project/view/folder -is\nstcmd ci -x -nologo -stop -p username:password@myhost:23456/project/view/folder -f NCI -is" );
105         assertEquals( scmUtil.developerAccessStarteam( starteam2 ),
106             "stcmd co -x -nologo -stop -p username:@myhost:23456/project/view/folder -is\nstcmd ci -x -nologo -stop -p username:@myhost:23456/project/view/folder -f NCI -is" );
107     }
108 */
109 
110     public void testDeveloperAccessClearCase()
111     {
112         assertEquals( scmUtil.developerAccessClearCase( clearcase ),
113             "cleartool checkout my_module_view" );
114     }
115 
116 }