diff options
author | waqas.ikram <waqas.ikram@est.tech> | 2019-10-16 13:59:46 +0100 |
---|---|---|
committer | waqas.ikram <waqas.ikram@est.tech> | 2019-10-23 11:51:27 +0100 |
commit | 3b83a490bace15afe62b171242f2315f8805269f (patch) | |
tree | 12de5b716f90271b66a8ea7af885c27efbec7fb7 /bpmn | |
parent | 86f62530f1813152efbcc3d61f85e1fa6c943e36 (diff) |
Adding preload capability using userParams
Change-Id: Id107f2c9c2da643ecb57daaef26dfa2bfd89f8aa
Issue-ID: SO-1635
Signed-off-by: waqas.ikram <waqas.ikram@est.tech>
Diffstat (limited to 'bpmn')
15 files changed, 766 insertions, 181 deletions
diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/Constants.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/Constants.java index c112d200e3..9f85feac07 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/Constants.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/Constants.java @@ -60,5 +60,8 @@ public class Constants { public static final String OPERATION_STATUS_PARAM_NAME = "operationStatus"; + public static final String EXT_VIRTUAL_LINKS = "extVirtualLinks"; + public static final String ADDITIONAL_PARAMS = "additionalParams"; + private Constants() {} } diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/InputParameterRetrieverTask.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/InputParameterRetrieverTask.java index 661fdb258b..877d065085 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/InputParameterRetrieverTask.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/InputParameterRetrieverTask.java @@ -21,12 +21,17 @@ package org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks; import static org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks.Constants.INPUT_PARAMETER; import static org.onap.so.bpmn.servicedecomposition.entities.ResourceKey.GENERIC_VNF_ID; +import java.util.HashMap; +import java.util.List; +import java.util.Map; import org.onap.so.bpmn.common.BuildingBlockExecution; import org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks.utils.InputParameter; import org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks.utils.InputParametersProvider; import org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks.utils.NullInputParameter; import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf; +import org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock; import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB; +import org.onap.so.client.exception.BBObjectNotFoundException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -42,14 +47,18 @@ public class InputParameterRetrieverTask { private static final Logger LOGGER = LoggerFactory.getLogger(InputParameterRetrieverTask.class); - private final InputParametersProvider inputParametersProvider; + private final InputParametersProvider<GenericVnf> sdncInputParametersProvider; private final ExtractPojosForBB extractPojosForBB; + private final InputParametersProvider<Map<String, Object>> userParamInputParametersProvider; + @Autowired - public InputParameterRetrieverTask(final InputParametersProvider inputParametersProvider, + public InputParameterRetrieverTask(final InputParametersProvider<GenericVnf> inputParametersProvider, + final InputParametersProvider<Map<String, Object>> userParamInputParametersProvider, final ExtractPojosForBB extractPojosForBB) { - this.inputParametersProvider = inputParametersProvider; + this.sdncInputParametersProvider = inputParametersProvider; + this.userParamInputParametersProvider = userParamInputParametersProvider; this.extractPojosForBB = extractPojosForBB; } @@ -57,17 +66,56 @@ public class InputParameterRetrieverTask { try { LOGGER.debug("Executing getInputParameters ..."); - final GenericVnf vnf = extractPojosForBB.extractByKey(execution, GENERIC_VNF_ID); - final InputParameter inputParameter = inputParametersProvider.getInputParameter(vnf); + final InputParameter inputParameter = new InputParameter(); + + final InputParameter userParamsInputParameter = getUserParamsInputParameter(execution); + final InputParameter sdncInputParameter = getSdncInputParameter(execution); + + inputParameter.putAdditionalParams(sdncInputParameter.getAdditionalParams()); + inputParameter.addExtVirtualLinks(sdncInputParameter.getExtVirtualLinks()); + + inputParameter.putAdditionalParams(userParamsInputParameter.getAdditionalParams()); + inputParameter.addExtVirtualLinks(userParamsInputParameter.getExtVirtualLinks()); LOGGER.debug("inputParameter: {}", inputParameter); execution.setVariable(INPUT_PARAMETER, inputParameter); LOGGER.debug("Finished executing getInputParameters ..."); } catch (final Exception exception) { - LOGGER.error("Unable to invoke create and instantiation request", exception); + LOGGER.error("Unable to get input parameters", exception); execution.setVariable(INPUT_PARAMETER, NullInputParameter.NULL_INSTANCE); } } + private InputParameter getSdncInputParameter(final BuildingBlockExecution execution) + throws BBObjectNotFoundException { + final GenericVnf vnf = extractPojosForBB.extractByKey(execution, GENERIC_VNF_ID); + return sdncInputParametersProvider.getInputParameter(vnf); + } + + private InputParameter getUserParamsInputParameter(final BuildingBlockExecution execution) { + final GeneralBuildingBlock generalBuildingBlock = execution.getGeneralBuildingBlock(); + + if (generalBuildingBlock != null && generalBuildingBlock.getRequestContext() != null + && generalBuildingBlock.getRequestContext().getRequestParameters() != null) { + + final List<Map<String, Object>> userParams = + generalBuildingBlock.getRequestContext().getRequestParameters().getUserParams(); + if (userParams != null) { + final Map<String, Object> params = new HashMap<>(); + + userParams.stream().forEach(obj -> { + params.putAll(obj); + }); + LOGGER.info("User params found : {}", params); + if (userParams != null && !userParams.isEmpty()) { + return userParamInputParametersProvider.getInputParameter(params); + } + } + + } + LOGGER.warn("No input parameters found in userparams ..."); + return NullInputParameter.NULL_INSTANCE; + } + } diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/utils/AbstractInputParametersProvider.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/utils/AbstractInputParametersProvider.java new file mode 100644 index 0000000000..5cd84a2e11 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/utils/AbstractInputParametersProvider.java @@ -0,0 +1,66 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.adapter.vnfm.tasks.utils; + +import static org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks.Constants.ADDITIONAL_PARAMS; +import static org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks.Constants.EXT_VIRTUAL_LINKS; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import org.onap.vnfmadapter.v1.model.ExternalVirtualLink; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.ObjectMapper; + +/** + * @author Waqas Ikram (waqas.ikram@ericsson.com) + * + */ +public abstract class AbstractInputParametersProvider<T> implements InputParametersProvider<T> { + + private static final Logger LOGGER = LoggerFactory.getLogger(AbstractInputParametersProvider.class); + + protected Map<String, String> parseAdditionalParameters(final String additionalParamsString) { + try { + final ObjectMapper mapper = new ObjectMapper(); + final TypeReference<Map<String, String>> typeRef = new TypeReference<Map<String, String>>() {}; + return mapper.readValue(additionalParamsString, typeRef); + } catch (final Exception exception) { + LOGGER.error("Unable to parse {} ", ADDITIONAL_PARAMS, exception); + } + return Collections.emptyMap(); + + } + + protected List<ExternalVirtualLink> parseExternalVirtualLinks(final String extVirtualLinksString) { + try { + final ObjectMapper mapper = new ObjectMapper(); + final TypeReference<List<ExternalVirtualLink>> extVirtualLinksStringTypeRef = + new TypeReference<List<ExternalVirtualLink>>() {}; + return mapper.readValue(extVirtualLinksString, extVirtualLinksStringTypeRef); + } catch (final Exception exception) { + LOGGER.error("Unable to parse {} ", EXT_VIRTUAL_LINKS, exception); + } + return Collections.emptyList(); + } + + +} diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/utils/InputParameter.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/utils/InputParameter.java index d01d494c58..fde69c7e91 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/utils/InputParameter.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/utils/InputParameter.java @@ -24,6 +24,8 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.stream.Collectors; +import java.util.stream.Stream; import org.onap.vnfmadapter.v1.model.ExternalVirtualLink; /** @@ -39,6 +41,8 @@ public class InputParameter implements Serializable { private List<ExternalVirtualLink> extVirtualLinks = new ArrayList<>(); + public InputParameter() {} + public InputParameter(final Map<String, String> additionalParams, final List<ExternalVirtualLink> extVirtualLinks) { this.additionalParams = additionalParams; this.extVirtualLinks = extVirtualLinks; @@ -65,6 +69,12 @@ public class InputParameter implements Serializable { this.additionalParams = additionalParams; } + public void putAdditionalParams(final Map<String, String> additionalParams) { + if (additionalParams != null) { + this.additionalParams.putAll(additionalParams); + } + } + /** * @param extVirtualLinks the extVirtualLinks to set */ @@ -72,9 +82,17 @@ public class InputParameter implements Serializable { this.extVirtualLinks = extVirtualLinks; } + public void addExtVirtualLinks(final List<ExternalVirtualLink> extVirtualLinks) { + if (extVirtualLinks != null) { + this.extVirtualLinks = Stream.concat(this.extVirtualLinks.stream(), extVirtualLinks.stream()).distinct() + .collect(Collectors.toList()); + } + } + @Override public String toString() { - return "InputParameter [additionalParams=" + additionalParams + ", extVirtualLinks=" + extVirtualLinks + "]"; + return this.getClass().getSimpleName() + " [additionalParams=" + additionalParams + ", extVirtualLinks=" + + extVirtualLinks + "]"; } } diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/utils/InputParametersProvider.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/utils/InputParametersProvider.java index 55203fb7cc..2d11143fff 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/utils/InputParametersProvider.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/utils/InputParametersProvider.java @@ -19,13 +19,11 @@ */ package org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks.utils; -import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf; - /** * @author waqas.ikram@est.tech */ -public interface InputParametersProvider { +public interface InputParametersProvider<T> { - InputParameter getInputParameter(final GenericVnf genericVnf); + InputParameter getInputParameter(final T object); } diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/utils/NullInputParameter.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/utils/NullInputParameter.java index fb877ac55d..2eed224eb7 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/utils/NullInputParameter.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/utils/NullInputParameter.java @@ -20,12 +20,18 @@ package org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks.utils; import java.util.Collections; +import java.util.List; +import java.util.Map; +import org.onap.vnfmadapter.v1.model.ExternalVirtualLink; /** * @author waqas.ikram@est.tech */ public class NullInputParameter extends InputParameter { + private static final String ERROR = + "method should not be called for null object " + NullInputParameter.class.getSimpleName(); + private static final long serialVersionUID = -7261286746726871696L; public static final NullInputParameter NULL_INSTANCE = new NullInputParameter(); @@ -34,4 +40,23 @@ public class NullInputParameter extends InputParameter { super(Collections.emptyMap(), Collections.emptyList()); } + @Override + public void setAdditionalParams(final Map<String, String> additionalParams) { + throw new UnsupportedOperationException("setAdditionalParams() " + ERROR); + } + + @Override + public void setExtVirtualLinks(final List<ExternalVirtualLink> extVirtualLinks) { + throw new UnsupportedOperationException("setExtVirtualLinks() " + ERROR); + } + + @Override + public void addExtVirtualLinks(final List<ExternalVirtualLink> extVirtualLinks) { + throw new UnsupportedOperationException("addExtVirtualLinks() " + ERROR); + } + + @Override + public void putAdditionalParams(final Map<String, String> additionalParams) { + throw new UnsupportedOperationException("putAdditionalParams() " + ERROR); + } } diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/utils/InputParametersProviderImpl.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/utils/SdncInputParametersProvider.java index bf4f16b355..7d81f4d5c2 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/utils/InputParametersProviderImpl.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/utils/SdncInputParametersProvider.java @@ -19,6 +19,8 @@ */ package org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks.utils; +import static org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks.Constants.ADDITIONAL_PARAMS; +import static org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks.Constants.EXT_VIRTUAL_LINKS; import static org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks.Constants.FORWARD_SLASH; import static org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks.Constants.PRELOAD_VNFS_URL; import java.io.IOException; @@ -35,8 +37,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; -import com.fasterxml.jackson.core.JsonParseException; -import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; import com.jayway.jsonpath.JsonPath; import net.minidev.json.JSONArray; @@ -48,18 +48,16 @@ import net.minidev.json.JSONArray; * @author waqas.ikram@est.tech */ @Service -public class InputParametersProviderImpl implements InputParametersProvider { +public class SdncInputParametersProvider extends AbstractInputParametersProvider<GenericVnf> { - private static final Logger LOGGER = LoggerFactory.getLogger(InputParametersProviderImpl.class); + private static final Logger LOGGER = LoggerFactory.getLogger(SdncInputParametersProvider.class); - private static final String EXT_VIRTUAL_LINKS = "extVirtualLinks"; - private static final String ADDITIONAL_PARAMS = "additionalParams"; private static final String VNF_PARAMETERS_PATH = "$..vnf-parameters"; private final SDNCClient sdncClient; @Autowired - public InputParametersProviderImpl(final SDNCClient sdncClient) { + public SdncInputParametersProvider(final SDNCClient sdncClient) { this.sdncClient = sdncClient; } @@ -80,8 +78,11 @@ public class InputParametersProviderImpl implements InputParametersProvider { if (vnfParametersObject instanceof JSONArray) { final JSONArray vnfParameters = (JSONArray) vnfParametersObject; final Map<String, String> vnfParametersMap = getVnfParameterMap(vnfParameters); - return new InputParameter(getAdditionalParameters(vnfParametersMap), - getExtVirtualLinks(vnfParametersMap)); + final Map<String, String> additionalParameters = getAdditionalParameters(vnfParametersMap); + final List<ExternalVirtualLink> extVirtualLinks = getExtVirtualLinks(vnfParametersMap); + final InputParameter inputParameter = new InputParameter(additionalParameters, extVirtualLinks); + LOGGER.info("InputParameter found in sdnc response : {}", inputParameter); + return inputParameter; } } } @@ -93,39 +94,24 @@ public class InputParametersProviderImpl implements InputParametersProvider { } - private List<ExternalVirtualLink> getExtVirtualLinks(final Map<String, String> vnfParametersMap) - throws JsonParseException, IOException { - try { - final String extVirtualLinksString = vnfParametersMap.get(EXT_VIRTUAL_LINKS); - - if (extVirtualLinksString != null && !extVirtualLinksString.isEmpty()) { - final ObjectMapper mapper = new ObjectMapper(); - final TypeReference<List<ExternalVirtualLink>> extVirtualLinksStringTypeRef = - new TypeReference<List<ExternalVirtualLink>>() {}; + private List<ExternalVirtualLink> getExtVirtualLinks(final Map<String, String> vnfParametersMap) { + final String extVirtualLinksString = vnfParametersMap.get(EXT_VIRTUAL_LINKS); - return mapper.readValue(extVirtualLinksString, extVirtualLinksStringTypeRef); - } - } catch (final Exception exception) { - LOGGER.error("Unable to parse {} ", EXT_VIRTUAL_LINKS, exception); + if (extVirtualLinksString != null && !extVirtualLinksString.isEmpty()) { + return parseExternalVirtualLinks(extVirtualLinksString); } return Collections.emptyList(); } - private Map<String, String> getAdditionalParameters(final Map<String, String> vnfParametersMap) - throws JsonParseException, IOException { - try { - final String additionalParamsString = vnfParametersMap.get(ADDITIONAL_PARAMS); - if (additionalParamsString != null && !additionalParamsString.isEmpty()) { - final ObjectMapper mapper = new ObjectMapper(); - final TypeReference<Map<String, String>> typeRef = new TypeReference<Map<String, String>>() {}; - return mapper.readValue(additionalParamsString, typeRef); - } - } catch (final Exception exception) { - LOGGER.error("Unable to parse {} ", ADDITIONAL_PARAMS, exception); + private Map<String, String> getAdditionalParameters(final Map<String, String> vnfParametersMap) { + final String additionalParamsString = vnfParametersMap.get(ADDITIONAL_PARAMS); + if (additionalParamsString != null && !additionalParamsString.isEmpty()) { + return parseAdditionalParameters(additionalParamsString); } return Collections.emptyMap(); } + private Map<String, String> getVnfParameterMap(final JSONArray array) { try { if (array != null) { diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/utils/UserParamInputParametersProvider.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/utils/UserParamInputParametersProvider.java new file mode 100644 index 0000000000..ac939d04ec --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/utils/UserParamInputParametersProvider.java @@ -0,0 +1,58 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.adapter.vnfm.tasks.utils; + +import static org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks.Constants.ADDITIONAL_PARAMS; +import static org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks.Constants.EXT_VIRTUAL_LINKS; +import java.util.Map; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Service; + +/** + * @author Waqas Ikram (waqas.ikram@ericsson.com) + * + */ +@Service +public class UserParamInputParametersProvider extends AbstractInputParametersProvider<Map<String, Object>> { + private static final Logger LOGGER = LoggerFactory.getLogger(UserParamInputParametersProvider.class); + + @Override + public InputParameter getInputParameter(final Map<String, Object> userParams) { + if (userParams != null) { + final InputParameter inputParameter = new InputParameter(); + final Object additionalParams = userParams.get(ADDITIONAL_PARAMS); + + if (additionalParams != null && additionalParams instanceof String) { + inputParameter.setAdditionalParams(parseAdditionalParameters(additionalParams.toString())); + } + + final Object extVirtualLinks = userParams.get(EXT_VIRTUAL_LINKS); + if (extVirtualLinks != null && extVirtualLinks instanceof String) { + inputParameter.setExtVirtualLinks(parseExternalVirtualLinks(extVirtualLinks.toString())); + } + LOGGER.info("InputParameter found in userParams : {}", inputParameter); + return inputParameter; + } + LOGGER.warn("No input parameters found ..."); + return NullInputParameter.NULL_INSTANCE; + } + +} diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/InputParameterRetrieverTaskTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/InputParameterRetrieverTaskTest.java deleted file mode 100644 index caae90bfff..0000000000 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/InputParameterRetrieverTaskTest.java +++ /dev/null @@ -1,128 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2019 Ericsson. All rights reserved. - * ================================================================================ - * 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.adapter.vnfm.tasks; - -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.when; -import java.io.Serializable; -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; -import org.junit.Test; -import org.mockito.Mock; -import org.mockito.Mockito; -import org.onap.so.bpmn.BaseTaskTest; -import org.onap.so.bpmn.common.BuildingBlockExecution; -import org.onap.so.bpmn.common.exceptions.RequiredExecutionVariableExeception; -import org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks.utils.InputParameter; -import org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks.utils.InputParametersProvider; -import org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks.utils.NullInputParameter; -import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf; -import org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock; -import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey; -import org.onap.so.client.exception.BBObjectNotFoundException; - -/** - * @author waqas.ikram@est.tech - */ -public class InputParameterRetrieverTaskTest extends BaseTaskTest { - - private final BuildingBlockExecution stubbedxecution = new StubbedBuildingBlockExecution(); - - @Mock - private InputParametersProvider inputParametersProvider; - - @Test - public void testGGetInputParameters_inputParameterStoredInExecutionContext() throws BBObjectNotFoundException { - final InputParameterRetrieverTask objUnderTest = - new InputParameterRetrieverTask(inputParametersProvider, extractPojosForBB); - - final InputParameter inputParameter = new InputParameter(Collections.emptyMap(), Collections.emptyList()); - when(inputParametersProvider.getInputParameter(Mockito.any(GenericVnf.class))).thenReturn(inputParameter); - when(extractPojosForBB.extractByKey(any(), eq(ResourceKey.GENERIC_VNF_ID))).thenReturn(new GenericVnf()); - objUnderTest.getInputParameters(stubbedxecution); - - final Object actual = stubbedxecution.getVariable(Constants.INPUT_PARAMETER); - assertNotNull(actual); - assertTrue(actual instanceof InputParameter); - } - - @Test - public void testGGetInputParameters_ThrowExecption_NullInputParameterStoredInExecutionContext() - throws BBObjectNotFoundException { - final InputParameterRetrieverTask objUnderTest = - new InputParameterRetrieverTask(inputParametersProvider, extractPojosForBB); - - when(inputParametersProvider.getInputParameter(Mockito.any(GenericVnf.class))) - .thenThrow(RuntimeException.class); - when(extractPojosForBB.extractByKey(any(), eq(ResourceKey.GENERIC_VNF_ID))).thenReturn(new GenericVnf()); - objUnderTest.getInputParameters(stubbedxecution); - - final Object actual = stubbedxecution.getVariable(Constants.INPUT_PARAMETER); - assertNotNull(actual); - assertTrue(actual instanceof NullInputParameter); - } - - - private class StubbedBuildingBlockExecution implements BuildingBlockExecution { - - private final Map<String, Serializable> execution = new HashMap<>(); - - @Override - public GeneralBuildingBlock getGeneralBuildingBlock() { - return null; - } - - @SuppressWarnings("unchecked") - @Override - public <T> T getVariable(final String key) { - return (T) execution.get(key); - } - - @Override - public <T> T getRequiredVariable(final String key) throws RequiredExecutionVariableExeception { - return null; - } - - @Override - public void setVariable(final String key, final Serializable value) { - execution.put(key, value); - } - - @Override - public Map<ResourceKey, String> getLookupMap() { - return Collections.emptyMap(); - } - - @Override - public String getFlowToBeCalled() { - return null; - } - - @Override - public int getCurrentSequence() { - return 0; - } - - } -} diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/TestConstants.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/TestConstants.java index 7b63e5f811..686b4f80cc 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/TestConstants.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/TestConstants.java @@ -20,9 +20,11 @@ package org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks; -import static org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks.TestConstants.DUMMY_URL; +import static org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks.Constants.ADDITIONAL_PARAMS; +import static org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks.Constants.EXT_VIRTUAL_LINKS; +import java.util.HashMap; +import java.util.Map; import java.util.UUID; -import org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks.VnfmBasicHttpConfigProvider; /** * @author waqas.ikram@est.tech @@ -30,6 +32,7 @@ import org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks.VnfmBasicHttpConfigPro */ public class TestConstants { + public static final String EXT_VIRTUAL_LINK_ID = "ac1ed33d-8dc1-4800-8ce8-309b99c38eec"; public static final String DUMMY_GENERIC_VND_ID = "5956a99d-9736-11e8-8caf-022ac9304eeb"; public static final String DUMMY_BASIC_AUTH = "Basic 123abc"; public static final String DUMMY_URL = "http://localhost:30406/so/vnfm-adapter/v1/"; @@ -38,6 +41,19 @@ public class TestConstants { public static final String DUMMY_JOB_ID = UUID.randomUUID().toString(); public static final String JOB_STATUS_EXPECTED_URL = DUMMY_URL + "jobs/" + DUMMY_JOB_ID; + public static final String EXT_VIRTUAL_LINK_VALUE = "{\"id\":\"" + EXT_VIRTUAL_LINK_ID + "\"," + + "\"tenant\":{\"cloudOwner\":\"CloudOwner\",\"regionName\":\"RegionOne\"," + + "\"tenantId\":\"80c26954-2536-4bca-9e20-10f8a2c9c2ad\"},\"resourceId\":\"8ef8cd54-75fd-4372-a6dd-2e05ea8fbd9b\"," + + "\"extCps\":[{\"cpdId\":\"f449292f-2f0f-4656-baa3-a18d86bac80f\"," + + "\"cpConfig\":[{\"cpInstanceId\":\"07876709-b66f-465c-99a7-0f4d026197f2\"," + + "\"linkPortId\":null,\"cpProtocolData\":null}]}],\"extLinkPorts\":null}"; + + public static final String ADDITIONAL_PARAMS_VALUE = "{\"image_id\": \"DUMMYVNF\",\"instance_type\": \"m1.small\"," + + "\"ftp_address\": \"ftp://0.0.0.0:2100/\"}"; + + public static final String EXT_VIRTUAL_LINKS_VALUE = "[" + EXT_VIRTUAL_LINK_VALUE + "]"; + + public static VnfmBasicHttpConfigProvider getVnfmBasicHttpConfigProvider() { return getVnfmBasicHttpConfigProvider(DUMMY_URL, DUMMY_BASIC_AUTH); } @@ -49,6 +65,14 @@ public class TestConstants { return vnfmBasicHttpConfigProvider; } + public static Map<String, Object> getUserParamsMap(final String additionalParams, + final String extVirtualLinksValue) { + final Map<String, Object> userParams = new HashMap<>(); + userParams.put(ADDITIONAL_PARAMS, additionalParams); + userParams.put(EXT_VIRTUAL_LINKS, extVirtualLinksValue); + return userParams; + } + private TestConstants() {} } diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/utils/InputParameterRetrieverTaskTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/utils/InputParameterRetrieverTaskTest.java new file mode 100644 index 0000000000..9003510be7 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/utils/InputParameterRetrieverTaskTest.java @@ -0,0 +1,248 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 Ericsson. All rights reserved. + * ================================================================================ + * 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.adapter.vnfm.tasks.utils; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.when; +import static org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks.TestConstants.ADDITIONAL_PARAMS_VALUE; +import static org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks.TestConstants.EXT_VIRTUAL_LINKS_VALUE; +import static org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks.TestConstants.EXT_VIRTUAL_LINK_ID; +import static org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks.TestConstants.getUserParamsMap; +import java.io.Serializable; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.UUID; +import org.junit.Test; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.onap.so.bpmn.BaseTaskTest; +import org.onap.so.bpmn.common.BuildingBlockExecution; +import org.onap.so.bpmn.common.exceptions.RequiredExecutionVariableExeception; +import org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks.Constants; +import org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks.InputParameterRetrieverTask; +import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf; +import org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock; +import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey; +import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext; +import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestParameters; +import org.onap.so.client.exception.BBObjectNotFoundException; +import org.onap.so.client.sdnc.SDNCClient; +import org.onap.vnfmadapter.v1.model.ExternalVirtualLink; +import org.onap.vnfmadapter.v1.model.ExternalVirtualLinkCpConfig; +import org.onap.vnfmadapter.v1.model.ExternalVirtualLinkExtCps; + +/** + * @author waqas.ikram@est.tech + */ +public class InputParameterRetrieverTaskTest extends BaseTaskTest { + + private static final String INSTANCE_TYPE_VALUE_1 = "m1.small"; + + private static final String INSTANCE_TYPE_VALUE_2 = "m1.large"; + + private static final String INSTANCE_TYPE = "instance_type"; + + private static final String RANDOM_EXT_VIRTUAL_LINK_ID = UUID.randomUUID().toString(); + + private static final String CPU_INSTANCE_ID = EXT_VIRTUAL_LINK_ID; + + private static final String FLAVOR_VALUE = "ubuntu"; + + private static final String FLAVOR = "flavor_type"; + + private final StubbedBuildingBlockExecution stubbedxecution = new StubbedBuildingBlockExecution(); + + @Mock + private InputParametersProvider<GenericVnf> sdncInputParametersProvider; + + private final InputParametersProvider<Map<String, Object>> userParamsinputParametersProvider = + new UserParamInputParametersProvider(); + + @Mock + private SDNCClient mockedSdncClient; + + @Test + public void testGetInputParameters_inputParameterStoredInExecutionContext() throws BBObjectNotFoundException { + final InputParameterRetrieverTask objUnderTest = new InputParameterRetrieverTask(sdncInputParametersProvider, + userParamsinputParametersProvider, extractPojosForBB); + + + final GeneralBuildingBlock buildingBlock = + getGeneralBuildingBlock(getUserParamsMap(ADDITIONAL_PARAMS_VALUE, null)); + stubbedxecution.setGeneralBuildingBlock(buildingBlock); + + final InputParameter inputParameter = new InputParameter(Collections.emptyMap(), Collections.emptyList()); + when(sdncInputParametersProvider.getInputParameter(Mockito.any(GenericVnf.class))).thenReturn(inputParameter); + + when(extractPojosForBB.extractByKey(any(), eq(ResourceKey.GENERIC_VNF_ID))).thenReturn(new GenericVnf()); + objUnderTest.getInputParameters(stubbedxecution); + + final Object actual = stubbedxecution.getVariable(Constants.INPUT_PARAMETER); + assertNotNull(actual); + assertTrue(actual instanceof InputParameter); + final InputParameter actualInputParameter = (InputParameter) actual; + final Map<String, String> actualAdditionalParams = actualInputParameter.getAdditionalParams(); + assertEquals(3, actualAdditionalParams.size()); + + final String actualInstanceType = actualAdditionalParams.get(INSTANCE_TYPE); + assertEquals(INSTANCE_TYPE_VALUE_1, actualInstanceType); + + } + + @Test + public void testGetInputParameters_ThrowExecption_NullInputParameterStoredInExecutionContext() + throws BBObjectNotFoundException { + final InputParameterRetrieverTask objUnderTest = new InputParameterRetrieverTask(sdncInputParametersProvider, + userParamsinputParametersProvider, extractPojosForBB); + + when(sdncInputParametersProvider.getInputParameter(Mockito.any(GenericVnf.class))) + .thenThrow(RuntimeException.class); + when(extractPojosForBB.extractByKey(any(), eq(ResourceKey.GENERIC_VNF_ID))).thenReturn(new GenericVnf()); + objUnderTest.getInputParameters(stubbedxecution); + + final Object actual = stubbedxecution.getVariable(Constants.INPUT_PARAMETER); + assertNotNull(actual); + assertTrue(actual instanceof NullInputParameter); + } + + @Test + public void testGetInputParameters_SdncAndUserParamInputParameterStoredInExecutionContext() + throws BBObjectNotFoundException { + final InputParameterRetrieverTask objUnderTest = new InputParameterRetrieverTask(sdncInputParametersProvider, + userParamsinputParametersProvider, extractPojosForBB); + + + final GeneralBuildingBlock buildingBlock = + getGeneralBuildingBlock(getUserParamsMap(ADDITIONAL_PARAMS_VALUE, EXT_VIRTUAL_LINKS_VALUE)); + stubbedxecution.setGeneralBuildingBlock(buildingBlock); + + final InputParameter inputParameter = new InputParameter(getAdditionalParams(), getExternalVirtualLink()); + when(sdncInputParametersProvider.getInputParameter(Mockito.any(GenericVnf.class))).thenReturn(inputParameter); + + when(extractPojosForBB.extractByKey(any(), eq(ResourceKey.GENERIC_VNF_ID))).thenReturn(new GenericVnf()); + objUnderTest.getInputParameters(stubbedxecution); + + final Object actual = stubbedxecution.getVariable(Constants.INPUT_PARAMETER); + assertNotNull(actual); + assertTrue(actual instanceof InputParameter); + final InputParameter actualInputParameter = (InputParameter) actual; + final Map<String, String> actualAdditionalParams = actualInputParameter.getAdditionalParams(); + assertEquals(4, actualAdditionalParams.size()); + + final String actualInstanceType = actualAdditionalParams.get(INSTANCE_TYPE); + assertEquals(INSTANCE_TYPE_VALUE_1, actualInstanceType); + + assertEquals(FLAVOR_VALUE, actualAdditionalParams.get(FLAVOR)); + final List<ExternalVirtualLink> actualExtVirtualLinks = actualInputParameter.getExtVirtualLinks(); + assertEquals(2, actualExtVirtualLinks.size()); + + final Optional<ExternalVirtualLink> externalVirtualLink0 = actualExtVirtualLinks.stream() + .filter(extVirtualLink -> EXT_VIRTUAL_LINK_ID.equals(extVirtualLink.getId())).findAny(); + assertTrue(externalVirtualLink0.isPresent()); + assertEquals(EXT_VIRTUAL_LINK_ID, externalVirtualLink0.get().getId()); + + final Optional<ExternalVirtualLink> externalVirtualLink1 = actualExtVirtualLinks.stream() + .filter(extVirtualLink -> RANDOM_EXT_VIRTUAL_LINK_ID.equals(extVirtualLink.getId())).findAny(); + assertTrue(externalVirtualLink1.isPresent()); + assertEquals(RANDOM_EXT_VIRTUAL_LINK_ID, externalVirtualLink1.get().getId()); + + + } + + private List<ExternalVirtualLink> getExternalVirtualLink() { + return Arrays.asList( + new ExternalVirtualLink().id(RANDOM_EXT_VIRTUAL_LINK_ID).addExtCpsItem(new ExternalVirtualLinkExtCps() + .addCpConfigItem(new ExternalVirtualLinkCpConfig().cpInstanceId(CPU_INSTANCE_ID)))); + } + + private Map<String, String> getAdditionalParams() { + final Map<String, String> additionalParams = new HashMap<>(); + additionalParams.put(FLAVOR, FLAVOR_VALUE); + additionalParams.put(INSTANCE_TYPE, INSTANCE_TYPE_VALUE_2); + return additionalParams; + } + + + private GeneralBuildingBlock getGeneralBuildingBlock(final Map<String, Object> userParams) { + final GeneralBuildingBlock buildingBlock = new GeneralBuildingBlock(); + final RequestContext requestContext = new RequestContext(); + final RequestParameters requestParameters = new RequestParameters(); + requestParameters.setUserParams(Arrays.asList(userParams)); + requestContext.setRequestParameters(requestParameters); + buildingBlock.setRequestContext(requestContext); + return buildingBlock; + + } + + private class StubbedBuildingBlockExecution implements BuildingBlockExecution { + + private final Map<String, Serializable> execution = new HashMap<>(); + private GeneralBuildingBlock buildingBlock; + + private void setGeneralBuildingBlock(final GeneralBuildingBlock buildingBlock) { + this.buildingBlock = buildingBlock; + } + + @Override + public GeneralBuildingBlock getGeneralBuildingBlock() { + return buildingBlock; + } + + @SuppressWarnings("unchecked") + @Override + public <T> T getVariable(final String key) { + return (T) execution.get(key); + } + + @Override + public <T> T getRequiredVariable(final String key) throws RequiredExecutionVariableExeception { + return null; + } + + @Override + public void setVariable(final String key, final Serializable value) { + execution.put(key, value); + } + + @Override + public Map<ResourceKey, String> getLookupMap() { + return Collections.emptyMap(); + } + + @Override + public String getFlowToBeCalled() { + return null; + } + + @Override + public int getCurrentSequence() { + return 0; + } + + } +} diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/utils/InputParameterTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/utils/InputParameterTest.java new file mode 100644 index 0000000000..6dee904fde --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/utils/InputParameterTest.java @@ -0,0 +1,79 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.adapter.vnfm.tasks.utils; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.UUID; +import org.junit.Test; +import org.onap.vnfmadapter.v1.model.ExternalVirtualLink; + +/** + * @author Waqas Ikram (waqas.ikram@ericsson.com) + * + */ +public class InputParameterTest { + @Test + public void test_putAdditionalParams_addsEntryToExistingMap() { + final InputParameter objUnderTest = new InputParameter(); + objUnderTest.setAdditionalParams(getMap("name", "value")); + objUnderTest.putAdditionalParams(getMap("name1", "value1")); + + final Map<String, String> additionalParams = objUnderTest.getAdditionalParams(); + assertEquals(2, additionalParams.size()); + assertTrue(additionalParams.containsKey("name")); + assertTrue(additionalParams.containsKey("name1")); + + } + + @Test + public void test_addExtVirtualLinks_adddistinctEntriesToExistingList() { + final InputParameter objUnderTest = new InputParameter(); + String firstId = UUID.randomUUID().toString(); + String secondId = UUID.randomUUID().toString(); + objUnderTest.setExtVirtualLinks(getExternalVirtualLinkList(firstId)); + objUnderTest.addExtVirtualLinks(getExternalVirtualLinkList(secondId)); + objUnderTest.addExtVirtualLinks(getExternalVirtualLinkList(secondId)); + objUnderTest.addExtVirtualLinks(getExternalVirtualLinkList(secondId)); + + final List<ExternalVirtualLink> externalVirtualLinks = objUnderTest.getExtVirtualLinks(); + assertEquals(2, externalVirtualLinks.size()); + + } + + private List<ExternalVirtualLink> getExternalVirtualLinkList(final String id) { + final ExternalVirtualLink externalVirtualLink = new ExternalVirtualLink(); + externalVirtualLink.setId(id); + final List<ExternalVirtualLink> list = new ArrayList<>(); + list.add(externalVirtualLink); + return list; + } + + private Map<String, String> getMap(final String name, final String value) { + final Map<String, String> map = new HashMap<>(); + map.put(name, value); + return map; + } + +} diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/utils/NullInputParameterTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/utils/NullInputParameterTest.java new file mode 100644 index 0000000000..e076df7a9b --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/utils/NullInputParameterTest.java @@ -0,0 +1,62 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.adapter.vnfm.tasks.utils; + +import static org.junit.Assert.assertTrue; +import java.util.Collections; +import org.junit.Test; + +/** + * @author Waqas Ikram (waqas.ikram@ericsson.com) + * + */ +public class NullInputParameterTest { + + @Test(expected = UnsupportedOperationException.class) + public void test_addExtVirtualLinks_throwException() { + NullInputParameter.NULL_INSTANCE.addExtVirtualLinks(Collections.emptyList()); + } + + @Test(expected = UnsupportedOperationException.class) + public void test_setAdditionalParams_throwException() { + NullInputParameter.NULL_INSTANCE.setAdditionalParams(Collections.emptyMap()); + } + + @Test(expected = UnsupportedOperationException.class) + public void test_setExtVirtualLinks_throwException() { + NullInputParameter.NULL_INSTANCE.setExtVirtualLinks(Collections.emptyList()); + } + + @Test(expected = UnsupportedOperationException.class) + public void test_putAdditionalParams_throwException() { + NullInputParameter.NULL_INSTANCE.putAdditionalParams(Collections.emptyMap()); + } + + @Test + public void test_getAdditionalParams_ReturnEmptyCollection() { + assertTrue(NullInputParameter.NULL_INSTANCE.getAdditionalParams().isEmpty()); + } + + @Test + public void test_getExtVirtualLinks_ReturnEmptyCollection() { + assertTrue(NullInputParameter.NULL_INSTANCE.getExtVirtualLinks().isEmpty()); + } + +} diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/utils/InputParametersProviderImplTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/utils/SdncInputParametersProviderImplTest.java index 51e86c1fea..e2e37ac6e4 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/utils/InputParametersProviderImplTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/utils/SdncInputParametersProviderImplTest.java @@ -48,7 +48,7 @@ import org.onap.vnfmadapter.v1.model.ExternalVirtualLink; * @author waqas.ikram@est.tech */ @RunWith(MockitoJUnitRunner.class) -public class InputParametersProviderImplTest { +public class SdncInputParametersProviderImplTest { private static final String BASE_DIR = "src/test/resources/__files/"; @@ -89,7 +89,7 @@ public class InputParametersProviderImplTest { @Test public void testGetInputParameter_ValidResponseFromSdncInvalidData_EmptyInputParameter() throws Exception { when(mockedSdncClient.get(Mockito.eq(URL))).thenReturn(getReponseAsString(INVALID_PRE_LOAD_SDNC_RESPONSE)); - final InputParametersProvider objUnderTest = new InputParametersProviderImpl(mockedSdncClient); + final InputParametersProvider<GenericVnf> objUnderTest = new SdncInputParametersProvider(mockedSdncClient); final InputParameter actual = objUnderTest.getInputParameter(getGenericVnf()); assertNotNull(actual); assertTrue(actual.getAdditionalParams().isEmpty()); @@ -99,7 +99,7 @@ public class InputParametersProviderImplTest { @Test public void testGetInputParameter_ExceptionThrownFromSdnc_EmptyInputParameter() throws Exception { when(mockedSdncClient.get(Mockito.eq(URL))).thenThrow(RuntimeException.class); - final InputParametersProvider objUnderTest = new InputParametersProviderImpl(mockedSdncClient); + final InputParametersProvider<GenericVnf> objUnderTest = new SdncInputParametersProvider(mockedSdncClient); final InputParameter actual = objUnderTest.getInputParameter(getGenericVnf()); assertNotNull(actual); assertTrue(actual instanceof NullInputParameter); @@ -110,7 +110,7 @@ public class InputParametersProviderImplTest { @Test public void testGetInputParameter_InvalidResponseData_EmptyInputParameter() throws Exception { when(mockedSdncClient.get(Mockito.eq(URL))).thenReturn(getReponseAsString(INVALID_ADDITIONAL_AND_EXT_VM_DATA)); - final InputParametersProvider objUnderTest = new InputParametersProviderImpl(mockedSdncClient); + final InputParametersProvider<GenericVnf> objUnderTest = new SdncInputParametersProvider(mockedSdncClient); final InputParameter actual = objUnderTest.getInputParameter(getGenericVnf()); assertNotNull(actual); assertTrue(actual.getAdditionalParams().isEmpty()); @@ -120,7 +120,7 @@ public class InputParametersProviderImplTest { @Test public void testGetInputParameter_EmptyResponseData_EmptyInputParameter() throws Exception { when(mockedSdncClient.get(Mockito.eq(URL))).thenReturn(""); - final InputParametersProvider objUnderTest = new InputParametersProviderImpl(mockedSdncClient); + final InputParametersProvider<GenericVnf> objUnderTest = new SdncInputParametersProvider(mockedSdncClient); final InputParameter actual = objUnderTest.getInputParameter(getGenericVnf()); assertNotNull(actual); assertTrue(actual instanceof NullInputParameter); @@ -131,7 +131,7 @@ public class InputParametersProviderImplTest { @Test public void testGetInputParameter_InvalidVnfParamsResponseData_EmptyInputParameter() throws Exception { when(mockedSdncClient.get(Mockito.eq(URL))).thenReturn(getReponseAsString(INVALID_VNF_PARAMS)); - final InputParametersProvider objUnderTest = new InputParametersProviderImpl(mockedSdncClient); + final InputParametersProvider<GenericVnf> objUnderTest = new SdncInputParametersProvider(mockedSdncClient); final InputParameter actual = objUnderTest.getInputParameter(getGenericVnf()); assertNotNull(actual); assertTrue(actual.getAdditionalParams().isEmpty()); @@ -140,7 +140,7 @@ public class InputParametersProviderImplTest { private void assertValues(final GenericVnf genericVnf) throws MapperException, BadResponseException, IOException { when(mockedSdncClient.get(Mockito.eq(URL))).thenReturn(getReponseAsString(PRE_LOAD_SDNC_RESPONSE)); - final InputParametersProvider objUnderTest = new InputParametersProviderImpl(mockedSdncClient); + final InputParametersProvider<GenericVnf> objUnderTest = new SdncInputParametersProvider(mockedSdncClient); final InputParameter actual = objUnderTest.getInputParameter(genericVnf); assertNotNull(actual); diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/utils/UserParamInputParametersProviderTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/utils/UserParamInputParametersProviderTest.java new file mode 100644 index 0000000000..e6d4ad056a --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/utils/UserParamInputParametersProviderTest.java @@ -0,0 +1,98 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.adapter.vnfm.tasks.utils; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks.TestConstants.ADDITIONAL_PARAMS_VALUE; +import static org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks.TestConstants.EXT_VIRTUAL_LINKS_VALUE; +import static org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks.TestConstants.EXT_VIRTUAL_LINK_VALUE; +import static org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks.TestConstants.getUserParamsMap; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import org.junit.Test; +import org.onap.vnfmadapter.v1.model.ExternalVirtualLink; + +/** + * @author Waqas Ikram (waqas.ikram@ericsson.com) + * + */ +public class UserParamInputParametersProviderTest { + + @Test + public void testGetInputParameter_ValidUserParams_NotEmptyInputParameter() throws Exception { + final InputParametersProvider<Map<String, Object>> objUnderTest = new UserParamInputParametersProvider(); + + final InputParameter actual = + objUnderTest.getInputParameter(getUserParamsMap(ADDITIONAL_PARAMS_VALUE, EXT_VIRTUAL_LINKS_VALUE)); + assertNotNull(actual); + + final Map<String, String> actualAdditionalParams = actual.getAdditionalParams(); + assertEquals(3, actualAdditionalParams.size()); + + final String actualInstanceType = actualAdditionalParams.get("instance_type"); + assertEquals("m1.small", actualInstanceType); + + final List<ExternalVirtualLink> actualExtVirtualLinks = actual.getExtVirtualLinks(); + assertEquals(1, actualExtVirtualLinks.size()); + + final ExternalVirtualLink actualExternalVirtualLink = actualExtVirtualLinks.get(0); + assertEquals("ac1ed33d-8dc1-4800-8ce8-309b99c38eec", actualExternalVirtualLink.getId()); + + } + + @Test + public void testGetInputParameter_EmptyOrNullUserParams_EmptyInputParameter() throws Exception { + final InputParametersProvider<Map<String, Object>> objUnderTest = new UserParamInputParametersProvider(); + + InputParameter actual = objUnderTest.getInputParameter(Collections.emptyMap()); + assertNotNull(actual); + assertTrue(actual.getAdditionalParams().isEmpty()); + assertTrue(actual.getExtVirtualLinks().isEmpty()); + + actual = objUnderTest.getInputParameter(null); + assertNotNull(actual); + assertTrue(actual instanceof NullInputParameter); + assertTrue(actual.getAdditionalParams().isEmpty()); + assertTrue(actual.getExtVirtualLinks().isEmpty()); + + } + + @Test + public void testGetInputParameter_InValidExtVirtualLinks_NotEmptyInputParameter() throws Exception { + final InputParametersProvider<Map<String, Object>> objUnderTest = new UserParamInputParametersProvider(); + + final InputParameter actual = + objUnderTest.getInputParameter(getUserParamsMap(ADDITIONAL_PARAMS_VALUE, EXT_VIRTUAL_LINK_VALUE)); + assertNotNull(actual); + + final Map<String, String> actualAdditionalParams = actual.getAdditionalParams(); + assertEquals(3, actualAdditionalParams.size()); + + final String actualInstanceType = actualAdditionalParams.get("instance_type"); + assertEquals("m1.small", actualInstanceType); + + assertTrue(actual.getExtVirtualLinks().isEmpty()); + + } + +} |