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.LinkedHashMap;
50 import java.util.List;
53 import static org.junit.Assert.assertArrayEquals;
54 import static org.junit.Assert.assertEquals;
55 import static org.junit.Assert.assertNotNull;
56 import static org.junit.Assert.assertTrue;
59 * @author : Ravi Mantena
60 * @date 10/16/2020 Application: ONAP - Blueprint Generator Test Utilities used in Test Suite and
65 public class OnapTestUtils extends BlueprintGeneratorTests {
67 @Value("${imports.onap.types}")
68 private String importsOnapTypes;
70 @Value("${imports.onap.K8s.plugintypes}")
71 private String importsOnapK8sPlugintypes;
73 @Value("${imports.onap.K8s.dcaepolicyplugin}")
74 private String importsOnapK8sDcaepolicyplugin;
76 @Value("${imports.dmaap.dmaapplugin}")
77 private String importsDmaapDmaapplugin;
79 @Value("${import.Postgres}")
80 private String importPostgres;
82 @Value("${import.Clamp}")
83 private String importClamp;
88 * @param componentSpecPath
90 * @param bluePrintName
93 * @param serviceNameOverride
96 public Input getInput(
97 String componentSpecPath,
102 String serviceNameOverride) {
103 Input input = new Input();
104 input.setComponentSpecPath(componentSpecPath);
105 input.setBluePrintName(bluePrintName);
106 input.setOutputPath(outputPath);
107 input.setBpType(bpType);
108 input.setServiceNameOverride(serviceNameOverride);
109 input.setImportPath(importPath);
114 * Creates Input from Component Spec Path
116 * @param componentSpecPath
119 public Input getInput(String componentSpecPath) {
120 Input input = new Input();
121 input.setComponentSpecPath(componentSpecPath);
126 * Verifies Tosca Def Version
130 * @param toscaDefVersion
132 public void verifyToscaDefVersion(String type, Blueprint blueprint, String toscaDefVersion) {
133 String bpToscaDefVersion = blueprint.getTosca_definitions_version();
134 assertNotNull(type + " TOSCA Definition Version is NULL", bpToscaDefVersion);
136 type + " TOSCA Definition Version is not Matching", bpToscaDefVersion, toscaDefVersion);
144 * @param validateimps
146 public void verifyBpImports(String type, Blueprint blueprint, boolean validateimps) {
147 String[] bpImports = blueprint.getImports()
148 .toArray(new String[blueprint.getImports().size()]);
150 String[] testImports = {
152 importsOnapK8sPlugintypes,
153 importsDmaapDmaapplugin,
159 + " Blueprint Imports is not matching with default Dmaap K8s Blueprint imports",
163 String[] testImports = {
165 importsOnapK8sPlugintypes,
166 importsOnapK8sDcaepolicyplugin,
171 type + " Blueprint Imports is not matching with default Onap K8s Blueprint imports",
178 * Verifies Imports from file
184 public void verifyBpImportsFromFile(String type, Blueprint blueprint, String importPath)
186 Blueprint importFileRead = yamlObjectMapper
187 .readValue(new File(importPath), Blueprint.class);
188 String[] importFileImports =
189 importFileRead.getImports().toArray(new String[importFileRead.getImports().size()]);
190 String[] bpImports = blueprint.getImports()
191 .toArray(new String[blueprint.getImports().size()]);
193 type + " Blueprint Imports is not matching with default Dmaap K8s Blueprint imports",
199 * Verifies Streams Publishes
202 * @param onapComponentSpec
203 * @param nodeTemplateProperties
205 public void verifyStreamsPublishes(
206 String type, OnapComponentSpec onapComponentSpec, Properties nodeTemplateProperties) {
207 List<Streams> streamsPublishes = nodeTemplateProperties.getStreams_publishes();
208 if (!(streamsPublishes == null)) {
210 type + " Blueprint:NodeTemplates:Properties:StreamsPublishes is NULL",
213 type + " Blueprint:NodeTemplates:Properties:StreamsPublishes Section Size is 0",
214 streamsPublishes.size() > 0);
216 type + " Blueprint:NodeTemplates:Properties:StreamsPublishes is Not Matching",
217 streamsPublishes.get(0).getType(),
218 Constants.MESSAGEROUTER_VALUE);
220 type + " Blueprint:NodeTemplates:Properties:StreamsPublishes is Not Matching",
221 streamsPublishes.get(1).getType(),
222 Constants.MESSAGEROUTER_VALUE);
227 * Verifies Streams Subscribes
230 * @param onapComponentSpec
231 * @param nodeTemplateProperties
233 public void verifyStreamsSubscribes(
234 String type, OnapComponentSpec onapComponentSpec, Properties nodeTemplateProperties) {
235 List<Streams> streamsSubscribes = nodeTemplateProperties.getStreams_subscribes();
236 if (!(streamsSubscribes == null)) {
238 type + " Blueprint:NodeTemplates:Properties:StreamsSubscribes is NULL",
241 type + " Blueprint:NodeTemplates:Properties:StreamsSubscribes Section Size is 0",
242 streamsSubscribes.size() > 0);
244 type + " Blueprint:NodeTemplates:Properties:StreamsSubscribes is Not Matching",
245 streamsSubscribes.get(0).getType(),
246 Constants.MESSAGE_ROUTER);
248 type + " Blueprint:NodeTemplates:Properties:StreamsSubscribes is Not Matching",
249 streamsSubscribes.get(1).getType(),
250 Constants.DATA_ROUTER);
255 * Verifies Services Calls
258 * @param onapComponentSpec
260 public void verifyServicesCalls(String type, OnapComponentSpec onapComponentSpec) {
261 Calls[] csServicesCalls = onapComponentSpec.getServices().getCalls();
262 assertNotNull(type + " ComponentSpec Services Calls is NULL", csServicesCalls);
263 // assertTrue(type + " ComponentSpec Services Calls Section Size is 0", csServicesCalls.length >
268 * Verifies Services Provides
271 * @param onapComponentSpec
273 public void verifyServicesProvides(String type, OnapComponentSpec onapComponentSpec) {
274 Provides[] csServicesProvides = onapComponentSpec.getServices().getProvides();
275 assertNotNull(type + " ComponentSpec Services Provides is NULL", csServicesProvides);
277 type + " ComponentSpec Services Provides Section Size is 0",
278 csServicesProvides.length > 0);
282 * Verifies Docker Config
285 * @param onapComponentSpec
286 * @param nodeTemplateProperties
288 public void verifyDockerConfig(
289 String type, OnapComponentSpec onapComponentSpec, Properties nodeTemplateProperties) {
290 OnapAuxilary dockerConfig = nodeTemplateProperties.getDocker_config();
291 assertNotNull(type + " Blueprint Docker Config Section is NULL", dockerConfig);
295 * Verifies Parameters
298 * @param onapComponentSpec
299 * @param nodeTemplates
301 public void verifyParameters(
302 String type, OnapComponentSpec onapComponentSpec, Map<String, Node> nodeTemplates) {
303 Parameters[] csParameters = onapComponentSpec.getParameters();
304 assertNotNull(type + " ComponentSpec Parameters Section is NULL", csParameters);
305 assertTrue(type + " ComponentSpec Parameters Section Size is 0", csParameters.length > 0);
312 * @param onapComponentSpec
314 public void verifyAuxilary(String type, OnapComponentSpec onapComponentSpec) {
315 OnapAuxilary csAuxilary = onapComponentSpec.getAuxilary();
316 assertNotNull(type + " ComponentSpec Auxilary Section is NULL", csAuxilary);
320 * Verifies HealthCheck
323 * @param onapComponentSpec
324 * @param nodeTemplateProperties
326 public void verifyHealthCheck(
327 String type, OnapComponentSpec onapComponentSpec, Properties nodeTemplateProperties) {
328 HealthCheck csAuxilaryHealthcheck = onapComponentSpec.getAuxilary().getHealthcheck();
330 type + " ComponentSpec Auxilary Health Check Section is NULL", csAuxilaryHealthcheck);
331 HealthCheck healthCheck = nodeTemplateProperties.getDocker_config().getHealthcheck();
333 type + " Blueprint:NodeTemplates:DockerConfig:Healthcheck Section is NULL",
336 type + " Blueprint:NodeTemplates:DockerConfig:Healthcheck:Interval Tag is not matching",
337 healthCheck.getInterval(),
338 csAuxilaryHealthcheck.getInterval());
340 type + " Blueprint:NodeTemplates:DockerConfig:Healthcheck:Timeout Tag is not matching",
341 healthCheck.getTimeout(),
342 csAuxilaryHealthcheck.getTimeout());
344 type + " Blueprint:NodeTemplates:DockerConfig:Healthcheck:Script Tag is not matching",
345 healthCheck.getEndpoint(),
346 csAuxilaryHealthcheck.getEndpoint());
348 type + " Blueprint:NodeTemplates:DockerConfig:Healthcheck:Type Tag is not matching",
349 healthCheck.getType(),
350 csAuxilaryHealthcheck.getType());
357 * @param onapComponentSpec
358 * @param nodeTemplateProperties
360 public void verifyVolumes(
361 String type, OnapComponentSpec onapComponentSpec, Properties nodeTemplateProperties) {
362 Volumes[] csAuxilaryVolumes = onapComponentSpec.getAuxilary().getVolumes();
364 type + " ComponentSpec Auxilary Live Health Check Section is NULL", csAuxilaryVolumes);
365 Volumes[] onapVolumes = nodeTemplateProperties.getDocker_config().getVolumes();
367 type + " Blueprint:NodeTemplates:DockerConfig:LiveHealthcheck Section is NULL",
369 assertNotNull(type + " Blueprint:NodeTemplates:DockerConfig:Volumes:ConfigVolume:GetName Section is NULL", Arrays.stream(onapVolumes)
370 .filter(c -> c.getConfigVolume() != null)
371 .filter(c -> c.getName() != null)
372 .filter(c -> c.equals("myConfig"))
380 * @param onapComponentSpec
384 public void verifyArtifacts(
386 OnapComponentSpec onapComponentSpec,
387 Map<String, LinkedHashMap<String, Object>> inputs,
389 Artifacts[] csArtifacts = onapComponentSpec.getArtifacts();
390 assertNotNull(type + " ComponentSpec Artifacts Section is NULL", csArtifacts);
392 type + " Blueprint:Artifacts:image is not matching",
393 ((String) inputs.get("image").get("default")),
394 "\"" + csArtifacts[0].getUri() + "\"");
395 // assertEquals(type + " Blueprint:Artifacts:image is not matching", ((String)
396 // inputs.get("tag_version").get("default")), "\"" + csArtifacts[0].getUri() + "\"");