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 ComponentAuthenticationTest
33  {
34  
35      private static class Component
36      {
37      }
38  
39      private RepositorySystemSession newSession()
40      {
41          return new DefaultRepositorySystemSession();
42      }
43  
44      private RemoteRepository newRepo( Authentication auth )
45      {
46          return new RemoteRepository.Builder( "test", "default", "http://localhost" ).setAuthentication( auth ).build();
47      }
48  
49      private AuthenticationContext newContext( Authentication auth )
50      {
51          return AuthenticationContext.forRepository( newSession(), newRepo( auth ) );
52      }
53  
54      private String newDigest( Authentication auth )
55      {
56          return AuthenticationDigest.forRepository( newSession(), newRepo( auth ) );
57      }
58  
59      @Test
60      public void testFill()
61      {
62          Component comp = new Component();
63          Authentication auth = new ComponentAuthentication( "key", comp );
64          AuthenticationContext context = newContext( auth );
65          assertNull( context.get( "another-key" ) );
66          assertSame( comp, context.get( "key", Component.class ) );
67      }
68  
69      @Test
70      public void testDigest()
71      {
72          Authentication auth1 = new ComponentAuthentication( "key", new Component() );
73          Authentication auth2 = new ComponentAuthentication( "key", new Component() );
74          String digest1 = newDigest( auth1 );
75          String digest2 = newDigest( auth2 );
76          assertEquals( digest1, digest2 );
77  
78          Authentication auth3 = new ComponentAuthentication( "key", new Object() );
79          String digest3 = newDigest( auth3 );
80          assertNotEquals( digest3, digest1 );
81  
82          Authentication auth4 = new ComponentAuthentication( "Key", new Component() );
83          String digest4 = newDigest( auth4 );
84          assertNotEquals( digest4, digest1 );
85      }
86  
87      @Test
88      public void testEquals()
89      {
90          Authentication auth1 = new ComponentAuthentication( "key", new Component() );
91          Authentication auth2 = new ComponentAuthentication( "key", new Component() );
92          Authentication auth3 = new ComponentAuthentication( "key", new Object() );
93          assertEquals( auth1, auth2 );
94          assertNotEquals( auth1, auth3 );
95          assertNotEquals( null, auth1 );
96      }
97  
98      @Test
99      public void testHashCode()
100     {
101         Authentication auth1 = new ComponentAuthentication( "key", new Component() );
102         Authentication auth2 = new ComponentAuthentication( "key", new Component() );
103         assertEquals( auth1.hashCode(), auth2.hashCode() );
104     }
105 
106 }