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