1 /*******************************************************************************
2 * ============LICENSE_START====================================================
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
11 * * http://www.apache.org/licenses/LICENSE-2.0
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====================================================
21 ******************************************************************************/
22 package org.onap.aaf.auth.env.test;
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;
42 import junit.framework.Assert;
44 @RunWith(PowerMockRunner.class)
45 public class JU_AuthzEnv {
46 private static final org.onap.aaf.cadi.Access.Level DEBUG = null;
48 enum Level {DEBUG, INFO, AUDIT, INIT, WARN, ERROR};
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);
61 public void testTransRate() {
62 Long Result = authzEnv.transRate();
63 System.out.println("value of result " +Result); //Expected 300000
64 assertNotNull(Result);
68 public void checkNewTransNoAvg() {
70 Assert.assertNotNull(authzEnv.newTransNoAvg());
74 public void checkNewTrans() {
75 Assert.assertNotNull(authzEnv.newTrans());
79 public void checkPropAccess() {
80 Assert.assertNotNull(authzEnv.access());
84 public void checkgetProperties() { //TODO:[GABE]No setter for this, add?
85 Assert.assertNotNull(authzEnv.getProperties());
86 Assert.assertNotNull(authzEnv.getProperties("test"));
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");
96 public void checkPropertyGetters(){
97 authzEnv.setProperty("key","value");
98 Assert.assertEquals(authzEnv.getProperty("key"), "value");
99 Assert.assertEquals(authzEnv.getProperty("key","value"), "value");
103 public void checkPropertySetters(){
104 Assert.assertEquals(authzEnv.getProperty("key","value"), authzEnv.setProperty("key","value"));
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);
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);
124 public void testClassLoader() {
125 ClassLoader cLoad = mock(ClassLoader.class);
126 cLoad = authzEnv.classLoader();
127 Assert.assertNotNull(cLoad);
131 public void testLoad() throws IOException {
132 InputStream is = mock(InputStream.class);
137 public void testLog() {
138 Access.Level lvl = Access.Level.DEBUG;
140 authzEnv.log(lvl, msgs);
144 public void testLog1() {
145 Exception e = new Exception();
147 authzEnv.log(e, msgs);
151 public void testPrintf() {
152 Access.Level lvl = Access.Level.DEBUG;
154 authzEnv.printf(lvl, "Test", msgs);
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);
169 public void testSetLogLevel() {
170 Access.Level lvl = Access.Level.DEBUG;
171 authzEnv.setLogLevel(lvl);