3 * * ============LICENSE_START=======================================================
5 * * ================================================================================
6 * * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved.
7 * * ================================================================================
8 * * Licensed under the Apache License, Version 2.0 (the "License");
9 * * you may not use this file except in compliance with the License.
10 * * You may obtain a copy of the License at
12 * * http://www.apache.org/licenses/LICENSE-2.0
14 * * Unless required by applicable law or agreed to in writing, software
15 * * distributed under the License is distributed on an "AS IS" BASIS,
16 * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * * See the License for the specific language governing permissions and
18 * * limitations under the License.
19 * * ============LICENSE_END=========================================================
24 package org.onap.blueprintgenerator.test;
26 import org.mockito.ArgumentCaptor;
27 import org.mockito.Mockito;
28 import org.onap.blueprintgenerator.constants.Constants;
29 import org.onap.blueprintgenerator.model.common.Input;
30 import org.onap.blueprintgenerator.model.common.Node;
31 import org.onap.blueprintgenerator.model.common.OnapBlueprint;
32 import org.onap.blueprintgenerator.model.common.Properties;
33 import org.junit.Test;
34 import org.junit.jupiter.api.DisplayName;
35 import picocli.CommandLine;
37 import java.io.IOException;
38 import java.io.PrintStream;
39 import java.nio.file.Paths;
40 import java.util.LinkedHashMap;
41 import java.util.List;
44 import static org.junit.Assert.assertEquals;
45 import static org.junit.Assert.assertNotNull;
46 import static org.junit.Assert.assertTrue;
47 import static org.junit.Assert.assertArrayEquals;
48 import static org.mockito.ArgumentMatchers.any;
49 import static org.mockito.Mockito.times;
50 import static org.mockito.Mockito.verify;
53 * @author : Ravi Mantena
54 * @date 10/16/2020 Application: ONAP - Blueprint Generator ONAP Blueprint Test Cases for ONAP and
57 public class OnapBlueprintServiceTest extends BlueprintGeneratorTests {
59 private String outputfilesPath =
60 Paths.get("src", "test", "resources", "outputfiles").toAbsolutePath().toString();
63 * Test Case for Service Name Override Component Spec Input File
66 @DisplayName("Testing K8s Blueprint for Service Name Override Component Spec Input File")
68 public void testServiceNameOverrideK8sBlueprint() throws IOException {
70 onapTestUtils.getInput(
71 Paths.get("src", "test", "resources", "componentspecs", ves).toFile()
74 "testServiceNameOverrideK8sBlueprint",
79 onapComponentSpecService.createComponentSpecFromFile(input.getComponentSpecPath());
81 "K8s Blueprint for Service Name Override Component Spec is NULL", onapComponentSpec);
83 OnapBlueprint onapBlueprint = onapBlueprintService
84 .createBlueprint(onapComponentSpec, input);
85 onapBlueprintService.blueprintToYaml(onapComponentSpec, onapBlueprint, input);
87 onapBlueprintService.blueprintToString(onapComponentSpec, onapBlueprint, input));
89 onapTestUtils.verifyToscaDefVersion(
90 "Service Name Override K8s", onapBlueprint, Constants.TOSCA_DEF_VERSION);
91 onapTestUtils.verifyBpImports("Service Name Override K8s", onapBlueprint, false);
93 Map<String, LinkedHashMap<String, Object>> k8sBpInputs = onapBlueprint.getInputs();
94 assertNotNull("Service Name Override K8s Blueprint Inputs Section is NULL", k8sBpInputs);
96 "Service Name Override K8s Blueprint Inputs Section is Empty", k8sBpInputs.size() > 0);
99 "Service Name Override K8s Blueprint:Inputs "
100 + Constants.ONAP_INPUT_CPU_LIMIT
101 + " Default is not matching",
102 k8sBpInputs.get(Constants.ONAP_INPUT_CPU_LIMIT).get("default"),
103 Constants.ONAP_DEFAULT250m);
105 "Service Name Override K8s Blueprint:Inputs "
106 + Constants.SERVICE_COMPONENT_NAME_OVERRIDE
107 + " Default is not matching",
108 k8sBpInputs.get(Constants.SERVICE_COMPONENT_NAME_OVERRIDE).get("default"),
109 Constants.ONAP_SERVICE_COMPONENTNAME_OVERRIDE_DEFAULT);
111 Map<String, Node> k8sBpNodeTemplates = onapBlueprint.getNode_templates();
113 "Service Name Override K8s Blueprint Node Templates Section is NULL in the K8s DMAAP Blueprint",
116 "Service Name Override K8s Blueprint Node Templates Section Size is Empty",
117 k8sBpNodeTemplates.size() > 0);
120 "Service Name Override K8s Blueprint:NodeTemplates:Type is not Matching",
121 k8sBpNodeTemplates.get(Constants.ONAP_NODETEMPLATES).getType(),
122 Constants.ONAP_NODETEMPLATES_TYPE);
124 Properties k8sBpNodeTemplateProperties =
125 ((Node) k8sBpNodeTemplates.get(Constants.ONAP_NODETEMPLATES)).getProperties();
127 "Service Name Override K8s Blueprint Node Templates:Properties Section is NULL",
128 k8sBpNodeTemplateProperties);
130 Map<String, LinkedHashMap<String, Object>> bpInputs = onapBlueprint.getInputs();
132 .verifyArtifacts("Service Name Override K8s", onapComponentSpec, bpInputs, "o");
134 onapTestUtils.verifyStreamsPublishes(
135 "Service Name Override K8s", onapComponentSpec, k8sBpNodeTemplateProperties);
136 onapTestUtils.verifyStreamsSubscribes(
137 "Service Name Override K8s", onapComponentSpec, k8sBpNodeTemplateProperties);
138 onapTestUtils.verifyAuxilary("Service Name Override K8s", onapComponentSpec);
139 onapTestUtils.verifyHealthCheck(
140 "Service Name Override K8s", onapComponentSpec, k8sBpNodeTemplateProperties);
141 onapTestUtils.verifyServicesCalls("Service Name Override K8s", onapComponentSpec);
142 onapTestUtils.verifyServicesProvides("Service Name Override K8s", onapComponentSpec);
143 onapTestUtils.verifyDockerConfig(
144 "Service Name Override K8s", onapComponentSpec, k8sBpNodeTemplateProperties);
145 onapTestUtils.verifyParameters(
146 "Service Name Override K8s", onapComponentSpec, k8sBpNodeTemplates);
147 onapTestUtils.verifyVolumes(
148 "Service Name Override K8s", onapComponentSpec, k8sBpNodeTemplateProperties);
152 * Test Case for Service Name Override Component Spec Input File with Import File
156 "Testing K8s Blueprint for Service Name Override Component Spec Input File with Import File")
158 public void testServiceNameOverrideImportFileK8sBlueprint() throws IOException {
160 onapTestUtils.getInput(
161 Paths.get("src", "test", "resources", "componentspecs", ves).toFile()
165 Paths.get("src", "test", "resources", "componentspecs", testImports)
171 onapComponentSpecService.createComponentSpecFromFile(input.getComponentSpecPath());
173 "K8s Blueprint for Service Name Override with Import File Component Spec is NULL",
176 OnapBlueprint onapBlueprint = onapBlueprintService
177 .createBlueprint(onapComponentSpec, input);
179 onapTestUtils.verifyToscaDefVersion(
180 "Service Name Override with Import File K8s", onapBlueprint,
181 Constants.TOSCA_DEF_VERSION);
182 onapTestUtils.verifyBpImportsFromFile(
183 "Service Name Override with Import File K8s", onapBlueprint, input.getImportPath());
185 Map<String, LinkedHashMap<String, Object>> k8sBpInputs = onapBlueprint.getInputs();
187 "Service Name Override with Import File K8s Blueprint Inputs Section is NULL",
190 "Service Name Override with Import File K8s Blueprint Inputs Section is Empty",
191 k8sBpInputs.size() > 0);
194 "Service Name Override with Import File K8s Blueprint:Inputs "
195 + Constants.ONAP_INPUT_CPU_LIMIT
196 + " Default is not matching",
197 k8sBpInputs.get(Constants.ONAP_INPUT_CPU_LIMIT).get("default"),
198 Constants.ONAP_DEFAULT250m);
200 "Service Name Override with Import File K8s Blueprint:Inputs "
201 + Constants.SERVICE_COMPONENT_NAME_OVERRIDE
202 + " Default is not matching",
203 k8sBpInputs.get(Constants.SERVICE_COMPONENT_NAME_OVERRIDE).get("default"),
204 Constants.ONAP_SERVICE_COMPONENTNAME_OVERRIDE_DEFAULT);
206 Map<String, Node> k8sBpNodeTemplates = onapBlueprint.getNode_templates();
208 "Service Name Override with Import File K8s Blueprint Node Templates Section is NULL in the K8s DMAAP Blueprint",
211 "Service Name Override with Import File K8s Blueprint Node Templates Section Size is Empty",
212 k8sBpNodeTemplates.size() > 0);
215 "Service Name Override with Import File K8s Blueprint:NodeTemplates:Type is not Matching",
216 k8sBpNodeTemplates.get(Constants.ONAP_NODETEMPLATES).getType(),
217 Constants.ONAP_NODETEMPLATES_TYPE);
219 Properties k8sBpNodeTemplateProperties =
220 ((Node) k8sBpNodeTemplates.get(Constants.ONAP_NODETEMPLATES)).getProperties();
222 "Service Name Override with Import File K8s Blueprint Node Templates:Properties Section is NULL",
223 k8sBpNodeTemplateProperties);
225 Map<String, LinkedHashMap<String, Object>> bpInputs = onapBlueprint.getInputs();
226 onapTestUtils.verifyArtifacts(
227 "Service Name Override with Import File K8s", onapComponentSpec, bpInputs, "o");
229 onapTestUtils.verifyStreamsPublishes(
230 "Service Name Override with Import File K8s",
232 k8sBpNodeTemplateProperties);
233 onapTestUtils.verifyStreamsSubscribes(
234 "Service Name Override with Import File K8s",
236 k8sBpNodeTemplateProperties);
238 .verifyAuxilary("Service Name Override with Import File K8s", onapComponentSpec);
239 onapTestUtils.verifyHealthCheck(
240 "Service Name Override with Import File K8s",
242 k8sBpNodeTemplateProperties);
243 onapTestUtils.verifyServicesCalls(
244 "Service Name Override with Import File K8s", onapComponentSpec);
245 onapTestUtils.verifyServicesProvides(
246 "Service Name Override with Import File K8s", onapComponentSpec);
247 onapTestUtils.verifyDockerConfig(
248 "Service Name Override with Import File K8s",
250 k8sBpNodeTemplateProperties);
251 onapTestUtils.verifyParameters(
252 "Service Name Override with Import File K8s", onapComponentSpec, k8sBpNodeTemplates);
253 onapTestUtils.verifyVolumes(
254 "Service Name Override with Import File K8s",
256 k8sBpNodeTemplateProperties);
260 * Test Case for K8s Blueprint with DB
263 @DisplayName("Testing K8s Blueprint with DB")
265 public void testDMAAPK8sBlueprintWithDB() {
267 onapTestUtils.getInput(
268 Paths.get("src", "test", "resources", "componentspecs", ves).toFile()
271 "testDMAAPK8sBlueprintWithDB",
276 onapComponentSpecService.createComponentSpecFromFile(input.getComponentSpecPath());
277 assertNotNull("K8s Blueprint for DMAAP Component Spec is NULL", onapComponentSpec);
279 OnapBlueprint onapBlueprint = dmaapBlueprintService
280 .createBlueprint(onapComponentSpec, input);
281 onapBlueprintService.blueprintToYaml(onapComponentSpec, onapBlueprint, input);
285 * Test Case for K8s Blueprint for DMAAP Component Spec Input File
288 @DisplayName("Testing K8s Blueprint for DMAAP Component Spec Input File")
290 public void testDMAAPK8sBlueprint() {
292 onapTestUtils.getInput(
293 Paths.get("src", "test", "resources", "componentspecs", ves).toFile()
296 "testDMAAPK8sBlueprint",
301 onapComponentSpecService.createComponentSpecFromFile(input.getComponentSpecPath());
302 assertNotNull("K8s Blueprint for DMAAP Component Spec is NULL", onapComponentSpec);
304 OnapBlueprint onapBlueprint = dmaapBlueprintService
305 .createBlueprint(onapComponentSpec, input);
306 onapBlueprintService.blueprintToYaml(onapComponentSpec, onapBlueprint, input);
308 onapBlueprintService.blueprintToString(onapComponentSpec, onapBlueprint, input));
310 policyModelService.createPolicyModels(onapComponentSpec.getParameters(), "models");
313 .verifyToscaDefVersion("DMAAP K8s", onapBlueprint, Constants.TOSCA_DEF_VERSION);
315 Map<String, LinkedHashMap<String, Object>> k8sBpInputs = onapBlueprint.getInputs();
316 assertNotNull("DMAAP K8s Blueprint Inputs Section is NULL", k8sBpInputs);
317 assertTrue("DMAAP K8s Blueprint Inputs Section is Empty", k8sBpInputs.size() > 0);
320 "DMAAP K8s Blueprint:Inputs " + Constants.ONAP_INPUT_CPU_LIMIT
321 + " Default is not matching",
322 k8sBpInputs.get(Constants.ONAP_INPUT_CPU_LIMIT).get("default"),
323 Constants.ONAP_DEFAULT250m);
325 "DMAAP K8s Blueprint:Inputs "
326 + Constants.SERVICE_COMPONENT_NAME_OVERRIDE
327 + " Default is not matching",
328 k8sBpInputs.get(Constants.SERVICE_COMPONENT_NAME_OVERRIDE).get("default"),
329 Constants.ONAP_SERVICE_COMPONENTNAME_OVERRIDE_DEFAULT);
331 Map<String, Node> k8sBpNodeTemplates = onapBlueprint.getNode_templates();
333 "DMAAP K8s Blueprint Node Templates Section is NULL in the K8s DMAAP Blueprint",
336 "DMAAP K8s Blueprint Node Templates Section Size is Empty",
337 k8sBpNodeTemplates.size() > 0);
340 "DMAAP K8s Blueprint:NodeTemplates:Type is not Matching",
341 k8sBpNodeTemplates.get(Constants.ONAP_NODETEMPLATES).getType(),
342 Constants.DMAAP_NODETEMPLATES_TYPE);
344 Properties k8sBpNodeTemplateProperties =
345 ((Node) k8sBpNodeTemplates.get(Constants.ONAP_NODETEMPLATES)).getProperties();
347 "DMAAP K8s Blueprint Node Templates:Properties Section is NULL",
348 k8sBpNodeTemplateProperties);
350 List bpNodeTemplateRelationships =
351 ((Node) k8sBpNodeTemplates.get(Constants.ONAP_NODETEMPLATES)).getRelationships();
353 "DMAAP K8s Blueprint Node Templates:Relationships Section is NULL",
354 bpNodeTemplateRelationships);
356 onapTestUtils.verifyStreamsPublishes(
357 "DMAAP K8s", onapComponentSpec, k8sBpNodeTemplateProperties);
358 onapTestUtils.verifyStreamsSubscribes(
359 "DMAAP K8s", onapComponentSpec, k8sBpNodeTemplateProperties);
360 onapTestUtils.verifyAuxilary("DMAAP K8s", onapComponentSpec);
362 .verifyHealthCheck("DMAAP K8s", onapComponentSpec, k8sBpNodeTemplateProperties);
363 onapTestUtils.verifyServicesCalls("DMAAP K8s", onapComponentSpec);
364 onapTestUtils.verifyServicesProvides("DMAAP K8s", onapComponentSpec);
366 .verifyDockerConfig("DMAAP K8s", onapComponentSpec, k8sBpNodeTemplateProperties);
367 onapTestUtils.verifyParameters("DMAAP K8s", onapComponentSpec, k8sBpNodeTemplates);
371 * Test Case for K8s Blueprint for DMAAP Component Spec Input File with Import File
374 @DisplayName("Testing K8s Blueprint for DMAAP Component Spec Input File with Import File")
376 public void testDMAAPK8sImportFileBlueprint() throws IOException {
378 onapTestUtils.getInput(
379 Paths.get("src", "test", "resources", "componentspecs", ves).toFile()
383 Paths.get("src", "test", "resources", "componentspecs", testImports)
389 onapComponentSpecService.createComponentSpecFromFile(input.getComponentSpecPath());
391 "K8s Blueprint for DMAAP Component Spec with Import File is NULL", onapComponentSpec);
393 OnapBlueprint onapBlueprint = dmaapBlueprintService
394 .createBlueprint(onapComponentSpec, input);
396 onapTestUtils.verifyToscaDefVersion(
397 "DMAAP with Import File K8s", onapBlueprint, Constants.TOSCA_DEF_VERSION);
398 onapTestUtils.verifyBpImportsFromFile(
399 "DMAAP with Import File K8s", onapBlueprint, input.getImportPath());
401 Map<String, LinkedHashMap<String, Object>> k8sBpInputs = onapBlueprint.getInputs();
402 assertNotNull("DMAAP with Import File K8s Blueprint Inputs Section is NULL", k8sBpInputs);
404 "DMAAP with Import File K8s Blueprint Inputs Section is Empty", k8sBpInputs.size() > 0);
407 "DMAAP with Import File K8s Blueprint:Inputs "
408 + Constants.ONAP_INPUT_CPU_LIMIT
409 + " Default is not matching",
410 k8sBpInputs.get(Constants.ONAP_INPUT_CPU_LIMIT).get("default"),
411 Constants.ONAP_DEFAULT250m);
413 "DMAAP with Import File K8s Blueprint:Inputs "
414 + Constants.SERVICE_COMPONENT_NAME_OVERRIDE
415 + " Default is not matching",
416 k8sBpInputs.get(Constants.SERVICE_COMPONENT_NAME_OVERRIDE).get("default"),
417 Constants.ONAP_SERVICE_COMPONENTNAME_OVERRIDE_DEFAULT);
419 Map<String, Node> k8sBpNodeTemplates = onapBlueprint.getNode_templates();
421 "DMAAP with Import File K8s Blueprint Node Templates Section is NULL in the K8s DMAAP Blueprint",
424 "DMAAP with Import File K8s Blueprint Node Templates Section Size is Empty",
425 k8sBpNodeTemplates.size() > 0);
428 "DMAAP with Import File K8s Blueprint:NodeTemplates:Type is not Matching",
429 k8sBpNodeTemplates.get(Constants.ONAP_NODETEMPLATES).getType(),
430 Constants.DMAAP_NODETEMPLATES_TYPE);
432 Properties k8sBpNodeTemplateProperties =
433 ((Node) k8sBpNodeTemplates.get(Constants.ONAP_NODETEMPLATES)).getProperties();
435 "DMAAP with Import File K8s Blueprint Node Templates:Properties Section is NULL",
436 k8sBpNodeTemplateProperties);
438 List bpNodeTemplateRelationships =
439 ((Node) k8sBpNodeTemplates.get(Constants.ONAP_NODETEMPLATES)).getRelationships();
441 "DMAAP with Import File K8s Blueprint Node Templates:Relationships Section is NULL",
442 bpNodeTemplateRelationships);
444 onapTestUtils.verifyStreamsPublishes(
445 "DMAAP with Import File K8s", onapComponentSpec, k8sBpNodeTemplateProperties);
446 onapTestUtils.verifyStreamsSubscribes(
447 "DMAAP with Import File K8s", onapComponentSpec, k8sBpNodeTemplateProperties);
448 onapTestUtils.verifyAuxilary("DMAAP with Import File K8s", onapComponentSpec);
449 onapTestUtils.verifyHealthCheck(
450 "DMAAP with Import File K8s", onapComponentSpec, k8sBpNodeTemplateProperties);
451 onapTestUtils.verifyServicesCalls("DMAAP with Import File K8s", onapComponentSpec);
452 onapTestUtils.verifyServicesProvides("DMAAP with Import File K8s", onapComponentSpec);
453 onapTestUtils.verifyDockerConfig(
454 "DMAAP with Import File K8s", onapComponentSpec, k8sBpNodeTemplateProperties);
455 onapTestUtils.verifyParameters(
456 "DMAAP with Import File K8s", onapComponentSpec, k8sBpNodeTemplates);