add junit coverage 55/117955/2
authorLukasz Muszkieta <lukasz.muszkieta@nokia.com>
Wed, 17 Feb 2021 14:49:17 +0000 (15:49 +0100)
committerLukasz Muszkieta <lukasz.muszkieta@nokia.com>
Thu, 4 Mar 2021 17:44:06 +0000 (18:44 +0100)
Issue-ID: SO-3433
Signed-off-by: Lukasz Muszkieta <lukasz.muszkieta@nokia.com>
Change-Id: If00e2a209cf28a57caa52a840bc8c10164a58ff4
Signed-off-by: Lukasz Muszkieta <lukasz.muszkieta@nokia.com>
bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/buildingblock/controller/sdnc/prepare/PrepareSdncUpgradePreCheckPnfBBTest.java
bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/service/level/ServiceLevelTest.java [new file with mode: 0644]

index 0ba1e27..5a070af 100644 (file)
@@ -55,16 +55,40 @@ public class PrepareSdncUpgradePreCheckPnfBBTest {
     }
 
     @Test
-    public void prepare_jsonWithoutActionPayload() {
+    public void prepareJson_payloadWithoutAction() {
         String payloadWithoutActionArray = "{\"json name\": \"test1\"}";
         ControllerContext<BuildingBlockExecution> 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<BuildingBlockExecution> 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<BuildingBlockExecution> controllerContext =
+                createControllerContext(payloadWithActionArray, "otherAction");
+
+        testedObject.prepare(controllerContext);
+
+        assertThat((String) controllerContext.getExecution().getVariable("payload")).isEqualTo(payloadWithActionArray);
+    }
+
     private ControllerContext<BuildingBlockExecution> createControllerContext(String actor, String action,
             String scope) {
         ControllerContext<BuildingBlockExecution> controllerContext = new ControllerContext<>();
@@ -74,9 +98,10 @@ public class PrepareSdncUpgradePreCheckPnfBBTest {
         return controllerContext;
     }
 
-    private ControllerContext<BuildingBlockExecution> createControllerContext(String payload) {
+    private ControllerContext<BuildingBlockExecution> createControllerContext(String payload, String action) {
         ControllerContext<BuildingBlockExecution> 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 (file)
index 0000000..cfaa404
--- /dev/null
@@ -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<String> createPnfNameList(String pnfName) {
+        List<String> pnfNameList = new ArrayList<>();
+        pnfNameList.add(pnfName);
+        return pnfNameList;
+    }
+}