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