AT&T 2.0.19 Code drop, stage 3
[aaf/authz.git] / auth / auth-cmd / src / test / java / org / onap / aaf / auth / cmd / test / user / JU_Cred.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.cmd.test.user;
23
24 import static org.junit.Assert.assertEquals;
25 import static org.junit.Assert.assertNotNull;
26 import static org.mockito.Mockito.mock;
27 import static org.mockito.Mockito.when;
28
29 import java.io.FileNotFoundException;
30 import java.io.PrintWriter;
31
32 import org.junit.BeforeClass;
33 import org.junit.Test;
34 import org.junit.runner.RunWith;
35 import org.mockito.Mockito;
36 import org.mockito.runners.MockitoJUnitRunner;
37 import org.onap.aaf.auth.cmd.AAFcli;
38 import org.onap.aaf.auth.cmd.Cmd;
39 import org.onap.aaf.auth.cmd.user.Cred;
40 import org.onap.aaf.auth.cmd.user.User;
41 import org.onap.aaf.auth.env.AuthzEnv;
42 import org.onap.aaf.cadi.CadiException;
43 import org.onap.aaf.cadi.LocatorException;
44 import org.onap.aaf.misc.env.APIException;
45
46 @RunWith(MockitoJUnitRunner.class)
47 public class JU_Cred {
48
49         private static Cred testCred;
50         private static User testUser;
51         private static AuthzEnv env;
52
53
54         @BeforeClass
55         public static void setUp() throws FileNotFoundException, APIException {
56                 
57                 testCred = mock(Cred.class);
58                 testUser = mock(User.class);
59                 env = mock(AuthzEnv.class);
60                 Mockito.when(env.getProperty(Cmd.STARTDATE,null)).thenReturn(null);
61                 Mockito.when(env.getProperty(Cmd.ENDDATE,null)).thenReturn(null);
62                 
63         }
64
65         @Test
66         public void exec() throws CadiException, APIException, LocatorException, FileNotFoundException {
67                 boolean isNullpointer=false;
68                 AAFcli aaFcli=  new AAFcli(env, new PrintWriter("temp"), null, null, null);
69         User user= new User(aaFcli);
70          Cred testCred= new Cred(user);
71         try {
72                 testCred._exec(0, "add", "del", "reset", "extend");
73         } catch (Exception e) {
74                 isNullpointer=true;
75         } 
76         assertEquals(isNullpointer, true);
77         }
78
79
80         @Test
81         public void exec_add() {                
82                 try {
83                         assertNotNull(testCred._exec(0, "zeroed","add","del","reset","extend"));
84                 } catch (CadiException | APIException | LocatorException e) {
85                         // TODO Auto-generated catch block
86                         e.printStackTrace();
87                 }
88
89         }
90
91         @Test
92         public void exec_del() {                
93                 try {
94                         assertNotNull(testCred._exec(1, "zeroed","add","del","reset","extend"));
95                 } catch (CadiException | APIException | LocatorException e) {
96                         // TODO Auto-generated catch block
97                         e.printStackTrace();
98                 }
99
100         }
101
102         @Test
103         public void exec_reset() {              
104                 try {
105                         assertNotNull(testCred._exec(2, "zeroed","add","del","reset","extend"));
106                 } catch (CadiException | APIException | LocatorException e) {
107                         // TODO Auto-generated catch block
108                         e.printStackTrace();
109                 }
110
111         }
112
113         @Test
114         public void exec_extend() {             
115                 try {
116                         assertNotNull(testCred._exec(3, "zeroed","add","del","reset","extend"));
117                 } catch (CadiException | APIException | LocatorException e) {
118                         // TODO Auto-generated catch block
119                         e.printStackTrace();
120                 }
121
122         }
123
124 }