7d4aaf3eccd48e9e667472225f3a602f29111142
[sdc/sdc-tosca.git] / sdc-tosca / src / test / java / org / onap / sdc / impl / ToscaParserReqAndCapTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * sdc-tosca
4  * ================================================================================
5  * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.sdc.impl;
22
23 import org.onap.sdc.tosca.parser.enums.SdcTypes;
24 import org.onap.sdc.toscaparser.api.CapabilityAssignments;
25 import org.onap.sdc.toscaparser.api.CapabilityAssignment;
26 import org.onap.sdc.toscaparser.api.NodeTemplate;
27 import org.onap.sdc.toscaparser.api.RequirementAssignments;
28 import org.testng.annotations.Test;
29
30 import java.util.List;
31
32 import static org.testng.Assert.assertEquals;
33 import static org.testng.Assert.assertNotNull;
34 import static org.testng.Assert.assertNull;
35
36 public class ToscaParserReqAndCapTest extends SdcToscaParserBasicTest {
37
38     //region getCapabilitiesOf
39     @Test
40     public void testGetCapabilitiesOfNodeTemplate() {
41         List<NodeTemplate> vfs = fdntCsarHelper.getServiceVfList();
42         CapabilityAssignments capabilityAssignments = fdntCsarHelper.getCapabilitiesOf(vfs.get(0));
43         assertNotNull(capabilityAssignments);
44         assertEquals(13, capabilityAssignments.getAll().size());
45         assertNotNull(capabilityAssignments.getCapabilityByName("DNT_FW_RHRG.binding_DNT_FW_INT_DNS_TRUSTED_RVMI"));
46         assertEquals(6, capabilityAssignments.getCapabilitiesByType("tosca.capabilities.network.Bindable").getAll().size());
47     }
48
49     @Test
50     public void testGetCapabilitiesOfNull() {
51         CapabilityAssignments capabilityAssignments = fdntCsarHelper.getCapabilitiesOf(null);
52         assertNull(capabilityAssignments);
53     }
54     //endregion
55
56     //region getRequirementsOf
57     @Test
58     public void testGetRequirementsOfNodeTemplate() {
59         List<NodeTemplate> vfs = fdntCsarHelper.getServiceVfList();
60         List<NodeTemplate> cps = fdntCsarHelper.getNodeTemplateBySdcType(vfs.get(0), SdcTypes.CP);
61         RequirementAssignments requirementAssignments = fdntCsarHelper.getRequirementsOf(cps.get(0));
62         assertNotNull(requirementAssignments);
63         assertEquals(1, requirementAssignments.getAll().size());
64         assertEquals("DNT_FW_RHRG", requirementAssignments.getRequirementsByName("binding").getAll().get(0).getNodeTemplateName());
65     }
66
67     @Test
68     public void testGetRequirementsOfNull() {
69         RequirementAssignments requirementAssignments = fdntCsarHelper.getRequirementsOf(null);
70         assertNull(requirementAssignments);
71     }
72     //endregion
73
74     //region getCapabilityPropertyLeafValue
75     @Test
76     public void testGetCapabilityPropertyLeafValue() {
77         NodeTemplate vf = fdntCsarHelper.getServiceNodeTemplateByNodeName("FDNT 1");
78         CapabilityAssignment capabilityAssignment = vf.getCapabilities().getCapabilityByName("DNT_FW_RHRG.scalable_DNT_FW_SERVER");
79         assertNotNull(capabilityAssignment);
80         String propValue = fdntCsarHelper.getCapabilityPropertyLeafValue(capabilityAssignment, "max_instances#type");
81         assertEquals("integer", propValue);
82     }
83
84     @Test
85     public void testGetCapabilityHierarchyPropertyLeafValue() {
86         NodeTemplate vf = fdntCsarHelper.getServiceNodeTemplateByNodeName("FDNT 1");
87         CapabilityAssignment capabilityAssignment = vf.getCapabilities().getCapabilityByName("DNT_FW_RHRG.endpoint_DNT_FW_SERVER");
88         assertNotNull(capabilityAssignment);
89         String propValue = fdntCsarHelper.getCapabilityPropertyLeafValue(capabilityAssignment, "ports#entry_schema#type");
90         assertEquals("PortSpec", propValue);
91     }
92
93     @Test
94     public void testGetCapabilityDummyPropertyLeafValue() {
95         NodeTemplate vf = fdntCsarHelper.getServiceNodeTemplateByNodeName("FDNT 1");
96         CapabilityAssignment capabilityAssignment = vf.getCapabilities().getCapabilityByName("DNT_FW_RHRG.scalable_DNT_FW_SERVER");
97         assertNotNull(capabilityAssignment);
98         String propValue = fdntCsarHelper.getCapabilityPropertyLeafValue(capabilityAssignment, "dummy");
99         assertNull(propValue);
100     }
101
102     @Test
103     public void testGetCapabilityNullPropertyLeafValue() {
104         NodeTemplate vf = fdntCsarHelper.getServiceNodeTemplateByNodeName("FDNT 1");
105         CapabilityAssignment capabilityAssignment = vf.getCapabilities().getCapabilityByName("DNT_FW_RHRG.scalable_DNT_FW_SERVER");
106         assertNotNull(capabilityAssignment);
107         String propValue = fdntCsarHelper.getCapabilityPropertyLeafValue(capabilityAssignment, null);
108         assertNull(propValue);
109     }
110
111     @Test
112     public void testGetNullCapabilityPropertyLeafValue() {
113         String propValue = fdntCsarHelper.getCapabilityPropertyLeafValue(null, "max_instances#type");
114         assertNull(propValue);
115     }
116     //endregion
117     
118         //QA tests region for US 319197 -port mirroring-
119     
120         //get-CapabilitiesOf (All Types)
121         @Test
122         public void getServiceNodeTemplateCapabilitiesOfTypeVF() {
123                 List<NodeTemplate> serviceVfList = QAServiceForToscaParserTests.getServiceNodeTemplateBySdcType(SdcTypes.VF);
124                 CapabilityAssignments capabilitiesOfVF = QAServiceForToscaParserTests.getCapabilitiesOf(serviceVfList.get(0));
125                 assertEquals(capabilitiesOfVF.getAll().size(),12);
126                 assertNotNull(capabilitiesOfVF.getCapabilityByName("neutronport0.network.incoming.packets.rate"));
127         }
128         
129         @Test
130         public void getServiceNodeTemplateCapabilitiesOfTypeExVL() {
131                 List<NodeTemplate> serviceExtVlList = QAServiceForToscaParserTests.getServiceNodeTemplatesByType("org.openecomp.resource.vl.extVL");
132                 CapabilityAssignments capabilitiesOfExtVL = QAServiceForToscaParserTests.getCapabilitiesOf(serviceExtVlList.get(0));
133                 assertEquals(capabilitiesOfExtVL.getAll().size(),2);
134                 assertNotNull(capabilitiesOfExtVL.getCapabilityByName("virtual_linkable").getProperties());
135         }
136         
137         @Test
138         public void getServiceNodeTemplateCapabilitiesOfTypeVL() {
139                 List<NodeTemplate> serviceVlList = QAServiceForToscaParserTests.getServiceNodeTemplatesByType("tosca.nodes.network.Network");
140                 CapabilityAssignments capabilitiesOfVL = QAServiceForToscaParserTests.getCapabilitiesOf(serviceVlList.get(0));
141                 assertEquals(capabilitiesOfVL.getAll().size(),2);
142                 assertNotNull(capabilitiesOfVL.getCapabilityByName("link").getProperties());
143         }
144         
145         @Test
146         public void getServiceNodeTemplateCapabilitiesOfTypeCP() {
147                 List<NodeTemplate> serviceCpList = QAServiceForToscaParserTests.getServiceNodeTemplateBySdcType(SdcTypes.CP);
148                 CapabilityAssignments capabilitiesOfCP = QAServiceForToscaParserTests.getCapabilitiesOf(serviceCpList.get(0));
149                 assertEquals(capabilitiesOfCP.getAll().size(),2);
150                 assertNotNull(capabilitiesOfCP.getCapabilityByName("internal_connectionPoint"));
151         }
152         
153         @Test
154         public void getServiceNodeTemplateCapabilitiesOfTypePNF() {
155                 List<NodeTemplate> servicePnfs = QAServiceForToscaParserTests.getServiceNodeTemplateBySdcType(SdcTypes.PNF);
156                 CapabilityAssignments capabilitiesOfPnf = QAServiceForToscaParserTests.getCapabilitiesOf(servicePnfs.get(0));
157                 assertEquals(capabilitiesOfPnf.getAll().size(),1);
158                 assertNotNull(capabilitiesOfPnf.getCapabilityByName("feature"));
159         }
160         
161         //get-RequirementsOf (All Types)-----------------------------
162         
163         @Test
164         public void getServiceNodeTemplateRequirementsOfTypeVF() {
165                 List<NodeTemplate> serviceVfList = QAServiceForToscaParserTests.getServiceNodeTemplateBySdcType(SdcTypes.VF);
166                 RequirementAssignments requirementsOfVF = QAServiceForToscaParserTests.getRequirementsOf(serviceVfList.get(6));
167                 assertEquals(requirementsOfVF.getAll().size(),3);
168 //              RequirementAssignments requirementsByName = 
169                 assertEquals(requirementsOfVF.getRequirementsByName("dependency").getAll().size(),2 );
170                 //check that API return empty list if requirement property not exist.
171                 assertEquals(requirementsOfVF.getRequirementsByName("blabla").getAll().size(),0);
172         }
173         
174         @Test
175         public void getServiceNodeTemplateRequirementsOfTypeExVL() {
176                 List<NodeTemplate> serviceExtVlList = QAServiceForToscaParserTests.getServiceNodeTemplatesByType("org.openecomp.resource.vl.extVL");
177                 RequirementAssignments requirementsOfExtVL = QAServiceForToscaParserTests.getRequirementsOf(serviceExtVlList.get(0));
178                 assertEquals(requirementsOfExtVL.getAll().size(),1);
179         }
180         
181         @Test
182         public void getServiceNodeTemplateRequirementsOfTypeVL() {
183                 List<NodeTemplate> serviceVlList = QAServiceForToscaParserTests.getServiceNodeTemplatesByType("tosca.nodes.network.Network");
184                 RequirementAssignments requirementsOfVL = QAServiceForToscaParserTests.getRequirementsOf(serviceVlList.get(1));
185                 assertEquals(requirementsOfVL.getAll().size(),2);
186                 assertNotNull(requirementsOfVL.getRequirementsByName("dependency"));
187         }
188         
189         @Test
190         public void getServiceNodeTemplateRequirementsOfTypeCP() {
191                 List<NodeTemplate> serviceCpList = QAServiceForToscaParserTests.getServiceNodeTemplateBySdcType(SdcTypes.CP);
192                 RequirementAssignments requirementsOfCP = QAServiceForToscaParserTests.getRequirementsOf(serviceCpList.get(0));
193                 assertEquals(requirementsOfCP.getAll().size(),2);
194                 assertEquals(requirementsOfCP.getRequirementsByName("virtualBinding").getAll().size(),1);
195         }
196         
197         @Test
198         public void getServiceNodeTemplateRequirementsOfTypePNF() {
199                 List<NodeTemplate> servicePnfs = QAServiceForToscaParserTests.getServiceNodeTemplateBySdcType(SdcTypes.PNF);
200                 RequirementAssignments requirementsOfPnf = QAServiceForToscaParserTests.getRequirementsOf(servicePnfs.get(0));
201                 assertEquals(requirementsOfPnf.getAll().size(),2);
202                 assertNotNull(requirementsOfPnf.getRequirementsByName("feature"));
203         }
204         
205         //QA end region for US 319197 -port mirroring
206         
207     // Added by QA CapabilityAssignments
208     @Test
209     public void testGetCapabilitiesByType() {
210         List<NodeTemplate> vfs = resolveGetInputCsarQA.getServiceVfList();
211         CapabilityAssignments capabilityAssignments = resolveGetInputCsarQA.getCapabilitiesOf(vfs.get(0));
212         assertNotNull(capabilityAssignments);
213         CapabilityAssignments capabilitiesByType = capabilityAssignments.getCapabilitiesByType("tosca.capabilities.Scalable");
214         int capsQty = capabilitiesByType.getAll().size();
215         assertEquals(1, capsQty);
216         CapabilityAssignment capabilityByName = capabilitiesByType.getCapabilityByName("abstract_pd_server.scalable_pd_server");
217         assertNotNull(capabilityByName);
218     }
219     
220     @Test
221     public void testGetCapabilityByName() {
222         List<NodeTemplate> vfs = resolveGetInputCsarQA.getServiceVfList();
223         CapabilityAssignments capabilityAssignments = resolveGetInputCsarQA.getCapabilitiesOf(vfs.get(0));
224         assertNotNull(capabilityAssignments);
225         CapabilityAssignment capabilityByName = capabilityAssignments.getCapabilityByName("abstract_pd_server.disk.iops_pd_server");
226         assertNotNull(capabilityByName);
227         String capName = capabilityByName.getName();
228         assertEquals(capName, "abstract_pd_server.disk.iops_pd_server");
229     }
230     
231     @Test
232     public void testGetCapabilitiesGetAll() {
233         List<NodeTemplate> vfs = resolveGetInputCsarQA.getServiceVfList();
234         CapabilityAssignments capabilityAssignments = resolveGetInputCsarQA.getCapabilitiesOf(vfs.get(0));
235         assertNotNull(capabilityAssignments);
236         int capsAssignmentSize = capabilityAssignments.getAll().size();
237         assertEquals(65, capsAssignmentSize);        
238     }
239     
240  // Added by QA RequirementsAssignments
241     @Test
242     public void testGetRequirementsByName() {
243          List<NodeTemplate> vfs = resolveReqsCapsCsarQA.getServiceVfList();
244          List<NodeTemplate> cps = resolveReqsCapsCsarQA.getNodeTemplateBySdcType(vfs.get(0), SdcTypes.CP);
245          RequirementAssignments requirementAssignments = resolveReqsCapsCsarQA.getRequirementsOf(cps.get(0));
246          assertNotNull(requirementAssignments);
247          assertEquals(2, requirementAssignments.getAll().size());
248          assertEquals("DNT_FW_RHRG2", requirementAssignments.getRequirementsByName("binding").getAll().get(1).getNodeTemplateName());
249   
250     }
251     
252     @Test
253     public void testRequirementAssignmentGetNodeGetCapability() {
254          List<NodeTemplate> vfs = resolveReqsCapsCsarQA.getServiceVfList();
255          List<NodeTemplate> cps = resolveReqsCapsCsarQA.getNodeTemplateBySdcType(vfs.get(0), SdcTypes.CP);
256          RequirementAssignments requirementAssignments = resolveReqsCapsCsarQA.getRequirementsOf(cps.get(0));
257          assertNotNull(requirementAssignments);
258          String nodeTemplateName = requirementAssignments.getAll().get(0).getNodeTemplateName();
259          String capabilityName = requirementAssignments.getAll().get(0).getCapabilityName();
260          assertEquals(nodeTemplateName, "DNT_FW_RHRG");
261          assertNull(capabilityName);
262     }
263     
264     
265     @Test
266     public void testRequirementAssignmentGetCapability() {
267          List<NodeTemplate> cps = QAServiceForToscaParserTests.getServiceNodeTemplateBySdcType(SdcTypes.CP);
268          RequirementAssignments requirementAssignments = QAServiceForToscaParserTests.getRequirementsOf(cps.get(0));
269          assertNotNull(requirementAssignments);        
270          String nodeTemplateName = requirementAssignments.getAll().get(0).getNodeTemplateName();
271          String capabilityName = requirementAssignments.getAll().get(0).getCapabilityName();
272          assertEquals(nodeTemplateName, "ExtVL 0");
273          assertEquals(capabilityName,"tosca.capabilities.network.Linkable");
274     }
275     
276     @Test
277     public void testGetCapabilityProperties() {
278         List<NodeTemplate> vfs = fdntCsarHelper.getServiceVfList();
279         List<NodeTemplate> cps = fdntCsarHelper.getNodeTemplateBySdcType(vfs.get(0), SdcTypes.CP);
280         CapabilityAssignments capabilityAssignments = cps.get(0).getCapabilities();
281         assertNotNull(capabilityAssignments);
282         assertEquals(12, capabilityAssignments.getAll().size());
283         CapabilityAssignment xxxCapability = capabilityAssignments.getCapabilityByName("xxx");
284         //GetInput property - resolved in any case
285         String getInputProp = fdntCsarHelper.getCapabilityPropertyLeafValue(xxxCapability, "DeploymentFlavor");
286         assertEquals("{aaa=bbb}", getInputProp);
287         //Simple property
288         String simpleProp = fdntCsarHelper.getCapabilityPropertyLeafValue(xxxCapability, "distribution");
289         assertEquals("rhel", simpleProp);
290     }
291
292 }