001package org.apache.maven.wagon.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 junit.framework.TestCase; 023 024import org.apache.maven.wagon.WagonConstants; 025 026/** 027 * @author <a href="mailto:jvanzyl@maven.org">Jason van Zyl</a> 028 * 029 */ 030public class RepositoryTest 031 extends TestCase 032{ 033 public RepositoryTest( final String name ) 034 { 035 super( name ); 036 } 037 038 public void setUp() 039 throws Exception 040 { 041 super.setUp(); 042 } 043 044 public void tearDown() 045 throws Exception 046 { 047 super.tearDown(); 048 } 049 050 public void testRepositoryProperties() 051 throws Exception 052 { 053 Repository repository = new Repository(); 054 055 repository.setBasedir( "directory" ); 056 057 assertEquals( "directory", repository.getBasedir() ); 058 059 repository.setName( "name" ); 060 061 assertEquals( "name", repository.getName() ); 062 063 repository.setPort( 0 ); 064 065 assertEquals( 0, repository.getPort() ); 066 067 assertEquals( "localhost", repository.getHost() ); 068 069 repository.setUrl( "http://www.ibiblio.org" ); 070 071 assertEquals( "http://www.ibiblio.org", repository.getUrl() ); 072 073 assertEquals( "http", repository.getProtocol() ); 074 075 assertEquals( "www.ibiblio.org", repository.getHost() ); 076 077 assertEquals( "/", repository.getBasedir() ); 078 079 assertEquals( WagonConstants.UNKNOWN_PORT, repository.getPort() ); 080 081 repository.setUrl( "https://www.ibiblio.org:100/maven" ); 082 083 assertEquals( "https://www.ibiblio.org:100/maven", repository.getUrl() ); 084 085 assertEquals( "https", repository.getProtocol() ); 086 087 assertEquals( "www.ibiblio.org", repository.getHost() ); 088 089 assertEquals( "/maven", repository.getBasedir() ); 090 091 assertEquals( 100, repository.getPort() ); 092 093 assertEquals( "www.ibiblio.org", repository.getHost() ); 094 095 repository.setBasedir( "basedir" ); 096 097 assertEquals( "basedir", repository.getBasedir() ); 098 099 repository.setUrl( "http://brett:porter@www.ibiblio.org" ); 100 101 assertEquals( "http://www.ibiblio.org", repository.getUrl() ); 102 103 repository.setUrl( "http://brett@www.ibiblio.org" ); 104 105 assertEquals( "http://www.ibiblio.org", repository.getUrl() ); 106 107 } 108 109 public void testIPv6() 110 { 111 assertRepository( "http://user:password@[fff:::1]:7891/oo/rest/users", "http://[fff:::1]:7891/oo/rest/users", 112 "/oo/rest/users", "user", "password", "fff:::1", 7891 ); 113 assertRepository( "http://[fff:::1]:7891/oo/rest/users", "http://[fff:::1]:7891/oo/rest/users", 114 "/oo/rest/users", null, null, "fff:::1", 7891 ); 115 assertRepository( "http://user:password@[fff:::1]/oo/rest/users", "http://[fff:::1]/oo/rest/users", 116 "/oo/rest/users", "user", "password", "fff:::1", -1 ); 117 assertRepository( "http://user:password@[fff:::1]:7891", "http://[fff:::1]:7891", "/", "user", "password", 118 "fff:::1", 7891 ); 119 120 assertRepository( "http://user:password@[fff:000::222:1111]:7891/oo/rest/users", 121 "http://[fff:000::222:1111]:7891/oo/rest/users", "/oo/rest/users", "user", "password", 122 "fff:000::222:1111", 7891 ); 123 assertRepository( "http://[fff:000::222:1111]:7891/oo/rest/users", 124 "http://[fff:000::222:1111]:7891/oo/rest/users", "/oo/rest/users", null, null, 125 "fff:000::222:1111", 7891 ); 126 assertRepository( "http://user:password@[fff:000::222:1111]/oo/rest/users", 127 "http://[fff:000::222:1111]/oo/rest/users", "/oo/rest/users", "user", "password", 128 "fff:000::222:1111", -1 ); 129 assertRepository( "http://user:password@[fff:000::222:1111]:7891", "http://[fff:000::222:1111]:7891", "/", 130 "user", "password", "fff:000::222:1111", 7891 ); 131 132 assertRepository( "http://user:password@16.60.56.58:7891/oo/rest/users", 133 "http://16.60.56.58:7891/oo/rest/users", "/oo/rest/users", "user", "password", "16.60.56.58", 134 7891 ); 135 assertRepository( "http://16.60.56.58:7891/oo/rest/users", "http://16.60.56.58:7891/oo/rest/users", 136 "/oo/rest/users", null, null, "16.60.56.58", 7891 ); 137 assertRepository( "http://user:password@16.60.56.58/oo/rest/users", "http://16.60.56.58/oo/rest/users", 138 "/oo/rest/users", "user", "password", "16.60.56.58", -1 ); 139 assertRepository( "http://user:password@16.60.56.58:7891", "http://16.60.56.58:7891", "/", "user", "password", 140 "16.60.56.58", 7891 ); 141 142 assertRepository( "http://user:password@16.60.56.58:7891/oo/rest/users", 143 "http://16.60.56.58:7891/oo/rest/users", "/oo/rest/users", "user", "password", "16.60.56.58", 144 7891 ); 145 assertRepository( "http://16.60.56.58:7891/oo/rest/users", "http://16.60.56.58:7891/oo/rest/users", 146 "/oo/rest/users", null, null, "16.60.56.58", 7891 ); 147 assertRepository( "http://user:password@16.60.56.58/oo/rest/users", "http://16.60.56.58/oo/rest/users", 148 "/oo/rest/users", "user", "password", "16.60.56.58", -1 ); 149 assertRepository( "http://user:password@16.60.56.58:7891", "http://16.60.56.58:7891", "/", "user", "password", 150 "16.60.56.58", 7891 ); 151 } 152 153 private void assertRepository( String url, String repoUrl, String baseDir, String user, String password, 154 String host, int port ) 155 { 156 Repository repo = new Repository( String.valueOf( System.currentTimeMillis() ), url ); 157 assertEquals( repoUrl, repo.getUrl() ); 158 assertEquals( baseDir, repo.getBasedir() ); 159 assertEquals( host, repo.getHost() ); 160 assertEquals( user, repo.getUsername() ); 161 assertEquals( password, repo.getPassword() ); 162 assertEquals( port, repo.getPort() ); 163 } 164}