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