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