001package org.eclipse.aether.util.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.DefaultRepositorySystemSession; 025import org.eclipse.aether.RepositorySystemSession; 026import org.eclipse.aether.repository.Authentication; 027import org.eclipse.aether.repository.AuthenticationContext; 028import org.eclipse.aether.repository.AuthenticationDigest; 029import org.eclipse.aether.repository.RemoteRepository; 030import org.junit.Test; 031 032public class StringAuthenticationTest 033{ 034 035 private RepositorySystemSession newSession() 036 { 037 return new DefaultRepositorySystemSession(); 038 } 039 040 private RemoteRepository newRepo( Authentication auth ) 041 { 042 return new RemoteRepository.Builder( "test", "default", "http://localhost" ).setAuthentication( auth ).build(); 043 } 044 045 private AuthenticationContext newContext( Authentication auth ) 046 { 047 return AuthenticationContext.forRepository( newSession(), newRepo( auth ) ); 048 } 049 050 private String newDigest( Authentication auth ) 051 { 052 return AuthenticationDigest.forRepository( newSession(), newRepo( auth ) ); 053 } 054 055 @Test 056 public void testFill() 057 { 058 Authentication auth = new StringAuthentication( "key", "value" ); 059 AuthenticationContext context = newContext( auth ); 060 assertEquals( null, context.get( "another-key" ) ); 061 assertEquals( "value", context.get( "key" ) ); 062 } 063 064 @Test 065 public void testDigest() 066 { 067 Authentication auth1 = new StringAuthentication( "key", "value" ); 068 Authentication auth2 = new StringAuthentication( "key", "value" ); 069 String digest1 = newDigest( auth1 ); 070 String digest2 = newDigest( auth2 ); 071 assertEquals( digest1, digest2 ); 072 073 Authentication auth3 = new StringAuthentication( "key", "Value" ); 074 String digest3 = newDigest( auth3 ); 075 assertFalse( digest3.equals( digest1 ) ); 076 077 Authentication auth4 = new StringAuthentication( "Key", "value" ); 078 String digest4 = newDigest( auth4 ); 079 assertFalse( digest4.equals( digest1 ) ); 080 } 081 082 @Test 083 public void testEquals() 084 { 085 Authentication auth1 = new StringAuthentication( "key", "value" ); 086 Authentication auth2 = new StringAuthentication( "key", "value" ); 087 Authentication auth3 = new StringAuthentication( "key", "Value" ); 088 assertEquals( auth1, auth2 ); 089 assertFalse( auth1.equals( auth3 ) ); 090 assertFalse( auth1.equals( null ) ); 091 } 092 093 @Test 094 public void testHashCode() 095 { 096 Authentication auth1 = new StringAuthentication( "key", "value" ); 097 Authentication auth2 = new StringAuthentication( "key", "value" ); 098 assertEquals( auth1.hashCode(), auth2.hashCode() ); 099 } 100 101}