View Javadoc
1   package org.eclipse.aether.util.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.DefaultRepositorySystemSession;
25  import org.eclipse.aether.RepositorySystemSession;
26  import org.eclipse.aether.repository.Authentication;
27  import org.eclipse.aether.repository.AuthenticationContext;
28  import org.eclipse.aether.repository.AuthenticationDigest;
29  import org.eclipse.aether.repository.RemoteRepository;
30  import org.junit.Test;
31  
32  public class StringAuthenticationTest
33  {
34  
35      private RepositorySystemSession newSession()
36      {
37          return new DefaultRepositorySystemSession();
38      }
39  
40      private RemoteRepository newRepo( Authentication auth )
41      {
42          return new RemoteRepository.Builder( "test", "default", "http://localhost" ).setAuthentication( auth ).build();
43      }
44  
45      private AuthenticationContext newContext( Authentication auth )
46      {
47          return AuthenticationContext.forRepository( newSession(), newRepo( auth ) );
48      }
49  
50      private String newDigest( Authentication auth )
51      {
52          return AuthenticationDigest.forRepository( newSession(), newRepo( auth ) );
53      }
54  
55      @Test
56      public void testFill()
57      {
58          Authentication auth = new StringAuthentication( "key", "value" );
59          AuthenticationContext context = newContext( auth );
60          assertNull( context.get( "another-key" ) );
61          assertEquals( "value", context.get( "key" ) );
62      }
63  
64      @Test
65      public void testDigest()
66      {
67          Authentication auth1 = new StringAuthentication( "key", "value" );
68          Authentication auth2 = new StringAuthentication( "key", "value" );
69          String digest1 = newDigest( auth1 );
70          String digest2 = newDigest( auth2 );
71          assertEquals( digest1, digest2 );
72  
73          Authentication auth3 = new StringAuthentication( "key", "Value" );
74          String digest3 = newDigest( auth3 );
75          assertNotEquals( digest3, digest1 );
76  
77          Authentication auth4 = new StringAuthentication( "Key", "value" );
78          String digest4 = newDigest( auth4 );
79          assertNotEquals( digest4, digest1 );
80      }
81  
82      @Test
83      public void testEquals()
84      {
85          Authentication auth1 = new StringAuthentication( "key", "value" );
86          Authentication auth2 = new StringAuthentication( "key", "value" );
87          Authentication auth3 = new StringAuthentication( "key", "Value" );
88          assertEquals( auth1, auth2 );
89          assertNotEquals( auth1, auth3 );
90          assertNotEquals( null, auth1 );
91      }
92  
93      @Test
94      public void testHashCode()
95      {
96          Authentication auth1 = new StringAuthentication( "key", "value" );
97          Authentication auth2 = new StringAuthentication( "key", "value" );
98          assertEquals( auth1.hashCode(), auth2.hashCode() );
99      }
100 
101 }