2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2018 Nokia. All rights reserved.
6 * Copyright (C) 2019 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;
26 import org.junit.Assert;
27 import org.junit.Before;
28 import org.junit.Test;
29 import org.onap.appc.flow.controller.dbervices.FlowControlDBService;
30 import org.onap.appc.flow.controller.interfaceData.Capabilities;
31 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
33 public class CapabilitiesDataExtractorTest {
35 private CapabilitiesDataExtractor capabilitiesDataExtractor;
36 private FlowControlDBService dbService;
37 private SvcLogicContext ctx;
41 dbService = mock(FlowControlDBService.class);
42 ctx = mock(SvcLogicContext.class);
43 capabilitiesDataExtractor = new CapabilitiesDataExtractor(dbService);
47 public void should_handle_capabilities_full_config() throws Exception {
49 String jsonPayload = "{'capabilities':{'vnfc':[],'vm':[{'AttachVolume':[]},{'DetachVolume':[]},{'Evacuate':['pld','ssc']},{'Migrate':['pld','ssc']},{'Reboot':['pld','ssc']},{'Rebuild':['pld','ssc']},{'Restart':['pld','ssc']},{'Snapshot':['pld','ssc']},{'Start':['pld','ssc']},{'Stop':['pld','ssc']}],'vf-module':[],'vnf':['Configure','AllAction','ConfigModify','OpenStack Actions']}}";
50 when(dbService.getCapabilitiesData(ctx)).thenReturn(jsonPayload.replaceAll("'", "\""));
52 Capabilities capabilitiesData = capabilitiesDataExtractor.getCapabilitiesData(ctx);
54 "Capabilities [vnf=[Configure, AllAction, ConfigModify, OpenStack Actions], vfModule=[], vm={Evacuate=[pld, ssc], DetachVolume=[], Snapshot=[pld, ssc], AttachVolume=[], Start=[pld, ssc], Stop=[pld, ssc], Migrate=[pld, ssc], Restart=[pld, ssc], Reboot=[pld, ssc], Rebuild=[pld, ssc]}, vnfc=[]]",
55 capabilitiesData.toString());
59 public void should_handle_capabilities_config_with_missing_params1() throws Exception {
61 // CASE: vm is empty, vnfc is absent
62 String jsonPayload = "{'capabilities':{'vnf':['vnf-1', 'vnf-2'],'vf-module':['vf-module-1'],'vm':[]}}";
63 when(dbService.getCapabilitiesData(ctx)).thenReturn(jsonPayload.replaceAll("'", "\""));
65 Capabilities capabilitiesData = capabilitiesDataExtractor.getCapabilitiesData(ctx);
67 Assert.assertEquals("Capabilities [vnf=[vnf-1, vnf-2], vfModule=[vf-module-1], vm={}, vnfc=[]]",
68 capabilitiesData.toString());
72 public void should_handle_capabilities_config_with_missing_params2() throws Exception {
74 // CASE: vm has action+vnfc format, vf-module is empty, vnfc is absent
75 String jsonPayload = "{'capabilities':{'vnf':['vnf-1', 'vnf-2'],'vf-module':[],'vm':[{'AttachVolume':['vnfc-1']}]}}";
76 when(dbService.getCapabilitiesData(ctx)).thenReturn(jsonPayload.replaceAll("'", "\""));
78 Capabilities capabilitiesData = capabilitiesDataExtractor.getCapabilitiesData(ctx);
80 Assert.assertEquals("Capabilities [vnf=[vnf-1, vnf-2], vfModule=[], vm={AttachVolume=[vnfc-1]}, vnfc=[]]",
81 capabilitiesData.toString());