3 * * ============LICENSE_START=======================================================
5 * * ================================================================================
6 * * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved.
7 * * Copyright (c) 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 org.onap.blueprintgenerator.constants.Constants;
28 import org.onap.blueprintgenerator.model.base.Blueprint;
29 import org.onap.blueprintgenerator.model.common.Input;
30 import org.onap.blueprintgenerator.model.common.Node;
31 import org.onap.blueprintgenerator.model.common.Properties;
32 import org.onap.blueprintgenerator.model.componentspec.OnapAuxilary;
33 import org.onap.blueprintgenerator.model.componentspec.OnapComponentSpec;
35 import org.onap.blueprintgenerator.model.componentspec.common.Calls;
36 import org.onap.blueprintgenerator.model.componentspec.common.Provides;
37 import org.onap.blueprintgenerator.model.componentspec.common.HealthCheck;
38 import org.onap.blueprintgenerator.model.componentspec.common.Parameters;
39 import org.onap.blueprintgenerator.model.componentspec.common.Volumes;
40 import org.onap.blueprintgenerator.model.componentspec.common.Artifacts;
41 import org.onap.blueprintgenerator.model.dmaap.Streams;
42 import org.junit.Ignore;
43 import org.springframework.beans.factory.annotation.Value;
44 import org.springframework.stereotype.Component;
47 import java.io.IOException;
48 import java.util.Arrays;
49 import java.util.List;
52 import static org.junit.Assert.assertArrayEquals;
53 import static org.junit.Assert.assertEquals;
54 import static org.junit.Assert.assertNotNull;
55 import static org.junit.Assert.assertTrue;
58 * @author : Ravi Mantena
59 * @date 10/16/2020 Application: ONAP - Blueprint Generator Test Utilities used in Test Suite and
64 public class OnapTestUtils extends BlueprintGeneratorTests {
66 @Value("${imports.onap.types}")
67 private String importsOnapTypes;
69 @Value("${imports.onap.K8s.plugintypes}")
70 private String importsOnapK8sPlugintypes;
72 @Value("${imports.onap.K8s.dcaepolicyplugin}")
73 private String importsOnapK8sDcaepolicyplugin;
75 @Value("${imports.dmaap.dmaapplugin}")
76 private String importsDmaapDmaapplugin;
78 @Value("${import.Postgres}")
79 private String importPostgres;
81 @Value("${import.Clamp}")
82 private String importClamp;
87 * @param componentSpecPath
89 * @param bluePrintName
92 * @param serviceNameOverride
95 public Input getInput(
96 String componentSpecPath,
101 String serviceNameOverride) {
102 Input input = new Input();
103 input.setComponentSpecPath(componentSpecPath);
104 input.setBluePrintName(bluePrintName);
105 input.setOutputPath(outputPath);
106 input.setBpType(bpType);
107 input.setServiceNameOverride(serviceNameOverride);
108 input.setImportPath(importPath);
113 * Creates Input from Component Spec Path
115 * @param componentSpecPath
118 public Input getInput(String componentSpecPath) {
119 Input input = new Input();
120 input.setComponentSpecPath(componentSpecPath);
125 * Verifies Tosca Def Version
129 * @param toscaDefVersion
131 public void verifyToscaDefVersion(String type, Blueprint blueprint, String toscaDefVersion) {
132 String bpToscaDefVersion = blueprint.getTosca_definitions_version();
133 assertNotNull(type + " TOSCA Definition Version is NULL", bpToscaDefVersion);
135 type + " TOSCA Definition Version is not Matching", bpToscaDefVersion, toscaDefVersion);
143 * @param validateimps
145 public void verifyBpImports(String type, Blueprint blueprint, boolean validateimps) {
146 String[] bpImports = blueprint.getImports()
147 .toArray(new String[blueprint.getImports().size()]);
149 String[] testImports = {
151 importsOnapK8sPlugintypes,
152 importsDmaapDmaapplugin,
158 + " Blueprint Imports is not matching with default Dmaap K8s Blueprint imports",
162 String[] testImports = {
164 importsOnapK8sPlugintypes,
165 importsOnapK8sDcaepolicyplugin,
170 type + " Blueprint Imports is not matching with default Onap K8s Blueprint imports",
177 * Verifies Imports from file
183 public void verifyBpImportsFromFile(String type, Blueprint blueprint, String importPath)
185 Blueprint importFileRead = yamlObjectMapper
186 .readValue(new File(importPath), Blueprint.class);
187 String[] importFileImports =
188 importFileRead.getImports().toArray(new String[importFileRead.getImports().size()]);
189 String[] bpImports = blueprint.getImports()
190 .toArray(new String[blueprint.getImports().size()]);
192 type + " Blueprint Imports is not matching with default Dmaap K8s Blueprint imports",
198 * Verifies Streams Publishes
201 * @param onapComponentSpec
202 * @param nodeTemplateProperties
204 public void verifyStreamsPublishes(
205 String type, OnapComponentSpec onapComponentSpec, Properties nodeTemplateProperties) {
206 List<Streams> streamsPublishes = nodeTemplateProperties.getStreams_publishes();
207 if (!(streamsPublishes == null)) {
209 type + " Blueprint:NodeTemplates:Properties:StreamsPublishes is NULL",
212 type + " Blueprint:NodeTemplates:Properties:StreamsPublishes Section Size is 0",
213 streamsPublishes.size() > 0);
215 type + " Blueprint:NodeTemplates:Properties:StreamsPublishes is Not Matching",
216 streamsPublishes.get(0).getType(),
217 Constants.MESSAGEROUTER_VALUE);
219 type + " Blueprint:NodeTemplates:Properties:StreamsPublishes is Not Matching",
220 streamsPublishes.get(1).getType(),
221 Constants.MESSAGEROUTER_VALUE);
226 * Verifies Streams Subscribes
229 * @param onapComponentSpec
230 * @param nodeTemplateProperties
232 public void verifyStreamsSubscribes(
233 String type, OnapComponentSpec onapComponentSpec, Properties nodeTemplateProperties) {
234 List<Streams> streamsSubscribes = nodeTemplateProperties.getStreams_subscribes();
235 if (!(streamsSubscribes == null)) {
237 type + " Blueprint:NodeTemplates:Properties:StreamsSubscribes is NULL",
240 type + " Blueprint:NodeTemplates:Properties:StreamsSubscribes Section Size is 0",
241 streamsSubscribes.size() > 0);
243 type + " Blueprint:NodeTemplates:Properties:StreamsSubscribes is Not Matching",
244 streamsSubscribes.get(0).getType(),
245 Constants.MESSAGE_ROUTER);
247 type + " Blueprint:NodeTemplates:Properties:StreamsSubscribes is Not Matching",
248 streamsSubscribes.get(1).getType(),
249 Constants.DATA_ROUTER);
254 * Verifies Services Calls
257 * @param onapComponentSpec
259 public void verifyServicesCalls(String type, OnapComponentSpec onapComponentSpec) {
260 Calls[] csServicesCalls = onapComponentSpec.getServices().getCalls();
261 assertNotNull(type + " ComponentSpec Services Calls is NULL", csServicesCalls);
262 // assertTrue(type + " ComponentSpec Services Calls Section Size is 0", csServicesCalls.length >
267 * Verifies Services Provides
270 * @param onapComponentSpec
272 public void verifyServicesProvides(String type, OnapComponentSpec onapComponentSpec) {
273 Provides[] csServicesProvides = onapComponentSpec.getServices().getProvides();
274 assertNotNull(type + " ComponentSpec Services Provides is NULL", csServicesProvides);
276 type + " ComponentSpec Services Provides Section Size is 0",
277 csServicesProvides.length > 0);
281 * Verifies Docker Config
284 * @param onapComponentSpec
285 * @param nodeTemplateProperties
287 public void verifyDockerConfig(
288 String type, OnapComponentSpec onapComponentSpec, Properties nodeTemplateProperties) {
289 OnapAuxilary dockerConfig = nodeTemplateProperties.getDocker_config();
290 assertNotNull(type + " Blueprint Docker Config Section is NULL", dockerConfig);
294 * Verifies Parameters
297 * @param onapComponentSpec
298 * @param nodeTemplates
300 public void verifyParameters(
301 String type, OnapComponentSpec onapComponentSpec, Map<String, Node> nodeTemplates) {
302 Parameters[] csParameters = onapComponentSpec.getParameters();
303 assertNotNull(type + " ComponentSpec Parameters Section is NULL", csParameters);
304 assertTrue(type + " ComponentSpec Parameters Section Size is 0", csParameters.length > 0);
311 * @param onapComponentSpec
313 public void verifyAuxilary(String type, OnapComponentSpec onapComponentSpec) {
314 OnapAuxilary csAuxilary = onapComponentSpec.getAuxilary();
315 assertNotNull(type + " ComponentSpec Auxilary Section is NULL", csAuxilary);
319 * Verifies HealthCheck
322 * @param onapComponentSpec
323 * @param nodeTemplateProperties
325 public void verifyHealthCheck(
326 String type, OnapComponentSpec onapComponentSpec, Properties nodeTemplateProperties) {
327 HealthCheck csAuxilaryHealthcheck = onapComponentSpec.getAuxilary().getHealthcheck();
329 type + " ComponentSpec Auxilary Health Check Section is NULL", csAuxilaryHealthcheck);
330 HealthCheck healthCheck = nodeTemplateProperties.getDocker_config().getHealthcheck();
332 type + " Blueprint:NodeTemplates:DockerConfig:Healthcheck Section is NULL",
335 type + " Blueprint:NodeTemplates:DockerConfig:Healthcheck:Interval Tag is not matching",
336 healthCheck.getInterval(),
337 csAuxilaryHealthcheck.getInterval());
339 type + " Blueprint:NodeTemplates:DockerConfig:Healthcheck:Timeout Tag is not matching",
340 healthCheck.getTimeout(),
341 csAuxilaryHealthcheck.getTimeout());
343 type + " Blueprint:NodeTemplates:DockerConfig:Healthcheck:Script Tag is not matching",
344 healthCheck.getEndpoint(),
345 csAuxilaryHealthcheck.getEndpoint());
347 type + " Blueprint:NodeTemplates:DockerConfig:Healthcheck:Type Tag is not matching",
348 healthCheck.getType(),
349 csAuxilaryHealthcheck.getType());
356 * @param onapComponentSpec
357 * @param nodeTemplateProperties
359 public void verifyVolumes(
360 String type, OnapComponentSpec onapComponentSpec, Properties nodeTemplateProperties) {
361 Volumes[] csAuxilaryVolumes = onapComponentSpec.getAuxilary().getVolumes();
363 type + " ComponentSpec Auxilary Live Health Check Section is NULL", csAuxilaryVolumes);
364 Volumes[] onapVolumes = nodeTemplateProperties.getDocker_config().getVolumes();
366 type + " Blueprint:NodeTemplates:DockerConfig:LiveHealthcheck Section is NULL",
368 assertNotNull(type + " Blueprint:NodeTemplates:DockerConfig:Volumes:ConfigVolume:GetName Section is NULL", Arrays.stream(onapVolumes)
369 .filter(c -> c.getConfigVolume() != null)
370 .filter(c -> c.getName() != null)
371 .filter(c -> c.equals("myConfig"))
379 * @param onapComponentSpec
383 public void verifyArtifacts(
385 OnapComponentSpec onapComponentSpec,
386 Map<String, Map<String, Object>> inputs,
388 Artifacts[] csArtifacts = onapComponentSpec.getArtifacts();
389 assertNotNull(type + " ComponentSpec Artifacts Section is NULL", csArtifacts);
391 type + " Blueprint:Artifacts:image is not matching",
392 ((String) inputs.get("image").get("default")),
393 "\"" + csArtifacts[0].getUri() + "\"");
394 // assertEquals(type + " Blueprint:Artifacts:image is not matching", ((String)
395 // inputs.get("tag_version").get("default")), "\"" + csArtifacts[0].getUri() + "\"");