View Javadoc
1   package org.eclipse.aether;
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 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             // expected
104         }
105 
106         try
107         {
108             session.getSystemProperties().put( "key", "test" );
109             fail( "system properties are modifiable" );
110         }
111         catch ( UnsupportedOperationException e )
112         {
113             // expected
114         }
115 
116         try
117         {
118             session.getConfigProperties().put( "key", "test" );
119             fail( "config properties are modifiable" );
120         }
121         catch ( UnsupportedOperationException e )
122         {
123             // expected
124         }
125     }
126 
127 }