2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 - 2018 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.infrastructure.activity;
23 import static org.junit.Assert.assertEquals;
24 import static org.mockito.Mockito.doNothing;
25 import static org.mockito.Mockito.doReturn;
26 import java.nio.file.Files;
27 import java.nio.file.Paths;
28 import org.camunda.bpm.engine.delegate.BpmnError;
29 import org.camunda.bpm.engine.delegate.DelegateExecution;
30 import org.camunda.bpm.extension.mockito.delegate.DelegateExecutionFake;
31 import org.junit.Before;
32 import org.junit.Rule;
33 import org.junit.Test;
34 import org.junit.rules.ExpectedException;
35 import org.junit.runner.RunWith;
36 import org.mockito.InjectMocks;
37 import org.mockito.Mock;
38 import org.mockito.Spy;
39 import org.mockito.junit.MockitoJUnitRunner;
40 import org.onap.so.bpmn.common.data.TestDataSetup;
41 import org.onap.so.bpmn.core.WorkflowException;
42 import org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowActionBBFailure;
43 import org.onap.so.bpmn.servicedecomposition.entities.BuildingBlock;
44 import org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock;
45 import org.onap.so.client.exception.ExceptionBuilder;
47 @RunWith(MockitoJUnitRunner.Silent.class)
48 public class ExecuteActivityTest extends TestDataSetup {
50 protected ExecuteActivity executeActivity;
54 private ExceptionBuilder exceptionBuilder;
57 private WorkflowActionBBFailure workflowActionBBFailure;
60 public ExpectedException thrown = ExpectedException.none();
62 private DelegateExecution execution;
65 public void before() throws Exception {
66 execution = new DelegateExecutionFake();
67 execution.setVariable("vnfType", "testVnfType");
68 execution.setVariable("requestAction", "testRequestAction");
69 execution.setVariable("mso-request-id", "testMsoRequestId");
70 execution.setVariable("vnfId", "testVnfId");
71 execution.setVariable("serviceInstanceId", "testServiceInstanceId");
73 new String(Files.readAllBytes(Paths.get("src/test/resources/__files/Macro/ServiceMacroAssign.json")));
74 execution.setVariable("bpmnRequest", bpmnRequest);
78 public void buildBuildingBlock_Test() {
79 BuildingBlock bb = executeActivity.buildBuildingBlock("testActivityName");
80 assertEquals(bb.getBpmnFlowName(), "testActivityName");
81 assertEquals(bb.getKey(), "");
85 public void executeBuildingBlock_Test() throws Exception {
86 BuildingBlock bb = executeActivity.buildBuildingBlock("testActivityName");
87 ExecuteBuildingBlock ebb = executeActivity.buildExecuteBuildingBlock(execution, "testMsoRequestId", bb);
88 assertEquals(ebb.getVnfType(), "testVnfType");
89 assertEquals(ebb.getRequestAction(), "testRequestAction");
90 assertEquals(ebb.getRequestId(), "testMsoRequestId");
91 assertEquals(ebb.getWorkflowResourceIds().getVnfId(), "testVnfId");
92 assertEquals(ebb.getWorkflowResourceIds().getServiceInstanceId(), "testServiceInstanceId");
93 assertEquals(ebb.getBuildingBlock(), bb);
97 public void executeException_Test() throws Exception {
98 execution.setVariable("workflowSyncAckSent", true);
99 execution.setVariable("testProcessKey", "testProcessKeyValue");
100 thrown.expect(BpmnError.class);
101 executeActivity.execute(execution);
102 String errorMessage = (String) execution.getVariable("ExecuteActivityErrorMessage");
103 assertEquals(errorMessage, "not implemented");
104 WorkflowException workflowException = (WorkflowException) execution.getVariable("WorkflowException");
105 assertEquals(workflowException.getErrorMessage(), "not implemented");
106 assertEquals(workflowException.getErrorCode(), 7000);
110 public void buildAndThrowException_Test() {
111 doNothing().when(workflowActionBBFailure).updateRequestStatusToFailed(execution);
112 doReturn("Process key").when(exceptionBuilder).getProcessKey(execution);
113 thrown.expect(BpmnError.class);
114 executeActivity.buildAndThrowException(execution, "TEST EXCEPTION MSG");
115 String errorMessage = (String) execution.getVariable("ExecuteActivityErrorMessage");
116 assertEquals(errorMessage, "TEST EXCEPTION MSG");
117 WorkflowException workflowException = (WorkflowException) execution.getVariable("WorkflowException");
118 assertEquals(workflowException.getErrorMessage(), "TEST EXCEPTION MSG");
119 assertEquals(workflowException.getErrorCode(), 7000);