3 * * ============LICENSE_START=======================================================
5 * * ================================================================================
6 * * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved.
7 * * Copyright (c) 2020-2021 Nokia. All rights reserved.
8 * * ================================================================================
9 * * Licensed under the Apache License, Version 2.0 (the "License");
10 * * you may not use this file except in compliance with the License.
11 * * You may obtain a copy of the License at
13 * * http://www.apache.org/licenses/LICENSE-2.0
15 * * Unless required by applicable law or agreed to in writing, software
16 * * distributed under the License is distributed on an "AS IS" BASIS,
17 * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * * See the License for the specific language governing permissions and
19 * * limitations under the License.
20 * * ============LICENSE_END=========================================================
25 package org.onap.blueprintgenerator.test;
27 import static org.junit.Assert.assertEquals;
28 import static org.junit.Assert.assertNotNull;
29 import static org.junit.Assert.assertTrue;
31 import java.io.IOException;
32 import java.nio.file.Paths;
33 import java.util.List;
35 import org.junit.Test;
36 import org.junit.jupiter.api.DisplayName;
37 import org.onap.blueprintgenerator.constants.Constants;
38 import org.onap.blueprintgenerator.model.common.Input;
39 import org.onap.blueprintgenerator.model.common.Node;
40 import org.onap.blueprintgenerator.model.common.OnapBlueprint;
41 import org.onap.blueprintgenerator.model.common.Properties;
44 * @author : Ravi Mantena
45 * @date 10/16/2020 Application: ONAP - Blueprint Generator ONAP Blueprint Test Cases for ONAP and
50 public class OnapBlueprintCreatorServiceTest extends BlueprintGeneratorTests {
52 private String outputfilesPath =
53 Paths.get("src", "test", "resources", "outputfiles").toAbsolutePath().toString();
56 * Test Case for Service Name Override Component Spec Input File
59 @DisplayName("Testing K8s Blueprint for Service Name Override Component Spec Input File")
61 public void testServiceNameOverrideK8sBlueprint() throws IOException {
63 onapTestUtils.getInput(
64 Paths.get("src", "test", "resources", "componentspecs", ves).toFile()
67 "testServiceNameOverrideK8sBlueprint",
72 onapComponentSpecService.createComponentSpecFromFile(input.getComponentSpecPath());
74 "K8s Blueprint for Service Name Override Component Spec is NULL", onapComponentSpec);
76 OnapBlueprint onapBlueprint = onapBlueprintCreatorService.createBlueprint(onapComponentSpec, input);
77 blueprintService.blueprintToYaml(onapComponentSpec, onapBlueprint, input);
78 System.out.println(blueprintService.blueprintToString(onapComponentSpec, onapBlueprint, input));
80 onapTestUtils.verifyToscaDefVersion(
81 "Service Name Override K8s", onapBlueprint, Constants.TOSCA_DEF_VERSION);
82 onapTestUtils.verifyBpImports("Service Name Override K8s", onapBlueprint, false);
84 Map<String, Map<String, Object>> k8sBpInputs = onapBlueprint.getInputs();
85 assertNotNull("Service Name Override K8s Blueprint Inputs Section is NULL", k8sBpInputs);
87 "Service Name Override K8s Blueprint Inputs Section is Empty", k8sBpInputs.size() > 0);
90 "Service Name Override K8s Blueprint:Inputs "
91 + Constants.ONAP_INPUT_CPU_LIMIT
92 + " Default is not matching",
93 k8sBpInputs.get(Constants.ONAP_INPUT_CPU_LIMIT).get("default"),
94 Constants.ONAP_DEFAULT250M);
96 "Service Name Override K8s Blueprint:Inputs "
97 + Constants.SERVICE_COMPONENT_NAME_OVERRIDE
98 + " Default is not matching",
99 k8sBpInputs.get(Constants.SERVICE_COMPONENT_NAME_OVERRIDE).get("default"),
100 Constants.ONAP_SERVICE_COMPONENTNAME_OVERRIDE_DEFAULT);
102 Map<String, Node> k8sBpNodeTemplates = onapBlueprint.getNode_templates();
104 "Service Name Override K8s Blueprint Node Templates Section is NULL in the K8s DMAAP Blueprint",
107 "Service Name Override K8s Blueprint Node Templates Section Size is Empty",
108 k8sBpNodeTemplates.size() > 0);
111 "Service Name Override K8s Blueprint:NodeTemplates:Type is not Matching",
112 k8sBpNodeTemplates.get(Constants.ONAP_NODETEMPLATES).getType(),
113 Constants.ONAP_NODETEMPLATES_TYPE);
115 Properties k8sBpNodeTemplateProperties =
116 ((Node) k8sBpNodeTemplates.get(Constants.ONAP_NODETEMPLATES)).getProperties();
118 "Service Name Override K8s Blueprint Node Templates:Properties Section is NULL",
119 k8sBpNodeTemplateProperties);
121 Map<String, Map<String, Object>> bpInputs = onapBlueprint.getInputs();
123 .verifyArtifacts("Service Name Override K8s", onapComponentSpec, bpInputs, "o");
125 onapTestUtils.verifyStreamsPublishes(
126 "Service Name Override K8s", onapComponentSpec, k8sBpNodeTemplateProperties);
127 onapTestUtils.verifyStreamsSubscribes(
128 "Service Name Override K8s", onapComponentSpec, k8sBpNodeTemplateProperties);
129 onapTestUtils.verifyAuxilary("Service Name Override K8s", onapComponentSpec);
130 onapTestUtils.verifyHealthCheck(
131 "Service Name Override K8s", onapComponentSpec, k8sBpNodeTemplateProperties);
132 onapTestUtils.verifyServicesCalls("Service Name Override K8s", onapComponentSpec);
133 onapTestUtils.verifyServicesProvides("Service Name Override K8s", onapComponentSpec);
134 onapTestUtils.verifyDockerConfig(
135 "Service Name Override K8s", onapComponentSpec, k8sBpNodeTemplateProperties);
136 onapTestUtils.verifyParameters(
137 "Service Name Override K8s", onapComponentSpec, k8sBpNodeTemplates);
138 onapTestUtils.verifyVolumes(
139 "Service Name Override K8s", onapComponentSpec, k8sBpNodeTemplateProperties);
143 * Test Case for Service Name Override Component Spec Input File with Import File
147 "Testing K8s Blueprint for Service Name Override Component Spec Input File with Import File")
149 public void testServiceNameOverrideImportFileK8sBlueprint() throws IOException {
151 onapTestUtils.getInput(
152 Paths.get("src", "test", "resources", "componentspecs", ves).toFile()
156 Paths.get("src", "test", "resources", "componentspecs", testImports)
162 onapComponentSpecService.createComponentSpecFromFile(input.getComponentSpecPath());
164 "K8s Blueprint for Service Name Override with Import File Component Spec is NULL",
167 OnapBlueprint onapBlueprint = onapBlueprintCreatorService.createBlueprint(onapComponentSpec, input);
169 onapTestUtils.verifyToscaDefVersion(
170 "Service Name Override with Import File K8s", onapBlueprint,
171 Constants.TOSCA_DEF_VERSION);
172 onapTestUtils.verifyBpImportsFromFile(
173 "Service Name Override with Import File K8s", onapBlueprint, input.getImportPath());
175 Map<String, Map<String, Object>> k8sBpInputs = onapBlueprint.getInputs();
177 "Service Name Override with Import File K8s Blueprint Inputs Section is NULL",
180 "Service Name Override with Import File K8s Blueprint Inputs Section is Empty",
181 k8sBpInputs.size() > 0);
184 "Service Name Override with Import File K8s Blueprint:Inputs "
185 + Constants.ONAP_INPUT_CPU_LIMIT
186 + " Default is not matching",
187 k8sBpInputs.get(Constants.ONAP_INPUT_CPU_LIMIT).get("default"),
188 Constants.ONAP_DEFAULT250M);
190 "Service Name Override with Import File K8s Blueprint:Inputs "
191 + Constants.SERVICE_COMPONENT_NAME_OVERRIDE
192 + " Default is not matching",
193 k8sBpInputs.get(Constants.SERVICE_COMPONENT_NAME_OVERRIDE).get("default"),
194 Constants.ONAP_SERVICE_COMPONENTNAME_OVERRIDE_DEFAULT);
196 Map<String, Node> k8sBpNodeTemplates = onapBlueprint.getNode_templates();
198 "Service Name Override with Import File K8s Blueprint Node Templates Section is NULL in the K8s DMAAP Blueprint",
201 "Service Name Override with Import File K8s Blueprint Node Templates Section Size is Empty",
202 k8sBpNodeTemplates.size() > 0);
205 "Service Name Override with Import File K8s Blueprint:NodeTemplates:Type is not Matching",
206 k8sBpNodeTemplates.get(Constants.ONAP_NODETEMPLATES).getType(),
207 Constants.ONAP_NODETEMPLATES_TYPE);
209 Properties k8sBpNodeTemplateProperties =
210 ((Node) k8sBpNodeTemplates.get(Constants.ONAP_NODETEMPLATES)).getProperties();
212 "Service Name Override with Import File K8s Blueprint Node Templates:Properties Section is NULL",
213 k8sBpNodeTemplateProperties);
215 Map<String, Map<String, Object>> bpInputs = onapBlueprint.getInputs();
216 onapTestUtils.verifyArtifacts(
217 "Service Name Override with Import File K8s", onapComponentSpec, bpInputs, "o");
219 onapTestUtils.verifyStreamsPublishes(
220 "Service Name Override with Import File K8s",
222 k8sBpNodeTemplateProperties);
223 onapTestUtils.verifyStreamsSubscribes(
224 "Service Name Override with Import File K8s",
226 k8sBpNodeTemplateProperties);
228 .verifyAuxilary("Service Name Override with Import File K8s", onapComponentSpec);
229 onapTestUtils.verifyHealthCheck(
230 "Service Name Override with Import File K8s",
232 k8sBpNodeTemplateProperties);
233 onapTestUtils.verifyServicesCalls(
234 "Service Name Override with Import File K8s", onapComponentSpec);
235 onapTestUtils.verifyServicesProvides(
236 "Service Name Override with Import File K8s", onapComponentSpec);
237 onapTestUtils.verifyDockerConfig(
238 "Service Name Override with Import File K8s",
240 k8sBpNodeTemplateProperties);
241 onapTestUtils.verifyParameters(
242 "Service Name Override with Import File K8s", onapComponentSpec, k8sBpNodeTemplates);
243 onapTestUtils.verifyVolumes(
244 "Service Name Override with Import File K8s",
246 k8sBpNodeTemplateProperties);
250 * Test Case for K8s Blueprint with DB
253 @DisplayName("Testing K8s Blueprint with DB")
255 public void testDMAAPK8sBlueprintWithDB() {
257 onapTestUtils.getInput(
258 Paths.get("src", "test", "resources", "componentspecs", ves).toFile()
261 "testDMAAPK8sBlueprintWithDB",
266 onapComponentSpecService.createComponentSpecFromFile(input.getComponentSpecPath());
267 assertNotNull("K8s Blueprint for DMAAP Component Spec is NULL", onapComponentSpec);
269 OnapBlueprint onapBlueprint = dmaapBlueprintCreatorService.createBlueprint(onapComponentSpec, input);
270 blueprintService.blueprintToYaml(onapComponentSpec, onapBlueprint, input);
274 * Test Case for K8s Blueprint for DMAAP Component Spec Input File
277 @DisplayName("Testing K8s Blueprint for DMAAP Component Spec Input File")
279 public void testDMAAPK8sBlueprint() {
281 onapTestUtils.getInput(
282 Paths.get("src", "test", "resources", "componentspecs", ves).toFile()
285 "testDMAAPK8sBlueprint",
290 onapComponentSpecService.createComponentSpecFromFile(input.getComponentSpecPath());
291 assertNotNull("K8s Blueprint for DMAAP Component Spec is NULL", onapComponentSpec);
293 OnapBlueprint onapBlueprint = dmaapBlueprintCreatorService.createBlueprint(onapComponentSpec, input);
294 blueprintService.blueprintToYaml(onapComponentSpec, onapBlueprint, input);
295 System.out.println(blueprintService.blueprintToString(onapComponentSpec, onapBlueprint, input));
297 policyModelService.createPolicyModels(onapComponentSpec.getParameters(), "models");
300 .verifyToscaDefVersion("DMAAP K8s", onapBlueprint, Constants.TOSCA_DEF_VERSION);
302 Map<String, Map<String, Object>> k8sBpInputs = onapBlueprint.getInputs();
303 assertNotNull("DMAAP K8s Blueprint Inputs Section is NULL", k8sBpInputs);
304 assertTrue("DMAAP K8s Blueprint Inputs Section is Empty", k8sBpInputs.size() > 0);
307 "DMAAP K8s Blueprint:Inputs " + Constants.ONAP_INPUT_CPU_LIMIT
308 + " Default is not matching",
309 k8sBpInputs.get(Constants.ONAP_INPUT_CPU_LIMIT).get("default"),
310 Constants.ONAP_DEFAULT250M);
312 "DMAAP K8s Blueprint:Inputs "
313 + Constants.SERVICE_COMPONENT_NAME_OVERRIDE
314 + " Default is not matching",
315 k8sBpInputs.get(Constants.SERVICE_COMPONENT_NAME_OVERRIDE).get("default"),
316 Constants.ONAP_SERVICE_COMPONENTNAME_OVERRIDE_DEFAULT);
318 Map<String, Node> k8sBpNodeTemplates = onapBlueprint.getNode_templates();
320 "DMAAP K8s Blueprint Node Templates Section is NULL in the K8s DMAAP Blueprint",
323 "DMAAP K8s Blueprint Node Templates Section Size is Empty",
324 k8sBpNodeTemplates.size() > 0);
327 "DMAAP K8s Blueprint:NodeTemplates:Type is not Matching",
328 k8sBpNodeTemplates.get(Constants.ONAP_NODETEMPLATES).getType(),
329 Constants.DMAAP_NODETEMPLATES_TYPE);
331 Properties k8sBpNodeTemplateProperties =
332 ((Node) k8sBpNodeTemplates.get(Constants.ONAP_NODETEMPLATES)).getProperties();
334 "DMAAP K8s Blueprint Node Templates:Properties Section is NULL",
335 k8sBpNodeTemplateProperties);
337 List bpNodeTemplateRelationships =
338 ((Node) k8sBpNodeTemplates.get(Constants.ONAP_NODETEMPLATES)).getRelationships();
340 "DMAAP K8s Blueprint Node Templates:Relationships Section is NULL",
341 bpNodeTemplateRelationships);
343 onapTestUtils.verifyStreamsPublishes(
344 "DMAAP K8s", onapComponentSpec, k8sBpNodeTemplateProperties);
345 onapTestUtils.verifyStreamsSubscribes(
346 "DMAAP K8s", onapComponentSpec, k8sBpNodeTemplateProperties);
347 onapTestUtils.verifyAuxilary("DMAAP K8s", onapComponentSpec);
349 .verifyHealthCheck("DMAAP K8s", onapComponentSpec, k8sBpNodeTemplateProperties);
350 onapTestUtils.verifyServicesCalls("DMAAP K8s", onapComponentSpec);
351 onapTestUtils.verifyServicesProvides("DMAAP K8s", onapComponentSpec);
353 .verifyDockerConfig("DMAAP K8s", onapComponentSpec, k8sBpNodeTemplateProperties);
354 onapTestUtils.verifyParameters("DMAAP K8s", onapComponentSpec, k8sBpNodeTemplates);
358 * Test Case for K8s Blueprint for DMAAP Component Spec Input File with Import File
361 @DisplayName("Testing K8s Blueprint for DMAAP Component Spec Input File with Import File")
363 public void testDMAAPK8sImportFileBlueprint() throws IOException {
365 onapTestUtils.getInput(
366 Paths.get("src", "test", "resources", "componentspecs", ves).toFile()
370 Paths.get("src", "test", "resources", "componentspecs", testImports)
376 onapComponentSpecService.createComponentSpecFromFile(input.getComponentSpecPath());
378 "K8s Blueprint for DMAAP Component Spec with Import File is NULL", onapComponentSpec);
380 OnapBlueprint onapBlueprint = dmaapBlueprintCreatorService.createBlueprint(onapComponentSpec, input);
382 onapTestUtils.verifyToscaDefVersion(
383 "DMAAP with Import File K8s", onapBlueprint, Constants.TOSCA_DEF_VERSION);
384 onapTestUtils.verifyBpImportsFromFile(
385 "DMAAP with Import File K8s", onapBlueprint, input.getImportPath());
387 Map<String, Map<String, Object>> k8sBpInputs = onapBlueprint.getInputs();
388 assertNotNull("DMAAP with Import File K8s Blueprint Inputs Section is NULL", k8sBpInputs);
390 "DMAAP with Import File K8s Blueprint Inputs Section is Empty", k8sBpInputs.size() > 0);
393 "DMAAP with Import File K8s Blueprint:Inputs "
394 + Constants.ONAP_INPUT_CPU_LIMIT
395 + " Default is not matching",
396 k8sBpInputs.get(Constants.ONAP_INPUT_CPU_LIMIT).get("default"),
397 Constants.ONAP_DEFAULT250M);
399 "DMAAP with Import File K8s Blueprint:Inputs "
400 + Constants.SERVICE_COMPONENT_NAME_OVERRIDE
401 + " Default is not matching",
402 k8sBpInputs.get(Constants.SERVICE_COMPONENT_NAME_OVERRIDE).get("default"),
403 Constants.ONAP_SERVICE_COMPONENTNAME_OVERRIDE_DEFAULT);
405 Map<String, Node> k8sBpNodeTemplates = onapBlueprint.getNode_templates();
407 "DMAAP with Import File K8s Blueprint Node Templates Section is NULL in the K8s DMAAP Blueprint",
410 "DMAAP with Import File K8s Blueprint Node Templates Section Size is Empty",
411 k8sBpNodeTemplates.size() > 0);
414 "DMAAP with Import File K8s Blueprint:NodeTemplates:Type is not Matching",
415 k8sBpNodeTemplates.get(Constants.ONAP_NODETEMPLATES).getType(),
416 Constants.DMAAP_NODETEMPLATES_TYPE);
418 Properties k8sBpNodeTemplateProperties =
419 ((Node) k8sBpNodeTemplates.get(Constants.ONAP_NODETEMPLATES)).getProperties();
421 "DMAAP with Import File K8s Blueprint Node Templates:Properties Section is NULL",
422 k8sBpNodeTemplateProperties);
424 List bpNodeTemplateRelationships =
425 ((Node) k8sBpNodeTemplates.get(Constants.ONAP_NODETEMPLATES)).getRelationships();
427 "DMAAP with Import File K8s Blueprint Node Templates:Relationships Section is NULL",
428 bpNodeTemplateRelationships);
430 onapTestUtils.verifyStreamsPublishes(
431 "DMAAP with Import File K8s", onapComponentSpec, k8sBpNodeTemplateProperties);
432 onapTestUtils.verifyStreamsSubscribes(
433 "DMAAP with Import File K8s", onapComponentSpec, k8sBpNodeTemplateProperties);
434 onapTestUtils.verifyAuxilary("DMAAP with Import File K8s", onapComponentSpec);
435 onapTestUtils.verifyHealthCheck(
436 "DMAAP with Import File K8s", onapComponentSpec, k8sBpNodeTemplateProperties);
437 onapTestUtils.verifyServicesCalls("DMAAP with Import File K8s", onapComponentSpec);
438 onapTestUtils.verifyServicesProvides("DMAAP with Import File K8s", onapComponentSpec);
439 onapTestUtils.verifyDockerConfig(
440 "DMAAP with Import File K8s", onapComponentSpec, k8sBpNodeTemplateProperties);
441 onapTestUtils.verifyParameters(
442 "DMAAP with Import File K8s", onapComponentSpec, k8sBpNodeTemplates);