View Javadoc

1   package org.apache.continuum.scm;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import junit.framework.TestCase;
23  import org.apache.commons.lang.StringUtils;
24  
25  /**
26   * @author <a href="mailto:oching@apache.org">Maria Odea Ching</a>
27   */
28  public class ContinuumScmUtilsTest
29      extends TestCase
30  {
31      public void testGitProviderWithSSHProtocolUsernameInUrl()
32          throws Exception
33      {
34          ContinuumScmConfiguration scmConfiguration = new ContinuumScmConfiguration();
35  
36          scmConfiguration = ContinuumScmUtils.setSCMCredentialsforSSH( scmConfiguration,
37                                                                        "scm:git:ssh://sshUser@gitrepo.com/myproject.git",
38                                                                        "dummyuser", "dummypassword" );
39  
40          assertEquals( "sshUser", scmConfiguration.getUsername() );
41          assertTrue( StringUtils.isBlank( scmConfiguration.getPassword() ) );
42      }
43  
44      public void testGitProviderWithSSHProtocolUsernameAndPasswordInUrl()
45          throws Exception
46      {
47          ContinuumScmConfiguration scmConfiguration = new ContinuumScmConfiguration();
48  
49          scmConfiguration = ContinuumScmUtils.setSCMCredentialsforSSH( scmConfiguration,
50                                                                        "scm:git:ssh://sshUser:sshPassword@gitrepo.com/myproject.git",
51                                                                        "dummyuser", "dummypassword" );
52  
53          assertEquals( "sshUser", scmConfiguration.getUsername() );
54          assertEquals( "sshPassword", scmConfiguration.getPassword() );
55      }
56  
57      public void testGitProviderWithSSHProtocolNoCredentialsInUrl()
58          throws Exception
59      {
60          ContinuumScmConfiguration scmConfiguration = new ContinuumScmConfiguration();
61  
62          scmConfiguration = ContinuumScmUtils.setSCMCredentialsforSSH( scmConfiguration,
63                                                                        "scm:git:ssh://gitrepo.com/myproject.git",
64                                                                        "dummyuser", "dummypassword" );
65  
66          assertEquals( "dummyuser", scmConfiguration.getUsername() );
67          assertEquals( "dummypassword", scmConfiguration.getPassword() );
68      }
69  
70      public void testNotGitProvider()
71          throws Exception
72      {
73          ContinuumScmConfiguration scmConfiguration = new ContinuumScmConfiguration();
74  
75          scmConfiguration = ContinuumScmUtils.setSCMCredentialsforSSH( scmConfiguration,
76                                                                        "scm:svn:ssh://svnrepo.com/repos/myproject/trunk",
77                                                                        "dummyuser", "dummypassword" );
78  
79          assertEquals( "dummyuser", scmConfiguration.getUsername() );
80          assertEquals( "dummypassword", scmConfiguration.getPassword() );
81      }
82  
83      public void testNotSSHProtocol()
84          throws Exception
85      {
86          ContinuumScmConfiguration scmConfiguration = new ContinuumScmConfiguration();
87  
88          scmConfiguration = ContinuumScmUtils.setSCMCredentialsforSSH( scmConfiguration,
89                                                                        "scm:git:https://gitrepo.com/myproject.git",
90                                                                        "dummyuser", "dummypassword" );
91  
92          assertEquals( "dummyuser", scmConfiguration.getUsername() );
93          assertEquals( "dummypassword", scmConfiguration.getPassword() );
94      }
95  }