2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019 Ericsson. All rights reserved.
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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
20 package org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks;
22 import static org.junit.Assert.assertNotNull;
23 import static org.junit.Assert.assertTrue;
24 import static org.mockito.ArgumentMatchers.any;
25 import static org.mockito.ArgumentMatchers.eq;
26 import static org.mockito.Mockito.when;
28 import java.io.Serializable;
29 import java.util.Collections;
30 import java.util.HashMap;
33 import org.junit.Test;
34 import org.mockito.Mock;
35 import org.mockito.Mockito;
36 import org.onap.so.bpmn.BaseTaskTest;
37 import org.onap.so.bpmn.common.BuildingBlockExecution;
38 import org.onap.so.bpmn.common.exceptions.RequiredExecutionVariableExeception;
39 import org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks.utils.InputParameter;
40 import org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks.utils.InputParametersProvider;
41 import org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks.utils.NullInputParameter;
42 import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf;
43 import org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock;
44 import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey;
45 import org.onap.so.client.exception.BBObjectNotFoundException;
48 * @author waqas.ikram@est.tech
50 public class InputParameterRetrieverTaskTest extends BaseTaskTest {
52 private final BuildingBlockExecution stubbedxecution = new StubbedBuildingBlockExecution();
55 private InputParametersProvider inputParametersProvider;
58 public void testGGetInputParameters_inputParameterStoredInExecutionContext() throws BBObjectNotFoundException {
59 final InputParameterRetrieverTask objUnderTest =
60 new InputParameterRetrieverTask(inputParametersProvider, extractPojosForBB);
62 final InputParameter inputParameter = new InputParameter(Collections.emptyMap(), Collections.emptyList());
63 when(inputParametersProvider.getInputParameter(Mockito.any(GenericVnf.class))).thenReturn(inputParameter);
64 when(extractPojosForBB.extractByKey(any(), eq(ResourceKey.GENERIC_VNF_ID))).thenReturn(new GenericVnf());
65 objUnderTest.getInputParameters(stubbedxecution);
67 final Object actual = stubbedxecution.getVariable(Constants.INPUT_PARAMETER);
68 assertNotNull(actual);
69 assertTrue(actual instanceof InputParameter);
73 public void testGGetInputParameters_ThrowExecption_NullInputParameterStoredInExecutionContext()
74 throws BBObjectNotFoundException {
75 final InputParameterRetrieverTask objUnderTest =
76 new InputParameterRetrieverTask(inputParametersProvider, extractPojosForBB);
78 when(inputParametersProvider.getInputParameter(Mockito.any(GenericVnf.class)))
79 .thenThrow(RuntimeException.class);
80 when(extractPojosForBB.extractByKey(any(), eq(ResourceKey.GENERIC_VNF_ID))).thenReturn(new GenericVnf());
81 objUnderTest.getInputParameters(stubbedxecution);
83 final Object actual = stubbedxecution.getVariable(Constants.INPUT_PARAMETER);
84 assertNotNull(actual);
85 assertTrue(actual instanceof NullInputParameter);
89 private class StubbedBuildingBlockExecution implements BuildingBlockExecution {
91 private final Map<String, Serializable> execution = new HashMap<>();
94 public GeneralBuildingBlock getGeneralBuildingBlock() {
98 @SuppressWarnings("unchecked")
100 public <T> T getVariable(final String key) {
101 return (T) execution.get(key);
105 public <T> T getRequiredVariable(final String key) throws RequiredExecutionVariableExeception {
110 public void setVariable(final String key, final Serializable value) {
111 execution.put(key, value);
115 public Map<ResourceKey, String> getLookupMap() {
116 return Collections.emptyMap();
120 public String getFlowToBeCalled() {