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.mockito.Mockito.mock;
27 import java.security.Principal;
29 import javax.servlet.http.HttpServletRequest;
30 import javax.servlet.http.HttpServletResponse;
32 import org.junit.Assert;
33 import org.junit.Before;
34 import org.junit.Test;
35 import org.junit.runner.RunWith;
36 import org.mockito.runners.MockitoJUnitRunner;
37 import org.onap.aaf.auth.env.AuthzEnv;
38 import org.onap.aaf.auth.env.AuthzTrans;
39 import org.onap.aaf.auth.env.NullTrans;
40 import org.onap.aaf.auth.org.Organization;
41 import org.onap.aaf.cadi.Permission;
42 import org.onap.aaf.misc.env.Decryptor;
43 import org.onap.aaf.misc.env.Encryptor;
44 import org.onap.aaf.misc.env.LogTarget;
45 import org.onap.aaf.misc.env.Slot;
46 import org.onap.aaf.misc.env.TimeTaken;
48 @RunWith(MockitoJUnitRunner.class)
49 public class JU_NullTrans {
54 nullTrans = new NullTrans();
58 public void testAuditTrail() {
59 Assert.assertNull(nullTrans.auditTrail(0, null, 0));
63 public void testSingleton() {
64 AuthzTrans single = nullTrans.singleton();
65 Assert.assertTrue(single instanceof AuthzTrans);
69 public void testCheckpoints() {
70 nullTrans.checkpoint("Test");
71 nullTrans.checkpoint(null, 0);
75 public void testFatal() {
76 LogTarget log = nullTrans.fatal();
77 Assert.assertEquals(LogTarget.NULL, log);
81 public void testError() {
82 LogTarget log = nullTrans.error();
83 Assert.assertEquals(LogTarget.NULL, log);
87 public void testAudit() {
88 LogTarget log = nullTrans.audit();
89 Assert.assertEquals(LogTarget.NULL, log);
93 public void testInit() {
94 LogTarget log = nullTrans.init();
95 Assert.assertEquals(LogTarget.NULL, log);
99 public void testWarn() {
100 LogTarget log = nullTrans.warn();
101 Assert.assertEquals(LogTarget.NULL, log);
105 public void testInfo() {
106 LogTarget log = nullTrans.info();
107 Assert.assertEquals(LogTarget.NULL, log);
111 public void testDebug() {
112 LogTarget log = nullTrans.debug();
113 Assert.assertEquals(LogTarget.NULL, log);
117 public void testTrace() {
118 LogTarget log = nullTrans.trace();
119 Assert.assertEquals(LogTarget.NULL, log);
123 public void testStart() {
124 TimeTaken test = nullTrans.start("test", 1);
125 StringBuilder sb = new StringBuilder();
127 StringBuilder sb1 = new StringBuilder();
129 String s = sb.toString();
130 String s1 = sb1.toString();
132 Assert.assertEquals(s,s1);
136 public void testSetProperty() {
138 String value = "value";
139 nullTrans.setProperty(tag, value);
140 String expected = nullTrans.getProperty(tag, value);
141 Assert.assertEquals(expected, value);
142 String expectedTag = nullTrans.getProperty(tag);
143 Assert.assertEquals(expectedTag, tag);
147 public void testDecryptor() {
148 Decryptor decry = nullTrans.decryptor();
149 Assert.assertNull(decry);
153 public void testEncryptor() {
154 Encryptor encry = nullTrans.encryptor();
155 Assert.assertNull(encry);
159 public void testSet() {
160 HttpServletRequest req = mock(HttpServletRequest.class);
161 HttpServletResponse res = mock(HttpServletResponse.class);
162 AuthzTrans set = nullTrans.set(req,res);
163 Assert.assertNull(set);
167 public void testUser() {
168 String user = nullTrans.user();
169 Assert.assertNull(user);
173 public void testGetUserPrincipal() {
174 Principal principal = nullTrans.getUserPrincipal();
175 Assert.assertNull(principal);
179 public void testIp() {
180 String ip = nullTrans.ip();
181 Assert.assertNull(ip);
185 public void testMeth() {
186 String meth = nullTrans.meth();
187 Assert.assertNull(meth);
191 public void testPort() {
192 int port = nullTrans.port();
193 Assert.assertEquals(port,0);
197 public void testPath() {
198 String path = nullTrans.path();
199 Assert.assertNull(path);
203 public void testPut() {
204 nullTrans.put(null, nullTrans);
208 public void testSetUser() {
209 Principal principal = mock(Principal.class);
210 //nullTrans.setUser(principal);
214 public void testSlot() {
215 Slot slot = nullTrans.slot(null);
216 Assert.assertNull(slot);
220 public void testEnv() {
221 AuthzEnv env = nullTrans.env();
222 Assert.assertNull(env);
226 public void testAgent() {
227 String agent = nullTrans.agent();
228 Assert.assertNull(agent);
232 public void testSetLur() {
233 nullTrans.setLur(null);
237 public void testFish() {
238 Permission perm = mock(Permission.class);
239 Boolean fish = nullTrans.fish(perm);
240 Assert.assertFalse(fish);
244 public void testOrg() {
245 Organization org = nullTrans.org();
246 Assert.assertEquals(Organization.NULL, org);
250 public void testLogAuditTrail() {
251 LogTarget lt = mock(LogTarget.class);
252 nullTrans.logAuditTrail(lt);
256 public void testRequested() {
257 Boolean reqd = nullTrans.requested(null);
258 Assert.assertFalse(reqd);
259 nullTrans.requested(null, true);
262 // This is very inconsistent, and rather pointless
264 // public void testNow() {
265 // Date date = new Date();
266 // Assert.assertEquals(date,nullTrans.now());
267 // //when(nullTrans.now()).thenReturn(null);