0ba1e27f5e4d8c6751d554082ae1e27c89fef387
[so.git] / bpmn / so-bpmn-tasks / src / test / java / org / onap / so / bpmn / infrastructure / decisionpoint / impl / buildingblock / controller / sdnc / prepare / PrepareSdncUpgradePreCheckPnfBBTest.java
1 /*-
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
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
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.
16  *
17  * SPDX-License-Identifier: Apache-2.0
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.so.bpmn.infrastructure.decisionpoint.impl.buildingblock.controller.sdnc.prepare;
22
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;
31
32 public class PrepareSdncUpgradePreCheckPnfBBTest {
33
34     private PrepareSdncUpgradePreCheckPnfBB testedObject;
35
36     @Before
37     public void setup() {
38         testedObject = new PrepareSdncUpgradePreCheckPnfBB();
39     }
40
41     @Test
42     public void understandTrue() {
43         ControllerContext<BuildingBlockExecution> controllerContext =
44                 createControllerContext("sdnc", "UpgradePreCheck", "pnf");
45         boolean result = testedObject.understand(controllerContext);
46         assertThat(result).isTrue();
47     }
48
49     @Test
50     public void understandFalse() {
51         ControllerContext<BuildingBlockExecution> controllerContext =
52                 createControllerContext("actor1", "action1", "scope1");
53         boolean result = testedObject.understand(controllerContext);
54         assertThat(result).isFalse();
55     }
56
57     @Test
58     public void prepare_jsonWithoutActionPayload() {
59         String payloadWithoutActionArray = "{\"json name\": \"test1\"}";
60         ControllerContext<BuildingBlockExecution> controllerContext =
61                 createControllerContext(payloadWithoutActionArray);
62         testedObject.prepare(controllerContext);
63
64         assertThat((String) controllerContext.getExecution().getVariable("payload"))
65                 .isEqualTo(payloadWithoutActionArray);
66     }
67
68     private ControllerContext<BuildingBlockExecution> createControllerContext(String actor, String action,
69             String scope) {
70         ControllerContext<BuildingBlockExecution> controllerContext = new ControllerContext<>();
71         controllerContext.setControllerActor(actor);
72         controllerContext.setControllerAction(action);
73         controllerContext.setControllerScope(scope);
74         return controllerContext;
75     }
76
77     private ControllerContext<BuildingBlockExecution> createControllerContext(String payload) {
78         ControllerContext<BuildingBlockExecution> controllerContext = new ControllerContext<>();
79         controllerContext.setExecution(prepareBuildingBlockExecution(payload));
80         return controllerContext;
81     }
82
83     private BuildingBlockExecution prepareBuildingBlockExecution(String payload) {
84         DelegateExecution execution = new DelegateExecutionFake();
85         execution.setVariable("payload", payload);
86         return new DelegateExecutionImpl(execution);
87     }
88 }