AT&T 2.0.19 Code drop, stage 3
[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 java.io.IOException;
27 import java.io.InputStream;
28 import java.util.Properties;
29 import org.onap.aaf.cadi.Access;
30 import static org.mockito.Mockito.when;
31 import org.junit.Before;
32 import org.junit.Test;
33 import org.junit.runner.RunWith;
34 import org.mockito.Mock;
35 import org.onap.aaf.auth.env.AuthzEnv;
36 import org.onap.aaf.cadi.PropAccess;
37 import org.onap.aaf.cadi.Access.Level;
38 import org.onap.aaf.cadi.config.Config;
39 import org.onap.aaf.misc.env.APIException;
40 import org.powermock.modules.junit4.PowerMockRunner;
41
42 import junit.framework.Assert;
43
44 @RunWith(PowerMockRunner.class)
45 public class JU_AuthzEnv {
46         private static final org.onap.aaf.cadi.Access.Level DEBUG = null;
47         AuthzEnv authzEnv;
48         enum Level {DEBUG, INFO, AUDIT, INIT, WARN, ERROR};
49         
50         @Before
51         public void setUp(){
52                 PropAccess access = null;
53                 Properties props = null;
54                 authzEnv = new AuthzEnv();
55                 AuthzEnv authzEnv1 = new AuthzEnv("Test");
56                 AuthzEnv authzEnv2 = new AuthzEnv(props);
57                 AuthzEnv authzEnv3 = new AuthzEnv(access);
58         }
59
60         @Test
61         public void testTransRate() {
62         Long Result =   authzEnv.transRate();
63         System.out.println("value of result " +Result); //Expected 300000
64         assertNotNull(Result);          
65         }
66         
67         @Test
68         public void checkNewTransNoAvg() {
69                 
70                 Assert.assertNotNull(authzEnv.newTransNoAvg());
71         }
72         
73         @Test
74         public void checkNewTrans() {
75                 Assert.assertNotNull(authzEnv.newTrans());
76         }
77         
78         @Test
79         public void checkPropAccess() {
80                 Assert.assertNotNull(authzEnv.access());
81         }
82         
83         @Test
84         public void checkgetProperties() { //TODO:[GABE]No setter for this, add?
85                 Assert.assertNotNull(authzEnv.getProperties());
86                 Assert.assertNotNull(authzEnv.getProperties("test"));
87         }
88         
89         @Test(expected = APIException.class)
90         public void checkSetLog4JNames() throws APIException {//TODO: Find better way to test instead of just seeing if strings pass
91                 authzEnv.setLog4JNames("path", "root","service","audit","init","trace");
92                 authzEnv.setLog4JNames("path", "root",null,"audit","init","trace");
93         }
94         
95         @Test
96         public void checkPropertyGetters(){
97                 authzEnv.setProperty("key","value");
98                 Assert.assertEquals(authzEnv.getProperty("key"), "value");
99                 Assert.assertEquals(authzEnv.getProperty("key","value"), "value");
100         }
101         
102         @Test
103         public void checkPropertySetters(){
104                 Assert.assertEquals(authzEnv.getProperty("key","value"), authzEnv.setProperty("key","value"));
105         }
106         
107         @Test(expected = IOException.class)
108         public void testDecryptException() throws IOException{
109                 String encrypted = "enc:";
110                 authzEnv.setProperty(Config.CADI_KEYFILE, "test");//TODO: Figure out setter for this
111                 authzEnv.decrypt(encrypted, true);
112                 authzEnv.decrypt("", false);
113         }
114         
115         @Test
116         public void testDecrypt() throws IOException{
117                 String encrypted = "encrypted";
118                 String Result = authzEnv.decrypt(encrypted, true);
119                 System.out.println("value of res " +Result);
120                 assertEquals("encrypted",Result);
121         }
122         
123         @Test
124         public void testClassLoader() {
125                 ClassLoader cLoad = mock(ClassLoader.class);
126                 cLoad = authzEnv.classLoader();
127                 Assert.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                 Assert.assertFalse(test);
163                 test = authzEnv.willLog(lvl1);
164                 Assert.assertTrue(test);
165                 
166         }
167         
168         @Test
169         public void testSetLogLevel() {
170                 Access.Level lvl = Access.Level.DEBUG;
171                 authzEnv.setLogLevel(lvl);
172         }
173
174 }