AT&T 2.0.19 Code drop, stage 3
[aaf/authz.git] / authz-cmd / src / test / java / org / onap / aaf / cmd / user / JU_Cred.java
1 /*******************************************************************************\r
2  * ============LICENSE_START====================================================\r
3  * * org.onap.aaf\r
4  * * ===========================================================================\r
5  * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
6  * * ===========================================================================\r
7  * * Licensed under the Apache License, Version 2.0 (the "License");\r
8  * * you may not use this file except in compliance with the License.\r
9  * * You may obtain a copy of the License at\r
10  * * \r
11  *  *      http://www.apache.org/licenses/LICENSE-2.0\r
12  * * \r
13  *  * Unless required by applicable law or agreed to in writing, software\r
14  * * distributed under the License is distributed on an "AS IS" BASIS,\r
15  * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
16  * * See the License for the specific language governing permissions and\r
17  * * limitations under the License.\r
18  * * ============LICENSE_END====================================================\r
19  * *\r
20  * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
21  * *\r
22  ******************************************************************************/\r
23 package org.onap.aaf.cmd.user;\r
24 \r
25 import static org.junit.Assert.assertEquals;\r
26 import static org.junit.Assert.assertNotNull;\r
27 import static org.mockito.Mockito.mock;\r
28 import static org.mockito.Mockito.when;\r
29 \r
30 import java.io.FileNotFoundException;\r
31 import java.io.PrintWriter;\r
32 \r
33 import org.junit.BeforeClass;\r
34 import org.junit.Test;\r
35 import org.junit.runner.RunWith;\r
36 import org.mockito.Mockito;\r
37 import org.mockito.runners.MockitoJUnitRunner;\r
38 import org.onap.aaf.cmd.AAFcli;\r
39 import org.onap.aaf.cmd.Cmd;\r
40 import org.onap.aaf.cmd.user.Cred;\r
41 import org.onap.aaf.cmd.user.User;\r
42 import org.onap.aaf.authz.env.AuthzEnv;\r
43 import org.onap.aaf.cadi.CadiException;\r
44 import org.onap.aaf.cadi.LocatorException;\r
45 import org.onap.aaf.inno.env.APIException;\r
46 \r
47 @RunWith(MockitoJUnitRunner.class)\r
48 public class JU_Cred {\r
49 \r
50         private static Cred testCred;\r
51         private static User testUser;\r
52         private static AuthzEnv env;\r
53 \r
54 \r
55         @BeforeClass\r
56         public static void setUp() throws FileNotFoundException, APIException {\r
57                 \r
58                 testCred = mock(Cred.class);\r
59                 testUser = mock(User.class);\r
60                 env = mock(AuthzEnv.class);\r
61                 Mockito.when(env.getProperty(Cmd.STARTDATE,null)).thenReturn(null);\r
62                 Mockito.when(env.getProperty(Cmd.ENDDATE,null)).thenReturn(null);\r
63                 \r
64         }\r
65 \r
66         @Test\r
67         public void exec() throws CadiException, APIException, LocatorException, FileNotFoundException {\r
68                 boolean isNullpointer=false;\r
69                 AAFcli aaFcli=  new AAFcli(env, new PrintWriter("temp"), null, null, null);\r
70         User user= new User(aaFcli);\r
71          Cred testCred= new Cred(user);\r
72         try {\r
73                 testCred._exec(0, "add", "del", "reset", "extend");\r
74         } catch (Exception e) {\r
75                 isNullpointer=true;\r
76         } \r
77         assertEquals(isNullpointer, true);\r
78         }\r
79 \r
80 \r
81         @Test\r
82         public void exec_add() {                \r
83                 try {\r
84                         assertNotNull(testCred._exec(0, "zeroed","add","del","reset","extend"));\r
85                 } catch (CadiException | APIException | LocatorException e) {\r
86                         // TODO Auto-generated catch block\r
87                         e.printStackTrace();\r
88                 }\r
89 \r
90         }\r
91 \r
92         @Test\r
93         public void exec_del() {                \r
94                 try {\r
95                         assertNotNull(testCred._exec(1, "zeroed","add","del","reset","extend"));\r
96                 } catch (CadiException | APIException | LocatorException e) {\r
97                         // TODO Auto-generated catch block\r
98                         e.printStackTrace();\r
99                 }\r
100 \r
101         }\r
102 \r
103         @Test\r
104         public void exec_reset() {              \r
105                 try {\r
106                         assertNotNull(testCred._exec(2, "zeroed","add","del","reset","extend"));\r
107                 } catch (CadiException | APIException | LocatorException e) {\r
108                         // TODO Auto-generated catch block\r
109                         e.printStackTrace();\r
110                 }\r
111 \r
112         }\r
113 \r
114         @Test\r
115         public void exec_extend() {             \r
116                 try {\r
117                         assertNotNull(testCred._exec(3, "zeroed","add","del","reset","extend"));\r
118                 } catch (CadiException | APIException | LocatorException e) {\r
119                         // TODO Auto-generated catch block\r
120                         e.printStackTrace();\r
121                 }\r
122 \r
123         }\r
124 \r
125 }\r