2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2018 Nokia Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Modifications Copyright (C) 2018 IBM.
8 * ================================================================================
9 * Modifications Copyright (C) 2019 Ericsson
10 * ================================================================================
11 * Licensed under the Apache License, Version 2.0 (the "License");
12 * you may not use this file except in compliance with the License.
13 * You may obtain a copy of the License at
15 * http://www.apache.org/licenses/LICENSE-2.0
17 * Unless required by applicable law or agreed to in writing, software
18 * distributed under the License is distributed on an "AS IS" BASIS,
19 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 * See the License for the specific language governing permissions and
21 * limitations under the License.
23 * ============LICENSE_END=========================================================
25 package org.onap.appc.flow.controller.data;
27 import static org.mockito.Mockito.mock;
28 import static org.mockito.Mockito.when;
29 import static org.junit.Assert.assertEquals;
30 import static org.junit.Assert.assertFalse;
31 import static org.junit.Assert.assertTrue;
32 import java.util.ArrayList;
33 import org.junit.Before;
34 import org.junit.Test;
36 public class TransactionTest {
38 private Transaction transaction;
42 transaction = new Transaction();
46 public void get_set_pass() {
47 String somePwsd = "some_pass";
48 transaction.setPswd(somePwsd);
49 assertEquals(somePwsd, transaction.getPswd());
53 public void get_set_precheck() {
54 PreCheck precheck = mock(PreCheck.class);
55 transaction.setPrecheck(precheck);
56 assertEquals(precheck, transaction.getPrecheck());
60 public void get_set_state() {
61 String state = "some_state";
62 transaction.setState(state);
63 assertEquals(state, transaction.getState());
67 public void get_set_status_code() {
68 String statusCode = "status_code";
69 transaction.setStatusCode(statusCode);
70 assertEquals(statusCode, transaction.getStatusCode());
74 public void get_set_transaction_id() {
76 transaction.setTransactionId(id);
77 assertEquals(id, transaction.getTransactionId());
81 public void get_set_responses() {
82 ArrayList<Response> responses = new ArrayList<>();
83 responses.add(mock(Response.class));
84 transaction.setResponses(responses);
85 assertEquals(responses, transaction.getResponses());
89 public void get_set_parameters() {
90 ArrayList<Parameters> parameters = new ArrayList<>();
91 parameters.add(mock(Parameters.class));
92 transaction.setParameters(parameters);
93 assertEquals(parameters, transaction.getParameters());
97 public void get_set_payload() {
98 String payload = "some_payload";
99 transaction.setPayload(payload);
100 assertEquals(payload, transaction.getPayload());
104 public void get_set_execution_rpc() {
105 String executionRPC = "some_exec_rpc";
106 transaction.setExecutionRPC(executionRPC);
107 assertEquals(executionRPC, transaction.getExecutionRPC());
111 public void get_set_execution_module() {
112 String executionModule = "some_exec_module";
113 transaction.setExecutionModule(executionModule);
114 assertEquals(executionModule, transaction.getExecutionModule());
118 public void get_set_execution_type() {
119 String executionType = "some_exec_type";
120 transaction.setExecutionType(executionType);
121 assertEquals(executionType, transaction.getExecutionType());
125 public void get_set_execution_endpoint() {
126 String executionEndpoint = "some_exec_endpoint";
127 transaction.setExecutionEndPoint(executionEndpoint);
128 assertEquals(executionEndpoint, transaction.getExecutionEndPoint());
132 public void get_set_uid() {
133 String uid = "some_uid";
134 transaction.setuId(uid);
135 assertEquals(uid, transaction.getuId());
139 public void get_set_action_level() {
140 String actionLevel = "some_action_level";
141 transaction.setActionLevel(actionLevel);
142 assertEquals(actionLevel, transaction.getActionLevel());
146 public void get_set_action_identifier() {
147 ActionIdentifier actionIdentifier = mock(ActionIdentifier.class);
148 transaction.setActionIdentifier(actionIdentifier);
149 assertEquals(actionIdentifier, transaction.getActionIdentifier());
153 public void get_set_action() {
154 String action = "some_action";
155 transaction.setAction(action);
156 assertEquals(action, transaction.getAction());
160 public void get_set_status() {
161 String status = "some_status";
162 transaction.setStatus(status);
163 assertEquals(status, transaction.getStatus());
167 public void to_string() {
169 ActionIdentifier actionIdentifier = mock(ActionIdentifier.class);
170 when(actionIdentifier.toString()).thenReturn("some_action_identifier");
172 PreCheck precheck = mock(PreCheck.class);
173 when(precheck.toString()).thenReturn("some_precheck");
175 Response response = mock(Response.class);
176 when(response.toString()).thenReturn("some_response");
177 ArrayList<Response> responses = new ArrayList<>();
178 responses.add(response);
180 Parameters parameters = mock(Parameters.class);
181 when(parameters.toString()).thenReturn("some_parameters");
182 ArrayList<Parameters> parametersList = new ArrayList<>();
183 parametersList.add(parameters);
185 transaction.setAction("some_action");
186 transaction.setActionIdentifier(actionIdentifier);
187 transaction.setActionLevel("some_action_level");
188 transaction.setExecutionRPC("some_execution_rpc");
189 transaction.setExecutionType("some_execution_type");
190 transaction.setExecutionModule("some_execution_module");
191 transaction.setExecutionEndPoint("some_execution_endpoint");
192 transaction.setState("some_state");
193 transaction.setStatus("some_status");
194 transaction.setStatusCode("some_status_code");
195 transaction.setPswd("some_pass");
196 transaction.setPayload("some_payload");
197 transaction.setPrecheck(precheck);
198 transaction.setParameters(parametersList);
199 transaction.setResponses(responses);
200 transaction.setTransactionId(133);
201 transaction.setuId("some_uid");
204 "Transaction [transactionId=133, action=some_action, actionLevel=some_action_level, actionIdentifier=some_action_identifier, parameters=[some_parameters], executionType=some_execution_type, uId=some_uid, statusCode=some_status_code, pswd=some_pass, executionEndPoint=some_execution_endpoint, executionModule=some_execution_module, executionRPC=some_execution_rpc, state=some_state, precheck=some_precheck, payload=some_payload, responses=[some_response], status=some_status]",
205 transaction.toString());
209 public void equals() {
210 ActionIdentifier actionIdentifier = mock(ActionIdentifier.class);
211 PreCheck precheck = mock(PreCheck.class);
212 ArrayList<Response> responses = new ArrayList<>();
213 responses.add(new Response());
214 Parameters parameters = mock(Parameters.class);
215 ArrayList<Parameters> parametersList = new ArrayList<>();
216 parametersList.add(parameters);
217 assertTrue(transaction.equals(transaction));
218 assertFalse(transaction.equals(null));
219 assertFalse(transaction.equals(""));
220 Transaction other = new Transaction();
221 other.setAction("different_action");
222 assertFalse(transaction.equals(other));
223 transaction.setAction("action");
224 assertFalse(transaction.equals(other));
225 other.setAction("action");
226 other.setActionIdentifier(actionIdentifier);
227 assertFalse(transaction.equals(other));
228 transaction.setActionIdentifier(new ActionIdentifier());
229 assertFalse(transaction.equals(other));
230 transaction.setActionIdentifier(actionIdentifier);
231 other.setActionLevel("different_action_level");
232 assertFalse(transaction.equals(other));
233 transaction.setActionLevel("some_action_level");
234 assertFalse(transaction.equals(other));
235 other.setActionLevel("some_action_level");
236 other.setExecutionEndPoint("different_execution_endpoint");
237 assertFalse(transaction.equals(other));
238 transaction.setExecutionEndPoint("some_execution_endpoint");
239 assertFalse(transaction.equals(other));
240 other.setExecutionEndPoint("some_execution_endpoint");
242 other.setExecutionModule("different_execution_module");
243 assertFalse(transaction.equals(other));
244 transaction.setExecutionModule("some_execution_module");
245 assertFalse(transaction.equals(other));
246 other.setExecutionModule("some_execution_module");
248 other.setExecutionRPC("different_execution_rpc");
249 assertFalse(transaction.equals(other));
250 transaction.setExecutionRPC("some_execution_rpc");
251 assertFalse(transaction.equals(other));
252 other.setExecutionRPC("some_execution_rpc");
254 other.setExecutionType("different_execution_type");
255 assertFalse(transaction.equals(other));
256 transaction.setExecutionType("some_execution_type");
257 assertFalse(transaction.equals(other));
258 other.setExecutionType("some_execution_type");
260 other.setParameters(new ArrayList<Parameters>(0));
261 assertFalse(transaction.equals(other));
262 transaction.setParameters(parametersList);
263 assertFalse(transaction.equals(other));
264 other.setParameters(parametersList);
266 other.setPayload("different_payload");
267 assertFalse(transaction.equals(other));
268 transaction.setPayload("some_payload");
269 assertFalse(transaction.equals(other));
270 other.setPayload("some_payload");
272 other.setPrecheck(new PreCheck());
273 assertFalse(transaction.equals(other));
274 transaction.setPrecheck(precheck);
275 assertFalse(transaction.equals(other));
276 other.setPrecheck(precheck);
278 other.setPswd("different_pass");
279 assertFalse(transaction.equals(other));
280 transaction.setPswd("some_pass");
281 assertFalse(transaction.equals(other));
282 other.setPswd("some_pass");
284 other.setPswd("different_pass");
285 assertFalse(transaction.equals(other));
286 transaction.setPswd("some_pass");
287 assertFalse(transaction.equals(other));
288 other.setPswd("some_pass");
290 other.setResponses(new ArrayList<Response>(0));
291 assertFalse(transaction.equals(other));
292 transaction.setResponses(responses);
293 assertFalse(transaction.equals(other));
294 other.setResponses(responses);
296 other.setState("different_state");
297 assertFalse(transaction.equals(other));
298 transaction.setState("some_state");
299 assertFalse(transaction.equals(other));
300 other.setState("some_state");
302 other.setStatus("different_status");
303 assertFalse(transaction.equals(other));
304 transaction.setStatus("some_status");
305 assertFalse(transaction.equals(other));
306 other.setStatus("some_status");
308 other.setStatusCode("different_status_code");
309 assertFalse(transaction.equals(other));
310 transaction.setStatusCode("some_status_code");
311 assertFalse(transaction.equals(other));
312 other.setStatusCode("some_status_code");
314 other.setTransactionId(0);
315 transaction.setTransactionId(1);
316 assertFalse(transaction.equals(other));
317 other.setTransactionId(1);
318 other.setuId("different_uid");
319 assertFalse(transaction.equals(other));
320 transaction.setuId("some_uid");
321 assertFalse(transaction.equals(other));
322 other.setuId("some_uid");
323 assertTrue(transaction.equals(other));
327 public void testHashCode()
329 transaction.setAction("some_action");
330 transaction.setActionLevel("some_action_level");
331 transaction.setExecutionRPC("some_execution_rpc");
332 transaction.setExecutionType("some_execution_type");
333 transaction.setExecutionModule("some_execution_module");
334 transaction.setExecutionEndPoint("some_execution_endpoint");
335 transaction.setState("some_state");
336 transaction.setStatus("some_status");
337 transaction.setStatusCode("some_status_code");
338 transaction.setPswd("some_pass");
339 transaction.setPayload("some_payload");
340 transaction.setTransactionId(133);
341 transaction.setuId("some_uid");
342 int hashcode= transaction.hashCode();
343 assertEquals(-955260883,hashcode);