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.IOException;
29 import java.io.InputStream;
30 import java.io.PrintStream;
31 import java.io.ByteArrayOutputStream;
32 import java.util.Properties;
34 import org.onap.aaf.auth.env.AuthzEnv;
35 import org.onap.aaf.cadi.Access;
36 import org.onap.aaf.cadi.PropAccess;
37 import org.onap.aaf.cadi.config.Config;
39 public class JU_AuthzEnv {
43 ByteArrayOutputStream outStream;
44 ByteArrayOutputStream errStream;
48 outStream = new ByteArrayOutputStream();
49 errStream = new ByteArrayOutputStream();
51 System.setOut(new PrintStream(outStream));
52 System.setErr(new PrintStream(errStream));
54 authzEnv = new AuthzEnv();
58 public void tearDown() {
59 System.setOut(System.out);
60 System.setErr(System.err);
64 @SuppressWarnings("unused")
65 public void testConstructors() {
66 AuthzEnv authzEnv1 = new AuthzEnv("Test");
67 AuthzEnv authzEnv2 = new AuthzEnv((PropAccess)null);
68 AuthzEnv authzEnv3 = new AuthzEnv((Properties)null);
72 public void testTransRate() {
73 Long Result = authzEnv.transRate();
74 assertNotNull(Result);
78 public void checkNewTransNoAvg() {
79 assertNotNull(authzEnv.newTransNoAvg());
83 public void checkNewTrans() {
84 assertNotNull(authzEnv.newTrans());
88 public void checkPropAccess() {
89 assertNotNull(authzEnv.access());
93 public void checkgetProperties() { //TODO:[GABE]No setter for this, add?
94 assertNotNull(authzEnv.getProperties());
95 assertNotNull(authzEnv.getProperties("test"));
99 public void checkPropertyGetters(){
100 authzEnv.setProperty("key","value");
101 assertEquals(authzEnv.getProperty("key"), "value");
102 assertEquals(authzEnv.getProperty("key","value"), "value");
106 public void checkPropertySetters(){
107 assertEquals(authzEnv.getProperty("key","value"), authzEnv.setProperty("key","value"));
110 @Test(expected = IOException.class)
111 public void testDecryptException() throws IOException{
112 authzEnv.setProperty(Config.CADI_KEYFILE, "test/keyfile");
113 authzEnv.decrypt(null, false);
117 public void testDecrypt() throws IOException{
118 String encrypted = "encrypted";
119 String Result = authzEnv.decrypt(encrypted, true);
120 assertEquals("encrypted",Result);
124 public void testClassLoader() {
125 ClassLoader cLoad = mock(ClassLoader.class);
126 cLoad = authzEnv.classLoader();
127 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);
163 test = authzEnv.willLog(lvl1);
168 public void testSetLogLevel() {
169 Access.Level lvl = Access.Level.DEBUG;
170 authzEnv.setLogLevel(lvl);