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 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 }