1 /*******************************************************************************
\r
2 * ============LICENSE_START====================================================
\r
4 * * ===========================================================================
\r
5 * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
\r
6 * * ===========================================================================
\r
7 * * Licensed under the Apache License, Version 2.0 (the "License");
\r
8 * * you may not use this file except in compliance with the License.
\r
9 * * You may obtain a copy of the License at
\r
11 * * http://www.apache.org/licenses/LICENSE-2.0
\r
13 * * Unless required by applicable law or agreed to in writing, software
\r
14 * * distributed under the License is distributed on an "AS IS" BASIS,
\r
15 * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
16 * * See the License for the specific language governing permissions and
\r
17 * * limitations under the License.
\r
18 * * ============LICENSE_END====================================================
\r
20 * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
\r
22 ******************************************************************************/
\r
23 package org.onap.aaf.cadi.filter;
\r
25 import static org.junit.Assert.assertEquals;
\r
26 import static org.mockito.Mockito.when;
\r
28 import javax.servlet.FilterConfig;
\r
29 import javax.servlet.ServletContext;
\r
31 import org.junit.Before;
\r
32 import org.junit.Test;
\r
33 import org.mockito.Mock;
\r
34 import org.mockito.MockitoAnnotations;
\r
35 import org.onap.aaf.cadi.PropAccess;
\r
37 public class JU_FCGetTest {
\r
40 private ServletContext context;
\r
43 private FilterConfig config;
\r
46 private PropAccess access = new PropAccess();
\r
49 public void setUp() {
\r
50 MockitoAnnotations.initMocks(this);
\r
54 public void testGetStringFromDef() {
\r
55 PropAccess access = new PropAccess();
\r
57 FCGet fcGet = new FCGet(access, context, config);
\r
59 String user = fcGet.get("user", "DefaultUser", true);
\r
61 assertEquals(user, "DefaultUser");
\r
65 public void testGetStringFromContext() {
\r
66 PropAccess access = new PropAccess();
\r
67 when(context.getInitParameter("user")).thenReturn("ContextUser");
\r
69 FCGet fcGet = new FCGet(access, context, null);
\r
71 String user = fcGet.get("user", "DefaultUser", true);
\r
73 assertEquals(user,"ContextUser");
\r
77 public void testGetStringFromFilter() {
\r
78 PropAccess access = new PropAccess();
\r
79 when(config.getInitParameter("user")).thenReturn("FilterUser");
\r
81 FCGet fcGet = new FCGet(access, null, config);
\r
83 String user = fcGet.get("user", "DefaultUser", true);
\r
85 assertEquals(user,"FilterUser");
\r
89 public void testGetStringWithNullContextFilter() {
\r
91 when(access.getProperty("user", "DefaultUser")).thenReturn(null);
\r
93 FCGet fcGet = new FCGet(access, null, null);
\r
95 String user = fcGet.get("user", "DefaultUser", true);
\r
97 assertEquals(user,"DefaultUser");
\r