2  * ============LICENSE_START=======================================================
 
   3  *  Copyright (C) 2019 Nordix Foundation.
 
   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.utils;
 
  22 import static org.junit.Assert.assertEquals;
 
  23 import static org.junit.Assert.assertNotNull;
 
  24 import static org.junit.Assert.assertTrue;
 
  25 import static org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks.TestConstants.ADDITIONAL_PARAMS_VALUE;
 
  26 import static org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks.TestConstants.EXT_VIRTUAL_LINKS_VALUE;
 
  27 import static org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks.TestConstants.EXT_VIRTUAL_LINK_VALUE;
 
  28 import static org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks.TestConstants.getUserParamsMap;
 
  29 import java.util.Collections;
 
  30 import java.util.List;
 
  32 import org.junit.Test;
 
  33 import org.onap.vnfmadapter.v1.model.ExternalVirtualLink;
 
  36  * @author Waqas Ikram (waqas.ikram@ericsson.com)
 
  39 public class UserParamInputParametersProviderTest {
 
  42     public void testGetInputParameter_ValidUserParams_NotEmptyInputParameter() throws Exception {
 
  43         final InputParametersProvider<Map<String, Object>> objUnderTest = new UserParamInputParametersProvider();
 
  45         final InputParameter actual =
 
  46                 objUnderTest.getInputParameter(getUserParamsMap(ADDITIONAL_PARAMS_VALUE, EXT_VIRTUAL_LINKS_VALUE));
 
  47         assertNotNull(actual);
 
  49         final Map<String, String> actualAdditionalParams = actual.getAdditionalParams();
 
  50         assertEquals(3, actualAdditionalParams.size());
 
  52         final String actualInstanceType = actualAdditionalParams.get("instance_type");
 
  53         assertEquals("m1.small", actualInstanceType);
 
  55         final List<ExternalVirtualLink> actualExtVirtualLinks = actual.getExtVirtualLinks();
 
  56         assertEquals(1, actualExtVirtualLinks.size());
 
  58         final ExternalVirtualLink actualExternalVirtualLink = actualExtVirtualLinks.get(0);
 
  59         assertEquals("ac1ed33d-8dc1-4800-8ce8-309b99c38eec", actualExternalVirtualLink.getId());
 
  64     public void testGetInputParameter_EmptyOrNullUserParams_EmptyInputParameter() throws Exception {
 
  65         final InputParametersProvider<Map<String, Object>> objUnderTest = new UserParamInputParametersProvider();
 
  67         InputParameter actual = objUnderTest.getInputParameter(Collections.emptyMap());
 
  68         assertNotNull(actual);
 
  69         assertTrue(actual.getAdditionalParams().isEmpty());
 
  70         assertTrue(actual.getExtVirtualLinks().isEmpty());
 
  72         actual = objUnderTest.getInputParameter(null);
 
  73         assertNotNull(actual);
 
  74         assertTrue(actual instanceof NullInputParameter);
 
  75         assertTrue(actual.getAdditionalParams().isEmpty());
 
  76         assertTrue(actual.getExtVirtualLinks().isEmpty());
 
  81     public void testGetInputParameter_InValidExtVirtualLinks_NotEmptyInputParameter() throws Exception {
 
  82         final InputParametersProvider<Map<String, Object>> objUnderTest = new UserParamInputParametersProvider();
 
  84         final InputParameter actual =
 
  85                 objUnderTest.getInputParameter(getUserParamsMap(ADDITIONAL_PARAMS_VALUE, EXT_VIRTUAL_LINK_VALUE));
 
  86         assertNotNull(actual);
 
  88         final Map<String, String> actualAdditionalParams = actual.getAdditionalParams();
 
  89         assertEquals(3, actualAdditionalParams.size());
 
  91         final String actualInstanceType = actualAdditionalParams.get("instance_type");
 
  92         assertEquals("m1.small", actualInstanceType);
 
  94         assertTrue(actual.getExtVirtualLinks().isEmpty());