Keep only clean TestCases, remove 2 license issues
[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         assertNotNull(Result);
64         }
65
66         @Test
67         public void checkNewTransNoAvg() {
68
69                 Assert.assertNotNull(authzEnv.newTransNoAvg());
70         }
71
72         @Test
73         public void checkNewTrans() {
74                 Assert.assertNotNull(authzEnv.newTrans());
75         }
76
77         @Test
78         public void checkPropAccess() {
79                 Assert.assertNotNull(authzEnv.access());
80         }
81
82         @Test
83         public void checkgetProperties() { //TODO:[GABE]No setter for this, add?
84                 Assert.assertNotNull(authzEnv.getProperties());
85                 Assert.assertNotNull(authzEnv.getProperties("test"));
86         }
87
88         @Test(expected = APIException.class)
89         public void checkSetLog4JNames() throws APIException {//TODO: Find better way to test instead of just seeing if strings pass
90                 authzEnv.setLog4JNames("path", "root","service","audit","init","trace");
91                 authzEnv.setLog4JNames("path", "root",null,"audit","init","trace");
92         }
93
94         @Test
95         public void checkPropertyGetters(){
96                 authzEnv.setProperty("key","value");
97                 Assert.assertEquals(authzEnv.getProperty("key"), "value");
98                 Assert.assertEquals(authzEnv.getProperty("key","value"), "value");
99         }
100
101         @Test
102         public void checkPropertySetters(){
103                 Assert.assertEquals(authzEnv.getProperty("key","value"), authzEnv.setProperty("key","value"));
104         }
105
106 //      @Test(expected = IOException.class)                             //TODO: AAF-111 make fail not happen
107 //      public void testDecryptException() throws IOException{
108 //              String encrypted = "enc:";
109 //              authzEnv.setProperty(Config.CADI_KEYFILE, "test");//TODO: Figure out setter for this
110 //              authzEnv.decrypt(encrypted, true);
111 //              authzEnv.decrypt("", false);            //TODO: AAF-111 fail without logging a fail
112 //      }
113
114         @Test
115         public void testDecrypt() throws IOException{
116                 String encrypted = "encrypted";
117                 String Result = authzEnv.decrypt(encrypted, true);
118                 assertEquals("encrypted",Result);
119         }
120
121         @Test
122         public void testClassLoader() {
123                 ClassLoader cLoad = mock(ClassLoader.class);
124                 cLoad = authzEnv.classLoader();
125                 Assert.assertNotNull(cLoad);
126         }
127
128         @Test
129         public void testLoad() throws IOException {
130                 InputStream is = mock(InputStream.class);
131                 authzEnv.load(is);
132         }
133
134         @Test
135         public void testLog() {
136                 Access.Level lvl = Access.Level.DEBUG;
137                 Object msgs = null;
138                 authzEnv.log(lvl, msgs);
139         }
140
141         @Test
142         public void testLog1() {
143                 Exception e = new Exception();
144                 Object msgs = null;
145                 authzEnv.log(e, msgs);
146         }
147
148         @Test
149         public void testPrintf() {
150                 Access.Level lvl = Access.Level.DEBUG;
151                 Object msgs = null;
152                 authzEnv.printf(lvl, "Test", msgs);
153         }
154
155         @Test
156         public void testWillLog() {
157                 Access.Level lvl = Access.Level.DEBUG;
158                 Access.Level lvl1 = Access.Level.AUDIT;
159                 boolean test = authzEnv.willLog(lvl);
160                 Assert.assertFalse(test);
161                 test = authzEnv.willLog(lvl1);
162                 Assert.assertTrue(test);
163
164         }
165
166         @Test
167         public void testSetLogLevel() {
168                 Access.Level lvl = Access.Level.DEBUG;
169                 authzEnv.setLogLevel(lvl);
170         }
171
172 }