View Javadoc
1   package org.apache.maven.scm.provider.hg.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 junit.framework.TestCase;
23  
24  public class HgScmProviderRepositoryTest
25      extends TestCase
26  {
27  
28  //    public void testInvalidRepo()
29  //    {
30  //        //No protocol - makes it invalid
31  //        String url = "username:password@myhost.com/~/dev/maven";
32  //        HgScmProviderRepository repo = new HgScmProviderRepository( url );
33  //        assertNotNull( repo.validateURI() );
34  //    }
35  
36      public void testFileRepo()
37      {
38          //1. Test *nix like paths
39          String url = "/home/username/dev/maven";
40          HgScmProviderRepository repo = new HgScmProviderRepository( url );
41          assertNull( repo.validateURI() );
42  
43          //2. Test windows like paths (with slash)
44          url = "C:/Documents and Settings/username/dev/maven";
45          repo = new HgScmProviderRepository( url );
46          assertNull( repo.validateURI() );
47  
48          //3. Test windows like paths (with backslash)
49          url = "C:\\Documents and Settings\\username\\dev\\maven";
50          repo = new HgScmProviderRepository( url );
51          assertNull( repo.validateURI() );
52  
53  //        //4. Test invalid file url
54  //        url = "file:/C:\\Documents and Settings\\username\\dev\\maven";
55  //        repo = new HgScmProviderRepository( url );
56  //        assertNotNull( repo.validateURI() );
57      }
58  
59      public void testSSHRepo()
60      {
61          //todo: check assert
62          //1. Test with relativ path
63          String url = "ssh://username:password@myhost.com/~/dev/maven";
64          HgScmProviderRepository repo = new HgScmProviderRepository( url );
65          assertEquals( url, repo.getURI() );
66          assertNull( repo.validateURI() );
67  
68          //2. Test with absolute path
69          url = "ssh://username:password@myhost.com/home/username/dev/maven";
70          repo = new HgScmProviderRepository( url );
71          assertEquals( url, repo.getURI() );
72          assertNull( repo.validateURI() );
73  
74          //3. Test with passwordless (Public-key auth)
75          String incompleteUrl = "ssh://username@myhost.com/home/username/dev/maven";
76          repo = new HgScmProviderRepository( incompleteUrl );
77          assertEquals( incompleteUrl, repo.getURI() );
78          assertNull( repo.validateURI() );
79      }
80  
81      public void testHTTPRepo()
82      {
83          //todo: check assert
84          //1. Test with relativ path
85          String url = "http://www.myhost.com/~username/dev/maven";
86          HgScmProviderRepository repo = new HgScmProviderRepository( url );
87          assertEquals( url, repo.getURI() );
88          assertEquals( null, repo.validateURI() );
89  
90          //2. Test with absolute path
91          url = "http://www.myhost.com/dev/maven";
92          repo = new HgScmProviderRepository( url );
93          assertEquals( url, repo.getURI() );
94          assertNull( repo.validateURI() );
95  
96          //3. Test with authentication information
97          repo.setPassword( "Password" );
98          repo.setUser( "User" );
99          repo.setPassphrase( "Passphrase" );
100         assertEquals( "http://User:Password@www.myhost.com/dev/maven", repo.getURI() );
101         assertNull( repo.validateURI() );
102         repo.setPort( 81 );
103         assertEquals( "http://User:Password@www.myhost.com:81/dev/maven", repo.getURI() );
104         assertNull( repo.validateURI() );
105         assertTrue( true );
106     }
107 
108     /**
109      * Test SCM-391
110      *
111      * @throws Exception
112      */
113     public void testParseHostAndPort()
114         throws Exception
115     {
116         String url = "http://localhost:8000/";
117         HgScmProviderRepository repo = new HgScmProviderRepository( url );
118         assertEquals( repo.getURI(), url );
119 
120         url = "http://localhost/";
121         repo = new HgScmProviderRepository( url );
122         assertEquals( repo.getURI(), url );
123 
124         url = "http://www.myhost.com:81/dev/maven";
125         repo = new HgScmProviderRepository( url );
126         assertEquals( repo.getURI(), url );
127     }
128 
129     /**
130      * Test SCM-431
131      *
132      * @throws Exception
133      */
134     public void testParseBasicAuth()
135         throws Exception
136     {
137         String url = "http://a:b@localhost:8000/";
138         HgScmProviderRepository repo = new HgScmProviderRepository( url );
139         assertEquals( url, repo.getURI() );
140 
141         url = "http://aa@localhost/";
142         repo = new HgScmProviderRepository( url );
143         assertEquals( url, repo.getURI() );
144 
145         url = "http://SCM:431@www.myhost.com:81/dev/maven";
146         repo = new HgScmProviderRepository( url );
147         assertEquals( url, repo.getURI() );
148     }
149 }