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