aboutsummaryrefslogtreecommitdiffstats
path: root/src/test/java/org/onap/sdc/impl/ToscaParserReqAndCapTest.java
blob: 7d4aaf3eccd48e9e667472225f3a602f29111142 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
/*-
 * ============LICENSE_START=======================================================
 * sdc-tosca
 * ================================================================================
 * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved.
 * ================================================================================
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * ============LICENSE_END=========================================================
 */

package org.onap.sdc.impl;

import org.onap.sdc.tosca.parser.enums.SdcTypes;
import org.onap.sdc.toscaparser.api.CapabilityAssignments;
import org.onap.sdc.toscaparser.api.CapabilityAssignment;
import org.onap.sdc.toscaparser.api.NodeTemplate;
import org.onap.sdc.toscaparser.api.RequirementAssignments;
import org.testng.annotations.Test;

import java.util.List;

import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertNull;

public class ToscaParserReqAndCapTest extends SdcToscaParserBasicTest {

    //region getCapabilitiesOf
    @Test
    public void testGetCapabilitiesOfNodeTemplate() {
        List<NodeTemplate> vfs = fdntCsarHelper.getServiceVfList();
        CapabilityAssignments capabilityAssignments = fdntCsarHelper.getCapabilitiesOf(vfs.get(0));
        assertNotNull(capabilityAssignments);
        assertEquals(13, capabilityAssignments.getAll().size());
        assertNotNull(capabilityAssignments.getCapabilityByName("DNT_FW_RHRG.binding_DNT_FW_INT_DNS_TRUSTED_RVMI"));
        assertEquals(6, capabilityAssignments.getCapabilitiesByType("tosca.capabilities.network.Bindable").getAll().size());
    }

    @Test
    public void testGetCapabilitiesOfNull() {
        CapabilityAssignments capabilityAssignments = fdntCsarHelper.getCapabilitiesOf(null);
        assertNull(capabilityAssignments);
    }
    //endregion

    //region getRequirementsOf
    @Test
    public void testGetRequirementsOfNodeTemplate() {
        List<NodeTemplate> vfs = fdntCsarHelper.getServiceVfList();
        List<NodeTemplate> cps = fdntCsarHelper.getNodeTemplateBySdcType(vfs.get(0), SdcTypes.CP);
        RequirementAssignments requirementAssignments = fdntCsarHelper.getRequirementsOf(cps.get(0));
        assertNotNull(requirementAssignments);
        assertEquals(1, requirementAssignments.getAll().size());
        assertEquals("DNT_FW_RHRG", requirementAssignments.getRequirementsByName("binding").getAll().get(0).getNodeTemplateName());
    }

    @Test
    public void testGetRequirementsOfNull() {
        RequirementAssignments requirementAssignments = fdntCsarHelper.getRequirementsOf(null);
        assertNull(requirementAssignments);
    }
    //endregion

    //region getCapabilityPropertyLeafValue
    @Test
    public void testGetCapabilityPropertyLeafValue() {
        NodeTemplate vf = fdntCsarHelper.getServiceNodeTemplateByNodeName("FDNT 1");
        CapabilityAssignment capabilityAssignment = vf.getCapabilities().getCapabilityByName("DNT_FW_RHRG.scalable_DNT_FW_SERVER");
        assertNotNull(capabilityAssignment);
        String propValue = fdntCsarHelper.getCapabilityPropertyLeafValue(capabilityAssignment, "max_instances#type");
        assertEquals("integer", propValue);
    }

    @Test
    public void testGetCapabilityHierarchyPropertyLeafValue() {
        NodeTemplate vf = fdntCsarHelper.getServiceNodeTemplateByNodeName("FDNT 1");
        CapabilityAssignment capabilityAssignment = vf.getCapabilities().getCapabilityByName("DNT_FW_RHRG.endpoint_DNT_FW_SERVER");
        assertNotNull(capabilityAssignment);
        String propValue = fdntCsarHelper.getCapabilityPropertyLeafValue(capabilityAssignment, "ports#entry_schema#type");
        assertEquals("PortSpec", propValue);
    }

    @Test
    public void testGetCapabilityDummyPropertyLeafValue() {
        NodeTemplate vf = fdntCsarHelper.getServiceNodeTemplateByNodeName("FDNT 1");
        CapabilityAssignment capabilityAssignment = vf.getCapabilities().getCapabilityByName("DNT_FW_RHRG.scalable_DNT_FW_SERVER");
        assertNotNull(capabilityAssignment);
        String propValue = fdntCsarHelper.getCapabilityPropertyLeafValue(capabilityAssignment, "dummy");
        assertNull(propValue);
    }

    @Test
    public void testGetCapabilityNullPropertyLeafValue() {
        NodeTemplate vf = fdntCsarHelper.getServiceNodeTemplateByNodeName("FDNT 1");
        CapabilityAssignment capabilityAssignment = vf.getCapabilities().getCapabilityByName("DNT_FW_RHRG.scalable_DNT_FW_SERVER");
        assertNotNull(capabilityAssignment);
        String propValue = fdntCsarHelper.getCapabilityPropertyLeafValue(capabilityAssignment, null);
        assertNull(propValue);
    }

    @Test
    public void testGetNullCapabilityPropertyLeafValue() {
        String propValue = fdntCsarHelper.getCapabilityPropertyLeafValue(null, "max_instances#type");
        assertNull(propValue);
    }
    //endregion
    
	//QA tests region for US 319197 -port mirroring-
    
	//get-CapabilitiesOf (All Types)
	@Test
	public void getServiceNodeTemplateCapabilitiesOfTypeVF() {
		List<NodeTemplate> serviceVfList = QAServiceForToscaParserTests.getServiceNodeTemplateBySdcType(SdcTypes.VF);
		CapabilityAssignments capabilitiesOfVF = QAServiceForToscaParserTests.getCapabilitiesOf(serviceVfList.get(0));
		assertEquals(capabilitiesOfVF.getAll().size(),12);
		assertNotNull(capabilitiesOfVF.getCapabilityByName("neutronport0.network.incoming.packets.rate"));
	}
	
	@Test
	public void getServiceNodeTemplateCapabilitiesOfTypeExVL() {
		List<NodeTemplate> serviceExtVlList = QAServiceForToscaParserTests.getServiceNodeTemplatesByType("org.openecomp.resource.vl.extVL");
		CapabilityAssignments capabilitiesOfExtVL = QAServiceForToscaParserTests.getCapabilitiesOf(serviceExtVlList.get(0));
		assertEquals(capabilitiesOfExtVL.getAll().size(),2);
		assertNotNull(capabilitiesOfExtVL.getCapabilityByName("virtual_linkable").getProperties());
	}
	
	@Test
	public void getServiceNodeTemplateCapabilitiesOfTypeVL() {
		List<NodeTemplate> serviceVlList = QAServiceForToscaParserTests.getServiceNodeTemplatesByType("tosca.nodes.network.Network");
		CapabilityAssignments capabilitiesOfVL = QAServiceForToscaParserTests.getCapabilitiesOf(serviceVlList.get(0));
		assertEquals(capabilitiesOfVL.getAll().size(),2);
		assertNotNull(capabilitiesOfVL.getCapabilityByName("link").getProperties());
	}
	
	@Test
	public void getServiceNodeTemplateCapabilitiesOfTypeCP() {
		List<NodeTemplate> serviceCpList = QAServiceForToscaParserTests.getServiceNodeTemplateBySdcType(SdcTypes.CP);
		CapabilityAssignments capabilitiesOfCP = QAServiceForToscaParserTests.getCapabilitiesOf(serviceCpList.get(0));
		assertEquals(capabilitiesOfCP.getAll().size(),2);
		assertNotNull(capabilitiesOfCP.getCapabilityByName("internal_connectionPoint"));
	}
	
	@Test
	public void getServiceNodeTemplateCapabilitiesOfTypePNF() {
		List<NodeTemplate> servicePnfs = QAServiceForToscaParserTests.getServiceNodeTemplateBySdcType(SdcTypes.PNF);
		CapabilityAssignments capabilitiesOfPnf = QAServiceForToscaParserTests.getCapabilitiesOf(servicePnfs.get(0));
		assertEquals(capabilitiesOfPnf.getAll().size(),1);
		assertNotNull(capabilitiesOfPnf.getCapabilityByName("feature"));
	}
	
	//get-RequirementsOf (All Types)-----------------------------
	
	@Test
	public void getServiceNodeTemplateRequirementsOfTypeVF() {
		List<NodeTemplate> serviceVfList = QAServiceForToscaParserTests.getServiceNodeTemplateBySdcType(SdcTypes.VF);
		RequirementAssignments requirementsOfVF = QAServiceForToscaParserTests.getRequirementsOf(serviceVfList.get(6));
		assertEquals(requirementsOfVF.getAll().size(),3);
//		RequirementAssignments requirementsByName = 
		assertEquals(requirementsOfVF.getRequirementsByName("dependency").getAll().size(),2 );
		//check that API return empty list if requirement property not exist.
		assertEquals(requirementsOfVF.getRequirementsByName("blabla").getAll().size(),0);
	}
	
	@Test
	public void getServiceNodeTemplateRequirementsOfTypeExVL() {
		List<NodeTemplate> serviceExtVlList = QAServiceForToscaParserTests.getServiceNodeTemplatesByType("org.openecomp.resource.vl.extVL");
		RequirementAssignments requirementsOfExtVL = QAServiceForToscaParserTests.getRequirementsOf(serviceExtVlList.get(0));
		assertEquals(requirementsOfExtVL.getAll().size(),1);
	}
	
	@Test
	public void getServiceNodeTemplateRequirementsOfTypeVL() {
		List<NodeTemplate> serviceVlList = QAServiceForToscaParserTests.getServiceNodeTemplatesByType("tosca.nodes.network.Network");
		RequirementAssignments requirementsOfVL = QAServiceForToscaParserTests.getRequirementsOf(serviceVlList.get(1));
		assertEquals(requirementsOfVL.getAll().size(),2);
		assertNotNull(requirementsOfVL.getRequirementsByName("dependency"));
	}
	
	@Test
	public void getServiceNodeTemplateRequirementsOfTypeCP() {
		List<NodeTemplate> serviceCpList = QAServiceForToscaParserTests.getServiceNodeTemplateBySdcType(SdcTypes.CP);
		RequirementAssignments requirementsOfCP = QAServiceForToscaParserTests.getRequirementsOf(serviceCpList.get(0));
		assertEquals(requirementsOfCP.getAll().size(),2);
		assertEquals(requirementsOfCP.getRequirementsByName("virtualBinding").getAll().size(),1);
	}
	
	@Test
	public void getServiceNodeTemplateRequirementsOfTypePNF() {
		List<NodeTemplate> servicePnfs = QAServiceForToscaParserTests.getServiceNodeTemplateBySdcType(SdcTypes.PNF);
		RequirementAssignments requirementsOfPnf = QAServiceForToscaParserTests.getRequirementsOf(servicePnfs.get(0));
		assertEquals(requirementsOfPnf.getAll().size(),2);
		assertNotNull(requirementsOfPnf.getRequirementsByName("feature"));
	}
	
	//QA end region for US 319197 -port mirroring
	
    // Added by QA CapabilityAssignments
    @Test
    public void testGetCapabilitiesByType() {
        List<NodeTemplate> vfs = resolveGetInputCsarQA.getServiceVfList();
        CapabilityAssignments capabilityAssignments = resolveGetInputCsarQA.getCapabilitiesOf(vfs.get(0));
        assertNotNull(capabilityAssignments);
        CapabilityAssignments capabilitiesByType = capabilityAssignments.getCapabilitiesByType("tosca.capabilities.Scalable");
        int capsQty = capabilitiesByType.getAll().size();
        assertEquals(1, capsQty);
        CapabilityAssignment capabilityByName = capabilitiesByType.getCapabilityByName("abstract_pd_server.scalable_pd_server");
        assertNotNull(capabilityByName);
    }
    
    @Test
    public void testGetCapabilityByName() {
        List<NodeTemplate> vfs = resolveGetInputCsarQA.getServiceVfList();
        CapabilityAssignments capabilityAssignments = resolveGetInputCsarQA.getCapabilitiesOf(vfs.get(0));
        assertNotNull(capabilityAssignments);
        CapabilityAssignment capabilityByName = capabilityAssignments.getCapabilityByName("abstract_pd_server.disk.iops_pd_server");
        assertNotNull(capabilityByName);
        String capName = capabilityByName.getName();
        assertEquals(capName, "abstract_pd_server.disk.iops_pd_server");
    }
    
    @Test
    public void testGetCapabilitiesGetAll() {
        List<NodeTemplate> vfs = resolveGetInputCsarQA.getServiceVfList();
        CapabilityAssignments capabilityAssignments = resolveGetInputCsarQA.getCapabilitiesOf(vfs.get(0));
        assertNotNull(capabilityAssignments);
        int capsAssignmentSize = capabilityAssignments.getAll().size();
        assertEquals(65, capsAssignmentSize);        
    }
    
 // Added by QA RequirementsAssignments
    @Test
    public void testGetRequirementsByName() {
    	 List<NodeTemplate> vfs = resolveReqsCapsCsarQA.getServiceVfList();
         List<NodeTemplate> cps = resolveReqsCapsCsarQA.getNodeTemplateBySdcType(vfs.get(0), SdcTypes.CP);
         RequirementAssignments requirementAssignments = resolveReqsCapsCsarQA.getRequirementsOf(cps.get(0));
         assertNotNull(requirementAssignments);
         assertEquals(2, requirementAssignments.getAll().size());
         assertEquals("DNT_FW_RHRG2", requirementAssignments.getRequirementsByName("binding").getAll().get(1).getNodeTemplateName());
  
    }
    
    @Test
    public void testRequirementAssignmentGetNodeGetCapability() {
    	 List<NodeTemplate> vfs = resolveReqsCapsCsarQA.getServiceVfList();
         List<NodeTemplate> cps = resolveReqsCapsCsarQA.getNodeTemplateBySdcType(vfs.get(0), SdcTypes.CP);
         RequirementAssignments requirementAssignments = resolveReqsCapsCsarQA.getRequirementsOf(cps.get(0));
         assertNotNull(requirementAssignments);
         String nodeTemplateName = requirementAssignments.getAll().get(0).getNodeTemplateName();
         String capabilityName = requirementAssignments.getAll().get(0).getCapabilityName();
         assertEquals(nodeTemplateName, "DNT_FW_RHRG");
         assertNull(capabilityName);
    }
    
    
    @Test
    public void testRequirementAssignmentGetCapability() {
    	 List<NodeTemplate> cps = QAServiceForToscaParserTests.getServiceNodeTemplateBySdcType(SdcTypes.CP);
         RequirementAssignments requirementAssignments = QAServiceForToscaParserTests.getRequirementsOf(cps.get(0));
         assertNotNull(requirementAssignments);        
         String nodeTemplateName = requirementAssignments.getAll().get(0).getNodeTemplateName();
         String capabilityName = requirementAssignments.getAll().get(0).getCapabilityName();
         assertEquals(nodeTemplateName, "ExtVL 0");
         assertEquals(capabilityName,"tosca.capabilities.network.Linkable");
    }
    
    @Test
    public void testGetCapabilityProperties() {
        List<NodeTemplate> vfs = fdntCsarHelper.getServiceVfList();
        List<NodeTemplate> cps = fdntCsarHelper.getNodeTemplateBySdcType(vfs.get(0), SdcTypes.CP);
        CapabilityAssignments capabilityAssignments = cps.get(0).getCapabilities();
        assertNotNull(capabilityAssignments);
        assertEquals(12, capabilityAssignments.getAll().size());
        CapabilityAssignment xxxCapability = capabilityAssignments.getCapabilityByName("xxx");
        //GetInput property - resolved in any case
        String getInputProp = fdntCsarHelper.getCapabilityPropertyLeafValue(xxxCapability, "DeploymentFlavor");
        assertEquals("{aaa=bbb}", getInputProp);
        //Simple property
        String simpleProp = fdntCsarHelper.getCapabilityPropertyLeafValue(xxxCapability, "distribution");
        assertEquals("rhel", simpleProp);
    }

}