351f94ed26dceeb1a75783efde10d64aef5e8c86
[dcaegen2/platform.git] / mod / bpgenerator / onap / src / test / java / org / onap / blueprintgenerator / test / OnapBlueprintServiceTest.java
1 /*
2  *
3  *  * ============LICENSE_START=======================================================
4  *  *  org.onap.dcae
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
11  *  *
12  *  *       http://www.apache.org/licenses/LICENSE-2.0
13  *  *
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=========================================================
20  *
21  *
22  */
23
24 package org.onap.blueprintgenerator.test;
25
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;
36
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;
42 import java.util.Map;
43
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;
51
52 /**
53  * @author : Ravi Mantena
54  * @date 10/16/2020
55  * Application: ONAP - Blueprint Generator
56  * ONAP Blueprint Test Cases for ONAP and DMAAP
57  */
58
59
60 public class OnapBlueprintServiceTest extends BlueprintGeneratorTests {
61
62     private String outputfilesPath = Paths.get("src", "test", "resources", "outputfiles").toAbsolutePath().toString();
63
64     @DisplayName("Testing K8s Blueprint for Service Name Override Component Spec Input File")
65     @Test
66     public void testServiceNameOverrideK8sBlueprint() throws IOException {
67         Input input = onapTestUtils.getInput(Paths.get("src", "test", "resources", "componentspecs" , ves).toFile().getAbsolutePath(), outputfilesPath, "testServiceNameOverrideK8sBlueprint", "", "o", "");
68         onapComponentSpec = onapComponentSpecService.createComponentSpecFromFile(input.getComponentSpecPath());
69         assertNotNull("K8s Blueprint for Service Name Override Component Spec is NULL", onapComponentSpec);
70
71         OnapBlueprint onapBlueprint = onapBlueprintService.createBlueprint(onapComponentSpec, input);
72         onapBlueprintService.blueprintToYaml(onapComponentSpec, onapBlueprint, input);
73         System.out.println(onapBlueprintService.blueprintToString(onapComponentSpec, onapBlueprint, input));
74
75         onapTestUtils.verifyToscaDefVersion("Service Name Override K8s",onapBlueprint, Constants.TOSCA_DEF_VERSION);
76         onapTestUtils.verifyBpImports("Service Name Override K8s",onapBlueprint,false);
77
78         Map<String, LinkedHashMap<String, Object>> k8sBpInputs = onapBlueprint.getInputs();
79         assertNotNull("Service Name Override K8s Blueprint Inputs Section is NULL", k8sBpInputs);
80         assertTrue("Service Name Override K8s Blueprint Inputs Section is Empty", k8sBpInputs.size() > 0);
81
82         assertEquals("Service Name Override K8s Blueprint:Inputs " + Constants.ONAP_INPUT_CPU_LIMIT + " Default is not matching", k8sBpInputs.get(Constants.ONAP_INPUT_CPU_LIMIT).get("default"), Constants.ONAP_DEFAULT250m);
83         assertEquals("Service Name Override K8s Blueprint:Inputs " + Constants.SERVICE_COMPONENT_NAME_OVERRIDE + " Default is not matching", k8sBpInputs.get(Constants.SERVICE_COMPONENT_NAME_OVERRIDE).get("default"), Constants.ONAP_SERVICE_COMPONENTNAME_OVERRIDE_DEFAULT);
84
85         Map<String, Node> k8sBpNodeTemplates = onapBlueprint.getNode_templates();
86         assertNotNull("Service Name Override K8s Blueprint Node Templates Section is NULL in the K8s DMAAP Blueprint", k8sBpNodeTemplates);
87         assertTrue("Service Name Override K8s Blueprint Node Templates Section Size is Empty", k8sBpNodeTemplates.size() > 0);
88
89         assertEquals("Service Name Override K8s Blueprint:NodeTemplates:Type is not Matching", k8sBpNodeTemplates.get(Constants.ONAP_NODETEMPLATES).getType(), Constants.ONAP_NODETEMPLATES_TYPE);
90
91         Properties k8sBpNodeTemplateProperties = ((Node) k8sBpNodeTemplates.get(Constants.ONAP_NODETEMPLATES)).getProperties();
92         assertNotNull("Service Name Override K8s Blueprint Node Templates:Properties Section is NULL", k8sBpNodeTemplateProperties);
93
94
95         Map<String, LinkedHashMap<String, Object>> bpInputs = onapBlueprint.getInputs();
96         onapTestUtils.verifyArtifacts("Service Name Override K8s",onapComponentSpec,bpInputs,"o");
97
98         onapTestUtils.verifyStreamsPublishes("Service Name Override K8s",onapComponentSpec,k8sBpNodeTemplateProperties);
99         onapTestUtils.verifyStreamsSubscribes("Service Name Override K8s",onapComponentSpec,k8sBpNodeTemplateProperties);
100         onapTestUtils.verifyAuxilary("Service Name Override K8s",onapComponentSpec);
101         onapTestUtils.verifyHealthCheck("Service Name Override K8s",onapComponentSpec,k8sBpNodeTemplateProperties);
102         onapTestUtils.verifyServicesCalls("Service Name Override K8s",onapComponentSpec);
103         onapTestUtils.verifyServicesProvides("Service Name Override K8s",onapComponentSpec);
104         onapTestUtils.verifyDockerConfig("Service Name Override K8s",onapComponentSpec,k8sBpNodeTemplateProperties);
105         onapTestUtils.verifyParameters("Service Name Override K8s",onapComponentSpec,k8sBpNodeTemplates);
106         onapTestUtils.verifyVolumes("Service Name Override K8s",onapComponentSpec,k8sBpNodeTemplateProperties);
107     }
108
109     @DisplayName("Testing K8s Blueprint for Service Name Override Component Spec Input File with Import File")
110     @Test
111     public void testServiceNameOverrideImportFileK8sBlueprint() throws IOException {
112         Input input = onapTestUtils.getInput(Paths.get("src", "test", "resources", "componentspecs", ves).toFile().getAbsolutePath(), "", "", Paths.get("src", "test", "resources", "componentspecs" , testImports).toFile().getAbsolutePath(), "o", "");
113         onapComponentSpec = onapComponentSpecService.createComponentSpecFromFile(input.getComponentSpecPath());
114         assertNotNull("K8s Blueprint for Service Name Override with Import File Component Spec is NULL", onapComponentSpec);
115
116         OnapBlueprint onapBlueprint = onapBlueprintService.createBlueprint(onapComponentSpec, input);
117
118         onapTestUtils.verifyToscaDefVersion("Service Name Override with Import File K8s",onapBlueprint, Constants.TOSCA_DEF_VERSION);
119         onapTestUtils.verifyBpImportsFromFile("Service Name Override with Import File K8s",onapBlueprint,input.getImportPath());
120
121
122         Map<String, LinkedHashMap<String, Object>> k8sBpInputs = onapBlueprint.getInputs();
123         assertNotNull("Service Name Override with Import File K8s Blueprint Inputs Section is NULL", k8sBpInputs);
124         assertTrue("Service Name Override with Import File K8s Blueprint Inputs Section is Empty", k8sBpInputs.size() > 0);
125
126         assertEquals("Service Name Override with Import File K8s Blueprint:Inputs " + Constants.ONAP_INPUT_CPU_LIMIT + " Default is not matching", k8sBpInputs.get(Constants.ONAP_INPUT_CPU_LIMIT).get("default"), Constants.ONAP_DEFAULT250m);
127         assertEquals("Service Name Override with Import File K8s Blueprint:Inputs " + Constants.SERVICE_COMPONENT_NAME_OVERRIDE + " Default is not matching", k8sBpInputs.get(Constants.SERVICE_COMPONENT_NAME_OVERRIDE).get("default"), Constants.ONAP_SERVICE_COMPONENTNAME_OVERRIDE_DEFAULT);
128
129         Map<String, Node> k8sBpNodeTemplates = onapBlueprint.getNode_templates();
130         assertNotNull("Service Name Override with Import File K8s Blueprint Node Templates Section is NULL in the K8s DMAAP Blueprint", k8sBpNodeTemplates);
131         assertTrue("Service Name Override with Import File K8s Blueprint Node Templates Section Size is Empty", k8sBpNodeTemplates.size() > 0);
132
133         assertEquals("Service Name Override with Import File K8s Blueprint:NodeTemplates:Type is not Matching", k8sBpNodeTemplates.get(Constants.ONAP_NODETEMPLATES).getType(), Constants.ONAP_NODETEMPLATES_TYPE);
134
135         Properties k8sBpNodeTemplateProperties = ((Node) k8sBpNodeTemplates.get(Constants.ONAP_NODETEMPLATES)).getProperties();
136         assertNotNull("Service Name Override with Import File K8s Blueprint Node Templates:Properties Section is NULL", k8sBpNodeTemplateProperties);
137
138
139         Map<String, LinkedHashMap<String, Object>> bpInputs = onapBlueprint.getInputs();
140         onapTestUtils.verifyArtifacts("Service Name Override with Import File K8s",onapComponentSpec,bpInputs,"o");
141
142         onapTestUtils.verifyStreamsPublishes("Service Name Override with Import File K8s",onapComponentSpec,k8sBpNodeTemplateProperties);
143         onapTestUtils.verifyStreamsSubscribes("Service Name Override with Import File K8s",onapComponentSpec,k8sBpNodeTemplateProperties);
144         onapTestUtils.verifyAuxilary("Service Name Override with Import File K8s",onapComponentSpec);
145         onapTestUtils.verifyHealthCheck("Service Name Override with Import File K8s",onapComponentSpec,k8sBpNodeTemplateProperties);
146         onapTestUtils.verifyServicesCalls("Service Name Override with Import File K8s",onapComponentSpec);
147         onapTestUtils.verifyServicesProvides("Service Name Override with Import File K8s",onapComponentSpec);
148         onapTestUtils.verifyDockerConfig("Service Name Override with Import File K8s",onapComponentSpec,k8sBpNodeTemplateProperties);
149         onapTestUtils.verifyParameters("Service Name Override with Import File K8s",onapComponentSpec,k8sBpNodeTemplates);
150         onapTestUtils.verifyVolumes("Service Name Override with Import File K8s",onapComponentSpec,k8sBpNodeTemplateProperties);
151     }
152
153     @DisplayName("Testing K8s Blueprint with DB")
154     @Test
155     public void testDMAAPK8sBlueprintWithDB() {
156         Input input = onapTestUtils.getInput(Paths.get("src", "test", "resources", "componentspecs", ves).toFile().getAbsolutePath(), outputfilesPath, "testDMAAPK8sBlueprintWithDB", "", "d", "");
157         onapComponentSpec = onapComponentSpecService.createComponentSpecFromFile(input.getComponentSpecPath());
158         assertNotNull("K8s Blueprint for DMAAP Component Spec is NULL", onapComponentSpec);
159
160         OnapBlueprint onapBlueprint = dmaapBlueprintService.createBlueprint(onapComponentSpec, input);
161         onapBlueprintService.blueprintToYaml(onapComponentSpec, onapBlueprint, input);
162     }
163
164     @DisplayName("Testing K8s Blueprint for DMAAP Component Spec Input File")
165     @Test
166     public void testDMAAPK8sBlueprint() {
167         Input input = onapTestUtils.getInput(Paths.get("src", "test", "resources", "componentspecs" , ves).toFile().getAbsolutePath(), outputfilesPath, "testDMAAPK8sBlueprint", "", "d", "");
168         onapComponentSpec = onapComponentSpecService.createComponentSpecFromFile(input.getComponentSpecPath());
169         assertNotNull("K8s Blueprint for DMAAP Component Spec is NULL", onapComponentSpec);
170
171         OnapBlueprint onapBlueprint = dmaapBlueprintService.createBlueprint(onapComponentSpec, input);
172         onapBlueprintService.blueprintToYaml(onapComponentSpec, onapBlueprint, input);
173         System.out.println(onapBlueprintService.blueprintToString(onapComponentSpec, onapBlueprint, input));
174
175         policyModelService.createPolicyModels(onapComponentSpec.getParameters(), "models");
176
177         onapTestUtils.verifyToscaDefVersion("DMAAP K8s",onapBlueprint, Constants.TOSCA_DEF_VERSION);
178         //onapTestUtils.verifyBpImports("DMAAP K8s",onapBlueprint,false);
179
180         Map<String, LinkedHashMap<String, Object>> k8sBpInputs = onapBlueprint.getInputs();
181         assertNotNull("DMAAP K8s Blueprint Inputs Section is NULL", k8sBpInputs);
182         assertTrue("DMAAP K8s Blueprint Inputs Section is Empty", k8sBpInputs.size() > 0);
183
184         //assertEquals("DMAAP K8s Blueprint:Inputs " + Constants.ALWAYS_PULL_IMAGE + " Type is not matching", k8sBpInputs.get(Constants.ALWAYS_PULL_IMAGE).get("type"), "boolean");
185         //assertEquals("DMAAP K8s Blueprint:Inputs Always Pull Image  Default is not matching", k8sBpInputs.get(Constants.ALWAYS_PULL_IMAGE).get("default"), Constants.ALWAYS_PULL_IMAGE_DEFAULT);
186         assertEquals("DMAAP K8s Blueprint:Inputs " + Constants.ONAP_INPUT_CPU_LIMIT + " Default is not matching", k8sBpInputs.get(Constants.ONAP_INPUT_CPU_LIMIT).get("default"), Constants.ONAP_DEFAULT250m);
187         assertEquals("DMAAP K8s Blueprint:Inputs " + Constants.SERVICE_COMPONENT_NAME_OVERRIDE + " Default is not matching", k8sBpInputs.get(Constants.SERVICE_COMPONENT_NAME_OVERRIDE).get("default"), Constants.ONAP_SERVICE_COMPONENTNAME_OVERRIDE_DEFAULT);
188
189         Map<String, Node> k8sBpNodeTemplates = onapBlueprint.getNode_templates();
190         assertNotNull("DMAAP K8s Blueprint Node Templates Section is NULL in the K8s DMAAP Blueprint", k8sBpNodeTemplates);
191         assertTrue("DMAAP K8s Blueprint Node Templates Section Size is Empty", k8sBpNodeTemplates.size() > 0);
192
193         assertEquals("DMAAP K8s Blueprint:NodeTemplates:Type is not Matching", k8sBpNodeTemplates.get(Constants.ONAP_NODETEMPLATES).getType(), Constants.DMAAP_NODETEMPLATES_TYPE);
194
195         Properties k8sBpNodeTemplateProperties = ((Node) k8sBpNodeTemplates.get(Constants.ONAP_NODETEMPLATES)).getProperties();
196         assertNotNull("DMAAP K8s Blueprint Node Templates:Properties Section is NULL", k8sBpNodeTemplateProperties);
197
198         List bpNodeTemplateRelationships = ((Node) k8sBpNodeTemplates.get(Constants.ONAP_NODETEMPLATES)).getRelationships();
199         assertNotNull("DMAAP K8s Blueprint Node Templates:Relationships Section is NULL", bpNodeTemplateRelationships);
200
201         onapTestUtils.verifyStreamsPublishes("DMAAP K8s",onapComponentSpec,k8sBpNodeTemplateProperties);
202         onapTestUtils.verifyStreamsSubscribes("DMAAP K8s",onapComponentSpec,k8sBpNodeTemplateProperties);
203         onapTestUtils.verifyAuxilary("DMAAP K8s",onapComponentSpec);
204         onapTestUtils.verifyHealthCheck("DMAAP K8s",onapComponentSpec,k8sBpNodeTemplateProperties);
205         onapTestUtils.verifyServicesCalls("DMAAP K8s",onapComponentSpec);
206         onapTestUtils.verifyServicesProvides("DMAAP K8s",onapComponentSpec);
207         onapTestUtils.verifyDockerConfig("DMAAP K8s",onapComponentSpec,k8sBpNodeTemplateProperties);
208         onapTestUtils.verifyParameters("DMAAP K8s",onapComponentSpec,k8sBpNodeTemplates);
209     }
210
211     @DisplayName("Testing K8s Blueprint for DMAAP Component Spec Input File with Import File")
212     @Test
213     public void testDMAAPK8sImportFileBlueprint() throws IOException {
214         Input input = onapTestUtils.getInput(Paths.get("src", "test", "resources", "componentspecs" , ves).toFile().getAbsolutePath(), "", "", Paths.get("src", "test", "resources", "componentspecs" , testImports).toFile().getAbsolutePath(), "d", "");
215         onapComponentSpec = onapComponentSpecService.createComponentSpecFromFile(input.getComponentSpecPath());
216         assertNotNull("K8s Blueprint for DMAAP Component Spec with Import File is NULL", onapComponentSpec);
217
218         OnapBlueprint onapBlueprint = dmaapBlueprintService.createBlueprint(onapComponentSpec, input);
219
220         onapTestUtils.verifyToscaDefVersion("DMAAP with Import File K8s",onapBlueprint, Constants.TOSCA_DEF_VERSION);
221         onapTestUtils.verifyBpImportsFromFile("DMAAP with Import File K8s",onapBlueprint,input.getImportPath());
222
223         Map<String, LinkedHashMap<String, Object>> k8sBpInputs = onapBlueprint.getInputs();
224         assertNotNull("DMAAP with Import File K8s Blueprint Inputs Section is NULL", k8sBpInputs);
225         assertTrue("DMAAP with Import File K8s Blueprint Inputs Section is Empty", k8sBpInputs.size() > 0);
226
227         //assertEquals("DMAAP with Import File K8s Blueprint:Inputs " + Constants.ALWAYS_PULL_IMAGE + " Type is not matching", k8sBpInputs.get(Constants.ALWAYS_PULL_IMAGE).get("type"), "boolean");
228         //assertEquals("DMAAP with Import File K8s Blueprint:Inputs Always Pull Image  Default is not matching", k8sBpInputs.get(Constants.ALWAYS_PULL_IMAGE).get("default"), Constants.ALWAYS_PULL_IMAGE_DEFAULT);
229         assertEquals("DMAAP with Import File K8s Blueprint:Inputs " + Constants.ONAP_INPUT_CPU_LIMIT + " Default is not matching", k8sBpInputs.get(Constants.ONAP_INPUT_CPU_LIMIT).get("default"), Constants.ONAP_DEFAULT250m);
230         assertEquals("DMAAP with Import File K8s Blueprint:Inputs " + Constants.SERVICE_COMPONENT_NAME_OVERRIDE + " Default is not matching", k8sBpInputs.get(Constants.SERVICE_COMPONENT_NAME_OVERRIDE).get("default"), Constants.ONAP_SERVICE_COMPONENTNAME_OVERRIDE_DEFAULT);
231
232         Map<String, Node> k8sBpNodeTemplates = onapBlueprint.getNode_templates();
233         assertNotNull("DMAAP with Import File K8s Blueprint Node Templates Section is NULL in the K8s DMAAP Blueprint", k8sBpNodeTemplates);
234         assertTrue("DMAAP with Import File K8s Blueprint Node Templates Section Size is Empty", k8sBpNodeTemplates.size() > 0);
235
236         assertEquals("DMAAP with Import File K8s Blueprint:NodeTemplates:Type is not Matching", k8sBpNodeTemplates.get(Constants.ONAP_NODETEMPLATES).getType(), Constants.DMAAP_NODETEMPLATES_TYPE);
237
238         Properties k8sBpNodeTemplateProperties = ((Node) k8sBpNodeTemplates.get(Constants.ONAP_NODETEMPLATES)).getProperties();
239         assertNotNull("DMAAP with Import File K8s Blueprint Node Templates:Properties Section is NULL", k8sBpNodeTemplateProperties);
240
241         List bpNodeTemplateRelationships = ((Node) k8sBpNodeTemplates.get(Constants.ONAP_NODETEMPLATES)).getRelationships();
242         assertNotNull("DMAAP with Import File K8s Blueprint Node Templates:Relationships Section is NULL", bpNodeTemplateRelationships);
243
244         onapTestUtils.verifyStreamsPublishes("DMAAP with Import File K8s",onapComponentSpec,k8sBpNodeTemplateProperties);
245         onapTestUtils.verifyStreamsSubscribes("DMAAP with Import File K8s",onapComponentSpec,k8sBpNodeTemplateProperties);
246         onapTestUtils.verifyAuxilary("DMAAP with Import File K8s",onapComponentSpec);
247         onapTestUtils.verifyHealthCheck("DMAAP with Import File K8s",onapComponentSpec,k8sBpNodeTemplateProperties);
248         onapTestUtils.verifyServicesCalls("DMAAP with Import File K8s",onapComponentSpec);
249         onapTestUtils.verifyServicesProvides("DMAAP with Import File K8s",onapComponentSpec);
250         onapTestUtils.verifyDockerConfig("DMAAP with Import File K8s",onapComponentSpec,k8sBpNodeTemplateProperties);
251         onapTestUtils.verifyParameters("DMAAP with Import File K8s",onapComponentSpec,k8sBpNodeTemplates);
252     }
253
254 }
255
256
257