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.junit.Assert.*;
27 import javax.servlet.http.HttpServletRequest;
29 import org.junit.Assert;
30 import org.junit.Before;
31 import org.junit.Test;
32 import org.junit.runner.RunWith;
33 import org.mockito.runners.MockitoJUnitRunner;
34 import org.onap.aaf.auth.env.AuthzEnv;
35 import org.onap.aaf.auth.env.AuthzTrans;
36 import org.onap.aaf.auth.env.NullTrans;
37 import org.onap.aaf.auth.env.AuthzTrans.REQD_TYPE;
38 import org.onap.aaf.auth.org.Organization;
39 import org.onap.aaf.cadi.Permission;
40 import org.onap.aaf.misc.env.Decryptor;
41 import org.onap.aaf.misc.env.Encryptor;
42 import org.onap.aaf.misc.env.LogTarget;
43 import org.onap.aaf.misc.env.Slot;
44 import org.onap.aaf.misc.env.TimeTaken;
46 import static org.mockito.Mockito.mock;
47 import static org.mockito.Mockito.when;
49 import java.security.Principal;
50 import java.util.Date;
52 @RunWith(MockitoJUnitRunner.class)
53 public class JU_NullTrans {
58 nullTrans = new NullTrans();
62 public void testAuditTrail() {
63 Assert.assertNull(nullTrans.auditTrail(0, null, 0));
67 public void testSingleton() {
68 AuthzTrans single = nullTrans.singleton();
69 Assert.assertTrue(single instanceof AuthzTrans);
73 public void testCheckpoints() {
74 nullTrans.checkpoint("Test");
75 nullTrans.checkpoint(null, 0);
79 public void testFatal() {
80 LogTarget log = nullTrans.fatal();
81 Assert.assertEquals(LogTarget.NULL, log);
85 public void testError() {
86 LogTarget log = nullTrans.error();
87 Assert.assertEquals(LogTarget.NULL, log);
91 public void testAudit() {
92 LogTarget log = nullTrans.audit();
93 Assert.assertEquals(LogTarget.NULL, log);
97 public void testInit() {
98 LogTarget log = nullTrans.init();
99 Assert.assertEquals(LogTarget.NULL, log);
103 public void testWarn() {
104 LogTarget log = nullTrans.warn();
105 Assert.assertEquals(LogTarget.NULL, log);
109 public void testInfo() {
110 LogTarget log = nullTrans.info();
111 Assert.assertEquals(LogTarget.NULL, log);
115 public void testDebug() {
116 LogTarget log = nullTrans.debug();
117 Assert.assertEquals(LogTarget.NULL, log);
121 public void testTrace() {
122 LogTarget log = nullTrans.trace();
123 Assert.assertEquals(LogTarget.NULL, log);
127 public void testStart() {
128 TimeTaken test = nullTrans.start("test", 1);
129 StringBuilder sb = new StringBuilder();
131 StringBuilder sb1 = new StringBuilder();
133 String s = sb.toString();
134 String s1 = sb1.toString();
136 Assert.assertEquals(s,s1);
140 public void testSetProperty() {
142 String value = "value";
143 nullTrans.setProperty(tag, value);
144 String expected = nullTrans.getProperty(tag, value);
145 Assert.assertEquals(expected, value);
146 String expectedTag = nullTrans.getProperty(tag);
147 Assert.assertEquals(expectedTag, tag);
151 public void testDecryptor() {
152 Decryptor decry = nullTrans.decryptor();
153 Assert.assertNull(decry);
157 public void testEncryptor() {
158 Encryptor encry = nullTrans.encryptor();
159 Assert.assertNull(encry);
163 public void testSet() {
164 HttpServletRequest req = mock(HttpServletRequest.class);
165 AuthzTrans set = nullTrans.set(req);
166 Assert.assertNull(set);
170 public void testUser() {
171 String user = nullTrans.user();
172 Assert.assertNull(user);
176 public void testGetUserPrincipal() {
177 Principal principal = nullTrans.getUserPrincipal();
178 Assert.assertNull(principal);
182 public void testIp() {
183 String ip = nullTrans.ip();
184 Assert.assertNull(ip);
188 public void testMeth() {
189 String meth = nullTrans.meth();
190 Assert.assertNull(meth);
194 public void testPort() {
195 int port = nullTrans.port();
196 Assert.assertEquals(port,0);
200 public void testPath() {
201 String path = nullTrans.path();
202 Assert.assertNull(path);
206 public void testPut() {
207 nullTrans.put(null, nullTrans);
211 public void testSetUser() {
212 Principal principal = mock(Principal.class);
213 //nullTrans.setUser(principal);
217 public void testSlot() {
218 Slot slot = nullTrans.slot(null);
219 Assert.assertNull(slot);
223 public void testEnv() {
224 AuthzEnv env = nullTrans.env();
225 Assert.assertNull(env);
229 public void testAgent() {
230 String agent = nullTrans.agent();
231 Assert.assertNull(agent);
235 public void testSetLur() {
236 nullTrans.setLur(null);
240 public void testFish() {
241 Permission perm = mock(Permission.class);
242 Boolean fish = nullTrans.fish(perm);
243 Assert.assertFalse(fish);
247 public void testOrg() {
248 Organization org = nullTrans.org();
249 Assert.assertEquals(Organization.NULL, org);
253 public void testLogAuditTrail() {
254 LogTarget lt = mock(LogTarget.class);
255 nullTrans.logAuditTrail(lt);
259 public void testRequested() {
260 Boolean reqd = nullTrans.requested(null);
261 Assert.assertFalse(reqd);
262 nullTrans.requested(null, true);
266 public void testNow() {
267 Date date = new Date();
268 Assert.assertEquals(date,nullTrans.now());
269 //when(nullTrans.now()).thenReturn(null);