View Javadoc
1   package org.eclipse.aether.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 static org.junit.Assert.*;
23  
24  import org.eclipse.aether.repository.RemoteRepository;
25  import org.junit.Test;
26  
27  /**
28   */
29  public class RemoteRepositoryTest
30  {
31  
32      @Test
33      public void testGetProtocol()
34      {
35          RemoteRepository.Builder builder = new RemoteRepository.Builder( "id", "type", "" );
36          RemoteRepository repo = builder.build();
37          assertEquals( "", repo.getProtocol() );
38  
39          repo = builder.setUrl( "http://localhost" ).build();
40          assertEquals( "http", repo.getProtocol() );
41  
42          repo = builder.setUrl( "HTTP://localhost" ).build();
43          assertEquals( "HTTP", repo.getProtocol() );
44  
45          repo = builder.setUrl( "dav+http://www.sonatype.org/" ).build();
46          assertEquals( "dav+http", repo.getProtocol() );
47  
48          repo = builder.setUrl( "dav:http://www.sonatype.org/" ).build();
49          assertEquals( "dav:http", repo.getProtocol() );
50  
51          repo = builder.setUrl( "file:/path" ).build();
52          assertEquals( "file", repo.getProtocol() );
53  
54          repo = builder.setUrl( "file:path" ).build();
55          assertEquals( "file", repo.getProtocol() );
56  
57          repo = builder.setUrl( "file:C:\\dir" ).build();
58          assertEquals( "file", repo.getProtocol() );
59  
60          repo = builder.setUrl( "file:C:/dir" ).build();
61          assertEquals( "file", repo.getProtocol() );
62      }
63  
64      @Test
65      public void testGetHost()
66      {
67          RemoteRepository.Builder builder = new RemoteRepository.Builder( "id", "type", "" );
68          RemoteRepository repo = builder.build();
69          assertEquals( "", repo.getHost() );
70  
71          repo = builder.setUrl( "http://localhost" ).build();
72          assertEquals( "localhost", repo.getHost() );
73  
74          repo = builder.setUrl( "http://localhost/" ).build();
75          assertEquals( "localhost", repo.getHost() );
76  
77          repo = builder.setUrl( "http://localhost:1234/" ).build();
78          assertEquals( "localhost", repo.getHost() );
79  
80          repo = builder.setUrl( "http://127.0.0.1" ).build();
81          assertEquals( "127.0.0.1", repo.getHost() );
82  
83          repo = builder.setUrl( "http://127.0.0.1/" ).build();
84          assertEquals( "127.0.0.1", repo.getHost() );
85  
86          repo = builder.setUrl( "http://user@localhost/path" ).build();
87          assertEquals( "localhost", repo.getHost() );
88  
89          repo = builder.setUrl( "http://user:pass@localhost/path" ).build();
90          assertEquals( "localhost", repo.getHost() );
91  
92          repo = builder.setUrl( "http://user:pass@localhost:1234/path" ).build();
93          assertEquals( "localhost", repo.getHost() );
94      }
95  
96  }