3 * * ============LICENSE_START=======================================================
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
12 * * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
24 package org.onap.blueprintgenerator.test;
26 import org.onap.blueprintgenerator.constants.Constants;
27 import org.onap.blueprintgenerator.model.base.Blueprint;
28 import org.onap.blueprintgenerator.model.common.Input;
29 import org.onap.blueprintgenerator.model.common.Node;
30 import org.onap.blueprintgenerator.model.common.Properties;
31 import org.onap.blueprintgenerator.model.componentspec.OnapAuxilary;
32 import org.onap.blueprintgenerator.model.componentspec.OnapComponentSpec;
34 import org.onap.blueprintgenerator.model.componentspec.common.Calls;
35 import org.onap.blueprintgenerator.model.componentspec.common.Provides;
36 import org.onap.blueprintgenerator.model.componentspec.common.HealthCheck;
37 import org.onap.blueprintgenerator.model.componentspec.common.Parameters;
38 import org.onap.blueprintgenerator.model.componentspec.common.Volumes;
39 import org.onap.blueprintgenerator.model.componentspec.common.Artifacts;
40 import org.onap.blueprintgenerator.model.dmaap.Streams;
41 import org.junit.Ignore;
42 import org.springframework.beans.factory.annotation.Value;
43 import org.springframework.stereotype.Component;
46 import java.io.IOException;
47 import java.util.LinkedHashMap;
48 import java.util.List;
51 import static org.junit.Assert.assertArrayEquals;
52 import static org.junit.Assert.assertEquals;
53 import static org.junit.Assert.assertNotNull;
54 import static org.junit.Assert.assertTrue;
57 * @author : Ravi Mantena
58 * @date 10/16/2020 Application: ONAP - Blueprint Generator Test Utilities used in Test Suite and
63 public class OnapTestUtils extends BlueprintGeneratorTests {
65 @Value("${imports.onap.types}")
66 private String importsOnapTypes;
68 @Value("${imports.onap.K8s.plugintypes}")
69 private String importsOnapK8sPlugintypes;
71 @Value("${imports.onap.K8s.dcaepolicyplugin}")
72 private String importsOnapK8sDcaepolicyplugin;
74 @Value("${imports.dmaap.dmaapplugin}")
75 private String importsDmaapDmaapplugin;
77 @Value("${import.Postgres}")
78 private String importPostgres;
80 @Value("${import.Clamp}")
81 private String importClamp;
86 * @param componentSpecPath
88 * @param bluePrintName
91 * @param serviceNameOverride
94 public Input getInput(
95 String componentSpecPath,
100 String serviceNameOverride) {
101 Input input = new Input();
102 input.setComponentSpecPath(componentSpecPath);
103 input.setBluePrintName(bluePrintName);
104 input.setOutputPath(outputPath);
105 input.setBpType(bpType);
106 input.setServiceNameOverride(serviceNameOverride);
107 input.setImportPath(importPath);
112 * Creates Input from Component Spec Path
114 * @param componentSpecPath
117 public Input getInput(String componentSpecPath) {
118 Input input = new Input();
119 input.setComponentSpecPath(componentSpecPath);
124 * Verifies Tosca Def Version
128 * @param toscaDefVersion
130 public void verifyToscaDefVersion(String type, Blueprint blueprint, String toscaDefVersion) {
131 String bpToscaDefVersion = blueprint.getTosca_definitions_version();
132 assertNotNull(type + " TOSCA Definition Version is NULL", bpToscaDefVersion);
134 type + " TOSCA Definition Version is not Matching", bpToscaDefVersion, toscaDefVersion);
142 * @param validateimps
144 public void verifyBpImports(String type, Blueprint blueprint, boolean validateimps) {
145 String[] bpImports = blueprint.getImports()
146 .toArray(new String[blueprint.getImports().size()]);
148 String[] testImports = {
150 importsOnapK8sPlugintypes,
151 importsDmaapDmaapplugin,
157 + " Blueprint Imports is not matching with default Dmaap K8s Blueprint imports",
161 String[] testImports = {
163 importsOnapK8sPlugintypes,
164 importsOnapK8sDcaepolicyplugin,
169 type + " Blueprint Imports is not matching with default Onap K8s Blueprint imports",
176 * Verifies Imports from file
182 public void verifyBpImportsFromFile(String type, Blueprint blueprint, String importPath)
184 Blueprint importFileRead = yamlObjectMapper
185 .readValue(new File(importPath), Blueprint.class);
186 String[] importFileImports =
187 importFileRead.getImports().toArray(new String[importFileRead.getImports().size()]);
188 String[] bpImports = blueprint.getImports()
189 .toArray(new String[blueprint.getImports().size()]);
191 type + " Blueprint Imports is not matching with default Dmaap K8s Blueprint imports",
197 * Verifies Streams Publishes
200 * @param onapComponentSpec
201 * @param nodeTemplateProperties
203 public void verifyStreamsPublishes(
204 String type, OnapComponentSpec onapComponentSpec, Properties nodeTemplateProperties) {
205 List<Streams> streamsPublishes = nodeTemplateProperties.getStreams_publishes();
206 if (!(streamsPublishes == null)) {
208 type + " Blueprint:NodeTemplates:Properties:StreamsPublishes is NULL",
211 type + " Blueprint:NodeTemplates:Properties:StreamsPublishes Section Size is 0",
212 streamsPublishes.size() > 0);
214 type + " Blueprint:NodeTemplates:Properties:StreamsPublishes is Not Matching",
215 streamsPublishes.get(0).getType(),
216 Constants.MESSAGEROUTER_VALUE);
218 type + " Blueprint:NodeTemplates:Properties:StreamsPublishes is Not Matching",
219 streamsPublishes.get(1).getType(),
220 Constants.MESSAGEROUTER_VALUE);
225 * Verifies Streams Subscribes
228 * @param onapComponentSpec
229 * @param nodeTemplateProperties
231 public void verifyStreamsSubscribes(
232 String type, OnapComponentSpec onapComponentSpec, Properties nodeTemplateProperties) {
233 List<Streams> streamsSubscribes = nodeTemplateProperties.getStreams_subscribes();
234 if (!(streamsSubscribes == null)) {
236 type + " Blueprint:NodeTemplates:Properties:StreamsSubscribes is NULL",
239 type + " Blueprint:NodeTemplates:Properties:StreamsSubscribes Section Size is 0",
240 streamsSubscribes.size() > 0);
242 type + " Blueprint:NodeTemplates:Properties:StreamsSubscribes is Not Matching",
243 streamsSubscribes.get(0).getType(),
244 Constants.MESSAGE_ROUTER);
246 type + " Blueprint:NodeTemplates:Properties:StreamsSubscribes is Not Matching",
247 streamsSubscribes.get(1).getType(),
248 Constants.DATA_ROUTER);
253 * Verifies Services Calls
256 * @param onapComponentSpec
258 public void verifyServicesCalls(String type, OnapComponentSpec onapComponentSpec) {
259 Calls[] csServicesCalls = onapComponentSpec.getServices().getCalls();
260 assertNotNull(type + " ComponentSpec Services Calls is NULL", csServicesCalls);
261 // assertTrue(type + " ComponentSpec Services Calls Section Size is 0", csServicesCalls.length >
266 * Verifies Services Provides
269 * @param onapComponentSpec
271 public void verifyServicesProvides(String type, OnapComponentSpec onapComponentSpec) {
272 Provides[] csServicesProvides = onapComponentSpec.getServices().getProvides();
273 assertNotNull(type + " ComponentSpec Services Provides is NULL", csServicesProvides);
275 type + " ComponentSpec Services Provides Section Size is 0",
276 csServicesProvides.length > 0);
280 * Verifies Docker Config
283 * @param onapComponentSpec
284 * @param nodeTemplateProperties
286 public void verifyDockerConfig(
287 String type, OnapComponentSpec onapComponentSpec, Properties nodeTemplateProperties) {
288 OnapAuxilary dockerConfig = nodeTemplateProperties.getDocker_config();
289 assertNotNull(type + " Blueprint Docker Config Section is NULL", dockerConfig);
293 * Verifies Parameters
296 * @param onapComponentSpec
297 * @param nodeTemplates
299 public void verifyParameters(
300 String type, OnapComponentSpec onapComponentSpec, Map<String, Node> nodeTemplates) {
301 Parameters[] csParameters = onapComponentSpec.getParameters();
302 assertNotNull(type + " ComponentSpec Parameters Section is NULL", csParameters);
303 assertTrue(type + " ComponentSpec Parameters Section Size is 0", csParameters.length > 0);
310 * @param onapComponentSpec
312 public void verifyAuxilary(String type, OnapComponentSpec onapComponentSpec) {
313 OnapAuxilary csAuxilary = onapComponentSpec.getAuxilary();
314 assertNotNull(type + " ComponentSpec Auxilary Section is NULL", csAuxilary);
318 * Verifies HealthCheck
321 * @param onapComponentSpec
322 * @param nodeTemplateProperties
324 public void verifyHealthCheck(
325 String type, OnapComponentSpec onapComponentSpec, Properties nodeTemplateProperties) {
326 HealthCheck csAuxilaryHealthcheck = onapComponentSpec.getAuxilary().getHealthcheck();
328 type + " ComponentSpec Auxilary Health Check Section is NULL", csAuxilaryHealthcheck);
329 HealthCheck healthCheck = nodeTemplateProperties.getDocker_config().getHealthcheck();
331 type + " Blueprint:NodeTemplates:DockerConfig:Healthcheck Section is NULL",
334 type + " Blueprint:NodeTemplates:DockerConfig:Healthcheck:Interval Tag is not matching",
335 healthCheck.getInterval(),
336 csAuxilaryHealthcheck.getInterval());
338 type + " Blueprint:NodeTemplates:DockerConfig:Healthcheck:Timeout Tag is not matching",
339 healthCheck.getTimeout(),
340 csAuxilaryHealthcheck.getTimeout());
342 type + " Blueprint:NodeTemplates:DockerConfig:Healthcheck:Script Tag is not matching",
343 healthCheck.getEndpoint(),
344 csAuxilaryHealthcheck.getEndpoint());
346 type + " Blueprint:NodeTemplates:DockerConfig:Healthcheck:Type Tag is not matching",
347 healthCheck.getType(),
348 csAuxilaryHealthcheck.getType());
355 * @param onapComponentSpec
356 * @param nodeTemplateProperties
358 public void verifyVolumes(
359 String type, OnapComponentSpec onapComponentSpec, Properties nodeTemplateProperties) {
360 Volumes[] csAuxilaryVolumes = onapComponentSpec.getAuxilary().getVolumes();
362 type + " ComponentSpec Auxilary Live Health Check Section is NULL", csAuxilaryVolumes);
363 Volumes[] onapVolumes = nodeTemplateProperties.getDocker_config().getVolumes();
365 type + " Blueprint:NodeTemplates:DockerConfig:LiveHealthcheck Section is NULL",
373 * @param onapComponentSpec
377 public void verifyArtifacts(
379 OnapComponentSpec onapComponentSpec,
380 Map<String, LinkedHashMap<String, Object>> inputs,
382 Artifacts[] csArtifacts = onapComponentSpec.getArtifacts();
383 assertNotNull(type + " ComponentSpec Artifacts Section is NULL", csArtifacts);
385 type + " Blueprint:Artifacts:image is not matching",
386 ((String) inputs.get("image").get("default")),
387 "\"" + csArtifacts[0].getUri() + "\"");
388 // assertEquals(type + " Blueprint:Artifacts:image is not matching", ((String)
389 // inputs.get("tag_version").get("default")), "\"" + csArtifacts[0].getUri() + "\"");