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 ******************************************************************************/
23 package org.onap.aaf.auth.env.test;
25 import static org.junit.Assert.*;
26 import static org.mockito.Mockito.mock;
29 import java.io.ByteArrayOutputStream;
30 import java.io.IOException;
31 import java.io.InputStream;
32 import java.io.PrintStream;
33 import java.util.Properties;
34 import org.junit.After;
35 import org.junit.Before;
36 import org.junit.Test;
37 import org.junit.runner.RunWith;
38 import org.onap.aaf.auth.env.AuthzEnv;
39 import org.onap.aaf.cadi.Access;
40 import org.onap.aaf.cadi.PropAccess;
41 import org.onap.aaf.cadi.config.Config;
43 public class JU_AuthzEnv {
46 ByteArrayOutputStream outStream;
47 ByteArrayOutputStream errStream;
48 enum Level {DEBUG, INFO, AUDIT, INIT, WARN, ERROR};
52 outStream = new ByteArrayOutputStream();
53 errStream = new ByteArrayOutputStream();
55 System.setOut(new PrintStream(outStream));
56 System.setErr(new PrintStream(errStream));
58 authzEnv = new AuthzEnv();
62 public void tearDown() {
63 System.setOut(System.out);
64 System.setErr(System.err);
68 @SuppressWarnings("unused")
69 public void testConstructors() {
70 AuthzEnv authzEnv1 = new AuthzEnv("Test");
71 AuthzEnv authzEnv2 = new AuthzEnv((PropAccess)null);
72 AuthzEnv authzEnv3 = new AuthzEnv((Properties)null);
76 public void testTransRate() {
77 Long Result = authzEnv.transRate();
78 assertNotNull(Result);
82 public void checkNewTransNoAvg() {
83 assertNotNull(authzEnv.newTransNoAvg());
87 public void checkNewTrans() {
88 assertNotNull(authzEnv.newTrans());
92 public void checkPropAccess() {
93 assertNotNull(authzEnv.access());
97 public void checkgetProperties() { //TODO:[GABE]No setter for this, add?
98 assertNotNull(authzEnv.getProperties());
99 assertNotNull(authzEnv.getProperties("test"));
103 public void checkPropertyGetters(){
104 authzEnv.setProperty("key","value");
105 assertEquals(authzEnv.getProperty("key"), "value");
106 assertEquals(authzEnv.getProperty("key","value"), "value");
110 public void checkPropertySetters(){
111 assertEquals(authzEnv.getProperty("key","value"), authzEnv.setProperty("key","value"));
114 @Test(expected = IOException.class)
115 public void testDecryptException() throws IOException{
116 authzEnv.setProperty(Config.CADI_KEYFILE, "test/keyfile");
117 authzEnv.decrypt(null, false);
121 public void testDecrypt() throws IOException{
122 String encrypted = "encrypted";
123 String Result = authzEnv.decrypt(encrypted, true);
124 assertEquals("encrypted",Result);
128 public void testClassLoader() {
129 ClassLoader cLoad = mock(ClassLoader.class);
130 cLoad = authzEnv.classLoader();
131 assertNotNull(cLoad);
135 public void testLoad() throws IOException {
136 InputStream is = mock(InputStream.class);
141 public void testLog() {
142 Access.Level lvl = Access.Level.DEBUG;
144 authzEnv.log(lvl, msgs);
148 public void testLog1() {
150 Exception e = new Exception();
152 authzEnv.log(e, msgs);
156 public void testPrintf() {
157 Access.Level lvl = Access.Level.DEBUG;
159 authzEnv.printf(lvl, "Test", msgs);
163 public void testWillLog() {
164 Access.Level lvl = Access.Level.DEBUG;
165 Access.Level lvl1 = Access.Level.AUDIT;
166 boolean test = authzEnv.willLog(lvl);
168 test = authzEnv.willLog(lvl1);
173 public void testSetLogLevel() {
174 Access.Level lvl = Access.Level.DEBUG;
175 authzEnv.setLogLevel(lvl);