Skip to main content
summaryrefslogtreecommitdiffstats
blob: 39b0419f9a5d9115cb8184530932df05d8226a24 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/*******************************************************************************
 * Copyright (c) 2013 Boeing.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Boeing - initial API and implementation
 *******************************************************************************/
package org.eclipse.osee.authorization.admin.internal;

import static org.junit.Assert.assertEquals;
import static org.mockito.MockitoAnnotations.initMocks;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import org.eclipse.osee.authorization.admin.AuthorizationConfiguration;
import org.eclipse.osee.authorization.admin.AuthorizationConfigurationBuilder;
import org.eclipse.osee.authorization.admin.AuthorizationConstants;
import org.eclipse.osee.authorization.admin.AuthorizationOverride;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;

/**
 * Test Case for {@link AuthorizationConfigurationBuilder}
 * 
 * @author Roberto E. Escobar
 */
public class AuthorizationConfigurationBuilderTest {

   private static final String SCHEME_1 = "scheme1";
   private static final String SCHEME_2 = "scheme2";

   @Rule
   public ExpectedException thrown = ExpectedException.none();

   private AuthorizationConfigurationBuilder builder;

   @Before
   public void testSetup() {
      initMocks(this);

      builder = AuthorizationConfigurationBuilder.newBuilder();
   }

   @Test
   public void testOverride() {
      builder.override(AuthorizationOverride.DENY_ALL);

      AuthorizationConfiguration actual = builder.build();

      assertEquals(AuthorizationOverride.DENY_ALL, actual.getOverride());
   }

   @Test
   public void testAddSchemes() {
      builder.scheme(SCHEME_1);
      builder.scheme(SCHEME_2);

      AuthorizationConfiguration actual = builder.build();

      Iterator<String> iterator = actual.getAllowedSchemes().iterator();
      assertEquals(SCHEME_1, iterator.next());
      assertEquals(SCHEME_2, iterator.next());
   }

   @Test
   public void testConfigProperties() {
      Map<String, Object> properties = new HashMap<String, Object>();
      properties.put(AuthorizationConstants.AUTHORIZATION_OVERRIDE, AuthorizationOverride.DENY_ALL);
      properties.put(AuthorizationConstants.AUTHORIZATION_SCHEME_ALLOWED, SCHEME_2);
      builder.properties(properties);

      AuthorizationConfiguration actual = builder.build();

      assertEquals(AuthorizationOverride.DENY_ALL, actual.getOverride());

      Iterator<String> iterator = actual.getAllowedSchemes().iterator();
      assertEquals(SCHEME_2, iterator.next());
   }

   @Test
   public void testNoChangeAfterBuild() {
      builder.override(AuthorizationOverride.DENY_ALL);
      builder.scheme(SCHEME_1);

      AuthorizationConfiguration actual = builder.build();

      assertEquals(AuthorizationOverride.DENY_ALL, actual.getOverride());

      Iterator<String> iterator = actual.getAllowedSchemes().iterator();
      assertEquals(SCHEME_1, iterator.next());
      assertEquals(false, iterator.hasNext());

      builder.override(AuthorizationOverride.PERMIT_ALL);
      builder.scheme(SCHEME_2);

      builder.build();

      assertEquals(AuthorizationOverride.DENY_ALL, actual.getOverride());
      iterator = actual.getAllowedSchemes().iterator();
      assertEquals(SCHEME_1, iterator.next());
      assertEquals(false, iterator.hasNext());
   }
}

Back to the top