View Javadoc
1   package org.apache.maven.scm.provider.cvslib.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.manager.ScmManager;
23  import org.apache.maven.scm.provider.cvslib.AbstractCvsScmTest;
24  import org.apache.maven.scm.repository.ScmRepository;
25  import org.apache.maven.scm.repository.ScmRepositoryException;
26  
27  /**
28   * @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a>
29   * @author <a href="mailto:trygvis@inamo.no">Trygve Laugst&oslash;l</a>
30   *
31   */
32  public class CvsScmProviderRepositoryTest
33      extends AbstractCvsScmTest
34  {
35      private ScmManager scmManager;
36  
37      public void setUp()
38          throws Exception
39      {
40          super.setUp();
41  
42          scmManager = getScmManager();
43      }
44  
45      public void testParseConnectionFromPath()
46          throws Exception
47      {
48          TestCvsScmProvider provider = new TestCvsScmProvider();
49  
50          CvsScmProviderRepository repo = (CvsScmProviderRepository) provider
51              .makeProviderScmRepository( getTestFile( "src/test/resources/checkoutdir" ) );
52  
53          assertEquals( "ext", repo.getTransport() );
54  
55          assertEquals( "evenisse", repo.getUser() );
56  
57          assertEquals( "cvs.surefire.codehaus.org", repo.getHost() );
58  
59          assertEquals( "/home/projects/surefire/scm", repo.getPath() );
60  
61          assertEquals( "surefire", repo.getModule() );
62      }
63  
64      public void testParseRemotePserverConnection()
65          throws Exception
66      {
67          String url = "pserver:anoncvs@cvs.apache.org:/home/cvspublic:maven";
68  
69          CvsScmProviderRepository repo = testUrl( url, url );
70  
71          assertEquals( "pserver", repo.getTransport() );
72  
73          assertEquals( "anoncvs", repo.getUser() );
74  
75          assertEquals( "cvs.apache.org", repo.getHost() );
76  
77          assertEquals( "/home/cvspublic", repo.getPath() );
78  
79          assertEquals( ":pserver:anoncvs@cvs.apache.org:/home/cvspublic", repo.getCvsRoot() );
80  
81          assertEquals( ":pserver:anoncvs@cvs.apache.org:2401/home/cvspublic", repo.getCvsRootForCvsPass() );
82      }
83  
84      public void testParseRemotePserverConnectionWithUsernameDefinedInScmRepository()
85          throws Exception
86      {
87          String url = "pserver:cvs.apache.org:/home/cvspublic:maven";
88  
89          CvsScmProviderRepository repo = testUrl( url, url.replaceFirst( ":cvs", "@cvs" ) );
90  
91          repo.setUser( "myusername" );
92  
93          assertEquals( "pserver", repo.getTransport() );
94  
95          assertEquals( "myusername", repo.getUser() );
96  
97          assertEquals( "cvs.apache.org", repo.getHost() );
98  
99          assertEquals( "/home/cvspublic", repo.getPath() );
100 
101         assertEquals( ":pserver:myusername@cvs.apache.org:/home/cvspublic", repo.getCvsRoot() );
102 
103         assertEquals( ":pserver:myusername@cvs.apache.org:2401/home/cvspublic", repo.getCvsRootForCvsPass() );
104     }
105 
106     public void testParseRemotePserverConnectionWithoutUsername()
107         throws Exception
108     {
109         String url = "pserver:cvs.apache.org:/home/cvspublic:maven";
110 
111         CvsScmProviderRepository repo = testUrl( url, url.replaceFirst( ":cvs", "@cvs" ) );
112 
113         try
114         {
115             repo.getCvsRoot();
116 
117             fail( "username isn't defined." );
118         }
119         catch ( Exception e )
120         {
121         }
122     }
123 
124     public void testParseRemotePserverConnection2()
125         throws Exception
126     {
127         String url = "pserver:anoncvs:@cvs.apache.org:/home/cvspublic:maven";
128 
129         CvsScmProviderRepository repo = testUrl( url, url.replaceFirst( ":@", "@" ) );
130 
131         assertEquals( "pserver", repo.getTransport() );
132 
133         assertEquals( "anoncvs", repo.getUser() );
134 
135         assertEquals( "cvs.apache.org", repo.getHost() );
136 
137         assertEquals( "/home/cvspublic", repo.getPath() );
138 
139         assertEquals( ":pserver:anoncvs@cvs.apache.org:/home/cvspublic", repo.getCvsRoot() );
140 
141         assertEquals( ":pserver:anoncvs@cvs.apache.org:2401/home/cvspublic", repo.getCvsRootForCvsPass() );
142     }
143 
144     public void testParseRemotePserverConnectionWithPort()
145         throws Exception
146     {
147         String url = "pserver:anoncvs:@cvs.apache.org:2401:/home/cvspublic:maven";
148 
149         CvsScmProviderRepository repo = testUrl( url, url.replaceFirst( ":2401", "" ).replaceFirst( ":@", "@" ) );
150 
151         assertEquals( "pserver", repo.getTransport() );
152 
153         assertEquals( "anoncvs", repo.getUser() );
154 
155         assertEquals( "", repo.getPassword() );
156 
157         assertEquals( "cvs.apache.org", repo.getHost() );
158 
159         assertEquals( "/home/cvspublic", repo.getPath() );
160 
161         assertEquals( 2401, repo.getPort() );
162 
163         assertEquals( ":pserver:anoncvs@cvs.apache.org:/home/cvspublic", repo.getCvsRoot() );
164 
165         assertEquals( ":pserver:anoncvs@cvs.apache.org:2401/home/cvspublic", repo.getCvsRootForCvsPass() );
166     }
167 
168     public void testParseRemotePserverConnectionWithPassword()
169         throws Exception
170     {
171         String url = "pserver:anoncvs:mypassword@cvs.apache.org:/home/cvspublic:maven";
172 
173         CvsScmProviderRepository repo = testUrl( url, url.replaceFirst( ":mypassword", "" ) );
174 
175         assertEquals( "pserver", repo.getTransport() );
176 
177         assertEquals( "anoncvs", repo.getUser() );
178 
179         assertEquals( "mypassword", repo.getPassword() );
180 
181         assertEquals( "cvs.apache.org", repo.getHost() );
182 
183         assertEquals( "/home/cvspublic", repo.getPath() );
184 
185         assertEquals( ":pserver:anoncvs@cvs.apache.org:/home/cvspublic", repo.getCvsRoot() );
186 
187         assertEquals( ":pserver:anoncvs@cvs.apache.org:2401/home/cvspublic", repo.getCvsRootForCvsPass() );
188     }
189 
190     public void testParseRemotePserverConnectionWithPortAndPassword()
191         throws Exception
192     {
193         String url = "pserver:anoncvs:mypassword@cvs.apache.org:2402:/home/cvspublic:maven";
194 
195         CvsScmProviderRepository repo =
196             testUrl( url, url.replaceFirst( ":mypassword", "" ).replaceFirst( ":2402:", ":2402" ) );
197 
198         assertEquals( "pserver", repo.getTransport() );
199 
200         assertEquals( "anoncvs", repo.getUser() );
201 
202         assertEquals( "mypassword", repo.getPassword() );
203 
204         assertEquals( "cvs.apache.org", repo.getHost() );
205 
206         assertEquals( "/home/cvspublic", repo.getPath() );
207 
208         assertEquals( 2402, repo.getPort() );
209 
210         assertEquals( ":pserver:anoncvs@cvs.apache.org:2402/home/cvspublic", repo.getCvsRoot() );
211 
212         assertEquals( ":pserver:anoncvs@cvs.apache.org:2402/home/cvspublic", repo.getCvsRootForCvsPass() );
213     }
214 
215     public void testParseRemotePserverConnectionWithBarsAsDelimiter()
216         throws Exception
217     {
218         String url = "pserver|anoncvs@cvs.apache.org|/home/cvspublic|maven";
219 
220         String urlResult = "pserver:anoncvs@cvs.apache.org:/home/cvspublic:maven";
221 
222         CvsScmProviderRepository repo = testUrl( url, urlResult, '|' );
223 
224         assertEquals( "pserver", repo.getTransport() );
225 
226         assertEquals( "anoncvs", repo.getUser() );
227 
228         assertEquals( "cvs.apache.org", repo.getHost() );
229 
230         assertEquals( "/home/cvspublic", repo.getPath() );
231 
232         assertEquals( ":pserver:anoncvs@cvs.apache.org:/home/cvspublic", repo.getCvsRoot() );
233 
234         assertEquals( ":pserver:anoncvs@cvs.apache.org:2401/home/cvspublic", repo.getCvsRootForCvsPass() );
235     }
236 
237     public void testIllegalRepository()
238         throws Exception
239     {
240         testIllegalUrl( "pserver:cvs.apache.org:/home/cvspublic:maven" );
241     }
242 
243     public void testParseLocalConnection()
244         throws Exception
245     {
246         String url = "local:/home/cvspublic:maven";
247 
248         CvsScmProviderRepository repo = testUrl( url, url );
249 
250         assertEquals( "local", repo.getTransport() );
251 
252         assertNull( repo.getUser() );
253 
254         assertNull( repo.getHost() );
255 
256         assertEquals( "/home/cvspublic", repo.getPath() );
257 
258         assertEquals( ":local:/home/cvspublic", repo.getCvsRoot() );
259     }
260 
261     /**
262      * Test SCM-387
263      *
264      * @throws Exception
265      */
266     public void testGetCvsRootForCvsPass()
267         throws Exception
268     {
269         String url = "scm:cvs|local|c:/cvsroot|test";
270 
271         ScmRepository repository = scmManager.makeScmRepository( url );
272         CvsScmProviderRepository repo = (CvsScmProviderRepository) repository.getProviderRepository();
273         assertEquals( ":local:c:/cvsroot", repo.getCvsRootForCvsPass() );
274     }
275 
276     /**
277      * Test SCM-376
278      *
279      * @throws Exception
280      */
281     public void testSCM376()
282         throws Exception
283     {
284         String url = "scm:cvs:pserver:continuum@gnllx002.ebit.be:2401:/data01/cvsroot_bkh:VCG_BKH/uBaseBkh";
285 
286         ScmRepository repository = scmManager.makeScmRepository( url );
287         
288         assertNotNull( repository );
289     }
290 
291     // ----------------------------------------------------------------------
292     //
293     // ----------------------------------------------------------------------
294 
295     /**
296      * @param expectedUrl url that should be printed in the toString method
297      */
298     private CvsScmProviderRepository testUrl( String url, String expectedUrl, char delimiter, int nbErrorMessages )
299         throws Exception
300     {
301         assertEquals( nbErrorMessages, scmManager.validateScmRepository( "scm:cvs" + delimiter + url ).size() );
302 
303         ScmRepository repository = scmManager.makeScmRepository( "scm:cvs" + delimiter + url );
304 
305         assertNotNull( "ScmManager.makeScmRepository() returned null", repository );
306 
307         assertNotNull( "The provider repository was null.", repository.getProviderRepository() );
308 
309         assertTrue( "The SCM Repository isn't a " + CvsScmProviderRepository.class.getName() + ".", repository
310             .getProviderRepository() instanceof CvsScmProviderRepository );
311 
312         assertEquals( "cvs:" + expectedUrl, repository.toString() );
313 
314         return (CvsScmProviderRepository) repository.getProviderRepository();
315     }
316 
317     private CvsScmProviderRepository testUrl( String url, String urlResult )
318         throws Exception
319     {
320         return testUrl( url, urlResult, ':', 0 );
321     }
322 
323     private CvsScmProviderRepository testUrl( String url, String urlResult, char delimiter )
324         throws Exception
325     {
326         return testUrl( url, urlResult, delimiter, 0 );
327     }
328 
329     private void testIllegalUrl( String url )
330         throws Exception
331     {
332         try
333         {
334             testUrl( "scm:cvs:" + url, null, ':', 1 );
335 
336             fail( "Expected a ScmRepositoryException while testing the url '" + url + "'." );
337         }
338         catch ( ScmRepositoryException e )
339         {
340             // expected
341         }
342     }
343 
344 }