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;
31 import org.junit.Assert;
32 import org.junit.Before;
33 import org.junit.Test;
34 import org.junit.runner.RunWith;
35 import org.mockito.runners.MockitoJUnitRunner;
36 import org.onap.aaf.auth.env.AuthzEnv;
37 import org.onap.aaf.auth.env.AuthzTrans;
38 import org.onap.aaf.auth.env.NullTrans;
39 import org.onap.aaf.auth.org.Organization;
40 import org.onap.aaf.cadi.Permission;
41 import org.onap.aaf.misc.env.Decryptor;
42 import org.onap.aaf.misc.env.Encryptor;
43 import org.onap.aaf.misc.env.LogTarget;
44 import org.onap.aaf.misc.env.Slot;
45 import org.onap.aaf.misc.env.TimeTaken;
47 @RunWith(MockitoJUnitRunner.class)
48 public class JU_NullTrans {
53 nullTrans = new NullTrans();
57 public void testAuditTrail() {
58 Assert.assertNull(nullTrans.auditTrail(0, null, 0));
62 public void testSingleton() {
63 AuthzTrans single = nullTrans.singleton();
64 Assert.assertTrue(single instanceof AuthzTrans);
68 public void testCheckpoints() {
69 nullTrans.checkpoint("Test");
70 nullTrans.checkpoint(null, 0);
74 public void testFatal() {
75 LogTarget log = nullTrans.fatal();
76 Assert.assertEquals(LogTarget.NULL, log);
80 public void testError() {
81 LogTarget log = nullTrans.error();
82 Assert.assertEquals(LogTarget.NULL, log);
86 public void testAudit() {
87 LogTarget log = nullTrans.audit();
88 Assert.assertEquals(LogTarget.NULL, log);
92 public void testInit() {
93 LogTarget log = nullTrans.init();
94 Assert.assertEquals(LogTarget.NULL, log);
98 public void testWarn() {
99 LogTarget log = nullTrans.warn();
100 Assert.assertEquals(LogTarget.NULL, log);
104 public void testInfo() {
105 LogTarget log = nullTrans.info();
106 Assert.assertEquals(LogTarget.NULL, log);
110 public void testDebug() {
111 LogTarget log = nullTrans.debug();
112 Assert.assertEquals(LogTarget.NULL, log);
116 public void testTrace() {
117 LogTarget log = nullTrans.trace();
118 Assert.assertEquals(LogTarget.NULL, log);
122 public void testStart() {
123 TimeTaken test = nullTrans.start("test", 1);
124 StringBuilder sb = new StringBuilder();
126 StringBuilder sb1 = new StringBuilder();
128 String s = sb.toString();
129 String s1 = sb1.toString();
131 Assert.assertEquals(s,s1);
135 public void testSetProperty() {
137 String value = "value";
138 nullTrans.setProperty(tag, value);
139 String expected = nullTrans.getProperty(tag, value);
140 Assert.assertEquals(expected, value);
141 String expectedTag = nullTrans.getProperty(tag);
142 Assert.assertEquals(expectedTag, tag);
146 public void testDecryptor() {
147 Decryptor decry = nullTrans.decryptor();
148 Assert.assertNull(decry);
152 public void testEncryptor() {
153 Encryptor encry = nullTrans.encryptor();
154 Assert.assertNull(encry);
158 public void testSet() {
159 HttpServletRequest req = mock(HttpServletRequest.class);
160 AuthzTrans set = nullTrans.set(req);
161 Assert.assertNull(set);
165 public void testUser() {
166 String user = nullTrans.user();
167 Assert.assertNull(user);
171 public void testGetUserPrincipal() {
172 Principal principal = nullTrans.getUserPrincipal();
173 Assert.assertNull(principal);
177 public void testIp() {
178 String ip = nullTrans.ip();
179 Assert.assertNull(ip);
183 public void testMeth() {
184 String meth = nullTrans.meth();
185 Assert.assertNull(meth);
189 public void testPort() {
190 int port = nullTrans.port();
191 Assert.assertEquals(port,0);
195 public void testPath() {
196 String path = nullTrans.path();
197 Assert.assertNull(path);
201 public void testPut() {
202 nullTrans.put(null, nullTrans);
206 public void testSetUser() {
207 Principal principal = mock(Principal.class);
208 //nullTrans.setUser(principal);
212 public void testSlot() {
213 Slot slot = nullTrans.slot(null);
214 Assert.assertNull(slot);
218 public void testEnv() {
219 AuthzEnv env = nullTrans.env();
220 Assert.assertNull(env);
224 public void testAgent() {
225 String agent = nullTrans.agent();
226 Assert.assertNull(agent);
230 public void testSetLur() {
231 nullTrans.setLur(null);
235 public void testFish() {
236 Permission perm = mock(Permission.class);
237 Boolean fish = nullTrans.fish(perm);
238 Assert.assertFalse(fish);
242 public void testOrg() {
243 Organization org = nullTrans.org();
244 Assert.assertEquals(Organization.NULL, org);
248 public void testLogAuditTrail() {
249 LogTarget lt = mock(LogTarget.class);
250 nullTrans.logAuditTrail(lt);
254 public void testRequested() {
255 Boolean reqd = nullTrans.requested(null);
256 Assert.assertFalse(reqd);
257 nullTrans.requested(null, true);
260 // This is very inconsistent, and rather pointless
262 // public void testNow() {
263 // Date date = new Date();
264 // Assert.assertEquals(date,nullTrans.now());
265 // //when(nullTrans.now()).thenReturn(null);