@@ -135,6 +135,31 @@ public void resolveServiceTemplateInputsTestThrowExceptionWhenInputIsNotDefinedA
135135 toscaOrchestratorSpy .resolveServiceTemplateInputs (serviceTemplate , Map .of ());
136136 }
137137
138+ @ Test
139+ public void resolveServiceTemplateInputsTestCorrectlyResolveAllGetInputFunctionCallsInsideOfCollections () {
140+ String serviceTemplateYaml = "{service_template: {inputs: {first-ip: {type: string}, second-ip: {type: string}, first-detail: {type: string}, second-detail: {type: string}}, node_templates: {instance: {type: Vm, properties: {type: SSVM, vcpus: 2, ip-addresses: [{$get_input: first-ip}, {$get_input: second-ip}], offering-details: {detail1: {$get_input: first-detail}, detail2: {$get_input: second-detail}}, name-value-mapping: [{name: {$get_input: first-detail}, value: {$get_input: first-ip}}, {name: {$get_input: second-detail}, value: {$get_input: second-ip}}]}}}}}" ;
141+ ToscaServiceTemplate serviceTemplate = toscaParser .parseServiceTemplate (serviceTemplateYaml , ToscaFixtures .getToscaProfileForTests (), null );
142+
143+ toscaOrchestratorSpy .resolveServiceTemplateInputs (serviceTemplate , Map .of ("first-ip" , "10.0.0.1" , "second-ip" , "10.0.0.2" , "first-detail" , "1st detail" , "second-detail" , "2nd detail" ));
144+
145+ List <?> instanceIpAddresses = ToscaYamlHelper .asList (serviceTemplate .getNodeTemplates ().get ("instance" ).getProperty ("ip-addresses" ).getEvaluatedValue ());
146+ Assert .assertEquals (2 , instanceIpAddresses .size ());
147+ Assert .assertEquals ("10.0.0.1" , instanceIpAddresses .get (0 ));
148+ Assert .assertEquals ("10.0.0.2" , instanceIpAddresses .get (1 ));
149+
150+ Map <String , Object > offeringDetails = ToscaYamlHelper .asMap (serviceTemplate .getNodeTemplates ().get ("instance" ).getProperty ("offering-details" ).getEvaluatedValue ());
151+ Assert .assertEquals (2 , offeringDetails .size ());
152+ Assert .assertEquals ("1st detail" , offeringDetails .get ("detail1" ));
153+ Assert .assertEquals ("2nd detail" , offeringDetails .get ("detail2" ));
154+
155+ List <?> nameValueMappings = ToscaYamlHelper .asList (serviceTemplate .getNodeTemplates ().get ("instance" ).getProperty ("name-value-mapping" ).getEvaluatedValue ());
156+ Assert .assertEquals (2 , nameValueMappings .size ());
157+ Assert .assertEquals ("1st detail" , ToscaYamlHelper .asMap (nameValueMappings .get (0 )).get ("name" ));
158+ Assert .assertEquals ("10.0.0.1" , ToscaYamlHelper .asMap (nameValueMappings .get (0 )).get ("value" ));
159+ Assert .assertEquals ("2nd detail" , ToscaYamlHelper .asMap (nameValueMappings .get (1 )).get ("name" ));
160+ Assert .assertEquals ("10.0.0.2" , ToscaYamlHelper .asMap (nameValueMappings .get (1 )).get ("value" ));
161+ }
162+
138163 @ Test
139164 public void populateNodeTemplateAttributesTestSuccessfullyPopulateNodeAttributes () {
140165 String serviceTemplateYaml = "{service_template: {node_templates: {instance: {type: Vm, properties: {type: VR, ssh-key-pair-name: {$get_property: [pair, name]}, vcpus: 2, ip-addresses: [10.0.0.1, 10.0.0.2]}}, other-instance: {type: Vm, properties: {type: SSVM, ssh-key-pair-name: {$get_attribute: [pair, uuid]}, vcpus: 1, ip-addresses: [10.0.0.1]}}, pair: {type: SshPair, properties: {name: Pair, public-key: Public Key}}}}}" ;
@@ -174,7 +199,7 @@ public void executeGetAttributeAndGetPropertyFunctionCallsTestSuccessfullyExecut
174199
175200 @ Test
176201 public void executeGetAttributeAndGetPropertyFunctionCallsTestSuccessfullyExecuteFunctionCallsContainedInsideOfCollections () {
177- String serviceTemplateYaml = "{service_template: {node_templates: {instance: {type: Vm, properties: {type: VR, vcpus: 2, ip-addresses: [{$get_property: [other-instance, type]}, {$get_attribute: [other-instance, uuid]}]}}, other-instance: {type: Vm, properties: {type: {$get_property: [pair, name]}, vcpus: 1, offering-details: {detail1: {$get_attribute: [pair, uuid]}, detail2: {$get_property: [pair, public-key]}}}}, pair: {type: SshPair, properties: {name: SSVM, public-key: Public Key}}}}}" ;
202+ String serviceTemplateYaml = "{service_template: {node_templates: {instance: {type: Vm, properties: {type: VR, vcpus: 2, name-value-mapping: [{name: {$get_property: [pair, name]}, value: {$get_attribute: [pair, uuid]}}, {name: {$get_property: [other-instance, type]}, value: {$get_attribute: [other-instance, uuid]}}], ip-addresses: [{$get_property: [other-instance, type]}, {$get_attribute: [other-instance, uuid]}]}}, other-instance: {type: Vm, properties: {type: {$get_property: [pair, name]}, vcpus: 1, offering-details: {detail1: {$get_attribute: [pair, uuid]}, detail2: {$get_property: [pair, public-key]}}}}, pair: {type: SshPair, properties: {name: SSVM, public-key: Public Key}}}}}" ;
178203 ToscaServiceTemplate serviceTemplate = toscaParser .parseServiceTemplate (serviceTemplateYaml , ToscaFixtures .getToscaProfileForTests (), null );
179204 serviceTemplate .getNodeTemplates ().get ("other-instance" ).addAttribute ("uuid" , "otherinstanceuuid" );
180205 serviceTemplate .getNodeTemplates ().get ("pair" ).addAttribute ("uuid" , "pairuuid" );
@@ -186,7 +211,15 @@ public void executeGetAttributeAndGetPropertyFunctionCallsTestSuccessfullyExecut
186211 Assert .assertEquals (serviceTemplate .getNodeTemplates ().get ("pair" ).getProperty ("public-key" ).getEvaluatedValue (), offeringDetails .get ("detail2" ));
187212
188213 toscaOrchestratorSpy .executeGetAttributeAndGetPropertyFunctionCalls (serviceTemplate .getNodeTemplates ().get ("instance" ), serviceTemplate );
214+ List <?> nameValueMappings = ToscaYamlHelper .asList (serviceTemplate .getNodeTemplates ().get ("instance" ).getProperty ("name-value-mapping" ).getEvaluatedValue ());
215+ Assert .assertEquals (2 , nameValueMappings .size ());
216+ Assert .assertEquals (serviceTemplate .getNodeTemplates ().get ("pair" ).getProperty ("name" ).getEvaluatedValue (), ToscaYamlHelper .asMap (nameValueMappings .get (0 )).get ("name" ));
217+ Assert .assertEquals (serviceTemplate .getNodeTemplates ().get ("pair" ).getAttribute ("uuid" ), ToscaYamlHelper .asMap (nameValueMappings .get (0 )).get ("value" ));
218+ Assert .assertEquals (serviceTemplate .getNodeTemplates ().get ("other-instance" ).getProperty ("type" ).getEvaluatedValue (), ToscaYamlHelper .asMap (nameValueMappings .get (1 )).get ("name" ));
219+ Assert .assertEquals (serviceTemplate .getNodeTemplates ().get ("other-instance" ).getAttribute ("uuid" ), ToscaYamlHelper .asMap (nameValueMappings .get (1 )).get ("value" ));
220+
189221 List <?> instanceIpAddresses = ToscaYamlHelper .asList (serviceTemplate .getNodeTemplates ().get ("instance" ).getProperty ("ip-addresses" ).getEvaluatedValue ());
222+ Assert .assertEquals (2 , offeringDetails .size ());
190223 Assert .assertEquals (serviceTemplate .getNodeTemplates ().get ("other-instance" ).getProperty ("type" ).getEvaluatedValue (), instanceIpAddresses .get (0 ));
191224 Assert .assertEquals (serviceTemplate .getNodeTemplates ().get ("other-instance" ).getAttribute ("uuid" ), instanceIpAddresses .get (1 ));
192225 }
0 commit comments