From b0172ee2f3986b2cf36e118301cd20745b9a78ba Mon Sep 17 00:00:00 2001 From: Lukasz Muszkieta Date: Wed, 17 Feb 2021 15:49:17 +0100 Subject: add junit coverage Issue-ID: SO-3433 Signed-off-by: Lukasz Muszkieta Change-Id: If00e2a209cf28a57caa52a840bc8c10164a58ff4 Signed-off-by: Lukasz Muszkieta --- .../PrepareSdncUpgradePreCheckPnfBBTest.java | 31 ++++++++++-- .../service/level/ServiceLevelTest.java | 55 ++++++++++++++++++++++ 2 files changed, 83 insertions(+), 3 deletions(-) create mode 100644 bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/service/level/ServiceLevelTest.java (limited to 'bpmn/so-bpmn-tasks/src/test/java/org') diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/buildingblock/controller/sdnc/prepare/PrepareSdncUpgradePreCheckPnfBBTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/buildingblock/controller/sdnc/prepare/PrepareSdncUpgradePreCheckPnfBBTest.java index 0ba1e27f5e..5a070aff4a 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/buildingblock/controller/sdnc/prepare/PrepareSdncUpgradePreCheckPnfBBTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/buildingblock/controller/sdnc/prepare/PrepareSdncUpgradePreCheckPnfBBTest.java @@ -55,16 +55,40 @@ public class PrepareSdncUpgradePreCheckPnfBBTest { } @Test - public void prepare_jsonWithoutActionPayload() { + public void prepareJson_payloadWithoutAction() { String payloadWithoutActionArray = "{\"json name\": \"test1\"}"; ControllerContext controllerContext = - createControllerContext(payloadWithoutActionArray); + createControllerContext(payloadWithoutActionArray, "action1"); testedObject.prepare(controllerContext); assertThat((String) controllerContext.getExecution().getVariable("payload")) .isEqualTo(payloadWithoutActionArray); } + @Test + public void prepareJson_payloadWithActionJsonObject() { + String jsonActionObjectKey = "action1"; + String jsonActionObject = String.format("{\"%s\":\"act1\"}", jsonActionObjectKey); + String payloadWithActionArray = String.format("{\"json name\":\"test1\",\"action\": [%s]}", jsonActionObject); + ControllerContext controllerContext = + createControllerContext(payloadWithActionArray, jsonActionObjectKey); + + testedObject.prepare(controllerContext); + + assertThat((String) controllerContext.getExecution().getVariable("payload")).isEqualTo(jsonActionObject); + } + + @Test + public void prepareJson_payloadWithActionJsonObjectButDifferentKey() { + String payloadWithActionArray = ("{\"json name\":\"test1\",\"action\": [{\"action1\":\"act1\"}]}"); + ControllerContext controllerContext = + createControllerContext(payloadWithActionArray, "otherAction"); + + testedObject.prepare(controllerContext); + + assertThat((String) controllerContext.getExecution().getVariable("payload")).isEqualTo(payloadWithActionArray); + } + private ControllerContext createControllerContext(String actor, String action, String scope) { ControllerContext controllerContext = new ControllerContext<>(); @@ -74,9 +98,10 @@ public class PrepareSdncUpgradePreCheckPnfBBTest { return controllerContext; } - private ControllerContext createControllerContext(String payload) { + private ControllerContext createControllerContext(String payload, String action) { ControllerContext controllerContext = new ControllerContext<>(); controllerContext.setExecution(prepareBuildingBlockExecution(payload)); + controllerContext.setControllerAction(action); return controllerContext; } diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/service/level/ServiceLevelTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/service/level/ServiceLevelTest.java new file mode 100644 index 0000000000..cfaa4040c7 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/service/level/ServiceLevelTest.java @@ -0,0 +1,55 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2021 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.so.bpmn.infrastructure.service.level; + +import static org.assertj.core.api.Assertions.assertThat; +import java.util.ArrayList; +import org.camunda.bpm.engine.delegate.DelegateExecution; +import org.camunda.bpm.extension.mockito.delegate.DelegateExecutionFake; +import org.junit.Test; +import java.util.List; +import org.onap.so.bpmn.infrastructure.service.level.impl.ServiceLevelConstants; + +public class ServiceLevelTest { + + private static final String EXECUTION_KEY_PNF_NAME_LIST = "pnfNameList"; + private static final String EXECUTION_KEY_PNF_COUNTER = "pnfCounter"; + + @Test + public void pnfCounterExecution_success() { + // given + String pnfName = "pnfName1"; + DelegateExecution execution = new DelegateExecutionFake(); + execution.setVariable(EXECUTION_KEY_PNF_NAME_LIST, createPnfNameList(pnfName)); + execution.setVariable(EXECUTION_KEY_PNF_COUNTER, 0); + // when + new ServiceLevel().pnfCounterExecution(execution); + // then + assertThat(execution.getVariable(ServiceLevelConstants.PNF_NAME)).isEqualTo(pnfName); + assertThat(execution.getVariable(EXECUTION_KEY_PNF_COUNTER)).isEqualTo(1); + } + + private List createPnfNameList(String pnfName) { + List pnfNameList = new ArrayList<>(); + pnfNameList.add(pnfName); + return pnfNameList; + } +} -- cgit 1.2.3-korg