AT&T 2.0.19 Code drop, stage 3
[aaf/authz.git] / auth / auth-core / src / test / java / org / onap / aaf / auth / env / test / JU_NullTrans.java
1 /*******************************************************************************
2  * ============LICENSE_START====================================================
3  * * org.onap.aaf
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
10  * * 
11  *  *      http://www.apache.org/licenses/LICENSE-2.0
12  * * 
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====================================================
19  * *
20  * *
21  ******************************************************************************/
22 package org.onap.aaf.auth.env.test;
23
24 import static org.junit.Assert.*;
25
26 import javax.servlet.http.HttpServletRequest;
27
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;
44
45 import static org.mockito.Mockito.mock;
46 import static org.mockito.Mockito.when;
47
48 import java.security.Principal;
49 import java.util.Date;
50
51 @RunWith(MockitoJUnitRunner.class)
52 public class JU_NullTrans {
53         NullTrans nullTrans;
54         
55         @Before
56         public void setUp(){
57                 nullTrans = new NullTrans();
58         }
59         
60         @Test
61         public void testAuditTrail() {
62                 Assert.assertNull(nullTrans.auditTrail(0, null, 0));
63         }
64         
65         @Test
66         public void testSingleton() {
67                 AuthzTrans single = nullTrans.singleton();
68                 Assert.assertTrue(single instanceof AuthzTrans);
69         }
70         
71         @Test
72         public void testCheckpoints() {
73                 nullTrans.checkpoint("Test");
74                 nullTrans.checkpoint(null, 0);
75         }
76         
77         @Test
78         public void testFatal() {
79                 LogTarget log = nullTrans.fatal();
80                 Assert.assertEquals(LogTarget.NULL, log);
81         }
82         
83         @Test
84         public void testError() {
85                 LogTarget log = nullTrans.error();
86                 Assert.assertEquals(LogTarget.NULL, log);
87         }
88         
89         @Test
90         public void testAudit() {
91                 LogTarget log = nullTrans.audit();
92                 Assert.assertEquals(LogTarget.NULL, log);
93         }
94         
95         @Test
96         public void testInit() {
97                 LogTarget log = nullTrans.init();
98                 Assert.assertEquals(LogTarget.NULL, log);
99         }
100         
101         @Test
102         public void testWarn() {
103                 LogTarget log = nullTrans.warn();
104                 Assert.assertEquals(LogTarget.NULL, log);
105         }
106         
107         @Test
108         public void testInfo() {
109                 LogTarget log = nullTrans.info();
110                 Assert.assertEquals(LogTarget.NULL, log);
111         }
112         
113         @Test
114         public void testDebug() {
115                 LogTarget log = nullTrans.debug();
116                 Assert.assertEquals(LogTarget.NULL, log);
117         }
118
119         @Test
120         public void testTrace() {
121                 LogTarget log = nullTrans.trace();
122                 Assert.assertEquals(LogTarget.NULL, log);
123         }
124         
125         @Test
126         public void testStart() {
127                 TimeTaken test = nullTrans.start("test", 1);
128                 StringBuilder sb = new StringBuilder();
129                 test.output(sb);
130                 StringBuilder sb1 = new StringBuilder();
131                 sb1.append(test);
132                 String s = sb.toString();
133                 String s1 = sb1.toString();
134                 s1 = s1.trim();
135                 Assert.assertEquals(s,s1);
136         }
137         
138         @Test
139         public void testSetProperty() {
140                 String tag = "tag";
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);
147         }
148         
149         @Test
150         public void testDecryptor() {
151                 Decryptor decry = nullTrans.decryptor();
152                 Assert.assertNull(decry);
153         }
154         
155         @Test
156         public void testEncryptor() {
157                 Encryptor encry = nullTrans.encryptor();
158                 Assert.assertNull(encry);
159         }
160         
161         @Test
162         public void testSet() {
163                 HttpServletRequest req = mock(HttpServletRequest.class);
164                 AuthzTrans set = nullTrans.set(req);
165                 Assert.assertNull(set);
166         }
167         
168         @Test
169         public void testUser() {
170                 String user = nullTrans.user();
171                 Assert.assertNull(user);
172         }
173         
174         @Test
175         public void testGetUserPrincipal() {
176                 Principal principal = nullTrans.getUserPrincipal();
177                 Assert.assertNull(principal);
178         }
179         
180         @Test
181         public void testIp() {
182                 String ip = nullTrans.ip();
183                 Assert.assertNull(ip);
184         }
185         
186         @Test
187         public void testMeth() {
188                 String meth = nullTrans.meth();
189                 Assert.assertNull(meth);
190         }
191         
192         @Test
193         public void testPort() {
194                 int port = nullTrans.port();
195                 Assert.assertEquals(port,0);
196         }
197         
198         @Test
199         public void testPath() {
200                 String path = nullTrans.path();
201                 Assert.assertNull(path);
202         }
203         
204         @Test
205         public void testPut() {
206                 nullTrans.put(null, nullTrans);
207         }
208         
209         @Test
210         public void testSetUser() {
211                 Principal principal = mock(Principal.class);
212                 //nullTrans.setUser(principal);
213         }
214         
215         @Test
216         public void testSlot() {
217                 Slot slot = nullTrans.slot(null);
218                 Assert.assertNull(slot);
219         }
220         
221         @Test
222         public void testEnv() {
223                 AuthzEnv env = nullTrans.env();
224                 Assert.assertNull(env);
225         }
226         
227         @Test
228         public void testAgent() {
229                 String agent = nullTrans.agent();
230                 Assert.assertNull(agent);
231         }
232         
233         @Test
234         public void testSetLur() {
235                 nullTrans.setLur(null);
236         }
237         
238         @Test
239         public void testFish() {
240                 Permission perm = mock(Permission.class);
241                 Boolean fish = nullTrans.fish(perm);
242                 Assert.assertFalse(fish);
243         }
244         
245         @Test
246         public void testOrg() {
247                 Organization org = nullTrans.org();
248                 Assert.assertEquals(Organization.NULL, org);
249         }
250         
251         @Test
252         public void testLogAuditTrail() {
253                 LogTarget lt = mock(LogTarget.class);
254                 nullTrans.logAuditTrail(lt);
255         }
256         
257         @Test
258         public void testRequested() {
259                 Boolean reqd = nullTrans.requested(null);
260                 Assert.assertFalse(reqd);
261                 nullTrans.requested(null, true);
262         }
263         
264         @Test
265         public void testNow() {
266                 Date date = new Date();
267                 Assert.assertEquals(date,nullTrans.now());
268                 //when(nullTrans.now()).thenReturn(null);
269         }
270         
271         
272         
273 }