2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2018 Nokia 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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 * ============LICENSE_END=========================================================
21 package org.onap.appc.flow.controller.data;
23 import static org.mockito.Mockito.mock;
24 import static org.mockito.Mockito.when;
26 import java.util.ArrayList;
27 import org.junit.Assert;
28 import org.junit.Before;
29 import org.junit.Test;
31 public class TransactionTest {
33 private Transaction transaction;
37 transaction = new Transaction();
41 public void get_set_pass() {
42 String somePwsd = "some_pass";
43 transaction.setPswd(somePwsd);
44 Assert.assertEquals(somePwsd, transaction.getPswd());
48 public void get_set_precheck() {
49 PreCheck precheck = mock(PreCheck.class);
50 transaction.setPrecheck(precheck);
51 Assert.assertEquals(precheck, transaction.getPrecheck());
55 public void get_set_state() {
56 String state = "some_state";
57 transaction.setState(state);
58 Assert.assertEquals(state, transaction.getState());
62 public void get_set_status_code() {
63 String statusCode = "status_code";
64 transaction.setStatusCode(statusCode);
65 Assert.assertEquals(statusCode, transaction.getStatusCode());
69 public void get_set_transaction_id() {
71 transaction.setTransactionId(id);
72 Assert.assertEquals(id, transaction.getTransactionId());
76 public void get_set_responses() {
77 ArrayList<Response> responses = new ArrayList<>();
78 responses.add(mock(Response.class));
79 transaction.setResponses(responses);
80 Assert.assertEquals(responses, transaction.getResponses());
84 public void get_set_parameters() {
85 ArrayList<Parameters> parameters = new ArrayList<>();
86 parameters.add(mock(Parameters.class));
87 transaction.setParameters(parameters);
88 Assert.assertEquals(parameters, transaction.getParameters());
92 public void get_set_payload() {
93 String payload = "some_payload";
94 transaction.setPayload(payload);
95 Assert.assertEquals(payload, transaction.getPayload());
99 public void get_set_execution_rpc() {
100 String executionRPC = "some_exec_rpc";
101 transaction.setExecutionRPC(executionRPC);
102 Assert.assertEquals(executionRPC, transaction.getExecutionRPC());
106 public void get_set_execution_module() {
107 String executionModule = "some_exec_module";
108 transaction.setExecutionModule(executionModule);
109 Assert.assertEquals(executionModule, transaction.getExecutionModule());
113 public void get_set_execution_type() {
114 String executionType = "some_exec_type";
115 transaction.setExecutionType(executionType);
116 Assert.assertEquals(executionType, transaction.getExecutionType());
120 public void get_set_execution_endpoint() {
121 String executionEndpoint = "some_exec_endpoint";
122 transaction.setExecutionEndPoint(executionEndpoint);
123 Assert.assertEquals(executionEndpoint, transaction.getExecutionEndPoint());
127 public void get_set_uid() {
128 String uid = "some_uid";
129 transaction.setuId(uid);
130 Assert.assertEquals(uid, transaction.getuId());
134 public void get_set_action_level() {
135 String actionLevel = "some_action_level";
136 transaction.setActionLevel(actionLevel);
137 Assert.assertEquals(actionLevel, transaction.getActionLevel());
141 public void get_set_action_identifier() {
142 ActionIdentifier actionIdentifier = mock(ActionIdentifier.class);
143 transaction.setActionIdentifier(actionIdentifier);
144 Assert.assertEquals(actionIdentifier, transaction.getActionIdentifier());
148 public void get_set_action() {
149 String action = "some_action";
150 transaction.setAction(action);
151 Assert.assertEquals(action, transaction.getAction());
155 public void get_set_status() {
156 String status = "some_status";
157 transaction.setStatus(status);
158 Assert.assertEquals(status, transaction.getStatus());
162 public void to_string() {
164 ActionIdentifier actionIdentifier = mock(ActionIdentifier.class);
165 when(actionIdentifier.toString()).thenReturn("some_action_identifier");
167 PreCheck precheck = mock(PreCheck.class);
168 when(precheck.toString()).thenReturn("some_precheck");
170 Response response = mock(Response.class);
171 when(response.toString()).thenReturn("some_response");
172 ArrayList<Response> responses = new ArrayList<>();
173 responses.add(response);
175 Parameters parameters = mock(Parameters.class);
176 when(parameters.toString()).thenReturn("some_parameters");
177 ArrayList<Parameters> parametersList = new ArrayList<>();
178 parametersList.add(parameters);
180 transaction.setAction("some_action");
181 transaction.setActionIdentifier(actionIdentifier);
182 transaction.setActionLevel("some_action_level");
183 transaction.setExecutionRPC("some_execution_rpc");
184 transaction.setExecutionType("some_execution_type");
185 transaction.setExecutionModule("some_execution_module");
186 transaction.setExecutionEndPoint("some_execution_endpoint");
187 transaction.setState("some_state");
188 transaction.setStatus("some_status");
189 transaction.setStatusCode("some_status_code");
190 transaction.setPswd("some_pass");
191 transaction.setPayload("some_payload");
192 transaction.setPrecheck(precheck);
193 transaction.setParameters(parametersList);
194 transaction.setResponses(responses);
195 transaction.setTransactionId(133);
196 transaction.setuId("some_uid");
199 "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]",
200 transaction.toString());
204 public void equals() {
205 transaction.setAction("action");
207 Transaction other = new Transaction();
208 other.setAction("action");
210 Assert.assertTrue(transaction.equals(other));