1 package org.eclipse.aether.util.repository;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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 assertEquals( null, 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 assertFalse( digest3.equals( digest1 ) );
76
77 Authentication auth4 = new StringAuthentication( "Key", "value" );
78 String digest4 = newDigest( auth4 );
79 assertFalse( digest4.equals( 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 assertFalse( auth1.equals( auth3 ) );
90 assertFalse( auth1.equals( null ) );
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 }