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.*;
26 import javax.servlet.http.HttpServletRequest;
28 import org.junit.Assert;
29 import org.junit.Before;
30 import org.junit.Test;
31 import org.junit.runner.RunWith;
32 import org.mockito.runners.MockitoJUnitRunner;
33 import org.onap.aaf.auth.env.AuthzEnv;
34 import org.onap.aaf.auth.env.AuthzTrans;
35 import org.onap.aaf.auth.env.NullTrans;
36 import org.onap.aaf.auth.env.AuthzTrans.REQD_TYPE;
37 import org.onap.aaf.auth.org.Organization;
38 import org.onap.aaf.cadi.Permission;
39 import org.onap.aaf.misc.env.Decryptor;
40 import org.onap.aaf.misc.env.Encryptor;
41 import org.onap.aaf.misc.env.LogTarget;
42 import org.onap.aaf.misc.env.Slot;
43 import org.onap.aaf.misc.env.TimeTaken;
45 import static org.mockito.Mockito.mock;
46 import static org.mockito.Mockito.when;
48 import java.security.Principal;
49 import java.util.Date;
51 @RunWith(MockitoJUnitRunner.class)
52 public class JU_NullTrans {
57 nullTrans = new NullTrans();
61 public void testAuditTrail() {
62 Assert.assertNull(nullTrans.auditTrail(0, null, 0));
66 public void testSingleton() {
67 AuthzTrans single = nullTrans.singleton();
68 Assert.assertTrue(single instanceof AuthzTrans);
72 public void testCheckpoints() {
73 nullTrans.checkpoint("Test");
74 nullTrans.checkpoint(null, 0);
78 public void testFatal() {
79 LogTarget log = nullTrans.fatal();
80 Assert.assertEquals(LogTarget.NULL, log);
84 public void testError() {
85 LogTarget log = nullTrans.error();
86 Assert.assertEquals(LogTarget.NULL, log);
90 public void testAudit() {
91 LogTarget log = nullTrans.audit();
92 Assert.assertEquals(LogTarget.NULL, log);
96 public void testInit() {
97 LogTarget log = nullTrans.init();
98 Assert.assertEquals(LogTarget.NULL, log);
102 public void testWarn() {
103 LogTarget log = nullTrans.warn();
104 Assert.assertEquals(LogTarget.NULL, log);
108 public void testInfo() {
109 LogTarget log = nullTrans.info();
110 Assert.assertEquals(LogTarget.NULL, log);
114 public void testDebug() {
115 LogTarget log = nullTrans.debug();
116 Assert.assertEquals(LogTarget.NULL, log);
120 public void testTrace() {
121 LogTarget log = nullTrans.trace();
122 Assert.assertEquals(LogTarget.NULL, log);
126 public void testStart() {
127 TimeTaken test = nullTrans.start("test", 1);
128 StringBuilder sb = new StringBuilder();
130 StringBuilder sb1 = new StringBuilder();
132 String s = sb.toString();
133 String s1 = sb1.toString();
135 Assert.assertEquals(s,s1);
139 public void testSetProperty() {
141 String value = "value";
142 nullTrans.setProperty(tag, value);
143 String expected = nullTrans.getProperty(tag, value);
144 Assert.assertEquals(expected, value);
145 String expectedTag = nullTrans.getProperty(tag);
146 Assert.assertEquals(expectedTag, tag);
150 public void testDecryptor() {
151 Decryptor decry = nullTrans.decryptor();
152 Assert.assertNull(decry);
156 public void testEncryptor() {
157 Encryptor encry = nullTrans.encryptor();
158 Assert.assertNull(encry);
162 public void testSet() {
163 HttpServletRequest req = mock(HttpServletRequest.class);
164 AuthzTrans set = nullTrans.set(req);
165 Assert.assertNull(set);
169 public void testUser() {
170 String user = nullTrans.user();
171 Assert.assertNull(user);
175 public void testGetUserPrincipal() {
176 Principal principal = nullTrans.getUserPrincipal();
177 Assert.assertNull(principal);
181 public void testIp() {
182 String ip = nullTrans.ip();
183 Assert.assertNull(ip);
187 public void testMeth() {
188 String meth = nullTrans.meth();
189 Assert.assertNull(meth);
193 public void testPort() {
194 int port = nullTrans.port();
195 Assert.assertEquals(port,0);
199 public void testPath() {
200 String path = nullTrans.path();
201 Assert.assertNull(path);
205 public void testPut() {
206 nullTrans.put(null, nullTrans);
210 public void testSetUser() {
211 Principal principal = mock(Principal.class);
212 //nullTrans.setUser(principal);
216 public void testSlot() {
217 Slot slot = nullTrans.slot(null);
218 Assert.assertNull(slot);
222 public void testEnv() {
223 AuthzEnv env = nullTrans.env();
224 Assert.assertNull(env);
228 public void testAgent() {
229 String agent = nullTrans.agent();
230 Assert.assertNull(agent);
234 public void testSetLur() {
235 nullTrans.setLur(null);
239 public void testFish() {
240 Permission perm = mock(Permission.class);
241 Boolean fish = nullTrans.fish(perm);
242 Assert.assertFalse(fish);
246 public void testOrg() {
247 Organization org = nullTrans.org();
248 Assert.assertEquals(Organization.NULL, org);
252 public void testLogAuditTrail() {
253 LogTarget lt = mock(LogTarget.class);
254 nullTrans.logAuditTrail(lt);
258 public void testRequested() {
259 Boolean reqd = nullTrans.requested(null);
260 Assert.assertFalse(reqd);
261 nullTrans.requested(null, true);
265 public void testNow() {
266 Date date = new Date();
267 Assert.assertEquals(date,nullTrans.now());
268 //when(nullTrans.now()).thenReturn(null);