001package org.eclipse.aether.repository;
002
003/*
004 * Licensed to the Apache Software Foundation (ASF) under one
005 * or more contributor license agreements.  See the NOTICE file
006 * distributed with this work for additional information
007 * regarding copyright ownership.  The ASF licenses this file
008 * to you under the Apache License, Version 2.0 (the
009 * "License"); you may not use this file except in compliance
010 * with the License.  You may obtain a copy of the License at
011 * 
012 *  http://www.apache.org/licenses/LICENSE-2.0
013 * 
014 * Unless required by applicable law or agreed to in writing,
015 * software distributed under the License is distributed on an
016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017 * KIND, either express or implied.  See the License for the
018 * specific language governing permissions and limitations
019 * under the License.
020 */
021
022import static org.junit.Assert.*;
023
024import org.eclipse.aether.repository.RemoteRepository;
025import org.junit.Test;
026
027/**
028 */
029public class RemoteRepositoryTest
030{
031
032    @Test
033    public void testGetProtocol()
034    {
035        RemoteRepository.Builder builder = new RemoteRepository.Builder( "id", "type", "" );
036        RemoteRepository repo = builder.build();
037        assertEquals( "", repo.getProtocol() );
038
039        repo = builder.setUrl( "http://localhost" ).build();
040        assertEquals( "http", repo.getProtocol() );
041
042        repo = builder.setUrl( "HTTP://localhost" ).build();
043        assertEquals( "HTTP", repo.getProtocol() );
044
045        repo = builder.setUrl( "dav+http://www.sonatype.org/" ).build();
046        assertEquals( "dav+http", repo.getProtocol() );
047
048        repo = builder.setUrl( "dav:http://www.sonatype.org/" ).build();
049        assertEquals( "dav:http", repo.getProtocol() );
050
051        repo = builder.setUrl( "file:/path" ).build();
052        assertEquals( "file", repo.getProtocol() );
053
054        repo = builder.setUrl( "file:path" ).build();
055        assertEquals( "file", repo.getProtocol() );
056
057        repo = builder.setUrl( "file:C:\\dir" ).build();
058        assertEquals( "file", repo.getProtocol() );
059
060        repo = builder.setUrl( "file:C:/dir" ).build();
061        assertEquals( "file", repo.getProtocol() );
062    }
063
064    @Test
065    public void testGetHost()
066    {
067        RemoteRepository.Builder builder = new RemoteRepository.Builder( "id", "type", "" );
068        RemoteRepository repo = builder.build();
069        assertEquals( "", repo.getHost() );
070
071        repo = builder.setUrl( "http://localhost" ).build();
072        assertEquals( "localhost", repo.getHost() );
073
074        repo = builder.setUrl( "http://localhost/" ).build();
075        assertEquals( "localhost", repo.getHost() );
076
077        repo = builder.setUrl( "http://localhost:1234/" ).build();
078        assertEquals( "localhost", repo.getHost() );
079
080        repo = builder.setUrl( "http://127.0.0.1" ).build();
081        assertEquals( "127.0.0.1", repo.getHost() );
082
083        repo = builder.setUrl( "http://127.0.0.1/" ).build();
084        assertEquals( "127.0.0.1", repo.getHost() );
085
086        repo = builder.setUrl( "http://user@localhost/path" ).build();
087        assertEquals( "localhost", repo.getHost() );
088
089        repo = builder.setUrl( "http://user:pass@localhost/path" ).build();
090        assertEquals( "localhost", repo.getHost() );
091
092        repo = builder.setUrl( "http://user:pass@localhost:1234/path" ).build();
093        assertEquals( "localhost", repo.getHost() );
094    }
095
096}