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;
28 import java.io.ByteArrayOutputStream;
29 import java.io.IOException;
30 import java.io.InputStream;
31 import java.io.PrintStream;
32 import java.util.Properties;
33 import org.junit.After;
34 import org.junit.Before;
35 import org.junit.Test;
36 import org.junit.runner.RunWith;
37 import org.onap.aaf.auth.env.AuthzEnv;
38 import org.onap.aaf.cadi.Access;
39 import org.onap.aaf.cadi.PropAccess;
40 import org.onap.aaf.cadi.config.Config;
42 public class JU_AuthzEnv {
45 ByteArrayOutputStream outStream;
46 ByteArrayOutputStream errStream;
47 enum Level {DEBUG, INFO, AUDIT, INIT, WARN, ERROR};
51 outStream = new ByteArrayOutputStream();
52 errStream = new ByteArrayOutputStream();
54 System.setOut(new PrintStream(outStream));
55 System.setErr(new PrintStream(errStream));
57 authzEnv = new AuthzEnv();
61 public void tearDown() {
62 System.setOut(System.out);
63 System.setErr(System.err);
67 @SuppressWarnings("unused")
68 public void testConstructors() {
69 AuthzEnv authzEnv1 = new AuthzEnv("Test");
70 AuthzEnv authzEnv2 = new AuthzEnv((PropAccess)null);
71 AuthzEnv authzEnv3 = new AuthzEnv((Properties)null);
75 public void testTransRate() {
76 Long Result = authzEnv.transRate();
77 assertNotNull(Result);
81 public void checkNewTransNoAvg() {
82 assertNotNull(authzEnv.newTransNoAvg());
86 public void checkNewTrans() {
87 assertNotNull(authzEnv.newTrans());
91 public void checkPropAccess() {
92 assertNotNull(authzEnv.access());
96 public void checkgetProperties() { //TODO:[GABE]No setter for this, add?
97 assertNotNull(authzEnv.getProperties());
98 assertNotNull(authzEnv.getProperties("test"));
102 public void checkPropertyGetters(){
103 authzEnv.setProperty("key","value");
104 assertEquals(authzEnv.getProperty("key"), "value");
105 assertEquals(authzEnv.getProperty("key","value"), "value");
109 public void checkPropertySetters(){
110 assertEquals(authzEnv.getProperty("key","value"), authzEnv.setProperty("key","value"));
113 @Test(expected = IOException.class)
114 public void testDecryptException() throws IOException{
115 authzEnv.setProperty(Config.CADI_KEYFILE, "test/keyfile");
116 authzEnv.decrypt(null, false);
120 public void testDecrypt() throws IOException{
121 String encrypted = "encrypted";
122 String Result = authzEnv.decrypt(encrypted, true);
123 assertEquals("encrypted",Result);
127 public void testClassLoader() {
128 ClassLoader cLoad = mock(ClassLoader.class);
129 cLoad = authzEnv.classLoader();
130 assertNotNull(cLoad);
134 public void testLoad() throws IOException {
135 InputStream is = mock(InputStream.class);
140 public void testLog() {
141 Access.Level lvl = Access.Level.DEBUG;
143 authzEnv.log(lvl, msgs);
147 public void testLog1() {
149 Exception e = new Exception();
151 authzEnv.log(e, msgs);
155 public void testPrintf() {
156 Access.Level lvl = Access.Level.DEBUG;
158 authzEnv.printf(lvl, "Test", msgs);
162 public void testWillLog() {
163 Access.Level lvl = Access.Level.DEBUG;
164 Access.Level lvl1 = Access.Level.AUDIT;
165 boolean test = authzEnv.willLog(lvl);
167 test = authzEnv.willLog(lvl1);
172 public void testSetLogLevel() {
173 Access.Level lvl = Access.Level.DEBUG;
174 authzEnv.setLogLevel(lvl);