3 * * ============LICENSE_START=======================================================
5 * * ================================================================================
6 * * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved.
7 * * Copyright (c) 2020 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.LinkedHashMap;
34 import java.util.List;
36 import org.junit.Test;
37 import org.junit.jupiter.api.DisplayName;
38 import org.onap.blueprintgenerator.constants.Constants;
39 import org.onap.blueprintgenerator.model.common.Input;
40 import org.onap.blueprintgenerator.model.common.Node;
41 import org.onap.blueprintgenerator.model.common.OnapBlueprint;
42 import org.onap.blueprintgenerator.model.common.Properties;
45 * @author : Ravi Mantena
46 * @date 10/16/2020 Application: ONAP - Blueprint Generator ONAP Blueprint Test Cases for ONAP and
51 public class OnapBlueprintCreatorServiceTest extends BlueprintGeneratorTests {
53 private String outputfilesPath =
54 Paths.get("src", "test", "resources", "outputfiles").toAbsolutePath().toString();
57 * Test Case for Service Name Override Component Spec Input File
60 @DisplayName("Testing K8s Blueprint for Service Name Override Component Spec Input File")
62 public void testServiceNameOverrideK8sBlueprint() throws IOException {
64 onapTestUtils.getInput(
65 Paths.get("src", "test", "resources", "componentspecs", ves).toFile()
68 "testServiceNameOverrideK8sBlueprint",
73 onapComponentSpecService.createComponentSpecFromFile(input.getComponentSpecPath());
75 "K8s Blueprint for Service Name Override Component Spec is NULL", onapComponentSpec);
77 OnapBlueprint onapBlueprint = onapBlueprintCreatorService.createBlueprint(onapComponentSpec, input);
78 blueprintService.blueprintToYaml(onapComponentSpec, onapBlueprint, input);
79 System.out.println(blueprintService.blueprintToString(onapComponentSpec, onapBlueprint, input));
81 onapTestUtils.verifyToscaDefVersion(
82 "Service Name Override K8s", onapBlueprint, Constants.TOSCA_DEF_VERSION);
83 onapTestUtils.verifyBpImports("Service Name Override K8s", onapBlueprint, false);
85 Map<String, LinkedHashMap<String, Object>> k8sBpInputs = onapBlueprint.getInputs();
86 assertNotNull("Service Name Override K8s Blueprint Inputs Section is NULL", k8sBpInputs);
88 "Service Name Override K8s Blueprint Inputs Section is Empty", k8sBpInputs.size() > 0);
91 "Service Name Override K8s Blueprint:Inputs "
92 + Constants.ONAP_INPUT_CPU_LIMIT
93 + " Default is not matching",
94 k8sBpInputs.get(Constants.ONAP_INPUT_CPU_LIMIT).get("default"),
95 Constants.ONAP_DEFAULT250m);
97 "Service Name Override K8s Blueprint:Inputs "
98 + Constants.SERVICE_COMPONENT_NAME_OVERRIDE
99 + " Default is not matching",
100 k8sBpInputs.get(Constants.SERVICE_COMPONENT_NAME_OVERRIDE).get("default"),
101 Constants.ONAP_SERVICE_COMPONENTNAME_OVERRIDE_DEFAULT);
103 Map<String, Node> k8sBpNodeTemplates = onapBlueprint.getNode_templates();
105 "Service Name Override K8s Blueprint Node Templates Section is NULL in the K8s DMAAP Blueprint",
108 "Service Name Override K8s Blueprint Node Templates Section Size is Empty",
109 k8sBpNodeTemplates.size() > 0);
112 "Service Name Override K8s Blueprint:NodeTemplates:Type is not Matching",
113 k8sBpNodeTemplates.get(Constants.ONAP_NODETEMPLATES).getType(),
114 Constants.ONAP_NODETEMPLATES_TYPE);
116 Properties k8sBpNodeTemplateProperties =
117 ((Node) k8sBpNodeTemplates.get(Constants.ONAP_NODETEMPLATES)).getProperties();
119 "Service Name Override K8s Blueprint Node Templates:Properties Section is NULL",
120 k8sBpNodeTemplateProperties);
122 Map<String, LinkedHashMap<String, Object>> bpInputs = onapBlueprint.getInputs();
124 .verifyArtifacts("Service Name Override K8s", onapComponentSpec, bpInputs, "o");
126 onapTestUtils.verifyStreamsPublishes(
127 "Service Name Override K8s", onapComponentSpec, k8sBpNodeTemplateProperties);
128 onapTestUtils.verifyStreamsSubscribes(
129 "Service Name Override K8s", onapComponentSpec, k8sBpNodeTemplateProperties);
130 onapTestUtils.verifyAuxilary("Service Name Override K8s", onapComponentSpec);
131 onapTestUtils.verifyHealthCheck(
132 "Service Name Override K8s", onapComponentSpec, k8sBpNodeTemplateProperties);
133 onapTestUtils.verifyServicesCalls("Service Name Override K8s", onapComponentSpec);
134 onapTestUtils.verifyServicesProvides("Service Name Override K8s", onapComponentSpec);
135 onapTestUtils.verifyDockerConfig(
136 "Service Name Override K8s", onapComponentSpec, k8sBpNodeTemplateProperties);
137 onapTestUtils.verifyParameters(
138 "Service Name Override K8s", onapComponentSpec, k8sBpNodeTemplates);
139 onapTestUtils.verifyVolumes(
140 "Service Name Override K8s", onapComponentSpec, k8sBpNodeTemplateProperties);
144 * Test Case for Service Name Override Component Spec Input File with Import File
148 "Testing K8s Blueprint for Service Name Override Component Spec Input File with Import File")
150 public void testServiceNameOverrideImportFileK8sBlueprint() throws IOException {
152 onapTestUtils.getInput(
153 Paths.get("src", "test", "resources", "componentspecs", ves).toFile()
157 Paths.get("src", "test", "resources", "componentspecs", testImports)
163 onapComponentSpecService.createComponentSpecFromFile(input.getComponentSpecPath());
165 "K8s Blueprint for Service Name Override with Import File Component Spec is NULL",
168 OnapBlueprint onapBlueprint = onapBlueprintCreatorService.createBlueprint(onapComponentSpec, input);
170 onapTestUtils.verifyToscaDefVersion(
171 "Service Name Override with Import File K8s", onapBlueprint,
172 Constants.TOSCA_DEF_VERSION);
173 onapTestUtils.verifyBpImportsFromFile(
174 "Service Name Override with Import File K8s", onapBlueprint, input.getImportPath());
176 Map<String, LinkedHashMap<String, Object>> k8sBpInputs = onapBlueprint.getInputs();
178 "Service Name Override with Import File K8s Blueprint Inputs Section is NULL",
181 "Service Name Override with Import File K8s Blueprint Inputs Section is Empty",
182 k8sBpInputs.size() > 0);
185 "Service Name Override with Import File K8s Blueprint:Inputs "
186 + Constants.ONAP_INPUT_CPU_LIMIT
187 + " Default is not matching",
188 k8sBpInputs.get(Constants.ONAP_INPUT_CPU_LIMIT).get("default"),
189 Constants.ONAP_DEFAULT250m);
191 "Service Name Override with Import File K8s Blueprint:Inputs "
192 + Constants.SERVICE_COMPONENT_NAME_OVERRIDE
193 + " Default is not matching",
194 k8sBpInputs.get(Constants.SERVICE_COMPONENT_NAME_OVERRIDE).get("default"),
195 Constants.ONAP_SERVICE_COMPONENTNAME_OVERRIDE_DEFAULT);
197 Map<String, Node> k8sBpNodeTemplates = onapBlueprint.getNode_templates();
199 "Service Name Override with Import File K8s Blueprint Node Templates Section is NULL in the K8s DMAAP Blueprint",
202 "Service Name Override with Import File K8s Blueprint Node Templates Section Size is Empty",
203 k8sBpNodeTemplates.size() > 0);
206 "Service Name Override with Import File K8s Blueprint:NodeTemplates:Type is not Matching",
207 k8sBpNodeTemplates.get(Constants.ONAP_NODETEMPLATES).getType(),
208 Constants.ONAP_NODETEMPLATES_TYPE);
210 Properties k8sBpNodeTemplateProperties =
211 ((Node) k8sBpNodeTemplates.get(Constants.ONAP_NODETEMPLATES)).getProperties();
213 "Service Name Override with Import File K8s Blueprint Node Templates:Properties Section is NULL",
214 k8sBpNodeTemplateProperties);
216 Map<String, LinkedHashMap<String, Object>> bpInputs = onapBlueprint.getInputs();
217 onapTestUtils.verifyArtifacts(
218 "Service Name Override with Import File K8s", onapComponentSpec, bpInputs, "o");
220 onapTestUtils.verifyStreamsPublishes(
221 "Service Name Override with Import File K8s",
223 k8sBpNodeTemplateProperties);
224 onapTestUtils.verifyStreamsSubscribes(
225 "Service Name Override with Import File K8s",
227 k8sBpNodeTemplateProperties);
229 .verifyAuxilary("Service Name Override with Import File K8s", onapComponentSpec);
230 onapTestUtils.verifyHealthCheck(
231 "Service Name Override with Import File K8s",
233 k8sBpNodeTemplateProperties);
234 onapTestUtils.verifyServicesCalls(
235 "Service Name Override with Import File K8s", onapComponentSpec);
236 onapTestUtils.verifyServicesProvides(
237 "Service Name Override with Import File K8s", onapComponentSpec);
238 onapTestUtils.verifyDockerConfig(
239 "Service Name Override with Import File K8s",
241 k8sBpNodeTemplateProperties);
242 onapTestUtils.verifyParameters(
243 "Service Name Override with Import File K8s", onapComponentSpec, k8sBpNodeTemplates);
244 onapTestUtils.verifyVolumes(
245 "Service Name Override with Import File K8s",
247 k8sBpNodeTemplateProperties);
251 * Test Case for K8s Blueprint with DB
254 @DisplayName("Testing K8s Blueprint with DB")
256 public void testDMAAPK8sBlueprintWithDB() {
258 onapTestUtils.getInput(
259 Paths.get("src", "test", "resources", "componentspecs", ves).toFile()
262 "testDMAAPK8sBlueprintWithDB",
267 onapComponentSpecService.createComponentSpecFromFile(input.getComponentSpecPath());
268 assertNotNull("K8s Blueprint for DMAAP Component Spec is NULL", onapComponentSpec);
270 OnapBlueprint onapBlueprint = dmaapBlueprintCreatorService.createBlueprint(onapComponentSpec, input);
271 blueprintService.blueprintToYaml(onapComponentSpec, onapBlueprint, input);
275 * Test Case for K8s Blueprint for DMAAP Component Spec Input File
278 @DisplayName("Testing K8s Blueprint for DMAAP Component Spec Input File")
280 public void testDMAAPK8sBlueprint() {
282 onapTestUtils.getInput(
283 Paths.get("src", "test", "resources", "componentspecs", ves).toFile()
286 "testDMAAPK8sBlueprint",
291 onapComponentSpecService.createComponentSpecFromFile(input.getComponentSpecPath());
292 assertNotNull("K8s Blueprint for DMAAP Component Spec is NULL", onapComponentSpec);
294 OnapBlueprint onapBlueprint = dmaapBlueprintCreatorService.createBlueprint(onapComponentSpec, input);
295 blueprintService.blueprintToYaml(onapComponentSpec, onapBlueprint, input);
296 System.out.println(blueprintService.blueprintToString(onapComponentSpec, onapBlueprint, input));
298 policyModelService.createPolicyModels(onapComponentSpec.getParameters(), "models");
301 .verifyToscaDefVersion("DMAAP K8s", onapBlueprint, Constants.TOSCA_DEF_VERSION);
303 Map<String, LinkedHashMap<String, Object>> k8sBpInputs = onapBlueprint.getInputs();
304 assertNotNull("DMAAP K8s Blueprint Inputs Section is NULL", k8sBpInputs);
305 assertTrue("DMAAP K8s Blueprint Inputs Section is Empty", k8sBpInputs.size() > 0);
308 "DMAAP K8s Blueprint:Inputs " + Constants.ONAP_INPUT_CPU_LIMIT
309 + " Default is not matching",
310 k8sBpInputs.get(Constants.ONAP_INPUT_CPU_LIMIT).get("default"),
311 Constants.ONAP_DEFAULT250m);
313 "DMAAP K8s Blueprint:Inputs "
314 + Constants.SERVICE_COMPONENT_NAME_OVERRIDE
315 + " Default is not matching",
316 k8sBpInputs.get(Constants.SERVICE_COMPONENT_NAME_OVERRIDE).get("default"),
317 Constants.ONAP_SERVICE_COMPONENTNAME_OVERRIDE_DEFAULT);
319 Map<String, Node> k8sBpNodeTemplates = onapBlueprint.getNode_templates();
321 "DMAAP K8s Blueprint Node Templates Section is NULL in the K8s DMAAP Blueprint",
324 "DMAAP K8s Blueprint Node Templates Section Size is Empty",
325 k8sBpNodeTemplates.size() > 0);
328 "DMAAP K8s Blueprint:NodeTemplates:Type is not Matching",
329 k8sBpNodeTemplates.get(Constants.ONAP_NODETEMPLATES).getType(),
330 Constants.DMAAP_NODETEMPLATES_TYPE);
332 Properties k8sBpNodeTemplateProperties =
333 ((Node) k8sBpNodeTemplates.get(Constants.ONAP_NODETEMPLATES)).getProperties();
335 "DMAAP K8s Blueprint Node Templates:Properties Section is NULL",
336 k8sBpNodeTemplateProperties);
338 List bpNodeTemplateRelationships =
339 ((Node) k8sBpNodeTemplates.get(Constants.ONAP_NODETEMPLATES)).getRelationships();
341 "DMAAP K8s Blueprint Node Templates:Relationships Section is NULL",
342 bpNodeTemplateRelationships);
344 onapTestUtils.verifyStreamsPublishes(
345 "DMAAP K8s", onapComponentSpec, k8sBpNodeTemplateProperties);
346 onapTestUtils.verifyStreamsSubscribes(
347 "DMAAP K8s", onapComponentSpec, k8sBpNodeTemplateProperties);
348 onapTestUtils.verifyAuxilary("DMAAP K8s", onapComponentSpec);
350 .verifyHealthCheck("DMAAP K8s", onapComponentSpec, k8sBpNodeTemplateProperties);
351 onapTestUtils.verifyServicesCalls("DMAAP K8s", onapComponentSpec);
352 onapTestUtils.verifyServicesProvides("DMAAP K8s", onapComponentSpec);
354 .verifyDockerConfig("DMAAP K8s", onapComponentSpec, k8sBpNodeTemplateProperties);
355 onapTestUtils.verifyParameters("DMAAP K8s", onapComponentSpec, k8sBpNodeTemplates);
359 * Test Case for K8s Blueprint for DMAAP Component Spec Input File with Import File
362 @DisplayName("Testing K8s Blueprint for DMAAP Component Spec Input File with Import File")
364 public void testDMAAPK8sImportFileBlueprint() throws IOException {
366 onapTestUtils.getInput(
367 Paths.get("src", "test", "resources", "componentspecs", ves).toFile()
371 Paths.get("src", "test", "resources", "componentspecs", testImports)
377 onapComponentSpecService.createComponentSpecFromFile(input.getComponentSpecPath());
379 "K8s Blueprint for DMAAP Component Spec with Import File is NULL", onapComponentSpec);
381 OnapBlueprint onapBlueprint = dmaapBlueprintCreatorService.createBlueprint(onapComponentSpec, input);
383 onapTestUtils.verifyToscaDefVersion(
384 "DMAAP with Import File K8s", onapBlueprint, Constants.TOSCA_DEF_VERSION);
385 onapTestUtils.verifyBpImportsFromFile(
386 "DMAAP with Import File K8s", onapBlueprint, input.getImportPath());
388 Map<String, LinkedHashMap<String, Object>> k8sBpInputs = onapBlueprint.getInputs();
389 assertNotNull("DMAAP with Import File K8s Blueprint Inputs Section is NULL", k8sBpInputs);
391 "DMAAP with Import File K8s Blueprint Inputs Section is Empty", k8sBpInputs.size() > 0);
394 "DMAAP with Import File K8s Blueprint:Inputs "
395 + Constants.ONAP_INPUT_CPU_LIMIT
396 + " Default is not matching",
397 k8sBpInputs.get(Constants.ONAP_INPUT_CPU_LIMIT).get("default"),
398 Constants.ONAP_DEFAULT250m);
400 "DMAAP with Import File K8s Blueprint:Inputs "
401 + Constants.SERVICE_COMPONENT_NAME_OVERRIDE
402 + " Default is not matching",
403 k8sBpInputs.get(Constants.SERVICE_COMPONENT_NAME_OVERRIDE).get("default"),
404 Constants.ONAP_SERVICE_COMPONENTNAME_OVERRIDE_DEFAULT);
406 Map<String, Node> k8sBpNodeTemplates = onapBlueprint.getNode_templates();
408 "DMAAP with Import File K8s Blueprint Node Templates Section is NULL in the K8s DMAAP Blueprint",
411 "DMAAP with Import File K8s Blueprint Node Templates Section Size is Empty",
412 k8sBpNodeTemplates.size() > 0);
415 "DMAAP with Import File K8s Blueprint:NodeTemplates:Type is not Matching",
416 k8sBpNodeTemplates.get(Constants.ONAP_NODETEMPLATES).getType(),
417 Constants.DMAAP_NODETEMPLATES_TYPE);
419 Properties k8sBpNodeTemplateProperties =
420 ((Node) k8sBpNodeTemplates.get(Constants.ONAP_NODETEMPLATES)).getProperties();
422 "DMAAP with Import File K8s Blueprint Node Templates:Properties Section is NULL",
423 k8sBpNodeTemplateProperties);
425 List bpNodeTemplateRelationships =
426 ((Node) k8sBpNodeTemplates.get(Constants.ONAP_NODETEMPLATES)).getRelationships();
428 "DMAAP with Import File K8s Blueprint Node Templates:Relationships Section is NULL",
429 bpNodeTemplateRelationships);
431 onapTestUtils.verifyStreamsPublishes(
432 "DMAAP with Import File K8s", onapComponentSpec, k8sBpNodeTemplateProperties);
433 onapTestUtils.verifyStreamsSubscribes(
434 "DMAAP with Import File K8s", onapComponentSpec, k8sBpNodeTemplateProperties);
435 onapTestUtils.verifyAuxilary("DMAAP with Import File K8s", onapComponentSpec);
436 onapTestUtils.verifyHealthCheck(
437 "DMAAP with Import File K8s", onapComponentSpec, k8sBpNodeTemplateProperties);
438 onapTestUtils.verifyServicesCalls("DMAAP with Import File K8s", onapComponentSpec);
439 onapTestUtils.verifyServicesProvides("DMAAP with Import File K8s", onapComponentSpec);
440 onapTestUtils.verifyDockerConfig(
441 "DMAAP with Import File K8s", onapComponentSpec, k8sBpNodeTemplateProperties);
442 onapTestUtils.verifyParameters(
443 "DMAAP with Import File K8s", onapComponentSpec, k8sBpNodeTemplates);