2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2020 Nokia
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.so.bpmn.infrastructure.decisionpoint.impl.buildingblock.controller.sdnc.prepare;
23 import static org.assertj.core.api.Assertions.assertThat;
24 import org.camunda.bpm.engine.delegate.DelegateExecution;
25 import org.camunda.bpm.extension.mockito.delegate.DelegateExecutionFake;
26 import org.junit.Before;
27 import org.junit.Test;
28 import org.onap.so.bpmn.common.BuildingBlockExecution;
29 import org.onap.so.bpmn.common.DelegateExecutionImpl;
30 import org.onap.so.bpmn.infrastructure.decisionpoint.api.ControllerContext;
32 public class PrepareSdncUpgradePreCheckPnfBBTest {
34 private PrepareSdncUpgradePreCheckPnfBB testedObject;
38 testedObject = new PrepareSdncUpgradePreCheckPnfBB();
42 public void understandTrue() {
43 ControllerContext<BuildingBlockExecution> controllerContext =
44 createControllerContext("sdnc", "UpgradePreCheck", "pnf");
45 boolean result = testedObject.understand(controllerContext);
46 assertThat(result).isTrue();
50 public void understandFalse() {
51 ControllerContext<BuildingBlockExecution> controllerContext =
52 createControllerContext("actor1", "action1", "scope1");
53 boolean result = testedObject.understand(controllerContext);
54 assertThat(result).isFalse();
58 public void prepare_jsonWithoutActionPayload() {
59 String payloadWithoutActionArray = "{\"json name\": \"test1\"}";
60 ControllerContext<BuildingBlockExecution> controllerContext =
61 createControllerContext(payloadWithoutActionArray);
62 testedObject.prepare(controllerContext);
64 assertThat((String) controllerContext.getExecution().getVariable("payload"))
65 .isEqualTo(payloadWithoutActionArray);
68 private ControllerContext<BuildingBlockExecution> createControllerContext(String actor, String action,
70 ControllerContext<BuildingBlockExecution> controllerContext = new ControllerContext<>();
71 controllerContext.setControllerActor(actor);
72 controllerContext.setControllerAction(action);
73 controllerContext.setControllerScope(scope);
74 return controllerContext;
77 private ControllerContext<BuildingBlockExecution> createControllerContext(String payload) {
78 ControllerContext<BuildingBlockExecution> controllerContext = new ControllerContext<>();
79 controllerContext.setExecution(prepareBuildingBlockExecution(payload));
80 return controllerContext;
83 private BuildingBlockExecution prepareBuildingBlockExecution(String payload) {
84 DelegateExecution execution = new DelegateExecutionFake();
85 execution.setVariable("payload", payload);
86 return new DelegateExecutionImpl(execution);