2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2018 Nokia. All rights reserved.
6 * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
7 * =============================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
21 package org.onap.appc.flow.controller.node;
23 import static org.mockito.Mockito.mock;
24 import static org.mockito.Mockito.when;
25 import static org.onap.appc.flow.controller.node.InputParamsCollector.SDNC_CONFIG_DIR_VAR;
26 import static org.onap.appc.flow.controller.utils.FlowControllerConstants.ACTION_LEVEL;
27 import static org.onap.appc.flow.controller.utils.FlowControllerConstants.PAYLOAD;
28 import static org.onap.appc.flow.controller.utils.FlowControllerConstants.REQUEST_ACTION;
29 import static org.onap.appc.flow.controller.utils.FlowControllerConstants.VNFC_NAME;
30 import static org.onap.appc.flow.controller.utils.FlowControllerConstants.VNF_ID;
31 import static org.onap.appc.flow.controller.utils.FlowControllerConstants.VSERVER_ID;
33 import com.fasterxml.jackson.core.JsonProcessingException;
34 import com.fasterxml.jackson.databind.ObjectMapper;
35 import java.util.ArrayList;
36 import java.util.HashMap;
37 import java.util.List;
39 import org.junit.Assert;
40 import org.junit.Before;
41 import org.junit.Test;
42 import org.onap.appc.flow.controller.data.Transaction;
43 import org.onap.appc.flow.controller.dbervices.FlowControlDBService;
44 import org.onap.appc.flow.controller.interfaceData.DependencyInfo;
45 import org.onap.appc.flow.controller.interfaceData.Vnfcs;
46 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
48 public class InputParamsCollectorTest {
50 private SvcLogicContext ctx;
51 private FlowControlDBService dbService;
52 private EnvVariables envVariables;
53 private InputParamsCollector inputParamsCollector;
58 ctx = mock(SvcLogicContext.class);
59 dbService = mock(FlowControlDBService.class);
60 envVariables = mock(EnvVariables.class);
62 when(envVariables.getenv(SDNC_CONFIG_DIR_VAR)).thenReturn("./src/test/resources");
64 inputParamsCollector = new InputParamsCollector(envVariables, dbService);
68 public void should_collect_input_params() throws Exception {
70 when(ctx.getAttribute(VNF_ID)).thenReturn("some-vnf-id");
71 when(ctx.getAttribute(REQUEST_ACTION)).thenReturn("some-request-action");
72 when(ctx.getAttribute(ACTION_LEVEL)).thenReturn("some-action-level");
73 when(ctx.getAttribute(PAYLOAD)).thenReturn("some-payload");
74 when(ctx.getAttribute(VSERVER_ID)).thenReturn("some-vserver-id");
75 when(ctx.getAttribute(VNFC_NAME)).thenReturn("some-vnfc-name");
77 when(dbService.getCapabilitiesData(ctx)).thenReturn(
78 "{'vnf':['vnf-1', 'vnf-2'],'vf-module':['vf-module-1', 'vf-module-2'],'vnfc':['vnfc-1', 'vnfc-2'],'vm':['vm-1', 'vm-2']}"
79 .replaceAll("'", "\""));
80 when(dbService.getDependencyInfo(ctx)).thenReturn(dependencyInfoPayload());
82 Transaction transaction = inputParamsCollector.collectInputParams(ctx);
84 Assert.assertEquals("{\"input\":{\"request-info\":{\"action\":\"some-request-action\",\"payload\":\"some-payload\",\"action-level\":\"some-action-level\",\"action-identifier\":{\"vnf-id\":\"some-vnf-id\",\"vserver-id\":\"some-vserver-id\",\"vnfc-name\":\"some-vnfc-name\"}},\"inventory-info\":{\"vnf-info\":{\"vnf-id\":\"some-vnf-id\",\"identity-url\":\"\",\"vm\":[]}},\"capabilities\":{\"vnf\":[\"vnf-1\",\"vnf-2\"],\"vm\":[\"vm-1\",\"vm-2\"],\"vnfc\":[\"vnfc-1\",\"vnfc-2\"],\"vf-module\":[\"vf-module-1\",\"vf-module-2\"]}}}",
85 transaction.getPayload());
86 Assert.assertEquals("POST", transaction.getExecutionRPC());
87 Assert.assertEquals("seq-generator-uid", transaction.getuId());
88 Assert.assertEquals("some-pswd", transaction.getPswd());
89 Assert.assertEquals("exec-endpoint", transaction.getExecutionEndPoint());
93 public void should_handle_dependency_config() throws Exception {
95 Vnfcs vnfcs = new Vnfcs();
96 vnfcs.setVnfcType("some-type");
97 vnfcs.setResilience("some-resilience");
98 vnfcs.setMandatory("some-mandatory");
99 Map<String, List<Vnfcs>> input = new HashMap<>();
100 List<Vnfcs> list = new ArrayList<>();
103 input.put("vnfcs", list);
105 String jsonPayload = new ObjectMapper().writeValueAsString(input);
107 when(dbService.getDependencyInfo(ctx)).thenReturn(jsonPayload);
109 DependencyInfo dependencyInfo = inputParamsCollector.getDependencyInfo(ctx);
112 "DependencyInfo [vnfcs=[Vnfcs [vnfcType=some-type, mandatory=some-mandatory, resilience=some-resilience, parents=[]], Vnfcs [vnfcType=some-type, mandatory=some-mandatory, resilience=some-resilience, parents=[]]]]",
113 dependencyInfo.toString());
116 private String dependencyInfoPayload() throws JsonProcessingException {
117 Vnfcs vnfcs = new Vnfcs();
118 vnfcs.setVnfcType("some-type");
119 vnfcs.setResilience("some-resilience");
120 vnfcs.setMandatory("some-mandatory");
121 Map<String, List<Vnfcs>> input = new HashMap<>();
122 List<Vnfcs> list = new ArrayList<>();
125 input.put("vnfcs", list);
127 return new ObjectMapper().writeValueAsString(input);