AT&T 2.0.19 Code drop, stage 3
[aaf/authz.git] / authz-cmd / src / test / java / org / onap / aaf / cmd / JU_BaseCmd.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;\r
24 \r
25 import static org.junit.Assert.assertEquals;\r
26 \r
27 import java.io.IOException;\r
28 import java.security.GeneralSecurityException;\r
29 import java.util.Date;\r
30 import java.util.GregorianCalendar;\r
31 \r
32 import javax.xml.datatype.DatatypeConfigurationException;\r
33 import javax.xml.datatype.DatatypeFactory;\r
34 import javax.xml.datatype.XMLGregorianCalendar;\r
35 \r
36 import org.junit.BeforeClass;\r
37 import org.junit.Test;\r
38 import org.junit.runner.RunWith;\r
39 import org.mockito.runners.MockitoJUnitRunner;\r
40 import org.onap.aaf.cadi.CadiException;\r
41 import org.onap.aaf.cadi.LocatorException;\r
42 import org.onap.aaf.cadi.client.Future;\r
43 import org.onap.aaf.inno.env.APIException;\r
44 \r
45 import aaf.v2_0.History;\r
46 \r
47 @RunWith(MockitoJUnitRunner.class)\r
48 public class JU_BaseCmd {\r
49 \r
50         private static AAFcli cli;\r
51         private static BaseCmd bCmd;\r
52 \r
53         @BeforeClass\r
54         public static void setUp() throws APIException, LocatorException, GeneralSecurityException, IOException {\r
55                 cli = JU_AAFCli.getAAfCli();\r
56                 bCmd = new BaseCmd<>(cli, "testString");\r
57         }\r
58 \r
59         @Test\r
60         public void exec() throws CadiException, APIException, LocatorException {\r
61                 assertEquals(bCmd._exec(4, "add", "del", "reset", "extend"), 0);\r
62 \r
63         }\r
64         \r
65         @Test\r
66         public void exec1() throws CadiException, APIException, LocatorException {\r
67                 assertEquals(bCmd._exec(0, "add", "del", "reset", "extend"), 0);\r
68 \r
69         }\r
70 \r
71         @Test\r
72         public void error() throws CadiException, APIException, LocatorException {\r
73                 boolean noError = true;\r
74                 Future<String> future = new Future<String>() {\r
75 \r
76                         @Override\r
77                         public boolean get(int timeout) throws CadiException {\r
78                                 // TODO Auto-generated method stub\r
79                                 return false;\r
80                         }\r
81 \r
82                         @Override\r
83                         public int code() {\r
84                                 // TODO Auto-generated method stub\r
85                                 return 0;\r
86                         }\r
87 \r
88                         @Override\r
89                         public String body() {\r
90                                 // TODO Auto-generated method stub\r
91                                 return "{%}";\r
92                         }\r
93 \r
94                         @Override\r
95                         public String header(String tag) {\r
96                                 // TODO Auto-generated method stub\r
97                                 return null;\r
98                         }\r
99                 };\r
100                 try {\r
101                         bCmd.error(future);\r
102                 } catch (Exception e) {\r
103                         noError = false;\r
104                 }\r
105                 assertEquals(noError, true);\r
106 \r
107         }\r
108 \r
109 \r
110 \r
111         @Test\r
112         public void activity() throws DatatypeConfigurationException {\r
113                 boolean noError = true;\r
114                 History history = new History();\r
115                 History.Item item = new History.Item();\r
116                 item.setTarget("target");\r
117                 item.setUser("user");\r
118                 item.setMemo("memo");\r
119 \r
120                 GregorianCalendar c = new GregorianCalendar();\r
121                 c.setTime(new Date());\r
122                 XMLGregorianCalendar date = DatatypeFactory.newInstance().newXMLGregorianCalendar(c);\r
123                 item.setTimestamp(date);\r
124                 history.getItem().add(item);\r
125                 try {\r
126                         bCmd.activity(history, "history");\r
127                 } catch (Exception e) {\r
128                         noError = false;\r
129                 }\r
130                 assertEquals(noError, true);\r
131 \r
132         }\r
133 \r
134         @Test\r
135         public void activity1() throws DatatypeConfigurationException {\r
136                 boolean noError = true;\r
137                 History history = new History();\r
138                 History.Item item = new History.Item();\r
139                 item.setTarget("target");\r
140                 item.setUser("user");\r
141                 item.setMemo("memo");\r
142 \r
143                 GregorianCalendar c = new GregorianCalendar();\r
144                 c.setTime(new Date());\r
145                 XMLGregorianCalendar date = DatatypeFactory.newInstance().newXMLGregorianCalendar(c);\r
146                 item.setTimestamp(date);\r
147                 history.getItem().add(item);\r
148                 try {\r
149                         bCmd.activity(history, "1[]");\r
150                 } catch (Exception e) {\r
151                         noError = false;\r
152                 }\r
153                 assertEquals(noError, true);\r
154 \r
155         }\r
156         \r
157 \r
158 \r
159         @Test\r
160         public void error1() {\r
161                 boolean noError = true;\r
162                 Future<String> future = new Future<String>() {\r
163 \r
164                         @Override\r
165                         public boolean get(int timeout) throws CadiException {\r
166                                 // TODO Auto-generated method stub\r
167                                 return false;\r
168                         }\r
169 \r
170                         @Override\r
171                         public int code() {\r
172                                 // TODO Auto-generated method stub\r
173                                 return 0;\r
174                         }\r
175 \r
176                         @Override\r
177                         public String body() {\r
178                                 // TODO Auto-generated method stub\r
179                                 return "{<html><code>1</code></html>";\r
180                         }\r
181 \r
182                         @Override\r
183                         public String header(String tag) {\r
184                                 // TODO Auto-generated method stub\r
185                                 return null;\r
186                         }\r
187                 };\r
188                 try {\r
189                         bCmd.error(future);\r
190                 } catch (Exception e) {\r
191                         noError = false;\r
192                 }\r
193                 assertEquals(noError, true);\r
194 \r
195         }\r
196 \r
197         @Test\r
198         public void error2() {\r
199                 boolean noError = true;\r
200                 Future<String> future = new Future<String>() {\r
201 \r
202                         @Override\r
203                         public boolean get(int timeout) throws CadiException {\r
204                                 // TODO Auto-generated method stub\r
205                                 return false;\r
206                         }\r
207 \r
208                         @Override\r
209                         public int code() {\r
210                                 // TODO Auto-generated method stub\r
211                                 return 0;\r
212                         }\r
213 \r
214                         @Override\r
215                         public String body() {\r
216                                 // TODO Auto-generated method stub\r
217                                 return "other";\r
218                         }\r
219 \r
220                         @Override\r
221                         public String header(String tag) {\r
222                                 // TODO Auto-generated method stub\r
223                                 return null;\r
224                         }\r
225                 };\r
226                 try {\r
227                         bCmd.error(future);\r
228                 } catch (Exception e) {\r
229                         noError = false;\r
230                 }\r
231                 assertEquals(noError, true);\r
232 \r
233         }\r
234 \r
235 }\r