2 * Copyright © 2016-2018 European Support Limited
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org.openecomp.sdc.tosca.services.impl;
19 import static org.junit.Assert.assertEquals;
20 import static org.junit.Assert.assertFalse;
21 import static org.junit.Assert.assertNotNull;
22 import static org.junit.Assert.assertTrue;
23 import static org.mockito.Mockito.when;
25 import java.io.IOException;
26 import java.io.InputStream;
27 import java.util.ArrayList;
28 import java.util.HashMap;
29 import java.util.List;
31 import java.util.Optional;
32 import org.junit.Assert;
33 import org.junit.Before;
34 import org.junit.BeforeClass;
35 import org.junit.Rule;
36 import org.junit.Test;
37 import org.junit.rules.ExpectedException;
38 import org.junit.runner.RunWith;
39 import org.mockito.Mock;
40 import org.mockito.MockitoAnnotations;
41 import org.mockito.runners.MockitoJUnitRunner;
42 import org.onap.sdc.tosca.datatypes.model.CapabilityDefinition;
43 import org.onap.sdc.tosca.datatypes.model.CapabilityType;
44 import org.onap.sdc.tosca.datatypes.model.DataType;
45 import org.onap.sdc.tosca.datatypes.model.DefinitionOfDataType;
46 import org.onap.sdc.tosca.datatypes.model.Import;
47 import org.onap.sdc.tosca.datatypes.model.InterfaceDefinitionType;
48 import org.onap.sdc.tosca.datatypes.model.InterfaceType;
49 import org.onap.sdc.tosca.datatypes.model.NodeTemplate;
50 import org.onap.sdc.tosca.datatypes.model.NodeType;
51 import org.onap.sdc.tosca.datatypes.model.OperationDefinitionType;
52 import org.onap.sdc.tosca.datatypes.model.ParameterDefinition;
53 import org.onap.sdc.tosca.datatypes.model.PropertyDefinition;
54 import org.onap.sdc.tosca.datatypes.model.RequirementAssignment;
55 import org.onap.sdc.tosca.datatypes.model.RequirementDefinition;
56 import org.onap.sdc.tosca.datatypes.model.ServiceTemplate;
57 import org.onap.sdc.tosca.datatypes.model.SubstitutionMapping;
58 import org.onap.sdc.tosca.datatypes.model.TopologyTemplate;
59 import org.onap.sdc.tosca.services.ToscaExtensionYamlUtil;
60 import org.openecomp.sdc.common.errors.CoreException;
61 import org.openecomp.sdc.tosca.TestUtil;
62 import org.openecomp.sdc.tosca.datatypes.ToscaElementTypes;
63 import org.openecomp.sdc.tosca.datatypes.ToscaFlatData;
64 import org.openecomp.sdc.tosca.datatypes.ToscaNodeType;
65 import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel;
66 import org.openecomp.sdc.tosca.services.ToscaAnalyzerService;
67 import org.openecomp.sdc.tosca.services.ToscaConstants;
70 @RunWith(MockitoJUnitRunner.class)
71 public class ToscaAnalyzerServiceImplTest {
73 private static final String CAPABILITY_TYPE_A = "capabilityTypeA";
74 private static final String CAPABILITY_TYPE_B = "capabilityTypeB";
75 private static final String TOSCA_CAPABILITIES_ROOT = "tosca.capabilities.Root";
76 private static final String CMAUI_IMAGE_EXTEND = "org.openecomp.resource.vfc.nodes.heat.cmaui_image_extend";
77 private static final String STANDARD_INTERFACE_KEY = "Standard";
78 private static final String TOSCA_LIFECYCLE_STANDARD = "tosca.interfaces.node.lifecycle.Standard";
79 private static final String CMAUI_INTERFACE_TEST =
80 "org.openecomp.resource.vfc.nodes.heat.cmaui_image_interfaceTest";
81 private static final String CMAUI_IMAGE_EXTEND2 = "org.openecomp.resource.vfc.nodes.heat.cmaui_image_extend2";
85 SrvTmp: ServiceTemplate
90 private static ToscaAnalyzerService toscaAnalyzerService;
91 private static ToscaServiceModel toscaServiceModel;
93 public ExpectedException thrown = ExpectedException.none();
96 private NodeTemplate nodeTemplateMock;
98 private ParameterDefinition parameterDefinitionMock;
100 private PropertyDefinition propertyDefinitionMock;
102 private InterfaceDefinitionType interfaceDefinitionMock;
104 private ToscaServiceModel toscaServiceModelMock;
107 public static void onlyOnceSetUp() throws IOException {
108 toscaAnalyzerService = new ToscaAnalyzerServiceImpl();
109 toscaServiceModel = TestUtil.loadToscaServiceModel("/mock/analyzerService/toscasubstitution/",
110 "/mock/globalServiceTemplates/", null);
114 public void init() throws IOException {
115 MockitoAnnotations.initMocks(this);
119 public void testGetFlatEntityNotFound() throws Exception {
120 thrown.expect(CoreException.class);
121 thrown.expectMessage(
122 "Entity Type 'org.openecomp.resource.vfc.notFound' or one of its derivedFrom type "
123 + "hierarchy, is not defined in tosca service model");
124 ToscaExtensionYamlUtil toscaExtensionYamlUtil = new ToscaExtensionYamlUtil();
125 try (InputStream yamlFile = toscaExtensionYamlUtil.loadYamlFileIs(
126 "/mock/analyzerService/NestedServiceTemplateReqTest.yaml")) {
128 ServiceTemplate serviceTemplateFromYaml =
129 toscaExtensionYamlUtil.yamlToObject(yamlFile, ServiceTemplate.class);
131 toscaAnalyzerService.getFlatEntity(ToscaElementTypes.NODE_TYPE, "org.openecomp.resource.vfc.notFound",
132 serviceTemplateFromYaml, toscaServiceModel);
137 public void testGetFlatEntityFileNotFound() throws Exception {
138 thrown.expect(CoreException.class);
139 thrown.expectMessage("Tosca file 'missingFile.yaml' was not found in tosca service model");
140 ToscaExtensionYamlUtil toscaExtensionYamlUtil = new ToscaExtensionYamlUtil();
141 try (InputStream yamlFile = toscaExtensionYamlUtil.loadYamlFileIs(
142 "/mock/analyzerService/ServiceTemplateFileNotFoundTest.yaml")) {
144 ServiceTemplate serviceTemplateFromYaml =
145 toscaExtensionYamlUtil.yamlToObject(yamlFile, ServiceTemplate.class);
148 .getFlatEntity(ToscaElementTypes.NODE_TYPE, "org.openecomp.resource.vfc.nodes.heat.cmaui_image",
149 serviceTemplateFromYaml, toscaServiceModel);
154 public void testGetFlatEntityNodeType() throws Exception {
155 ToscaExtensionYamlUtil toscaExtensionYamlUtil = new ToscaExtensionYamlUtil();
156 try (InputStream yamlFile = toscaExtensionYamlUtil.loadYamlFileIs(
157 "/mock/analyzerService/NestedServiceTemplateReqTest.yaml")) {
159 ServiceTemplate serviceTemplateFromYaml =
160 toscaExtensionYamlUtil.yamlToObject(yamlFile, ServiceTemplate.class);
162 ToscaFlatData flatData = toscaAnalyzerService.getFlatEntity(ToscaElementTypes.NODE_TYPE,
163 "org.openecomp.resource.vfc.nodes.heat" + ".cmaui_image", serviceTemplateFromYaml,
166 Assert.assertNotNull(flatData);
167 checkNodeTypeFlatEntity(flatData);
168 checkNodeTypeInheritanceHierarchy(flatData);
172 private void checkNodeTypeInheritanceHierarchy(ToscaFlatData flatData) {
173 List<String> inheritanceHierarchyType = flatData.getInheritanceHierarchyType();
174 Assert.assertNotNull(inheritanceHierarchyType);
175 Assert.assertEquals(4, inheritanceHierarchyType.size());
176 Assert.assertTrue(inheritanceHierarchyType.contains("org.openecomp.resource.vfc.nodes.heat.cmaui_image"));
177 Assert.assertTrue(inheritanceHierarchyType.contains("org.openecomp.resource.vfc.nodes.heat.nova.Server"));
178 Assert.assertTrue(inheritanceHierarchyType.contains("tosca.nodes.Compute"));
179 Assert.assertTrue(inheritanceHierarchyType.contains("tosca.nodes.Root"));
182 private void checkNodeTypeFlatEntity(ToscaFlatData flatData) {
183 Assert.assertNotNull(flatData.getFlatEntity());
184 NodeType flatEntity = (NodeType) flatData.getFlatEntity();
185 Assert.assertEquals("org.openecomp.resource.vfc.nodes.heat.nova.Server", flatEntity.getDerived_from());
186 Assert.assertEquals(20, flatEntity.getProperties().size());
187 Assert.assertEquals("overridden default value", flatEntity.getProperties().get("admin_pass").get_default());
188 Assert.assertEquals("REBUILD", flatEntity.getProperties().get("image_update_policy").get_default());
189 Assert.assertNotNull(flatEntity.getProperties().get("new_property"));
193 public void testGetFlatEntityNodeTypeInterface() throws Exception {
194 ToscaExtensionYamlUtil toscaExtensionYamlUtil = new ToscaExtensionYamlUtil();
195 try (InputStream yamlFile = toscaExtensionYamlUtil.loadYamlFileIs(
196 "/mock/analyzerService/ServiceTemplateInterfaceInheritanceTest.yaml")) {
198 ServiceTemplate serviceTemplateFromYaml =
199 toscaExtensionYamlUtil.yamlToObject(yamlFile, ServiceTemplate.class);
201 ToscaFlatData flatData = toscaAnalyzerService.getFlatEntity(ToscaElementTypes.NODE_TYPE, CMAUI_IMAGE_EXTEND,
202 serviceTemplateFromYaml, toscaServiceModel);
204 Assert.assertNotNull(flatData);
205 Assert.assertNotNull(flatData.getFlatEntity());
206 NodeType flatEntity = (NodeType) flatData.getFlatEntity();
207 Assert.assertNotNull(flatEntity.getInterfaces());
208 Object standardInterfaceObj = flatEntity.getInterfaces().get(STANDARD_INTERFACE_KEY);
209 Assert.assertNotNull(standardInterfaceObj);
210 InterfaceDefinitionType standardInterface = new InterfaceDefinitionType(standardInterfaceObj);
211 Assert.assertEquals(2, standardInterface.getInputs().size());
212 Assert.assertEquals(3, standardInterface.getOperations().size());
213 OperationDefinitionType createOperation = toscaExtensionYamlUtil.yamlToObject(
214 toscaExtensionYamlUtil.objectToYaml(standardInterface.getOperations().get("create")),
215 OperationDefinitionType.class);
216 Assert.assertEquals(2, createOperation.getInputs().size());
218 List<String> inheritanceHierarchyType = flatData.getInheritanceHierarchyType();
219 Assert.assertNotNull(inheritanceHierarchyType);
220 Assert.assertEquals(5, inheritanceHierarchyType.size());
226 public void testGetFlatEntityDataType() throws Exception {
227 ToscaExtensionYamlUtil toscaExtensionYamlUtil = new ToscaExtensionYamlUtil();
228 try (InputStream yamlFile = toscaExtensionYamlUtil.loadYamlFileIs(
229 "/mock/analyzerService/NestedServiceTemplateReqTest.yaml")) {
231 ServiceTemplate serviceTemplateFromYaml =
232 toscaExtensionYamlUtil.yamlToObject(yamlFile, ServiceTemplate.class);
234 ToscaFlatData flatData = toscaAnalyzerService.getFlatEntity(ToscaElementTypes.DATA_TYPE,
235 "org.openecomp.datatypes.heat.network.MyNewAddressPair", serviceTemplateFromYaml,
238 Assert.assertNotNull(flatData);
239 Assert.assertNotNull(flatData.getFlatEntity());
240 DataType flatEntity = (DataType) flatData.getFlatEntity();
241 Assert.assertEquals("org.openecomp.datatypes.heat.network.MyAddressPair", flatEntity.getDerived_from());
242 Assert.assertEquals(3, flatEntity.getProperties().size());
243 Assert.assertEquals("overridden default value",
244 flatEntity.getProperties().get("mac_address").get_default());
245 Assert.assertEquals(true, flatEntity.getProperties().get("mac_address").getRequired());
246 Assert.assertNotNull(flatEntity.getProperties().get("new_property"));
248 List<String> inheritanceHierarchyType = flatData.getInheritanceHierarchyType();
249 Assert.assertNotNull(inheritanceHierarchyType);
250 Assert.assertEquals(4, inheritanceHierarchyType.size());
255 public void testGetFlatEntityDataTypeDerivedFromPrimitive() throws Exception {
256 ToscaExtensionYamlUtil toscaExtensionYamlUtil = new ToscaExtensionYamlUtil();
257 try (InputStream yamlFile = toscaExtensionYamlUtil.loadYamlFileIs(
258 "/mock/analyzerService/ServiceTemplateDatatypeFlatTest.yaml")) {
260 ServiceTemplate serviceTemplateFromYaml =
261 toscaExtensionYamlUtil.yamlToObject(yamlFile, ServiceTemplate.class);
263 ToscaFlatData flatData = toscaAnalyzerService.getFlatEntity(ToscaElementTypes.DATA_TYPE,
264 "org.openecomp.datatypes.heat.network.MyNewString", serviceTemplateFromYaml, toscaServiceModel);
266 Assert.assertNotNull(flatData);
267 Assert.assertNotNull(flatData.getFlatEntity());
268 DataType flatEntity = (DataType) flatData.getFlatEntity();
269 Assert.assertEquals("org.openecomp.datatypes.heat.network.MyString", flatEntity.getDerived_from());
270 Assert.assertEquals(2, flatEntity.getConstraints().size());
271 Assert.assertNotNull(flatEntity.getConstraints().get(0).getValid_values());
272 Assert.assertNotNull(flatEntity.getConstraints().get(1).getMax_length());
274 List<String> inheritanceHierarchyType = flatData.getInheritanceHierarchyType();
275 Assert.assertNotNull(inheritanceHierarchyType);
276 Assert.assertEquals(2, inheritanceHierarchyType.size());
281 public void testCalculateExposedRequirements() throws Exception {
282 RequirementDefinition rd = new RequirementDefinition();
283 rd.setCapability("tosca.capabilities.Node");
284 rd.setNode("tosca.nodes.Root");
285 rd.setRelationship("tosca.relationships.DependsOn");
286 Object[] occurences = new Object[] {0, "UNBOUNDED"};
287 rd.setOccurrences(occurences);
289 rd.setCapability("tosca.capabilities.network.Bindable");
291 rd.setRelationship("tosca.relationships.network.BindsTo");
292 Object[] occurences1 = new Object[] {1, 1};
293 RequirementDefinition rd1 = new RequirementDefinition();
294 rd1.setOccurrences(occurences1);
296 Map<String, RequirementDefinition> nodeTypeRequirementDefinition = new HashMap<>();
297 nodeTypeRequirementDefinition.put("binding", rd1);
298 nodeTypeRequirementDefinition.put("dependency", rd);
300 Map<String, Map<String, RequirementAssignment>> fullFilledRequirementsDefinition = new HashMap<>();
301 RequirementAssignment ra = new RequirementAssignment();
302 ra.setCapability("tosca.capabilities.network.Bindable");
303 ra.setNode("pd_server");
304 ra.setRelationship("tosca.relationships.network.BindsTo");
305 Map<String, RequirementAssignment> nodeTemplateRequirementsAssignment = new HashMap<>();
306 nodeTemplateRequirementsAssignment.put("binding", ra);
308 List<Map<String, RequirementDefinition>> nodeTypeRequirementsDefinition = new ArrayList<>();
309 nodeTypeRequirementsDefinition.add(nodeTypeRequirementDefinition);
311 List<Map<String, RequirementDefinition>> exposedRequirements = toscaAnalyzerService
312 .calculateExposedRequirements(
313 nodeTypeRequirementsDefinition,
314 nodeTemplateRequirementsAssignment);
315 Assert.assertEquals(1, exposedRequirements.size());
319 public void testCalExpReqWithNullNodeInReqAssignment() throws Exception {
320 RequirementDefinition rd = new RequirementDefinition();
321 rd.setCapability("tosca.capabilities.Node");
322 rd.setNode("tosca.nodes.Root");
323 rd.setRelationship("tosca.relationships.DependsOn");
324 Object[] occurences = new Object[] {0, "UNBOUNDED"};
325 rd.setOccurrences(occurences);
327 rd.setCapability("tosca.capabilities.network.Bindable");
329 rd.setRelationship("tosca.relationships.network.BindsTo");
330 Object[] occurences1 = new Object[] {1, 1};
331 RequirementDefinition rd1 = new RequirementDefinition();
332 rd1.setOccurrences(occurences1);
334 Map<String, RequirementDefinition> nodeTypeRequirementDefinition = new HashMap<>();
335 nodeTypeRequirementDefinition.put("binding", rd1);
336 nodeTypeRequirementDefinition.put("dependency", rd);
338 Map<String, Map<String, RequirementAssignment>> fullFilledRequirementsDefinition = new HashMap<>();
339 RequirementAssignment ra = new RequirementAssignment();
340 ra.setCapability("tosca.capabilities.network.Bindable");
342 ra.setRelationship("tosca.relationships.network.BindsTo");
343 Map<String, RequirementAssignment> nodeTemplateRequirementsAssignment = new HashMap<>();
344 nodeTemplateRequirementsAssignment.put("binding", ra);
346 List<Map<String, RequirementDefinition>> nodeTypeRequirementsDefinition = new ArrayList<>();
347 nodeTypeRequirementsDefinition.add(nodeTypeRequirementDefinition);
349 List<Map<String, RequirementDefinition>> exposedRequirements = toscaAnalyzerService
350 .calculateExposedRequirements(
351 nodeTypeRequirementsDefinition,
352 nodeTemplateRequirementsAssignment);
353 Assert.assertEquals(1, exposedRequirements.size());
357 public void testCalculateExposedCapabilities() throws Exception {
358 Map<String, CapabilityDefinition> nodeTypeCapabilitiesDefinition = new HashMap<>();
359 CapabilityDefinition cd = new CapabilityDefinition();
360 cd.setType("tosca.capabilities.Scalable");
361 nodeTypeCapabilitiesDefinition.put("tosca.capabilities.network.Bindable_pd_server", cd);
362 RequirementAssignment ra = new RequirementAssignment();
363 ra.setCapability("tosca.capabilities.network.Bindable");
364 ra.setNode("pd_server");
365 ra.setRelationship("tosca.relationships.network.BindsTo");
366 Map<String, RequirementAssignment> nodeTemplateRequirementsAssignment = new HashMap<>();
367 nodeTemplateRequirementsAssignment.put("binding", ra);
368 Map<String, Map<String, RequirementAssignment>> fullFilledRequirementsDefinition = new HashMap<>();
369 fullFilledRequirementsDefinition.put("pd_server", nodeTemplateRequirementsAssignment);
370 Map<String, CapabilityDefinition> exposedCapabilities = toscaAnalyzerService.calculateExposedCapabilities(
371 nodeTypeCapabilitiesDefinition, fullFilledRequirementsDefinition);
372 Assert.assertEquals(1, exposedCapabilities.size());
376 public void testIsRequirementExistsWithInvalidReqId() throws Exception {
377 ToscaExtensionYamlUtil toscaExtensionYamlUtil = new ToscaExtensionYamlUtil();
378 try (InputStream yamlFile = toscaExtensionYamlUtil.loadYamlFileIs(
379 "/mock/analyzerService/NestedServiceTemplateReqTest.yaml")) {
381 ServiceTemplate serviceTemplateFromYaml =
382 toscaExtensionYamlUtil.yamlToObject(yamlFile, ServiceTemplate.class);
384 TestUtil.createConcreteRequirementObjectsInServiceTemplate(serviceTemplateFromYaml, toscaExtensionYamlUtil);
387 RequirementAssignment ra = new RequirementAssignment();
388 ra.setCapability("tosca.capabilities.network.Bindable");
389 ra.setNode("server_cmaui");
390 ra.setRelationship("tosca.relationships.network.BindsTo");
392 NodeTemplate port0 = serviceTemplateFromYaml.getTopology_template().getNode_templates().get("cmaui_port_0");
393 //Test With Empty requirementId
394 Assert.assertFalse(toscaAnalyzerService.isRequirementExistInNodeTemplate(port0, "", ra));
396 //Test With valid requirementId
397 Assert.assertTrue(toscaAnalyzerService.isRequirementExistInNodeTemplate(port0, "binding", ra));
399 //Test With invalid requirement assignment
400 RequirementAssignment ra1 = new RequirementAssignment();
401 ra1.setCapability("tosca.capabilities.network.Bindable1");
402 ra1.setNode("server_cmaui1");
403 ra1.setRelationship("tosca.relationships.network.BindsTo1");
404 Assert.assertFalse(toscaAnalyzerService.isRequirementExistInNodeTemplate(port0, "binding", ra1));
409 public void testGetRequirements() throws Exception {
410 ToscaExtensionYamlUtil toscaExtensionYamlUtil = new ToscaExtensionYamlUtil();
411 try (InputStream yamlFile = toscaExtensionYamlUtil.loadYamlFileIs(
412 "/mock/analyzerService/NestedServiceTemplateReqTest.yaml")) {
414 ServiceTemplate serviceTemplateFromYaml =
415 toscaExtensionYamlUtil.yamlToObject(yamlFile, ServiceTemplate.class);
417 NodeTemplate port0 = serviceTemplateFromYaml.getTopology_template().getNode_templates().get("cmaui_port_0");
418 List<RequirementAssignment> reqList =
419 toscaAnalyzerService.getRequirements(port0, ToscaConstants.BINDING_REQUIREMENT_ID);
420 assertEquals(1, reqList.size());
424 serviceTemplateFromYaml.getTopology_template().getNode_templates().get("cmaui1_port_1");
425 reqList = toscaAnalyzerService.getRequirements(port1, ToscaConstants.LINK_REQUIREMENT_ID);
426 assertEquals(2, reqList.size());
429 reqList = toscaAnalyzerService.getRequirements(port0, ToscaConstants.LINK_REQUIREMENT_ID);
430 assertEquals(0, reqList.size());
435 public void testGetNodeTemplateById() throws Exception {
436 ServiceTemplate emptyServiceTemplate = new ServiceTemplate();
437 Optional<NodeTemplate> nodeTemplate =
438 toscaAnalyzerService.getNodeTemplateById(emptyServiceTemplate, "test_net222");
439 assertFalse(nodeTemplate.isPresent());
441 ServiceTemplate mainServiceTemplate =
442 toscaServiceModel.getServiceTemplates().get(toscaServiceModel.getEntryDefinitionServiceTemplate());
443 nodeTemplate = toscaAnalyzerService.getNodeTemplateById(mainServiceTemplate, "test_net");
444 assertTrue(nodeTemplate.isPresent());
446 nodeTemplate = toscaAnalyzerService.getNodeTemplateById(mainServiceTemplate, "test_net222");
447 assertFalse(nodeTemplate.isPresent());
451 public void testGetSubstituteServiceTemplateName() throws Exception {
452 thrown.expect(CoreException.class);
453 thrown.expectMessage(
454 "Invalid Substitute Node Template invalid2, mandatory map property service_template_filter "
455 + "with mandatory key substitute_service_template must be defined.");
457 Optional<String> substituteServiceTemplateName;
459 ServiceTemplate mainServiceTemplate =
460 toscaServiceModel.getServiceTemplates().get(toscaServiceModel.getEntryDefinitionServiceTemplate());
461 Optional<NodeTemplate> notSubstitutableNodeTemplate =
462 toscaAnalyzerService.getNodeTemplateById(mainServiceTemplate, "test_net");
463 assertTrue(notSubstitutableNodeTemplate.isPresent());
465 if (notSubstitutableNodeTemplate.isPresent()) {
466 substituteServiceTemplateName = toscaAnalyzerService.getSubstituteServiceTemplateName("test_net",
467 notSubstitutableNodeTemplate.get());
468 assertFalse(substituteServiceTemplateName.isPresent());
471 Optional<NodeTemplate> substitutableNodeTemplate =
472 toscaAnalyzerService.getNodeTemplateById(mainServiceTemplate, "test_nested");
473 assertTrue(substitutableNodeTemplate.isPresent());
474 if (substitutableNodeTemplate.isPresent()) {
475 substituteServiceTemplateName = toscaAnalyzerService.getSubstituteServiceTemplateName("test_nested",
476 substitutableNodeTemplate.get());
477 assertTrue(substituteServiceTemplateName.isPresent());
478 assertEquals("nestedServiceTemplate.yaml", substituteServiceTemplateName.get());
481 NodeTemplate invalidSubstitutableNodeTemplate1 = new NodeTemplate();
482 substituteServiceTemplateName =
483 toscaAnalyzerService.getSubstituteServiceTemplateName("invalid1", invalidSubstitutableNodeTemplate1);
484 assertFalse(substituteServiceTemplateName.isPresent());
486 substitutableNodeTemplate.ifPresent(nodeTemplate -> {
487 Object serviceTemplateFilter =
488 nodeTemplate.getProperties().get(ToscaConstants.SERVICE_TEMPLATE_FILTER_PROPERTY_NAME);
489 ((Map) serviceTemplateFilter).clear();
490 toscaAnalyzerService.getSubstituteServiceTemplateName("invalid2", nodeTemplate);
497 public void testGetSubstitutableNodeTemplates() throws Exception {
498 ToscaExtensionYamlUtil toscaExtensionYamlUtil = new ToscaExtensionYamlUtil();
499 try (InputStream yamlFile = toscaExtensionYamlUtil.loadYamlFileIs(
500 "/mock/analyzerService/ServiceTemplateSubstituteTest.yaml")) {
501 ServiceTemplate serviceTemplateFromYaml =
502 toscaExtensionYamlUtil.yamlToObject(yamlFile, ServiceTemplate.class);
504 Map<String, NodeTemplate> substitutableNodeTemplates =
505 toscaAnalyzerService.getSubstitutableNodeTemplates(serviceTemplateFromYaml);
506 assertEquals(2, substitutableNodeTemplates.size());
507 assertNotNull(substitutableNodeTemplates.get("test_nested1"));
508 assertNotNull(substitutableNodeTemplates.get("test_nested2"));
510 ServiceTemplate emptyServiceTemplate = new ServiceTemplate();
511 emptyServiceTemplate.setTopology_template(new TopologyTemplate());
512 substitutableNodeTemplates = toscaAnalyzerService.getSubstitutableNodeTemplates(emptyServiceTemplate);
513 assertEquals(0, substitutableNodeTemplates.size());
516 try (InputStream yamlFile = toscaExtensionYamlUtil.loadYamlFileIs(
517 "/mock/analyzerService/NestedServiceTemplateReqTest.yaml")) {
518 ServiceTemplate serviceTemplateFromYaml =
519 toscaExtensionYamlUtil.yamlToObject(yamlFile, ServiceTemplate.class);
520 Map<String, NodeTemplate> substitutableNodeTemplates =
521 toscaAnalyzerService.getSubstitutableNodeTemplates(serviceTemplateFromYaml);
522 assertEquals(0, substitutableNodeTemplates.size());
527 public void testGetSubstitutionMappedNodeTemplateByExposedReq() throws Exception {
528 thrown.expect(CoreException.class);
529 thrown.expectMessage(
530 "Invalid Tosca model data, missing 'Node Template' entry for 'Node Template' id cmaui_port_9");
531 ToscaExtensionYamlUtil toscaExtensionYamlUtil = new ToscaExtensionYamlUtil();
532 try (InputStream yamlFile = toscaExtensionYamlUtil.loadYamlFileIs(
533 "/mock/analyzerService/NestedServiceTemplateReqTest.yaml")) {
534 ServiceTemplate nestedServiceTemplateFromYaml =
535 toscaExtensionYamlUtil.yamlToObject(yamlFile, ServiceTemplate.class);
537 Optional<Map.Entry<String, NodeTemplate>> mappedNodeTemplate =
538 toscaAnalyzerService.getSubstitutionMappedNodeTemplateByExposedReq(
539 "NestedServiceTemplateSubstituteTest.yaml",
540 nestedServiceTemplateFromYaml,
541 "local_storage_server_cmaui");
543 assertTrue(mappedNodeTemplate.isPresent());
544 mappedNodeTemplate.ifPresent(stringNodeTemplateEntry -> {
545 assertEquals("server_cmaui", stringNodeTemplateEntry.getKey());
546 assertNotNull(stringNodeTemplateEntry.getValue());
549 mappedNodeTemplate = toscaAnalyzerService.getSubstitutionMappedNodeTemplateByExposedReq(
550 "NestedServiceTemplateSubstituteTest.yaml", nestedServiceTemplateFromYaml,
551 "link_cmaui_port_invalid");
552 assertTrue(mappedNodeTemplate.isPresent());
553 mappedNodeTemplate.ifPresent(stringNodeTemplateEntry -> {
554 assertEquals("server_cmaui", stringNodeTemplateEntry.getKey());
555 assertNotNull(stringNodeTemplateEntry.getValue());
558 ServiceTemplate mainServiceTemplate =
559 toscaServiceModel.getServiceTemplates().get(toscaServiceModel.getEntryDefinitionServiceTemplate());
560 mappedNodeTemplate = toscaAnalyzerService.getSubstitutionMappedNodeTemplateByExposedReq(
561 toscaServiceModel.getEntryDefinitionServiceTemplate(), mainServiceTemplate,
562 "local_storage_server_cmaui");
563 assertFalse(mappedNodeTemplate.isPresent());
568 public void invalidSubstitutableMapping() throws Exception {
569 thrown.expect(CoreException.class);
570 thrown.expectMessage(
571 "Invalid Substitution Service Template invalidMappingServiceTemplate.yaml, "
572 + "missing mandatory file 'Node type' in substitution mapping.");
573 ServiceTemplate invalidMappingServiceTemplate = new ServiceTemplate();
574 invalidMappingServiceTemplate.setTopology_template(new TopologyTemplate());
575 invalidMappingServiceTemplate.getTopology_template().setSubstitution_mappings(new SubstitutionMapping());
576 toscaAnalyzerService.getSubstitutionMappedNodeTemplateByExposedReq("invalidMappingServiceTemplate.yaml",
577 invalidMappingServiceTemplate, "local_storage_server_cmaui");
581 public void substitutableMappingWithNoReqMap() throws Exception {
582 ServiceTemplate emptyReqMapping = new ServiceTemplate();
583 emptyReqMapping.setTopology_template(new TopologyTemplate());
584 emptyReqMapping.getTopology_template().setSubstitution_mappings(new SubstitutionMapping());
585 emptyReqMapping.getTopology_template().getSubstitution_mappings().setNode_type("temp");
586 ServiceTemplate mainServiceTemplate =
587 toscaServiceModel.getServiceTemplates().get(toscaServiceModel.getEntryDefinitionServiceTemplate());
588 Optional<Map.Entry<String, NodeTemplate>> mappedNodeTemplate =
589 toscaAnalyzerService.getSubstitutionMappedNodeTemplateByExposedReq(
590 toscaServiceModel.getEntryDefinitionServiceTemplate(),mainServiceTemplate,
591 "local_storage_server_cmaui");
592 assertFalse(mappedNodeTemplate.isPresent());
596 public void testGetSubstitutionMappedNodeTemplateByExposedReqInvalid() throws Exception {
597 thrown.expect(CoreException.class);
598 thrown.expectMessage(
599 "Invalid Tosca model data, missing 'Node Template' entry for 'Node Template' id cmaui_port_9");
600 ToscaExtensionYamlUtil toscaExtensionYamlUtil = new ToscaExtensionYamlUtil();
601 try (InputStream yamlFile = toscaExtensionYamlUtil.loadYamlFileIs(
602 "/mock/analyzerService/NestedServiceTemplateReqTest.yaml")) {
603 ServiceTemplate nestedServiceTemplateFromYaml =
604 toscaExtensionYamlUtil.yamlToObject(yamlFile, ServiceTemplate.class);
607 .getSubstitutionMappedNodeTemplateByExposedReq("NestedServiceTemplateSubstituteTest.yaml",
608 nestedServiceTemplateFromYaml, "link_cmaui_port_invalid");
613 public void testIsDesiredRequirementAssignmentMatch() throws Exception {
615 RequirementAssignment requirementAssignment = new RequirementAssignment();
616 String capability = "Test.Capability";
617 String node = "Test.node";
618 String relationship = "Test.relationship";
619 requirementAssignment.setCapability(capability);
620 requirementAssignment.setNode(node);
621 requirementAssignment.setRelationship(relationship);
623 assertTrue(toscaAnalyzerService
624 .isDesiredRequirementAssignment(requirementAssignment, capability, node, relationship));
626 toscaAnalyzerService.isDesiredRequirementAssignment(requirementAssignment, null, node, relationship));
627 assertTrue(toscaAnalyzerService
628 .isDesiredRequirementAssignment(requirementAssignment, capability, null, relationship));
629 assertTrue(toscaAnalyzerService.isDesiredRequirementAssignment(requirementAssignment, capability, node, null));
631 toscaAnalyzerService.isDesiredRequirementAssignment(requirementAssignment, null, null, relationship));
632 assertTrue(toscaAnalyzerService.isDesiredRequirementAssignment(requirementAssignment, capability, null, null));
633 assertTrue(toscaAnalyzerService.isDesiredRequirementAssignment(requirementAssignment, null, node, null));
638 public void testIsDesiredRequirementAssignmentNoMatch() throws Exception {
640 RequirementAssignment requirementAssignment = new RequirementAssignment();
641 String capability = "Test.Capability";
642 String node = "Test.node";
643 String relationship = "Test.relationship";
644 requirementAssignment.setCapability(capability);
645 requirementAssignment.setNode(node);
646 requirementAssignment.setRelationship(relationship);
649 toscaAnalyzerService.isDesiredRequirementAssignment(requirementAssignment, "no", node, relationship));
651 toscaAnalyzerService.isDesiredRequirementAssignment(requirementAssignment, "no", "no", relationship));
652 assertFalse(toscaAnalyzerService.isDesiredRequirementAssignment(requirementAssignment, "no", "no", "no"));
653 assertFalse(toscaAnalyzerService
654 .isDesiredRequirementAssignment(requirementAssignment, capability, "no", relationship));
655 assertFalse(toscaAnalyzerService.isDesiredRequirementAssignment(requirementAssignment, capability, node, "no"));
656 assertFalse(toscaAnalyzerService.isDesiredRequirementAssignment(requirementAssignment, capability, "no", "no"));
657 assertFalse(toscaAnalyzerService.isDesiredRequirementAssignment(requirementAssignment, "no", null, null));
658 assertFalse(toscaAnalyzerService.isDesiredRequirementAssignment(requirementAssignment, null, null, null));
664 public void shouldReturnFalseIfNdTmpIsNull() {
665 NodeTemplate nodeTemplate = null;
666 assertFalse(toscaAnalyzerService.isTypeOf(nodeTemplate, ToscaNodeType.NATIVE_NETWORK, new ServiceTemplate(),
667 toscaServiceModelMock));
671 public void shouldReturnTrueIfNdTmpTypeIsOfRequestedType() {
672 NodeTemplate nodeTemplate = new NodeTemplate();
673 String nodeTypeToSearch = ToscaNodeType.NATIVE_BLOCK_STORAGE;
674 nodeTemplate.setType(nodeTypeToSearch);
675 assertTrue(toscaAnalyzerService
676 .isTypeOf(nodeTemplate, nodeTypeToSearch, new ServiceTemplate(), toscaServiceModelMock));
680 public void shouldReturnTrueIfDataTypeIsOfRequestedType() {
681 PropertyDefinition propertyDefinition = new PropertyDefinition();
682 String propertyTypeToSearch = "tosca.datatypes.TimeInterval";
683 propertyDefinition.setType(propertyTypeToSearch);
684 assertTrue(toscaAnalyzerService.isTypeOf(propertyDefinition, propertyTypeToSearch, new ServiceTemplate(),
685 toscaServiceModelMock));
689 public void shouldReturnTrueIfInterfaceTypeIsOfRequestedType() {
690 InterfaceDefinitionType interfaceDefinition = new InterfaceDefinitionType();
691 String interfaceTypeToSearch = "test.interface.A";
692 interfaceDefinition.setType(interfaceTypeToSearch);
693 assertTrue(toscaAnalyzerService.isTypeOf(interfaceDefinition, interfaceTypeToSearch, new ServiceTemplate(),
694 toscaServiceModelMock));
698 public void interfaceInheritanceNoOperIsTypeTrue() throws IOException {
699 ToscaExtensionYamlUtil toscaExtensionYamlUtil = new ToscaExtensionYamlUtil();
700 try (InputStream yamlFile = toscaExtensionYamlUtil.loadYamlFileIs(
701 "/mock/analyzerService/ServiceTemplateInterfaceInheritanceTest.yaml")) {
702 interfaceIsTypeTest(toscaExtensionYamlUtil, CMAUI_IMAGE_EXTEND, yamlFile);
706 private void interfaceIsTypeTest(ToscaExtensionYamlUtil toscaExtensionYamlUtil, String nodeTypeKey,
707 InputStream yamlFile) {
708 ServiceTemplate serviceTemplateFromYaml = toscaExtensionYamlUtil.yamlToObject(yamlFile, ServiceTemplate.class);
710 ToscaFlatData flatData = toscaAnalyzerService.getFlatEntity(ToscaElementTypes.NODE_TYPE, nodeTypeKey,
711 serviceTemplateFromYaml, toscaServiceModel);
713 Assert.assertNotNull(flatData);
714 Object standardInterfaceDefinition =
715 ((NodeType) flatData.getFlatEntity()).getInterfaces().get(STANDARD_INTERFACE_KEY);
716 InterfaceDefinitionType standardInterfaceDefinitionType =
717 new InterfaceDefinitionType(standardInterfaceDefinition);
718 assertTrue(toscaAnalyzerService
719 .isTypeOf(standardInterfaceDefinitionType, TOSCA_LIFECYCLE_STANDARD, serviceTemplateFromYaml,
724 public void interfaceInheritanceWithOperIsTypeTrue() throws IOException {
725 ToscaExtensionYamlUtil toscaExtensionYamlUtil = new ToscaExtensionYamlUtil();
726 try (InputStream yamlFile = toscaExtensionYamlUtil.loadYamlFileIs(
727 "/mock/analyzerService/ServiceTemplateInterfaceInheritanceTest.yaml")) {
728 interfaceIsTypeTest(toscaExtensionYamlUtil, CMAUI_INTERFACE_TEST, yamlFile);
734 public void shouldReturnTrueIfNdTmpTypeIsFoundInSrvTmpNdTyAndNdTyDerivedFromRequestedType() {
735 String typeToMatch = ToscaNodeType.CINDER_VOLUME;
736 when(nodeTemplateMock.getType()).thenReturn(typeToMatch);
737 Map<String, NodeType> stNodeTypes = new HashMap<>();
738 addNodeType(stNodeTypes, ToscaNodeType.NATIVE_COMPUTE, new NodeType());
739 NodeType nodeType = createNodeType(ToscaNodeType.NATIVE_BLOCK_STORAGE);
740 addNodeType(stNodeTypes, typeToMatch, nodeType);
741 ServiceTemplate serviceTemplate = new ServiceTemplate();
742 serviceTemplate.setNode_types(stNodeTypes);
743 assertTrue(toscaAnalyzerService.isTypeOf(nodeTemplateMock, ToscaNodeType.NATIVE_BLOCK_STORAGE, serviceTemplate,
744 toscaServiceModelMock));
749 public void dataTypeParameterExistInHierarchy() {
750 String testedDataTypeKey = "test.dataType.B";
751 when(parameterDefinitionMock.getType()).thenReturn(testedDataTypeKey);
752 dataTypeExistInHierarchy(testedDataTypeKey, parameterDefinitionMock);
757 public void dataTypePropertyExistInHierarchy() {
758 String testedDataTypeKey = "test.dataType.B";
759 when(propertyDefinitionMock.getType()).thenReturn(testedDataTypeKey);
760 dataTypeExistInHierarchy(testedDataTypeKey, propertyDefinitionMock);
763 private void dataTypeExistInHierarchy(String testedDataTypeKey, DefinitionOfDataType testedDefinitionDataType) {
764 String typeToMatch = "test.dataType.A";
765 Map<String, DataType> stDataTypes = new HashMap<>();
766 addDataType(stDataTypes, "tosca.datatypes.network.NetworkInfo", new DataType());
767 DataType testedDataType = createDataType(typeToMatch);
768 addDataType(stDataTypes, testedDataTypeKey, testedDataType);
769 ServiceTemplate serviceTemplate = new ServiceTemplate();
770 serviceTemplate.setData_types(stDataTypes);
771 assertTrue(toscaAnalyzerService
772 .isTypeOf(testedDefinitionDataType, typeToMatch, serviceTemplate, toscaServiceModelMock));
776 public void interfaceTypeExistInHierarchy() {
777 String typeToMatch = "test.interfaceType.A";
778 String testedInterfaceTypeKey = "test.interfaceType.B";
779 when(interfaceDefinitionMock.getType()).thenReturn(testedInterfaceTypeKey);
780 Map<String, Object> stInterfaceTypes = new HashMap<>();
781 stInterfaceTypes.put("tosca.interfaces.network.NetworkInfo", new InterfaceType());
782 InterfaceType testedInterfaceType = createInterfaceType(typeToMatch);
783 stInterfaceTypes.put(testedInterfaceTypeKey, testedInterfaceType);
784 ServiceTemplate serviceTemplate = new ServiceTemplate();
785 serviceTemplate.setInterface_types(stInterfaceTypes);
786 assertTrue(toscaAnalyzerService.isTypeOf(interfaceDefinitionMock, "test.interfaceType.A", serviceTemplate,
787 toscaServiceModelMock));
791 public void shouldThrowCoreExceptionForInvalidNodeType() {
792 thrown.expect(CoreException.class);
793 thrown.expectMessage("Entity Type 'AAA' or one of its derivedFrom type hierarchy, is not defined in "
794 + "tosca service model");
795 when(nodeTemplateMock.getType()).thenReturn("AAA");
796 Map<String, NodeType> stNodeTypes = new HashMap<>();
797 addNodeType(stNodeTypes, "notImportant", new NodeType());
798 ServiceTemplate serviceTemplate = new ServiceTemplate();
799 serviceTemplate.setNode_types(stNodeTypes);
801 .isTypeOf(nodeTemplateMock, ToscaNodeType.NATIVE_COMPUTE, serviceTemplate, toscaServiceModelMock);
805 public void shouldThrowCoreExceptionForInvalidNodeType2Level() {
806 thrown.expect(CoreException.class);
807 thrown.expectMessage(
808 "Entity Type 'A' or one of its derivedFrom type hierarchy, is not defined in tosca " + "service model");
809 String typeToMatch = "A";
810 when(nodeTemplateMock.getType()).thenReturn(typeToMatch);
811 Map<String, NodeType> stNodeTypes = new HashMap<>();
812 addNodeType(stNodeTypes, "notImportant", new NodeType());
813 addNodeType(stNodeTypes, "A", createNodeType("ADerivedFromB"));
814 addNodeType(stNodeTypes, "ADerivedFromB'", createNodeType("BDerivedFromC"));
815 ServiceTemplate serviceTemplate = new ServiceTemplate();
816 serviceTemplate.setNode_types(stNodeTypes);
817 assertTrue(toscaAnalyzerService
818 .isTypeOf(nodeTemplateMock, "BDerivedFromC", serviceTemplate, toscaServiceModelMock));
823 shouldReturnTrueIfNdTmpTypeIsFoundInSrvTmpNdTyAndNotDerivedFromRequestedTypeBut2ndLevelDerivedFromMatch() {
824 String typeToMatch = "A";
825 when(nodeTemplateMock.getType()).thenReturn(typeToMatch);
826 Map<String, NodeType> stNodeTypes = new HashMap<>();
827 addNodeType(stNodeTypes, "notImportant", new NodeType());
828 addNodeType(stNodeTypes, "A", createNodeType("ADerivedFromB"));
829 addNodeType(stNodeTypes, "ADerivedFromB", createNodeType("BDerivedFromC"));
830 ServiceTemplate serviceTemplate = new ServiceTemplate();
831 serviceTemplate.setNode_types(stNodeTypes);
832 assertTrue(toscaAnalyzerService
833 .isTypeOf(nodeTemplateMock, "BDerivedFromC", serviceTemplate, toscaServiceModelMock));
836 private NodeType createNodeType(String derivedFrom) {
837 NodeType nodeType = new NodeType();
838 nodeType.setDerived_from(derivedFrom);
842 private DataType createDataType(String derivedFrom) {
843 DataType dataType = new DataType();
844 dataType.setDerived_from(derivedFrom);
848 private InterfaceType createInterfaceType(String derivedFrom) {
849 InterfaceType interfaceType = new InterfaceType();
850 interfaceType.setDerived_from(derivedFrom);
851 return interfaceType;
854 private void addNodeType(Map<String, NodeType> stNodeTypes, String key, NodeType nodeType) {
855 stNodeTypes.put(key, nodeType);
858 private void addDataType(Map<String, DataType> stDataTypes, String key, DataType dataType) {
859 stDataTypes.put(key, dataType);
863 public void shouldReturnTrueIfNdTmpTypeIsFoundInSrvTmpNdTyButRequestedTypeNotMatchButFoundIn1stLevelImports() {
864 String typeToMatch = ToscaNodeType.CINDER_VOLUME;
865 when(nodeTemplateMock.getType()).thenReturn(typeToMatch);
866 List<Map<String, Import>> imports = new ArrayList<>();
867 Map<String, Import> importMap = new HashMap<>();
868 Import anImport = new Import();
869 anImport.setFile("mainImport");
870 importMap.put("bla bla", anImport);
871 imports.add(importMap);
872 ServiceTemplate mainSt = new ServiceTemplate();
873 mainSt.setImports(imports);
875 //create searchable service template
876 Map<String, NodeType> stNodeTypes = new HashMap<>();
877 addNodeType(stNodeTypes, ToscaNodeType.NATIVE_COMPUTE, new NodeType());
878 NodeType nodeType = createNodeType(ToscaNodeType.NATIVE_BLOCK_STORAGE);
879 addNodeType(stNodeTypes, typeToMatch, nodeType);
880 ServiceTemplate serviceTemplate = new ServiceTemplate();
881 serviceTemplate.setNode_types(stNodeTypes);
883 // add service templates to tosca service model
884 Map<String, ServiceTemplate> serviceTemplates = toscaServiceModelMock.getServiceTemplates();
885 serviceTemplates.put("testMainServiceTemplate", mainSt);
886 serviceTemplates.put("mainImport", serviceTemplate);
887 when(toscaServiceModelMock.getServiceTemplates()).thenReturn(serviceTemplates);
889 assertTrue(toscaAnalyzerService.isTypeOf(nodeTemplateMock, ToscaNodeType.NATIVE_BLOCK_STORAGE, mainSt,
890 toscaServiceModelMock));
894 public void shouldReturnTrueIfNdTmpTypeIsFoundInSrvTmpNdTyButRequestedTypeNotMatchButFoundIn2ndLevelImports() {
895 String typeToMatch = ToscaNodeType.CINDER_VOLUME;
896 when(nodeTemplateMock.getType()).thenReturn(typeToMatch);
897 List<Map<String, Import>> imports = new ArrayList<>();
898 Map<String, Import> importMap = new HashMap<>();
899 Import anImport = new Import();
900 anImport.setFile("refToMainImport");
901 importMap.put("bla bla", anImport);
902 imports.add(importMap);
903 ServiceTemplate mainSt = new ServiceTemplate();
904 mainSt.setImports(imports);
906 //create searchable service template
907 Map<String, NodeType> stNodeTypes = new HashMap<>();
908 addNodeType(stNodeTypes, ToscaNodeType.NATIVE_COMPUTE, new NodeType());
909 NodeType nodeType = createNodeType(ToscaNodeType.NATIVE_BLOCK_STORAGE);
910 addNodeType(stNodeTypes, typeToMatch, nodeType);
911 ServiceTemplate serviceTemplate = new ServiceTemplate();
912 serviceTemplate.setNode_types(stNodeTypes);
914 // create 1st level service template with import only
915 List<Map<String, Import>> firstLevelImports = new ArrayList<>();
916 Map<String, Import> firstLevelImportsMap = new HashMap<>();
917 Import firstLevelImport = new Import();
918 firstLevelImport.setFile("mainImport");
919 firstLevelImportsMap.put("bla bla 2", firstLevelImport);
920 firstLevelImports.add(firstLevelImportsMap);
921 ServiceTemplate firstLevelSt = new ServiceTemplate();
922 firstLevelSt.setImports(firstLevelImports);
924 // add service templates to tosca service model
925 Map<String, ServiceTemplate> serviceTemplates = toscaServiceModelMock.getServiceTemplates();
926 serviceTemplates.put("testMainServiceTemplate", mainSt);
927 serviceTemplates.put("refToMainImport", firstLevelSt);
928 serviceTemplates.put("mainImport", serviceTemplate);
929 when(toscaServiceModelMock.getServiceTemplates()).thenReturn(serviceTemplates);
931 assertTrue(toscaAnalyzerService.isTypeOf(nodeTemplateMock, ToscaNodeType.NATIVE_BLOCK_STORAGE, mainSt,
932 toscaServiceModelMock));
935 // not found at all should throw core exception
939 public void capabilityDefinitionIsTypeOfDirectTypeFound() {
940 CapabilityDefinition capabilityDefinition = new CapabilityDefinition();
941 capabilityDefinition.setType(CAPABILITY_TYPE_A);
942 assertTrue(toscaAnalyzerService.isTypeOf(capabilityDefinition, CAPABILITY_TYPE_A, new ServiceTemplate(),
943 toscaServiceModelMock));
947 public void capabilityDefinitionIsTypeOfReturnNo() {
948 CapabilityDefinition capabilityDefinition = new CapabilityDefinition();
949 capabilityDefinition.setType(CAPABILITY_TYPE_A);
950 ServiceTemplate serviceTemplate = new ServiceTemplate();
951 serviceTemplate.setCapability_types(new HashMap<>());
952 CapabilityType capabilityType = new CapabilityType();
953 capabilityType.setDerived_from(TOSCA_CAPABILITIES_ROOT);
954 serviceTemplate.getCapability_types().put(CAPABILITY_TYPE_A, capabilityType);
955 assertFalse(toscaAnalyzerService
956 .isTypeOf(capabilityDefinition, CAPABILITY_TYPE_B, serviceTemplate, toscaServiceModelMock));
960 public void capabilityDefinitionIsTypeOfInheritanceTypeFound() {
961 CapabilityDefinition capabilityDefinition = new CapabilityDefinition();
962 capabilityDefinition.setType(CAPABILITY_TYPE_A);
963 ServiceTemplate serviceTemplate = new ServiceTemplate();
964 serviceTemplate.setCapability_types(new HashMap<>());
965 CapabilityType capabilityType = new CapabilityType();
966 capabilityType.setDerived_from(CAPABILITY_TYPE_B);
967 serviceTemplate.getCapability_types().put(CAPABILITY_TYPE_A, capabilityType);
968 assertTrue(toscaAnalyzerService
969 .isTypeOf(capabilityDefinition, CAPABILITY_TYPE_B, serviceTemplate, toscaServiceModelMock));