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