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 assertNotNull(Result);
67 public void checkNewTransNoAvg() {
69 Assert.assertNotNull(authzEnv.newTransNoAvg());
73 public void checkNewTrans() {
74 Assert.assertNotNull(authzEnv.newTrans());
78 public void checkPropAccess() {
79 Assert.assertNotNull(authzEnv.access());
83 public void checkgetProperties() { //TODO:[GABE]No setter for this, add?
84 Assert.assertNotNull(authzEnv.getProperties());
85 Assert.assertNotNull(authzEnv.getProperties("test"));
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");
95 public void checkPropertyGetters(){
96 authzEnv.setProperty("key","value");
97 Assert.assertEquals(authzEnv.getProperty("key"), "value");
98 Assert.assertEquals(authzEnv.getProperty("key","value"), "value");
102 public void checkPropertySetters(){
103 Assert.assertEquals(authzEnv.getProperty("key","value"), authzEnv.setProperty("key","value"));
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
115 public void testDecrypt() throws IOException{
116 String encrypted = "encrypted";
117 String Result = authzEnv.decrypt(encrypted, true);
118 assertEquals("encrypted",Result);
122 public void testClassLoader() {
123 ClassLoader cLoad = mock(ClassLoader.class);
124 cLoad = authzEnv.classLoader();
125 Assert.assertNotNull(cLoad);
129 public void testLoad() throws IOException {
130 InputStream is = mock(InputStream.class);
135 public void testLog() {
136 Access.Level lvl = Access.Level.DEBUG;
138 authzEnv.log(lvl, msgs);
142 public void testLog1() {
143 Exception e = new Exception();
145 authzEnv.log(e, msgs);
149 public void testPrintf() {
150 Access.Level lvl = Access.Level.DEBUG;
152 authzEnv.printf(lvl, "Test", msgs);
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);
167 public void testSetLogLevel() {
168 Access.Level lvl = Access.Level.DEBUG;
169 authzEnv.setLogLevel(lvl);