2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2018 Nokia Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Modifications Copyright (C) 2018 IBM.
8 * ================================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
21 * ============LICENSE_END=========================================================
23 package org.onap.appc.flow.controller.data;
25 import static org.mockito.Mockito.mock;
26 import static org.mockito.Mockito.when;
27 import static org.junit.Assert.assertEquals;
28 import java.util.ArrayList;
29 import org.junit.Assert;
30 import org.junit.Before;
31 import org.junit.Test;
33 public class TransactionTest {
35 private Transaction transaction;
39 transaction = new Transaction();
43 public void get_set_pass() {
44 String somePwsd = "some_pass";
45 transaction.setPswd(somePwsd);
46 Assert.assertEquals(somePwsd, transaction.getPswd());
50 public void get_set_precheck() {
51 PreCheck precheck = mock(PreCheck.class);
52 transaction.setPrecheck(precheck);
53 Assert.assertEquals(precheck, transaction.getPrecheck());
57 public void get_set_state() {
58 String state = "some_state";
59 transaction.setState(state);
60 Assert.assertEquals(state, transaction.getState());
64 public void get_set_status_code() {
65 String statusCode = "status_code";
66 transaction.setStatusCode(statusCode);
67 Assert.assertEquals(statusCode, transaction.getStatusCode());
71 public void get_set_transaction_id() {
73 transaction.setTransactionId(id);
74 Assert.assertEquals(id, transaction.getTransactionId());
78 public void get_set_responses() {
79 ArrayList<Response> responses = new ArrayList<>();
80 responses.add(mock(Response.class));
81 transaction.setResponses(responses);
82 Assert.assertEquals(responses, transaction.getResponses());
86 public void get_set_parameters() {
87 ArrayList<Parameters> parameters = new ArrayList<>();
88 parameters.add(mock(Parameters.class));
89 transaction.setParameters(parameters);
90 Assert.assertEquals(parameters, transaction.getParameters());
94 public void get_set_payload() {
95 String payload = "some_payload";
96 transaction.setPayload(payload);
97 Assert.assertEquals(payload, transaction.getPayload());
101 public void get_set_execution_rpc() {
102 String executionRPC = "some_exec_rpc";
103 transaction.setExecutionRPC(executionRPC);
104 Assert.assertEquals(executionRPC, transaction.getExecutionRPC());
108 public void get_set_execution_module() {
109 String executionModule = "some_exec_module";
110 transaction.setExecutionModule(executionModule);
111 Assert.assertEquals(executionModule, transaction.getExecutionModule());
115 public void get_set_execution_type() {
116 String executionType = "some_exec_type";
117 transaction.setExecutionType(executionType);
118 Assert.assertEquals(executionType, transaction.getExecutionType());
122 public void get_set_execution_endpoint() {
123 String executionEndpoint = "some_exec_endpoint";
124 transaction.setExecutionEndPoint(executionEndpoint);
125 Assert.assertEquals(executionEndpoint, transaction.getExecutionEndPoint());
129 public void get_set_uid() {
130 String uid = "some_uid";
131 transaction.setuId(uid);
132 Assert.assertEquals(uid, transaction.getuId());
136 public void get_set_action_level() {
137 String actionLevel = "some_action_level";
138 transaction.setActionLevel(actionLevel);
139 Assert.assertEquals(actionLevel, transaction.getActionLevel());
143 public void get_set_action_identifier() {
144 ActionIdentifier actionIdentifier = mock(ActionIdentifier.class);
145 transaction.setActionIdentifier(actionIdentifier);
146 Assert.assertEquals(actionIdentifier, transaction.getActionIdentifier());
150 public void get_set_action() {
151 String action = "some_action";
152 transaction.setAction(action);
153 Assert.assertEquals(action, transaction.getAction());
157 public void get_set_status() {
158 String status = "some_status";
159 transaction.setStatus(status);
160 Assert.assertEquals(status, transaction.getStatus());
164 public void to_string() {
166 ActionIdentifier actionIdentifier = mock(ActionIdentifier.class);
167 when(actionIdentifier.toString()).thenReturn("some_action_identifier");
169 PreCheck precheck = mock(PreCheck.class);
170 when(precheck.toString()).thenReturn("some_precheck");
172 Response response = mock(Response.class);
173 when(response.toString()).thenReturn("some_response");
174 ArrayList<Response> responses = new ArrayList<>();
175 responses.add(response);
177 Parameters parameters = mock(Parameters.class);
178 when(parameters.toString()).thenReturn("some_parameters");
179 ArrayList<Parameters> parametersList = new ArrayList<>();
180 parametersList.add(parameters);
182 transaction.setAction("some_action");
183 transaction.setActionIdentifier(actionIdentifier);
184 transaction.setActionLevel("some_action_level");
185 transaction.setExecutionRPC("some_execution_rpc");
186 transaction.setExecutionType("some_execution_type");
187 transaction.setExecutionModule("some_execution_module");
188 transaction.setExecutionEndPoint("some_execution_endpoint");
189 transaction.setState("some_state");
190 transaction.setStatus("some_status");
191 transaction.setStatusCode("some_status_code");
192 transaction.setPswd("some_pass");
193 transaction.setPayload("some_payload");
194 transaction.setPrecheck(precheck);
195 transaction.setParameters(parametersList);
196 transaction.setResponses(responses);
197 transaction.setTransactionId(133);
198 transaction.setuId("some_uid");
201 "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]",
202 transaction.toString());
206 public void equals() {
207 ActionIdentifier actionIdentifier = mock(ActionIdentifier.class);
208 PreCheck precheck = mock(PreCheck.class);
209 ArrayList<Response> responses = new ArrayList<>();
210 Parameters parameters = mock(Parameters.class);
211 ArrayList<Parameters> parametersList = new ArrayList<>();
212 parametersList.add(parameters);
213 transaction.setAction("action");
214 transaction.setActionIdentifier(actionIdentifier);
215 transaction.setActionLevel("some_action_level");
216 transaction.setExecutionRPC("some_execution_rpc");
217 transaction.setExecutionType("some_execution_type");
218 transaction.setExecutionModule("some_execution_module");
219 transaction.setExecutionEndPoint("some_execution_endpoint");
220 transaction.setState("some_state");
221 transaction.setStatus("some_status");
222 transaction.setStatusCode("some_status_code");
223 transaction.setPswd("some_pass");
224 transaction.setPayload("some_payload");
225 transaction.setPrecheck(precheck);
226 transaction.setParameters(parametersList);
227 transaction.setResponses(responses);
228 transaction.setTransactionId(133);
229 transaction.setuId("some_uid");
230 Transaction other = new Transaction();
231 other.setAction("action");
232 other.setAction("action");
233 other.setActionIdentifier(actionIdentifier);
234 other.setActionLevel("some_action_level");
235 other.setExecutionRPC("some_execution_rpc");
236 other.setExecutionType("some_execution_type");
237 other.setExecutionModule("some_execution_module");
238 other.setExecutionEndPoint("some_execution_endpoint");
239 other.setState("some_state");
240 other.setStatus("some_status");
241 other.setStatusCode("some_status_code");
242 other.setPswd("some_pass");
243 other.setPayload("some_payload");
244 other.setPrecheck(precheck);
245 other.setParameters(parametersList);
246 other.setResponses(responses);
247 other.setTransactionId(133);
248 other.setuId("some_uid");
249 Assert.assertTrue(transaction.equals(other));
253 public void testHashCode()
255 transaction.setAction("some_action");
256 transaction.setActionLevel("some_action_level");
257 transaction.setExecutionRPC("some_execution_rpc");
258 transaction.setExecutionType("some_execution_type");
259 transaction.setExecutionModule("some_execution_module");
260 transaction.setExecutionEndPoint("some_execution_endpoint");
261 transaction.setState("some_state");
262 transaction.setStatus("some_status");
263 transaction.setStatusCode("some_status_code");
264 transaction.setPswd("some_pass");
265 transaction.setPayload("some_payload");
266 transaction.setTransactionId(133);
267 transaction.setuId("some_uid");
268 int hashcode= transaction.hashCode();
269 assertEquals(-955260883,hashcode);