Changes to config bundle for vnf level enhancement
[appc.git] / appc-config / appc-flow-controller / provider / src / test / java / org / onap / appc / flow / controller / node / CapabilitiesDataExtractorTest.java
1 /*
2  * ============LICENSE_START=======================================================
3  * ONAP : APPC
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
11  *
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  *
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=========================================================
20  */
21 package org.onap.appc.flow.controller.node;
22
23 import static org.mockito.Mockito.mock;
24 import static org.mockito.Mockito.when;
25
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;
32
33 public class CapabilitiesDataExtractorTest {
34
35     private CapabilitiesDataExtractor capabilitiesDataExtractor;
36     private FlowControlDBService dbService;
37     private SvcLogicContext ctx;
38
39     @Before
40     public void setUp() {
41         dbService = mock(FlowControlDBService.class);
42         ctx = mock(SvcLogicContext.class);
43         capabilitiesDataExtractor = new CapabilitiesDataExtractor(dbService);
44     }
45
46     @Test
47     public void should_handle_capabilities_full_config() throws Exception {
48
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("'", "\""));
51
52         Capabilities capabilitiesData = capabilitiesDataExtractor.getCapabilitiesData(ctx);
53         Assert.assertEquals(
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());
56     }
57
58     @Test
59     public void should_handle_capabilities_config_with_missing_params1() throws Exception {
60
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("'", "\""));
64
65         Capabilities capabilitiesData = capabilitiesDataExtractor.getCapabilitiesData(ctx);
66
67         Assert.assertEquals("Capabilities [vnf=[vnf-1, vnf-2], vfModule=[vf-module-1], vm={}, vnfc=[]]",
68                 capabilitiesData.toString());
69     }
70
71     @Test
72     public void should_handle_capabilities_config_with_missing_params2() throws Exception {
73
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("'", "\""));
77
78         Capabilities capabilitiesData = capabilitiesDataExtractor.getCapabilitiesData(ctx);
79
80         Assert.assertEquals("Capabilities [vnf=[vnf-1, vnf-2], vfModule=[], vm={AttachVolume=[vnfc-1]}, vnfc=[]]",
81                 capabilitiesData.toString());
82     }
83 }