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
|
/*******************************************************************************
* 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.authentication.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.authentication.admin.AuthenticationConfiguration;
import org.eclipse.osee.authentication.admin.AuthenticationConfigurationBuilder;
import org.eclipse.osee.authentication.admin.AuthenticationConstants;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
/**
* Test Case for {@link AuthenticationConfigurationBuilder}
*
* @author Roberto E. Escobar
*/
public class AuthenticationConfigurationBuilderTest {
private static final String SCHEME_1 = "scheme1";
private static final String SCHEME_2 = "scheme2";
@Rule
public ExpectedException thrown = ExpectedException.none();
private AuthenticationConfigurationBuilder builder;
@Before
public void testSetup() {
initMocks(this);
builder = AuthenticationConfigurationBuilder.newBuilder();
}
@Test
public void testAddSchemes() {
builder.scheme(SCHEME_1);
builder.scheme(SCHEME_2);
AuthenticationConfiguration actual = builder.build();
Iterator<String> iterator = actual.getAllowedSchemes().iterator();
assertEquals(SCHEME_1, iterator.next());
assertEquals(SCHEME_2, iterator.next());
}
@Test
public void testDefaultScheme() {
builder.defaultScheme(SCHEME_2);
AuthenticationConfiguration actual = builder.build();
assertEquals(SCHEME_2, actual.getDefaultScheme());
}
@Test
public void testConfigProperties() {
Map<String, Object> properties = new HashMap<String, Object>();
properties.put(AuthenticationConstants.AUTHENTICATION_SCHEME_ALLOWED, SCHEME_1 + "," + SCHEME_2);
properties.put(AuthenticationConstants.AUTHENTICATION_SCHEME_ALLOWED_DEFAULT, SCHEME_2);
builder.properties(properties);
AuthenticationConfiguration actual = builder.build();
Iterator<String> iterator = actual.getAllowedSchemes().iterator();
assertEquals(SCHEME_1, iterator.next());
assertEquals(SCHEME_2, iterator.next());
assertEquals(SCHEME_2, actual.getDefaultScheme());
}
@Test
public void testNoChangeAfterBuild() {
builder.scheme(SCHEME_1);
builder.defaultScheme(SCHEME_1);
AuthenticationConfiguration actual = builder.build();
Iterator<String> iterator = actual.getAllowedSchemes().iterator();
assertEquals(SCHEME_1, iterator.next());
assertEquals(false, iterator.hasNext());
assertEquals(SCHEME_1, actual.getDefaultScheme());
builder.scheme(SCHEME_2);
builder.defaultScheme(SCHEME_2);
iterator = actual.getAllowedSchemes().iterator();
assertEquals(SCHEME_1, iterator.next());
assertEquals(false, iterator.hasNext());
assertEquals(SCHEME_1, actual.getDefaultScheme());
}
}
|