View Javadoc

1   package com.atlassian.sal.core.net;
2   
3   import org.apache.http.HttpHost;
4   import org.apache.http.auth.AuthScheme;
5   import org.apache.http.impl.auth.BasicScheme;
6   import org.junit.BeforeClass;
7   import org.junit.Test;
8   
9   import static org.hamcrest.MatcherAssert.assertThat;
10  import static org.hamcrest.Matchers.is;
11  import static org.hamcrest.Matchers.nullValue;
12  
13  public class AllPortsAuthCacheTest {
14      private static AllPortsAuthCache authCache = new AllPortsAuthCache();
15      private static final String hostName = "sample.host";
16      private static final HttpHost specificHost = new HttpHost(hostName, 80);
17      private static final AuthScheme specificAuthScheme = new BasicScheme();
18      private static final AuthScheme allPortsAuthScheme = new BasicScheme();
19  
20      @BeforeClass
21      public static void before() {
22          authCache = new AllPortsAuthCache();
23          authCache.put(specificHost, specificAuthScheme);
24          authCache.put(new HttpHost(hostName), allPortsAuthScheme);
25      }
26  
27      @Test
28      public void assertSpecificFoundFirst() {
29          assertThat(authCache.get(specificHost), is(specificAuthScheme));
30      }
31  
32      @Test
33      public void assertAllPortsFound() {
34          assertThat(authCache.get(new HttpHost(hostName, 8090)), is(allPortsAuthScheme));
35      }
36  
37      @Test
38      public void assertOtherHostNotFound() {
39          assertThat(authCache.get(new HttpHost("other.host", 80)), is(nullValue()));
40      }
41  }