add junit coverage
[so.git] / bpmn / so-bpmn-tasks / src / test / java / org / onap / so / bpmn / infrastructure / workflow / tasks / listeners / HomingListenerTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2020 Nokia
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.infrastructure.workflow.tasks.listeners;
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.Test;
27 import org.onap.so.bpmn.common.BuildingBlockExecution;
28 import org.onap.so.bpmn.common.DelegateExecutionImpl;
29 import org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock;
30
31 public class HomingListenerTest {
32
33     private static final String CALLED_HOMING = "calledHoming";
34
35     @Test
36     public void shouldRunForAssignVnfBB() {
37         assertThat(new HomingListener().shouldRunFor("AssignVnfBB", false, null)).isTrue();
38     }
39
40     @Test
41     public void shouldNotRunForDifferentThanAssignVnfBB() {
42         assertThat(new HomingListener().shouldRunFor("someDifferentBB", false, null)).isFalse();
43     }
44
45     @Test
46     public void runWithHoming() {
47         // given
48         DelegateExecution execution = new DelegateExecutionFake();
49         execution.setVariable("homing", true);
50         execution.setVariable(CALLED_HOMING, false);
51         BuildingBlockExecution buildingBlockExecution = new DelegateExecutionImpl(execution);
52         ExecuteBuildingBlock executeBuildingBlock = new ExecuteBuildingBlock();
53         // when
54         new HomingListener().run(null, executeBuildingBlock, buildingBlockExecution);
55         // then
56         assertThat(executeBuildingBlock.isHoming()).isTrue();
57         assertThat((boolean) buildingBlockExecution.getVariable(CALLED_HOMING)).isTrue();
58     }
59 }