1 package org.eclipse.aether;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 import static org.junit.Assert.assertEquals;
22 import static org.junit.Assert.assertNull;
23 import static org.junit.Assert.assertSame;
24 import static org.junit.Assert.fail;
25
26 import java.lang.reflect.Method;
27 import java.util.Map;
28
29 import org.eclipse.aether.repository.Authentication;
30 import org.eclipse.aether.repository.AuthenticationContext;
31 import org.eclipse.aether.repository.AuthenticationDigest;
32 import org.eclipse.aether.repository.Proxy;
33 import org.eclipse.aether.repository.RemoteRepository;
34 import org.junit.Test;
35 import org.mockito.Mockito;
36
37
38
39 public class DefaultRepositorySystemSessionTest
40 {
41
42 @Test
43 public void testDefaultProxySelectorUsesExistingProxy()
44 {
45 DefaultRepositorySystemSession session = new DefaultRepositorySystemSession();
46
47 RemoteRepository repo = new RemoteRepository.Builder( "id", "default", "void" ).build();
48 assertSame( null, session.getProxySelector().getProxy( repo ) );
49
50 Proxy proxy = new Proxy( "http", "localhost", 8080, null );
51 repo = new RemoteRepository.Builder( repo ).setProxy( proxy ).build();
52 assertSame( proxy, session.getProxySelector().getProxy( repo ) );
53 }
54
55 @Test
56 public void testDefaultAuthenticationSelectorUsesExistingAuth()
57 {
58 DefaultRepositorySystemSession session = new DefaultRepositorySystemSession();
59
60 RemoteRepository repo = new RemoteRepository.Builder( "id", "default", "void" ).build();
61 assertSame( null, session.getAuthenticationSelector().getAuthentication( repo ) );
62
63 Authentication auth = new Authentication()
64 {
65 public void fill( AuthenticationContext context, String key, Map<String, String> data )
66 {
67 }
68
69 public void digest( AuthenticationDigest digest )
70 {
71 }
72 };
73 repo = new RemoteRepository.Builder( repo ).setAuthentication( auth ).build();
74 assertSame( auth, session.getAuthenticationSelector().getAuthentication( repo ) );
75 }
76
77 @Test
78 public void testCopyConstructorCopiesPropertiesDeep()
79 {
80 DefaultRepositorySystemSession session1 = new DefaultRepositorySystemSession();
81 session1.setUserProperties( System.getProperties() );
82 session1.setSystemProperties( System.getProperties() );
83 session1.setConfigProperties( System.getProperties() );
84
85 DefaultRepositorySystemSession session2 = new DefaultRepositorySystemSession( session1 );
86 session2.setUserProperty( "key", "test" );
87 session2.setSystemProperty( "key", "test" );
88 session2.setConfigProperty( "key", "test" );
89
90 assertNull( session1.getUserProperties().get( "key" ) );
91 assertNull( session1.getSystemProperties().get( "key" ) );
92 assertNull( session1.getConfigProperties().get( "key" ) );
93 }
94
95 @Test
96 public void testReadOnlyProperties()
97 {
98 DefaultRepositorySystemSession session = new DefaultRepositorySystemSession();
99
100 try
101 {
102 session.getUserProperties().put( "key", "test" );
103 fail( "user properties are modifiable" );
104 }
105 catch ( UnsupportedOperationException e )
106 {
107
108 }
109
110 try
111 {
112 session.getSystemProperties().put( "key", "test" );
113 fail( "system properties are modifiable" );
114 }
115 catch ( UnsupportedOperationException e )
116 {
117
118 }
119
120 try
121 {
122 session.getConfigProperties().put( "key", "test" );
123 fail( "config properties are modifiable" );
124 }
125 catch ( UnsupportedOperationException e )
126 {
127
128 }
129 }
130
131
132 @Test
133 public void testCopyRepositorySystemSession() throws Exception
134 {
135 RepositorySystemSession session = Mockito.mock( RepositorySystemSession.class, Mockito.RETURNS_MOCKS );
136
137 RepositorySystemSession newSession = new DefaultRepositorySystemSession( session );
138
139 Method[] methods = RepositorySystemSession.class.getMethods();
140
141 for ( Method method : methods )
142 {
143 assertEquals( method.getName(), method.invoke( session ) == null, method.invoke( newSession ) == null );
144 }
145 }
146
147 }