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