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;
24 import static org.junit.Assert.assertEquals;
25 import static org.mockito.Mockito.doNothing;
26 import static org.mockito.Mockito.doReturn;
27 import java.nio.file.Files;
28 import java.nio.file.Paths;
29 import org.camunda.bpm.engine.delegate.BpmnError;
30 import org.camunda.bpm.engine.delegate.DelegateExecution;
31 import org.camunda.bpm.extension.mockito.delegate.DelegateExecutionFake;
32 import org.junit.Before;
33 import org.junit.Rule;
34 import org.junit.Test;
35 import org.junit.rules.ExpectedException;
36 import org.mockito.InjectMocks;
37 import org.mockito.Mock;
38 import org.mockito.Spy;
39 import org.onap.so.bpmn.BaseTaskTest;
40 import org.onap.so.bpmn.core.WorkflowException;
41 import org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowActionBBFailure;
42 import org.onap.so.bpmn.servicedecomposition.entities.BuildingBlock;
43 import org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock;
44 import org.onap.so.client.exception.ExceptionBuilder;
46 public class ExecuteActivityTest extends BaseTaskTest {
48 protected ExecuteActivity executeActivity = new ExecuteActivity();
52 private ExceptionBuilder exceptionBuilder;
55 private WorkflowActionBBFailure workflowActionBBFailure;
58 public ExpectedException thrown = ExpectedException.none();
60 private DelegateExecution execution;
63 public void before() throws Exception {
64 execution = new DelegateExecutionFake();
65 execution.setVariable("vnfType", "testVnfType");
66 execution.setVariable("requestAction", "testRequestAction");
67 execution.setVariable("mso-request-id", "testMsoRequestId");
68 execution.setVariable("vnfId", "testVnfId");
69 execution.setVariable("serviceInstanceId", "testServiceInstanceId");
71 new String(Files.readAllBytes(Paths.get("src/test/resources/__files/Macro/ServiceMacroAssign.json")));
72 execution.setVariable("bpmnRequest", bpmnRequest);
76 public void buildBuildingBlock_Test() {
77 BuildingBlock bb = executeActivity.buildBuildingBlock("testActivityName");
78 assertEquals(bb.getBpmnFlowName(), "testActivityName");
79 assertEquals(bb.getKey(), "");
83 public void executeBuildingBlock_Test() throws Exception {
84 BuildingBlock bb = executeActivity.buildBuildingBlock("testActivityName");
85 ExecuteBuildingBlock ebb = executeActivity.buildExecuteBuildingBlock(execution, "testMsoRequestId", bb);
86 assertEquals(ebb.getVnfType(), "testVnfType");
87 assertEquals(ebb.getRequestAction(), "testRequestAction");
88 assertEquals(ebb.getRequestId(), "testMsoRequestId");
89 assertEquals(ebb.getWorkflowResourceIds().getVnfId(), "testVnfId");
90 assertEquals(ebb.getWorkflowResourceIds().getServiceInstanceId(), "testServiceInstanceId");
91 assertEquals(ebb.getBuildingBlock(), bb);
95 public void executeException_Test() throws Exception {
96 execution.setVariable("workflowSyncAckSent", true);
97 execution.setVariable("testProcessKey", "testProcessKeyValue");
98 thrown.expect(BpmnError.class);
99 executeActivity.execute(execution);
100 String errorMessage = (String) execution.getVariable("ExecuteActivityErrorMessage");
101 assertEquals(errorMessage, "not implemented");
102 WorkflowException workflowException = (WorkflowException) execution.getVariable("WorkflowException");
103 assertEquals(workflowException.getErrorMessage(), "not implemented");
104 assertEquals(workflowException.getErrorCode(), 7000);
108 public void buildAndThrowException_Test() throws Exception {
109 doNothing().when(workflowActionBBFailure).updateRequestStatusToFailed(execution);
110 doReturn("Process key").when(exceptionBuilder).getProcessKey(execution);
111 thrown.expect(BpmnError.class);
112 executeActivity.buildAndThrowException(execution, "TEST EXCEPTION MSG");
113 String errorMessage = (String) execution.getVariable("ExecuteActivityErrorMessage");
114 assertEquals(errorMessage, "TEST EXCEPTION MSG");
115 WorkflowException workflowException = (WorkflowException) execution.getVariable("WorkflowException");
116 assertEquals(workflowException.getErrorMessage(), "TEST EXCEPTION MSG");
117 assertEquals(workflowException.getErrorCode(), 7000);