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
22 import static org.junit.Assert.*;
23
24 import java.util.Map;
25
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.Proxy;
30 import org.eclipse.aether.repository.RemoteRepository;
31 import org.junit.Test;
32
33
34
35 public class DefaultRepositorySystemSessionTest
36 {
37
38 @Test
39 public void testDefaultProxySelectorUsesExistingProxy()
40 {
41 DefaultRepositorySystemSession session = new DefaultRepositorySystemSession();
42
43 RemoteRepository repo = new RemoteRepository.Builder( "id", "default", "void" ).build();
44 assertSame( null, session.getProxySelector().getProxy( repo ) );
45
46 Proxy proxy = new Proxy( "http", "localhost", 8080, null );
47 repo = new RemoteRepository.Builder( repo ).setProxy( proxy ).build();
48 assertSame( proxy, session.getProxySelector().getProxy( repo ) );
49 }
50
51 @Test
52 public void testDefaultAuthenticationSelectorUsesExistingAuth()
53 {
54 DefaultRepositorySystemSession session = new DefaultRepositorySystemSession();
55
56 RemoteRepository repo = new RemoteRepository.Builder( "id", "default", "void" ).build();
57 assertSame( null, session.getAuthenticationSelector().getAuthentication( repo ) );
58
59 Authentication auth = new Authentication()
60 {
61 public void fill( AuthenticationContext context, String key, Map<String, String> data )
62 {
63 }
64
65 public void digest( AuthenticationDigest digest )
66 {
67 }
68 };
69 repo = new RemoteRepository.Builder( repo ).setAuthentication( auth ).build();
70 assertSame( auth, session.getAuthenticationSelector().getAuthentication( repo ) );
71 }
72
73 @Test
74 public void testCopyConstructorCopiesPropertiesDeep()
75 {
76 DefaultRepositorySystemSession session1 = new DefaultRepositorySystemSession();
77 session1.setUserProperties( System.getProperties() );
78 session1.setSystemProperties( System.getProperties() );
79 session1.setConfigProperties( System.getProperties() );
80
81 DefaultRepositorySystemSession session2 = new DefaultRepositorySystemSession( session1 );
82 session2.setUserProperty( "key", "test" );
83 session2.setSystemProperty( "key", "test" );
84 session2.setConfigProperty( "key", "test" );
85
86 assertEquals( null, session1.getUserProperties().get( "key" ) );
87 assertEquals( null, session1.getSystemProperties().get( "key" ) );
88 assertEquals( null, session1.getConfigProperties().get( "key" ) );
89 }
90
91 @Test
92 public void testReadOnlyProperties()
93 {
94 DefaultRepositorySystemSession session = new DefaultRepositorySystemSession();
95
96 try
97 {
98 session.getUserProperties().put( "key", "test" );
99 fail( "user properties are modifiable" );
100 }
101 catch ( UnsupportedOperationException e )
102 {
103
104 }
105
106 try
107 {
108 session.getSystemProperties().put( "key", "test" );
109 fail( "system properties are modifiable" );
110 }
111 catch ( UnsupportedOperationException e )
112 {
113
114 }
115
116 try
117 {
118 session.getConfigProperties().put( "key", "test" );
119 fail( "config properties are modifiable" );
120 }
121 catch ( UnsupportedOperationException e )
122 {
123
124 }
125 }
126
127 }