6a48558d114233baff088681e80d798327647d13
[so.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
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
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  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.so.bpmn.servicedecomposition.tasks;
22
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;
40
41 @RunWith(MockitoJUnitRunner.class)
42 public class ExecuteBuildingBlockRainyDayUnitTest {
43
44     @Mock
45     private RequestsDbClient requestsDbClient;
46
47     @InjectMocks
48     @Spy
49     private ExecuteBuildingBlockRainyDay executeBuildingBlockRainyDay;
50
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;
57
58     @Before
59     public void setup() {
60         exception = new WorkflowException("Test exception", 7000, "", "", TargetEntity.SDNC);
61         noExtSystemErrorSourceException =
62                 new WorkflowException("Test exception without extsystemErrorSource", 7000, "", "");
63
64         execution = new DelegateExecutionFake();
65         execution.setVariable("mso-request-id", "ef7c004b-829f-4773-a7d8-4de29feef5b1");
66
67         executionNullisRollback = new DelegateExecutionFake();
68         executionNullisRollback.setVariable("mso-request-id", "ef7c004b-829f-4773-a7d8-4de29feef5b1");
69     }
70
71     @Test
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());
79
80         verify(requestsDbClient, Mockito.times(1)).updateInfraActiveRequests(request);
81     }
82
83     @Test
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());
91
92         verify(requestsDbClient, Mockito.times(1)).updateInfraActiveRequests(request);
93     }
94
95     @Test
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());
103
104         verify(requestsDbClient, Mockito.times(1)).updateInfraActiveRequests(request);
105     }
106
107     @Test
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());
115
116         verify(requestsDbClient, Mockito.times(1)).updateInfraActiveRequests(request);
117     }
118
119     @Test
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());
126
127         verify(requestsDbClient, Mockito.times(1)).updateInfraActiveRequests(request);
128     }
129 }