Fix sonar issues
[dcaegen2/platform.git] / mod / bpgenerator / onap / src / test / java / org / onap / blueprintgenerator / test / OnapBlueprintCreatorServiceTest.java
1 /*
2  *
3  *  * ============LICENSE_START=======================================================
4  *  *  org.onap.dcae
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
12  *  *
13  *  *       http://www.apache.org/licenses/LICENSE-2.0
14  *  *
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=========================================================
21  *
22  *
23  */
24
25 package org.onap.blueprintgenerator.test;
26
27 import static org.junit.Assert.assertEquals;
28 import static org.junit.Assert.assertNotNull;
29 import static org.junit.Assert.assertTrue;
30
31 import java.io.IOException;
32 import java.nio.file.Paths;
33 import java.util.List;
34 import java.util.Map;
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;
42
43 /**
44  * @author : Ravi Mantena
45  * @date 10/16/2020 Application: ONAP - Blueprint Generator ONAP Blueprint Test Cases for ONAP and
46  * DMAAP
47  */
48
49
50 public class OnapBlueprintCreatorServiceTest extends BlueprintGeneratorTests {
51
52     private String outputfilesPath =
53         Paths.get("src", "test", "resources", "outputfiles").toAbsolutePath().toString();
54
55     /**
56      * Test Case for Service Name Override Component Spec Input File
57      *
58      */
59     @DisplayName("Testing K8s Blueprint for Service Name Override Component Spec Input File")
60     @Test
61     public void testServiceNameOverrideK8sBlueprint() throws IOException {
62         Input input =
63             onapTestUtils.getInput(
64                 Paths.get("src", "test", "resources", "componentspecs", ves).toFile()
65                     .getAbsolutePath(),
66                 outputfilesPath,
67                 "testServiceNameOverrideK8sBlueprint",
68                 "",
69                 "o",
70                 "");
71         onapComponentSpec =
72             onapComponentSpecService.createComponentSpecFromFile(input.getComponentSpecPath());
73         assertNotNull(
74             "K8s Blueprint for Service Name Override Component Spec is NULL", onapComponentSpec);
75
76         OnapBlueprint onapBlueprint = onapBlueprintCreatorService.createBlueprint(onapComponentSpec, input);
77         blueprintService.blueprintToYaml(onapComponentSpec, onapBlueprint, input);
78         System.out.println(blueprintService.blueprintToString(onapComponentSpec, onapBlueprint, input));
79
80         onapTestUtils.verifyToscaDefVersion(
81             "Service Name Override K8s", onapBlueprint, Constants.TOSCA_DEF_VERSION);
82         onapTestUtils.verifyBpImports("Service Name Override K8s", onapBlueprint, false);
83
84         Map<String, Map<String, Object>> k8sBpInputs = onapBlueprint.getInputs();
85         assertNotNull("Service Name Override K8s Blueprint Inputs Section is NULL", k8sBpInputs);
86         assertTrue(
87             "Service Name Override K8s Blueprint Inputs Section is Empty", k8sBpInputs.size() > 0);
88
89         assertEquals(
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);
95         assertEquals(
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);
101
102         Map<String, Node> k8sBpNodeTemplates = onapBlueprint.getNode_templates();
103         assertNotNull(
104             "Service Name Override K8s Blueprint Node Templates Section is NULL in the K8s DMAAP Blueprint",
105             k8sBpNodeTemplates);
106         assertTrue(
107             "Service Name Override K8s Blueprint Node Templates Section Size is Empty",
108             k8sBpNodeTemplates.size() > 0);
109
110         assertEquals(
111             "Service Name Override K8s Blueprint:NodeTemplates:Type is not Matching",
112             k8sBpNodeTemplates.get(Constants.ONAP_NODETEMPLATES).getType(),
113             Constants.ONAP_NODETEMPLATES_TYPE);
114
115         Properties k8sBpNodeTemplateProperties =
116             ((Node) k8sBpNodeTemplates.get(Constants.ONAP_NODETEMPLATES)).getProperties();
117         assertNotNull(
118             "Service Name Override K8s Blueprint Node Templates:Properties Section is NULL",
119             k8sBpNodeTemplateProperties);
120
121         Map<String, Map<String, Object>> bpInputs = onapBlueprint.getInputs();
122         onapTestUtils
123             .verifyArtifacts("Service Name Override K8s", onapComponentSpec, bpInputs, "o");
124
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);
140     }
141
142     /**
143      * Test Case for Service Name Override Component Spec Input File with Import File
144      *
145      */
146     @DisplayName(
147         "Testing K8s Blueprint for Service Name Override Component Spec Input File with Import File")
148     @Test
149     public void testServiceNameOverrideImportFileK8sBlueprint() throws IOException {
150         Input input =
151             onapTestUtils.getInput(
152                 Paths.get("src", "test", "resources", "componentspecs", ves).toFile()
153                     .getAbsolutePath(),
154                 "",
155                 "",
156                 Paths.get("src", "test", "resources", "componentspecs", testImports)
157                     .toFile()
158                     .getAbsolutePath(),
159                 "o",
160                 "");
161         onapComponentSpec =
162             onapComponentSpecService.createComponentSpecFromFile(input.getComponentSpecPath());
163         assertNotNull(
164             "K8s Blueprint for Service Name Override with Import File Component Spec is NULL",
165             onapComponentSpec);
166
167         OnapBlueprint onapBlueprint = onapBlueprintCreatorService.createBlueprint(onapComponentSpec, input);
168
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());
174
175         Map<String, Map<String, Object>> k8sBpInputs = onapBlueprint.getInputs();
176         assertNotNull(
177             "Service Name Override with Import File K8s Blueprint Inputs Section is NULL",
178             k8sBpInputs);
179         assertTrue(
180             "Service Name Override with Import File K8s Blueprint Inputs Section is Empty",
181             k8sBpInputs.size() > 0);
182
183         assertEquals(
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);
189         assertEquals(
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);
195
196         Map<String, Node> k8sBpNodeTemplates = onapBlueprint.getNode_templates();
197         assertNotNull(
198             "Service Name Override with Import File K8s Blueprint Node Templates Section is NULL in the K8s DMAAP Blueprint",
199             k8sBpNodeTemplates);
200         assertTrue(
201             "Service Name Override with Import File K8s Blueprint Node Templates Section Size is Empty",
202             k8sBpNodeTemplates.size() > 0);
203
204         assertEquals(
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);
208
209         Properties k8sBpNodeTemplateProperties =
210             ((Node) k8sBpNodeTemplates.get(Constants.ONAP_NODETEMPLATES)).getProperties();
211         assertNotNull(
212             "Service Name Override with Import File K8s Blueprint Node Templates:Properties Section is NULL",
213             k8sBpNodeTemplateProperties);
214
215         Map<String, Map<String, Object>> bpInputs = onapBlueprint.getInputs();
216         onapTestUtils.verifyArtifacts(
217             "Service Name Override with Import File K8s", onapComponentSpec, bpInputs, "o");
218
219         onapTestUtils.verifyStreamsPublishes(
220             "Service Name Override with Import File K8s",
221             onapComponentSpec,
222             k8sBpNodeTemplateProperties);
223         onapTestUtils.verifyStreamsSubscribes(
224             "Service Name Override with Import File K8s",
225             onapComponentSpec,
226             k8sBpNodeTemplateProperties);
227         onapTestUtils
228             .verifyAuxilary("Service Name Override with Import File K8s", onapComponentSpec);
229         onapTestUtils.verifyHealthCheck(
230             "Service Name Override with Import File K8s",
231             onapComponentSpec,
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",
239             onapComponentSpec,
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",
245             onapComponentSpec,
246             k8sBpNodeTemplateProperties);
247     }
248
249     /**
250      * Test Case for K8s Blueprint with DB
251      *
252      */
253     @DisplayName("Testing K8s Blueprint with DB")
254     @Test
255     public void testDMAAPK8sBlueprintWithDB() {
256         Input input =
257             onapTestUtils.getInput(
258                 Paths.get("src", "test", "resources", "componentspecs", ves).toFile()
259                     .getAbsolutePath(),
260                 outputfilesPath,
261                 "testDMAAPK8sBlueprintWithDB",
262                 "",
263                 "d",
264                 "");
265         onapComponentSpec =
266             onapComponentSpecService.createComponentSpecFromFile(input.getComponentSpecPath());
267         assertNotNull("K8s Blueprint for DMAAP Component Spec is NULL", onapComponentSpec);
268
269         OnapBlueprint onapBlueprint = dmaapBlueprintCreatorService.createBlueprint(onapComponentSpec, input);
270         blueprintService.blueprintToYaml(onapComponentSpec, onapBlueprint, input);
271     }
272
273     /**
274      * Test Case for K8s Blueprint for DMAAP Component Spec Input File
275      *
276      */
277     @DisplayName("Testing K8s Blueprint for DMAAP Component Spec Input File")
278     @Test
279     public void testDMAAPK8sBlueprint() {
280         Input input =
281             onapTestUtils.getInput(
282                 Paths.get("src", "test", "resources", "componentspecs", ves).toFile()
283                     .getAbsolutePath(),
284                 outputfilesPath,
285                 "testDMAAPK8sBlueprint",
286                 "",
287                 "d",
288                 "");
289         onapComponentSpec =
290             onapComponentSpecService.createComponentSpecFromFile(input.getComponentSpecPath());
291         assertNotNull("K8s Blueprint for DMAAP Component Spec is NULL", onapComponentSpec);
292
293         OnapBlueprint onapBlueprint = dmaapBlueprintCreatorService.createBlueprint(onapComponentSpec, input);
294         blueprintService.blueprintToYaml(onapComponentSpec, onapBlueprint, input);
295         System.out.println(blueprintService.blueprintToString(onapComponentSpec, onapBlueprint, input));
296
297         policyModelService.createPolicyModels(onapComponentSpec.getParameters(), "models");
298
299         onapTestUtils
300             .verifyToscaDefVersion("DMAAP K8s", onapBlueprint, Constants.TOSCA_DEF_VERSION);
301
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);
305
306         assertEquals(
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);
311         assertEquals(
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);
317
318         Map<String, Node> k8sBpNodeTemplates = onapBlueprint.getNode_templates();
319         assertNotNull(
320             "DMAAP K8s Blueprint Node Templates Section is NULL in the K8s DMAAP Blueprint",
321             k8sBpNodeTemplates);
322         assertTrue(
323             "DMAAP K8s Blueprint Node Templates Section Size is Empty",
324             k8sBpNodeTemplates.size() > 0);
325
326         assertEquals(
327             "DMAAP K8s Blueprint:NodeTemplates:Type is not Matching",
328             k8sBpNodeTemplates.get(Constants.ONAP_NODETEMPLATES).getType(),
329             Constants.DMAAP_NODETEMPLATES_TYPE);
330
331         Properties k8sBpNodeTemplateProperties =
332             ((Node) k8sBpNodeTemplates.get(Constants.ONAP_NODETEMPLATES)).getProperties();
333         assertNotNull(
334             "DMAAP K8s Blueprint Node Templates:Properties Section is NULL",
335             k8sBpNodeTemplateProperties);
336
337         List bpNodeTemplateRelationships =
338             ((Node) k8sBpNodeTemplates.get(Constants.ONAP_NODETEMPLATES)).getRelationships();
339         assertNotNull(
340             "DMAAP K8s Blueprint Node Templates:Relationships Section is NULL",
341             bpNodeTemplateRelationships);
342
343         onapTestUtils.verifyStreamsPublishes(
344             "DMAAP K8s", onapComponentSpec, k8sBpNodeTemplateProperties);
345         onapTestUtils.verifyStreamsSubscribes(
346             "DMAAP K8s", onapComponentSpec, k8sBpNodeTemplateProperties);
347         onapTestUtils.verifyAuxilary("DMAAP K8s", onapComponentSpec);
348         onapTestUtils
349             .verifyHealthCheck("DMAAP K8s", onapComponentSpec, k8sBpNodeTemplateProperties);
350         onapTestUtils.verifyServicesCalls("DMAAP K8s", onapComponentSpec);
351         onapTestUtils.verifyServicesProvides("DMAAP K8s", onapComponentSpec);
352         onapTestUtils
353             .verifyDockerConfig("DMAAP K8s", onapComponentSpec, k8sBpNodeTemplateProperties);
354         onapTestUtils.verifyParameters("DMAAP K8s", onapComponentSpec, k8sBpNodeTemplates);
355     }
356
357     /**
358      * Test Case for K8s Blueprint for DMAAP Component Spec Input File with Import File
359      *
360      */
361     @DisplayName("Testing K8s Blueprint for DMAAP Component Spec Input File with Import File")
362     @Test
363     public void testDMAAPK8sImportFileBlueprint() throws IOException {
364         Input input =
365             onapTestUtils.getInput(
366                 Paths.get("src", "test", "resources", "componentspecs", ves).toFile()
367                     .getAbsolutePath(),
368                 "",
369                 "",
370                 Paths.get("src", "test", "resources", "componentspecs", testImports)
371                     .toFile()
372                     .getAbsolutePath(),
373                 "d",
374                 "");
375         onapComponentSpec =
376             onapComponentSpecService.createComponentSpecFromFile(input.getComponentSpecPath());
377         assertNotNull(
378             "K8s Blueprint for DMAAP Component Spec with Import File is NULL", onapComponentSpec);
379
380         OnapBlueprint onapBlueprint = dmaapBlueprintCreatorService.createBlueprint(onapComponentSpec, input);
381
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());
386
387         Map<String, Map<String, Object>> k8sBpInputs = onapBlueprint.getInputs();
388         assertNotNull("DMAAP with Import File K8s Blueprint Inputs Section is NULL", k8sBpInputs);
389         assertTrue(
390             "DMAAP with Import File K8s Blueprint Inputs Section is Empty", k8sBpInputs.size() > 0);
391
392         assertEquals(
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);
398         assertEquals(
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);
404
405         Map<String, Node> k8sBpNodeTemplates = onapBlueprint.getNode_templates();
406         assertNotNull(
407             "DMAAP with Import File K8s Blueprint Node Templates Section is NULL in the K8s DMAAP Blueprint",
408             k8sBpNodeTemplates);
409         assertTrue(
410             "DMAAP with Import File K8s Blueprint Node Templates Section Size is Empty",
411             k8sBpNodeTemplates.size() > 0);
412
413         assertEquals(
414             "DMAAP with Import File K8s Blueprint:NodeTemplates:Type is not Matching",
415             k8sBpNodeTemplates.get(Constants.ONAP_NODETEMPLATES).getType(),
416             Constants.DMAAP_NODETEMPLATES_TYPE);
417
418         Properties k8sBpNodeTemplateProperties =
419             ((Node) k8sBpNodeTemplates.get(Constants.ONAP_NODETEMPLATES)).getProperties();
420         assertNotNull(
421             "DMAAP with Import File K8s Blueprint Node Templates:Properties Section is NULL",
422             k8sBpNodeTemplateProperties);
423
424         List bpNodeTemplateRelationships =
425             ((Node) k8sBpNodeTemplates.get(Constants.ONAP_NODETEMPLATES)).getRelationships();
426         assertNotNull(
427             "DMAAP with Import File K8s Blueprint Node Templates:Relationships Section is NULL",
428             bpNodeTemplateRelationships);
429
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);
443     }
444 }