1   package org.apache.maven.scm.provider.integrity.repository;
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 org.apache.maven.scm.ScmTestCase;
23  import org.apache.maven.scm.manager.ScmManager;
24  import org.apache.maven.scm.repository.ScmRepository;
25  
26  /**
27   * IntegrityScmProviderRepositoryTest
28   *
29   * @author <a href="mailto:cletus@mks.com">Cletus D'Souza</a>
30   * @version $Id: IntegrityScmProviderRepositoryTest.java 1.1 2011/08/29 00:30:11EDT Cletus D'Souza (dsouza) Exp  $
31   */
32  public class IntegrityScmProviderRepositoryTest
33      extends ScmTestCase
34  {
35      private ScmManager scmManager;
36  
37      /**
38       * Initialize our ScmManager object
39       */
40      public void setUp()
41          throws Exception
42      {
43          super.setUp();
44          scmManager = getScmManager();
45      }
46  
47      /**
48       * Executes a test with the bare minimum required for the Integrity Scm URL String
49       *
50       * @throws Exception
51       */
52      public void testMinimumUrlString()
53          throws Exception
54      {
55          // Minimum url string
56          testValidUrl( "scm:integrity|#/repo/project", "#/repo/project", "", 0, "", "" );
57      }
58  
59      /**
60       * Executes a test with only the hostname specified
61       *
62       * @throws Exception
63       */
64      public void testWithHostname()
65          throws Exception
66      {
67          // Test with host
68          testValidUrl( "scm:integrity|@localhost|#/repo/project", "#/repo/project", "localhost", 0, "", "" );
69      }
70  
71      /**
72       * Executes a test with only the hostname and port specified
73       *
74       * @throws Exception
75       */
76      public void testWithHostAndPort()
77          throws Exception
78      {
79          // Test host and port
80          testValidUrl( "scm:integrity|@localhost:7001|#/repo/project", "#/repo/project", "localhost", 7001, "", "" );
81      }
82  
83      /**
84       * Executes a test with only the username specified
85       *
86       * @throws Exception
87       */
88      public void testWithUser()
89          throws Exception
90      {
91          // Test with user
92          testValidUrl( "scm:integrity|dsouza@|#/repo/project", "#/repo/project", "", 0, "dsouza", "" );
93      }
94  
95      /**
96       * Executes a test with the username and password specified
97       *
98       * @throws Exception
99       */
100     public void testWithUserAndPassword()
101         throws Exception
102     {
103         // Test with user and password
104         testValidUrl( "scm:integrity|dsouza/password@|#/repo/project", "#/repo/project", "", 0, "dsouza", "password" );
105     }
106 
107     /**
108      * Executes a test with the username and hostname specified
109      *
110      * @throws Exception
111      */
112     public void testWithUserAndHost()
113         throws Exception
114     {
115         // Test with user and host
116         testValidUrl( "scm:integrity|dsouza@localhost|#/repo/project", "#/repo/project", "localhost", 0, "dsouza", "" );
117     }
118 
119     /**
120      * Executes a test with the username and hostname plus port specified
121      *
122      * @throws Exception
123      */
124     public void testWithUserAndHostPort()
125         throws Exception
126     {
127         // Test with user and host:port
128         testValidUrl( "scm:integrity|dsouza@localhost:7001|#/repo/project", "#/repo/project", "localhost", 7001,
129                       "dsouza", "" );
130     }
131 
132     /**
133      * Executes a test with the username and password plus hostname specified
134      *
135      * @throws Exception
136      */
137     public void testWithUserPasswordAndHost()
138         throws Exception
139     {
140         // Test with user/password and host
141         testValidUrl( "scm:integrity|dsouza/password@localhost|#/repo/project", "#/repo/project", "localhost", 0,
142                       "dsouza", "password" );
143     }
144 
145     /**
146      * Executes a test with all the components of the SCM URL string specified
147      *
148      * @throws Exception
149      */
150     public void testWithWholeURL()
151         throws Exception
152     {
153         // Test with the complete url
154         testValidUrl( "scm:integrity|dsouza/password@localhost:7001|#/repo/project", "#/repo/project", "localhost",
155                       7001, "dsouza", "password" );
156     }
157 
158     /**
159      * Tests the various components of the Integrity SCM URL
160      *
161      * @param scmUrl             Integrity SCM URL
162      * @param expectedConfigPath Expected Configuration Path
163      * @param expectedHost       Expected Hostname
164      * @param expectedPort       Expected Port
165      * @param expectedUser       Expected Username
166      * @param expectedPassword   Expected Password
167      * @throws Exception
168      */
169     private void testValidUrl( String scmUrl, String expectedConfigPath, String expectedHost, int expectedPort,
170                                String expectedUser, String expectedPassword )
171         throws Exception
172     {
173         ScmRepository repo = scmManager.makeScmRepository( scmUrl );
174         assertNotNull( "ScmManager.makeScmRepository() returned null", repo );
175         assertNotNull( "The provider repository was null.", repo.getProviderRepository() );
176         assertTrue( "The SCM Repository isn't a " + IntegrityScmProviderRepository.class.getName() + ".",
177                     repo.getProviderRepository() instanceof IntegrityScmProviderRepository );
178         IntegrityScmProviderRepository iRepo = (IntegrityScmProviderRepository) repo.getProviderRepository();
179         assertEquals( "Configration Path is incorrect", expectedConfigPath, iRepo.getConfigruationPath() );
180         assertEquals( "Hostname is incorrect", expectedHost, iRepo.getHost() );
181         assertEquals( "Port is incorrect", expectedPort, iRepo.getPort() );
182         assertEquals( "Username is incorrect", expectedUser, iRepo.getUser() );
183         assertEquals( "Password is incorrect", expectedPassword, iRepo.getPassword() );
184     }
185 }