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