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.assertEquals;
25 import static org.junit.Assert.assertNotNull;
26 import static org.mockito.Mockito.mock;
28 import java.io.IOException;
29 import java.io.InputStream;
30 import java.util.Properties;
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;
40 import junit.framework.Assert;
42 @RunWith(PowerMockRunner.class)
43 public class JU_AuthzEnv {
44 private static final org.onap.aaf.cadi.Access.Level DEBUG = null;
46 enum Level {DEBUG, INFO, AUDIT, INIT, WARN, ERROR};
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);
59 public void testTransRate() {
60 Long Result = authzEnv.transRate();
61 assertNotNull(Result);
65 public void checkNewTransNoAvg() {
67 Assert.assertNotNull(authzEnv.newTransNoAvg());
71 public void checkNewTrans() {
72 Assert.assertNotNull(authzEnv.newTrans());
76 public void checkPropAccess() {
77 Assert.assertNotNull(authzEnv.access());
81 public void checkgetProperties() { //TODO:[GABE]No setter for this, add?
82 Assert.assertNotNull(authzEnv.getProperties());
83 Assert.assertNotNull(authzEnv.getProperties("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");
94 public void checkPropertySetters(){
95 Assert.assertEquals(authzEnv.getProperty("key","value"), authzEnv.setProperty("key","value"));
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
107 public void testDecrypt() throws IOException{
108 String encrypted = "encrypted";
109 String Result = authzEnv.decrypt(encrypted, true);
110 assertEquals("encrypted",Result);
114 public void testClassLoader() {
115 ClassLoader cLoad = mock(ClassLoader.class);
116 cLoad = authzEnv.classLoader();
117 Assert.assertNotNull(cLoad);
121 public void testLoad() throws IOException {
122 InputStream is = mock(InputStream.class);
127 public void testLog() {
128 Access.Level lvl = Access.Level.DEBUG;
130 authzEnv.log(lvl, msgs);
134 public void testLog1() {
135 Exception e = new Exception();
137 authzEnv.log(e, msgs);
141 public void testPrintf() {
142 Access.Level lvl = Access.Level.DEBUG;
144 authzEnv.printf(lvl, "Test", msgs);
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);
159 public void testSetLogLevel() {
160 Access.Level lvl = Access.Level.DEBUG;
161 authzEnv.setLogLevel(lvl);