View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.scm.provider.hg.repository;
20  
21  import org.junit.Test;
22  
23  import static org.junit.Assert.assertEquals;
24  import static org.junit.Assert.assertNull;
25  import static org.junit.Assert.assertTrue;
26  
27  public class HgScmProviderRepositoryTest {
28  
29      //    public void testInvalidRepo()
30      //    {
31      //        //No protocol - makes it invalid
32      //        String url = "username:password@myhost.com/~/dev/maven";
33      //        HgScmProviderRepository repo = new HgScmProviderRepository( url );
34      //        assertNotNull( repo.validateURI() );
35      //    }
36  
37      @Test
38      public void testFileRepo() {
39          // 1. Test *nix like paths
40          String url = "/home/username/dev/maven";
41          HgScmProviderRepository repo = new HgScmProviderRepository(url);
42          assertNull(repo.validateURI());
43  
44          // 2. Test windows like paths (with slash)
45          url = "C:/Documents and Settings/username/dev/maven";
46          repo = new HgScmProviderRepository(url);
47          assertNull(repo.validateURI());
48  
49          // 3. Test windows like paths (with backslash)
50          url = "C:\\Documents and Settings\\username\\dev\\maven";
51          repo = new HgScmProviderRepository(url);
52          assertNull(repo.validateURI());
53  
54          //        //4. Test invalid file url
55          //        url = "file:/C:\\Documents and Settings\\username\\dev\\maven";
56          //        repo = new HgScmProviderRepository( url );
57          //        assertNotNull( repo.validateURI() );
58      }
59  
60      @Test
61      public void testSSHRepo() {
62          // todo: check assert
63          // 1. Test with relativ path
64          String url = "ssh://username:password@myhost.com/~/dev/maven";
65          HgScmProviderRepository repo = new HgScmProviderRepository(url);
66          assertEquals(url, repo.getURI());
67          assertNull(repo.validateURI());
68  
69          // 2. Test with absolute path
70          url = "ssh://username:password@myhost.com/home/username/dev/maven";
71          repo = new HgScmProviderRepository(url);
72          assertEquals(url, repo.getURI());
73          assertNull(repo.validateURI());
74  
75          // 3. Test with passwordless (Public-key auth)
76          String incompleteUrl = "ssh://username@myhost.com/home/username/dev/maven";
77          repo = new HgScmProviderRepository(incompleteUrl);
78          assertEquals(incompleteUrl, repo.getURI());
79          assertNull(repo.validateURI());
80      }
81  
82      @Test
83      public void testHTTPRepo() {
84          // todo: check assert
85          // 1. Test with relativ path
86          String url = "http://www.myhost.com/~username/dev/maven";
87          HgScmProviderRepository repo = new HgScmProviderRepository(url);
88          assertEquals(url, repo.getURI());
89          assertNull(repo.validateURI());
90  
91          // 2. Test with absolute path
92          url = "http://www.myhost.com/dev/maven";
93          repo = new HgScmProviderRepository(url);
94          assertEquals(url, repo.getURI());
95          assertNull(repo.validateURI());
96  
97          // 3. Test with authentication information
98          repo.setPassword("Password");
99          repo.setUser("User");
100         repo.setPassphrase("Passphrase");
101         assertEquals("http://User:Password@www.myhost.com/dev/maven", repo.getURI());
102         assertNull(repo.validateURI());
103         repo.setPort(81);
104         assertEquals("http://User:Password@www.myhost.com:81/dev/maven", repo.getURI());
105         assertNull(repo.validateURI());
106         assertTrue(true);
107     }
108 
109     @Test
110     public void testHTTPRepoWithHgInUrl() {
111         String url = "http://hg/hg/maven";
112         HgScmProviderRepository repo = new HgScmProviderRepository(url);
113         assertEquals(url, repo.getURI());
114         assertNull(repo.validateURI());
115     }
116 
117     /**
118      * Test SCM-391
119      *
120      * @throws Exception
121      */
122     @Test
123     public void testParseHostAndPort() throws Exception {
124         String url = "http://localhost:8000/";
125         HgScmProviderRepository repo = new HgScmProviderRepository(url);
126         assertEquals(repo.getURI(), url);
127 
128         url = "http://localhost/";
129         repo = new HgScmProviderRepository(url);
130         assertEquals(repo.getURI(), url);
131 
132         url = "http://www.myhost.com:81/dev/maven";
133         repo = new HgScmProviderRepository(url);
134         assertEquals(repo.getURI(), url);
135     }
136 
137     /**
138      * Test SCM-431
139      *
140      * @throws Exception
141      */
142     @Test
143     public void testParseBasicAuth() throws Exception {
144         String url = "http://a:b@localhost:8000/";
145         HgScmProviderRepository repo = new HgScmProviderRepository(url);
146         assertEquals(url, repo.getURI());
147 
148         url = "http://aa@localhost/";
149         repo = new HgScmProviderRepository(url);
150         assertEquals(url, repo.getURI());
151 
152         url = "http://SCM:431@www.myhost.com:81/dev/maven";
153         repo = new HgScmProviderRepository(url);
154         assertEquals(url, repo.getURI());
155     }
156 }