Mass removal of all Tabs (Style Warnings)
[aaf/authz.git] / auth / auth-core / src / test / java / org / onap / aaf / auth / env / test / JU_AuthzEnv.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 package org.onap.aaf.auth.env.test;
23
24 import static org.junit.Assert.*;
25 import static org.mockito.Mockito.mock;
26 import org.junit.*;
27
28 import java.io.ByteArrayOutputStream;
29 import java.io.IOException;
30 import java.io.InputStream;
31 import java.io.PrintStream;
32 import java.util.Properties;
33 import org.junit.After;
34 import org.junit.Before;
35 import org.junit.Test;
36 import org.junit.runner.RunWith;
37 import org.onap.aaf.auth.env.AuthzEnv;
38 import org.onap.aaf.cadi.Access;
39 import org.onap.aaf.cadi.PropAccess;
40 import org.onap.aaf.cadi.config.Config;
41
42 public class JU_AuthzEnv {
43
44     AuthzEnv authzEnv;
45     ByteArrayOutputStream outStream;
46     ByteArrayOutputStream errStream;
47     enum Level {DEBUG, INFO, AUDIT, INIT, WARN, ERROR};
48
49     @Before
50     public void setUp() {
51         outStream = new ByteArrayOutputStream();
52         errStream = new ByteArrayOutputStream();
53
54         System.setOut(new PrintStream(outStream));
55         System.setErr(new PrintStream(errStream));
56
57         authzEnv = new AuthzEnv();
58     }
59
60     @After
61     public void tearDown() {
62         System.setOut(System.out);
63         System.setErr(System.err);
64     }
65
66     @Test
67     @SuppressWarnings("unused")
68     public void testConstructors() {
69         AuthzEnv authzEnv1 = new AuthzEnv("Test");
70         AuthzEnv authzEnv2 = new AuthzEnv((PropAccess)null);
71         AuthzEnv authzEnv3 = new AuthzEnv((Properties)null);
72     }
73
74     @Test
75     public void testTransRate() {
76         Long Result = authzEnv.transRate();
77         assertNotNull(Result);
78     }
79
80     @Test
81     public void checkNewTransNoAvg() {
82         assertNotNull(authzEnv.newTransNoAvg());
83     }
84
85     @Test
86     public void checkNewTrans() {
87         assertNotNull(authzEnv.newTrans());
88     }
89
90     @Test
91     public void checkPropAccess() {
92         assertNotNull(authzEnv.access());
93     }
94
95     @Test
96     public void checkgetProperties() { //TODO:[GABE]No setter for this, add?
97         assertNotNull(authzEnv.getProperties());
98         assertNotNull(authzEnv.getProperties("test"));
99     }
100
101     @Test
102     public void checkPropertyGetters(){
103         authzEnv.setProperty("key","value");
104         assertEquals(authzEnv.getProperty("key"), "value");
105         assertEquals(authzEnv.getProperty("key","value"), "value");
106     }
107
108     @Test
109     public void checkPropertySetters(){
110         assertEquals(authzEnv.getProperty("key","value"), authzEnv.setProperty("key","value"));
111     }
112
113     @Test(expected = IOException.class)
114     public void testDecryptException() throws IOException{
115         authzEnv.setProperty(Config.CADI_KEYFILE, "test/keyfile");
116         authzEnv.decrypt(null, false);
117     }
118
119     @Test
120     public void testDecrypt() throws IOException{
121         String encrypted = "encrypted";
122         String Result = authzEnv.decrypt(encrypted, true);
123         assertEquals("encrypted",Result);
124     }
125
126     @Test
127     public void testClassLoader() {
128         ClassLoader cLoad = mock(ClassLoader.class);
129         cLoad = authzEnv.classLoader();
130         assertNotNull(cLoad);
131     }
132
133     @Test
134     public void testLoad() throws IOException {
135         InputStream is = mock(InputStream.class);
136         authzEnv.load(is);
137     }
138
139     @Test
140     public void testLog() {
141         Access.Level lvl = Access.Level.DEBUG;
142         Object msgs = null;
143         authzEnv.log(lvl, msgs);
144     }
145
146     @Test
147     public void testLog1() {
148         
149         Exception e = new Exception();
150         Object msgs = null;
151         authzEnv.log(e, msgs);
152     }
153
154     @Test
155     public void testPrintf() {
156         Access.Level lvl = Access.Level.DEBUG;
157         Object msgs = null;
158         authzEnv.printf(lvl, "Test", msgs);
159     }
160
161     @Test
162     public void testWillLog() {
163         Access.Level lvl = Access.Level.DEBUG;
164         Access.Level lvl1 = Access.Level.AUDIT;
165         boolean test = authzEnv.willLog(lvl);
166         assertFalse(test);
167         test = authzEnv.willLog(lvl1);
168         assertTrue(test);
169     }
170
171     @Test
172     public void testSetLogLevel() {
173         Access.Level lvl = Access.Level.DEBUG;
174         authzEnv.setLogLevel(lvl);
175     }
176
177 }