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