2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 AT&T 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.
18 * ============LICENSE_END=========================================================
21 package org.onap.so.bpmn.servicedecomposition.tasks;
23 import static org.mockito.Mockito.doNothing;
24 import static org.mockito.Mockito.doReturn;
25 import static org.mockito.Mockito.verify;
26 import org.camunda.bpm.engine.delegate.DelegateExecution;
27 import org.camunda.bpm.extension.mockito.delegate.DelegateExecutionFake;
28 import org.junit.Before;
29 import org.junit.Test;
30 import org.junit.runner.RunWith;
31 import org.mockito.InjectMocks;
32 import org.mockito.Mock;
33 import org.mockito.Mockito;
34 import org.mockito.Spy;
35 import org.mockito.junit.MockitoJUnitRunner;
36 import org.onap.so.bpmn.core.WorkflowException;
37 import org.onap.so.db.request.beans.InfraActiveRequests;
38 import org.onap.so.db.request.client.RequestsDbClient;
39 import org.onap.so.utils.TargetEntity;
41 @RunWith(MockitoJUnitRunner.class)
42 public class ExecuteBuildingBlockRainyDayUnitTest {
45 private RequestsDbClient requestsDbClient;
49 private ExecuteBuildingBlockRainyDay executeBuildingBlockRainyDay;
51 private DelegateExecution execution;
52 private DelegateExecution executionNullisRollback;
53 private String msoRequestId = "ef7c004b-829f-4773-a7d8-4de29feef5b1";
54 private InfraActiveRequests request = new InfraActiveRequests();
55 private WorkflowException exception;
56 private WorkflowException noExtSystemErrorSourceException;
60 exception = new WorkflowException("Test exception", 7000, "", "", TargetEntity.SDNC);
61 noExtSystemErrorSourceException =
62 new WorkflowException("Test exception without extsystemErrorSource", 7000, "", "");
64 execution = new DelegateExecutionFake();
65 execution.setVariable("mso-request-id", "ef7c004b-829f-4773-a7d8-4de29feef5b1");
67 executionNullisRollback = new DelegateExecutionFake();
68 executionNullisRollback.setVariable("mso-request-id", "ef7c004b-829f-4773-a7d8-4de29feef5b1");
72 public void updateExtSystemErrorSourceTest() {
73 doReturn(request).when(requestsDbClient).getInfraActiveRequestbyRequestId(msoRequestId);
74 doNothing().when(requestsDbClient).updateInfraActiveRequests(request);
75 execution.setVariable("isRollback", false);
76 execution.setVariable("WorkflowException", exception);
77 executeBuildingBlockRainyDay.updateExtSystemErrorSource(execution);
78 request.setExtSystemErrorSource(TargetEntity.SDNC.toString());
80 verify(requestsDbClient, Mockito.times(1)).updateInfraActiveRequests(request);
84 public void updateExtSystemErrorSourceisRollbackTest() {
85 doReturn(request).when(requestsDbClient).getInfraActiveRequestbyRequestId(msoRequestId);
86 doNothing().when(requestsDbClient).updateInfraActiveRequests(request);
87 execution.setVariable("isRollback", true);
88 execution.setVariable("WorkflowException", exception);
89 executeBuildingBlockRainyDay.updateExtSystemErrorSource(execution);
90 request.setExtSystemErrorSource(TargetEntity.SDNC.toString());
92 verify(requestsDbClient, Mockito.times(1)).updateInfraActiveRequests(request);
96 public void updateExtSystemErrorSourceisRollbackTargetEntityNullTest() {
97 doReturn(request).when(requestsDbClient).getInfraActiveRequestbyRequestId(msoRequestId);
98 doNothing().when(requestsDbClient).updateInfraActiveRequests(request);
99 execution.setVariable("isRollback", true);
100 execution.setVariable("WorkflowException", noExtSystemErrorSourceException);
101 executeBuildingBlockRainyDay.updateExtSystemErrorSource(execution);
102 request.setExtSystemErrorSource(TargetEntity.UNKNOWN.toString());
104 verify(requestsDbClient, Mockito.times(1)).updateInfraActiveRequests(request);
108 public void updateExtSystemErrorSourceTargetEntityNullTest() {
109 doReturn(request).when(requestsDbClient).getInfraActiveRequestbyRequestId(msoRequestId);
110 doNothing().when(requestsDbClient).updateInfraActiveRequests(request);
111 execution.setVariable("isRollback", false);
112 execution.setVariable("WorkflowException", noExtSystemErrorSourceException);
113 executeBuildingBlockRainyDay.updateExtSystemErrorSource(execution);
114 request.setExtSystemErrorSource(TargetEntity.UNKNOWN.toString());
116 verify(requestsDbClient, Mockito.times(1)).updateInfraActiveRequests(request);
120 public void updateExtSystemErrorSourceTargetEntityisRollbackNullTest() {
121 doReturn(request).when(requestsDbClient).getInfraActiveRequestbyRequestId(msoRequestId);
122 doNothing().when(requestsDbClient).updateInfraActiveRequests(request);
123 executionNullisRollback.setVariable("WorkflowException", exception);
124 executeBuildingBlockRainyDay.updateExtSystemErrorSource(executionNullisRollback);
125 request.setExtSystemErrorSource(TargetEntity.SDNC.toString());
127 verify(requestsDbClient, Mockito.times(1)).updateInfraActiveRequests(request);