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