Sonar Fixes, Formatting
[aaf/authz.git] / auth / auth-core / src / test / java / org / onap / aaf / auth / env / test / JU_AuthzTransFilter.java
1 /*******************************************************************************
2  * ============LICENSE_START====================================================
3  * * org.onap.aaf
4  * * ===========================================================================
5  * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6  * * ===========================================================================
7  * * Licensed under the Apache License, Version 2.0 (the "License");
8  * * you may not use this file except in compliance with the License.
9  * * You may obtain a copy of the License at
10  * *
11  *  *      http://www.apache.org/licenses/LICENSE-2.0
12  * *
13  *  * Unless required by applicable law or agreed to in writing, software
14  * * distributed under the License is distributed on an "AS IS" BASIS,
15  * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * * See the License for the specific language governing permissions and
17  * * limitations under the License.
18  * * ============LICENSE_END====================================================
19  * *
20  * *
21  ******************************************************************************/
22
23 package org.onap.aaf.auth.env.test;
24
25 import static org.junit.Assert.*;
26
27 import org.junit.Before;
28 import org.junit.Test;
29
30 import static org.mockito.Matchers.*;
31 import static org.mockito.Mockito.*;
32 import org.mockito.*;
33
34 import java.security.Principal;
35 import java.io.ByteArrayOutputStream;
36 import java.io.PrintStream;
37 import java.lang.reflect.InvocationTargetException;
38 import java.lang.reflect.Method;
39 import org.onap.aaf.auth.env.AuthzEnv;
40 import org.onap.aaf.auth.env.AuthzTrans;
41 import org.onap.aaf.auth.env.AuthzTransFilter;
42 import org.onap.aaf.cadi.CadiException;
43 import org.onap.aaf.cadi.Connector;
44 import org.onap.aaf.cadi.PropAccess;
45 import org.onap.aaf.cadi.TrustChecker;
46 import org.onap.aaf.cadi.principal.TaggedPrincipal;
47 import org.onap.aaf.misc.env.LogTarget;
48 import org.onap.aaf.misc.env.Slot;
49 import org.onap.aaf.misc.env.Trans.Metric;
50
51 public class JU_AuthzTransFilter {
52
53     @Mock private AuthzEnv envMock;
54     @Mock private Connector connectorMock;
55     @Mock private TrustChecker tcMock;
56     @Mock private AuthzTrans authzTransMock;
57     @Mock private Object additionalTafLurs;
58
59     private PropAccess access;
60
61     @Before
62     public void setUp() throws CadiException{
63         MockitoAnnotations.initMocks(this);
64
65         access = new PropAccess(new PrintStream(new ByteArrayOutputStream()), new String[0]);
66
67         when(envMock.access()).thenReturn(access);
68     }
69
70     // TODO: These tests only work on the AT&T network. Fix them - Ian
71     @Test
72     public void testAuthenticated() throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException, CadiException {
73 //        AuthzTransFilter filter = new AuthzTransFilter(envMock, connectorMock, tcMock);
74 //        AuthzTransFilter aTF = new AuthzTransFilter(authzEnvMock, connectorMock, trustCheckerMock, (Object)null);
75 //        Class<?> c = aTF.getClass();
76 //        Class<?>[] cArg = new Class[2];
77 //        cArg[0] = AuthzTrans.class;
78 //        cArg[1] = Principal.class;        //Steps to test a protected method
79 //        Method authenticatedMethod = c.getDeclaredMethod("authenticated", cArg);
80 //        authenticatedMethod.setAccessible(true);
81 //        authenticatedMethod.invoke(aTF, authzTransMock, null);
82     }
83
84     @Test
85     public void testTallyHo() throws CadiException, NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
86 //        Slot specialLogSlot = authzEnvMock.slot("SPECIAL_LOG_SLOT");
87 //        LogTarget lt = mock(LogTarget.class);
88 //        AuthzTransFilter aTF = new AuthzTransFilter(authzEnvMock, connectorMock, trustCheckerMock, additionalTafLurs);
89 //        TaggedPrincipal tPrin = mock(TaggedPrincipal.class);
90 //        Metric met = new Metric();
91 //        met.total = 199.33F;
92 //        met.entries = 15;
93 //        met.buckets = new float[] {199.33F,99.33F};
94 //        Class<?> c = aTF.getClass();
95 //        Class<?>[] cArg = new Class[1];
96 //        cArg[0] = AuthzTrans.class;        //Steps to test a protected method
97 //        Method tallyHoMethod = c.getDeclaredMethod("tallyHo", cArg);
98 //
99 //        when(authzTransMock.auditTrail(((LogTarget)any()), anyInt(), (StringBuilder)any(), anyInt(), anyInt())).thenReturn(met);
100 //        tallyHoMethod.setAccessible(true);
101 //
102 //        when(authzTransMock.get(specialLogSlot, false)).thenReturn(false);
103 //        when(authzTransMock.warn()).thenReturn(lt);
104 //        when(authzTransMock.info()).thenReturn(lt);
105 //        tallyHoMethod.invoke(aTF, authzTransMock);
106 //
107 //        when(authzTransMock.getUserPrincipal()).thenReturn(tPrin);
108 //        tallyHoMethod.invoke(aTF, authzTransMock);
109     }
110
111 }