From 5a545844519050ea9efbb58c87b085777494ed6c Mon Sep 17 00:00:00 2001 From: Lukasz Muszkieta Date: Thu, 16 Jul 2020 17:47:19 +0200 Subject: [PATCH] add junit coverage Issue-ID: SO-1576 Signed-off-by: Lukasz Muszkieta Change-Id: Ia4f6e4e531b9acaab748a7683887827ddef7c517 --- .../workflow/tasks/listeners/HomingListener.java | 5 +- .../tasks/listeners/HomingListenerTest.java | 59 ++++++++++++++++++++++ 2 files changed, 61 insertions(+), 3 deletions(-) create mode 100644 bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/listeners/HomingListenerTest.java diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/listeners/HomingListener.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/listeners/HomingListener.java index 6254aae029..bc32489944 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/listeners/HomingListener.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/listeners/HomingListener.java @@ -39,13 +39,12 @@ public class HomingListener implements FlowManipulator { public void run(List flowsToExecute, ExecuteBuildingBlock currentBB, BuildingBlockExecution execution) { - boolean homing = (boolean) execution.getVariable("homing"); - boolean calledHoming = (boolean) execution.getVariable("calledHoming"); + boolean homing = execution.getVariable("homing"); + boolean calledHoming = execution.getVariable("calledHoming"); if (homing && !calledHoming) { currentBB.setHoming(true); execution.setVariable("calledHoming", true); } } - } diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/listeners/HomingListenerTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/listeners/HomingListenerTest.java new file mode 100644 index 0000000000..d2383185d0 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/listeners/HomingListenerTest.java @@ -0,0 +1,59 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2020 Nokia + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.bpmn.infrastructure.workflow.tasks.listeners; + +import static org.assertj.core.api.Assertions.assertThat; +import org.camunda.bpm.engine.delegate.DelegateExecution; +import org.camunda.bpm.extension.mockito.delegate.DelegateExecutionFake; +import org.junit.Test; +import org.onap.so.bpmn.common.BuildingBlockExecution; +import org.onap.so.bpmn.common.DelegateExecutionImpl; +import org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock; + +public class HomingListenerTest { + + private static final String CALLED_HOMING = "calledHoming"; + + @Test + public void shouldRunForAssignVnfBB() { + assertThat(new HomingListener().shouldRunFor("AssignVnfBB", false, null)).isTrue(); + } + + @Test + public void shouldNotRunForDifferentThanAssignVnfBB() { + assertThat(new HomingListener().shouldRunFor("someDifferentBB", false, null)).isFalse(); + } + + @Test + public void runWithHoming() { + // given + DelegateExecution execution = new DelegateExecutionFake(); + execution.setVariable("homing", true); + execution.setVariable(CALLED_HOMING, false); + BuildingBlockExecution buildingBlockExecution = new DelegateExecutionImpl(execution); + ExecuteBuildingBlock executeBuildingBlock = new ExecuteBuildingBlock(); + // when + new HomingListener().run(null, executeBuildingBlock, buildingBlockExecution); + // then + assertThat(executeBuildingBlock.isHoming()).isTrue(); + assertThat((boolean) buildingBlockExecution.getVariable(CALLED_HOMING)).isTrue(); + } +} -- 2.16.6