cb8f088d85f828f7d7cfeee679f9596e1fa5a6e4
[appc.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP : APPC
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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  *
19  * ============LICENSE_END=========================================================
20  */
21 package org.onap.appc.flow.controller.data;
22
23 import static org.mockito.Mockito.mock;
24 import static org.mockito.Mockito.when;
25
26 import java.util.ArrayList;
27 import org.junit.Assert;
28 import org.junit.Before;
29 import org.junit.Test;
30
31 public class TransactionTest {
32
33     private Transaction transaction;
34
35     @Before
36     public void setUp() {
37         transaction = new Transaction();
38     }
39
40     @Test
41     public void get_set_pass() {
42         String somePwsd = "some_pass";
43         transaction.setPswd(somePwsd);
44         Assert.assertEquals(somePwsd, transaction.getPswd());
45     }
46
47     @Test
48     public void get_set_precheck() {
49         PreCheck precheck = mock(PreCheck.class);
50         transaction.setPrecheck(precheck);
51         Assert.assertEquals(precheck, transaction.getPrecheck());
52     }
53
54     @Test
55     public void get_set_state() {
56         String state = "some_state";
57         transaction.setState(state);
58         Assert.assertEquals(state, transaction.getState());
59     }
60
61     @Test
62     public void get_set_status_code() {
63         String statusCode = "status_code";
64         transaction.setStatusCode(statusCode);
65         Assert.assertEquals(statusCode, transaction.getStatusCode());
66     }
67
68     @Test
69     public void get_set_transaction_id() {
70         int id = 133;
71         transaction.setTransactionId(id);
72         Assert.assertEquals(id, transaction.getTransactionId());
73     }
74
75     @Test
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());
81     }
82
83     @Test
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());
89     }
90
91     @Test
92     public void get_set_payload() {
93         String payload = "some_payload";
94         transaction.setPayload(payload);
95         Assert.assertEquals(payload, transaction.getPayload());
96     }
97
98     @Test
99     public void get_set_execution_rpc() {
100         String executionRPC = "some_exec_rpc";
101         transaction.setExecutionRPC(executionRPC);
102         Assert.assertEquals(executionRPC, transaction.getExecutionRPC());
103     }
104
105     @Test
106     public void get_set_execution_module() {
107         String executionModule = "some_exec_module";
108         transaction.setExecutionModule(executionModule);
109         Assert.assertEquals(executionModule, transaction.getExecutionModule());
110     }
111
112     @Test
113     public void get_set_execution_type() {
114         String executionType = "some_exec_type";
115         transaction.setExecutionType(executionType);
116         Assert.assertEquals(executionType, transaction.getExecutionType());
117     }
118
119     @Test
120     public void get_set_execution_endpoint() {
121         String executionEndpoint = "some_exec_endpoint";
122         transaction.setExecutionEndPoint(executionEndpoint);
123         Assert.assertEquals(executionEndpoint, transaction.getExecutionEndPoint());
124     }
125
126     @Test
127     public void get_set_uid() {
128         String uid = "some_uid";
129         transaction.setuId(uid);
130         Assert.assertEquals(uid, transaction.getuId());
131     }
132
133     @Test
134     public void get_set_action_level() {
135         String actionLevel = "some_action_level";
136         transaction.setActionLevel(actionLevel);
137         Assert.assertEquals(actionLevel, transaction.getActionLevel());
138     }
139
140     @Test
141     public void get_set_action_identifier() {
142         ActionIdentifier actionIdentifier = mock(ActionIdentifier.class);
143         transaction.setActionIdentifier(actionIdentifier);
144         Assert.assertEquals(actionIdentifier, transaction.getActionIdentifier());
145     }
146
147     @Test
148     public void get_set_action() {
149         String action = "some_action";
150         transaction.setAction(action);
151         Assert.assertEquals(action, transaction.getAction());
152     }
153
154     @Test
155     public void get_set_status() {
156         String status = "some_status";
157         transaction.setStatus(status);
158         Assert.assertEquals(status, transaction.getStatus());
159     }
160
161     @Test
162     public void to_string() {
163
164         ActionIdentifier actionIdentifier = mock(ActionIdentifier.class);
165         when(actionIdentifier.toString()).thenReturn("some_action_identifier");
166
167         PreCheck precheck = mock(PreCheck.class);
168         when(precheck.toString()).thenReturn("some_precheck");
169
170         Response response = mock(Response.class);
171         when(response.toString()).thenReturn("some_response");
172         ArrayList<Response> responses = new ArrayList<>();
173         responses.add(response);
174
175         Parameters parameters = mock(Parameters.class);
176         when(parameters.toString()).thenReturn("some_parameters");
177         ArrayList<Parameters> parametersList = new ArrayList<>();
178         parametersList.add(parameters);
179
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");
197
198         Assert.assertEquals(
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());
201     }
202
203     @Test
204     public void equals() {
205         transaction.setAction("action");
206
207         Transaction other = new Transaction();
208         other.setAction("action");
209
210         Assert.assertTrue(transaction.equals(other));
211     }
212
213 }