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;
58 * @author : Ravi Mantena
60 * Application: ONAP - Blueprint Generator
61 * Test Utilities used in Test Suite and Test Cases
66 public class OnapTestUtils extends BlueprintGeneratorTests {
68 @Value("${imports.onap.types}")
69 private String importsOnapTypes;
71 @Value("${imports.onap.K8s.plugintypes}")
72 private String importsOnapK8sPlugintypes;
74 @Value("${imports.onap.K8s.dcaepolicyplugin}")
75 private String importsOnapK8sDcaepolicyplugin;
77 @Value("${imports.dmaap.dmaapplugin}")
78 private String importsDmaapDmaapplugin;
80 @Value("${import.Postgres}")
81 private String importPostgres;
83 @Value("${import.Clamp}")
84 private String importClamp;
88 public Input getInput(String componentSpecPath,String outputPath,String bluePrintName,String importPath,String bpType,String serviceNameOverride){
89 Input input = new Input();
90 input.setComponentSpecPath(componentSpecPath);
91 input.setBluePrintName(bluePrintName);
92 input.setOutputPath(outputPath);
93 input.setBpType(bpType);
94 input.setServiceNameOverride(serviceNameOverride);
95 input.setImportPath(importPath);
99 public Input getInput(String componentSpecPath){
100 Input input = new Input();
101 input.setComponentSpecPath(componentSpecPath);
105 public void verifyToscaDefVersion(String type,Blueprint blueprint,String toscaDefVersion){
106 String bpToscaDefVersion = blueprint.getTosca_definitions_version();
107 assertNotNull(type + " TOSCA Definition Version is NULL", bpToscaDefVersion);
108 assertEquals(type + " TOSCA Definition Version is not Matching", bpToscaDefVersion, toscaDefVersion);
111 public void verifyBpImports(String type,Blueprint blueprint, boolean validateimps) {
112 String[] bpImports = blueprint.getImports().toArray(new String[blueprint.getImports().size()]);
114 String[] testImports = {importsOnapTypes,importsOnapK8sPlugintypes,importsDmaapDmaapplugin,importPostgres,importClamp};
115 assertArrayEquals(type + " Blueprint Imports is not matching with default Dmaap K8s Blueprint imports", bpImports, testImports);
118 String[] testImports = {importsOnapTypes,importsOnapK8sPlugintypes,importsOnapK8sDcaepolicyplugin,importPostgres,importClamp};
119 assertArrayEquals(type + " Blueprint Imports is not matching with default Onap K8s Blueprint imports", bpImports, testImports);
124 public void verifyBpImportsFromFile(String type,Blueprint blueprint, String importPath) throws IOException {
125 Blueprint importFileRead = yamlObjectMapper.readValue(new File(importPath), Blueprint.class);
126 String[] importFileImports = importFileRead.getImports().toArray(new String[importFileRead.getImports().size()]);
127 String[] bpImports = blueprint.getImports().toArray(new String[blueprint.getImports().size()]);
128 assertArrayEquals(type + " Blueprint Imports is not matching with default Dmaap K8s Blueprint imports", bpImports, importFileImports);
132 public void verifyStreamsPublishes(String type, OnapComponentSpec onapComponentSpec, Properties nodeTemplateProperties) {
133 List<Streams> streamsPublishes = nodeTemplateProperties.getStreams_publishes();
134 if (!(streamsPublishes == null)) {
135 assertNotNull(type + " Blueprint:NodeTemplates:Properties:StreamsPublishes is NULL", streamsPublishes);
136 assertTrue(type + " Blueprint:NodeTemplates:Properties:StreamsPublishes Section Size is 0", streamsPublishes.size() > 0);
137 assertEquals(type + " Blueprint:NodeTemplates:Properties:StreamsPublishes is Not Matching", streamsPublishes.get(0).getType(), Constants.MESSAGEROUTER_VALUE);
138 assertEquals(type + " Blueprint:NodeTemplates:Properties:StreamsPublishes is Not Matching", streamsPublishes.get(1).getType(), Constants.MESSAGEROUTER_VALUE);
142 public void verifyStreamsSubscribes(String type,OnapComponentSpec onapComponentSpec, Properties nodeTemplateProperties){
143 List<Streams> streamsSubscribes = nodeTemplateProperties.getStreams_subscribes();
144 if (!(streamsSubscribes == null)) {
145 assertNotNull(type + " Blueprint:NodeTemplates:Properties:StreamsSubscribes is NULL", streamsSubscribes);
146 assertTrue(type + " Blueprint:NodeTemplates:Properties:StreamsSubscribes Section Size is 0", streamsSubscribes.size() > 0);
147 assertEquals(type + " Blueprint:NodeTemplates:Properties:StreamsSubscribes is Not Matching", streamsSubscribes.get(0).getType(), Constants.MESSAGE_ROUTER);
148 assertEquals(type + " Blueprint:NodeTemplates:Properties:StreamsSubscribes is Not Matching", streamsSubscribes.get(1).getType(), Constants.DATA_ROUTER);
152 public void verifyServicesCalls(String type, OnapComponentSpec onapComponentSpec){
153 Calls[] csServicesCalls = onapComponentSpec.getServices().getCalls();
154 assertNotNull(type + " ComponentSpec Services Calls is NULL", csServicesCalls);
155 //assertTrue(type + " ComponentSpec Services Calls Section Size is 0", csServicesCalls.length > 0);
158 public void verifyServicesProvides(String type, OnapComponentSpec onapComponentSpec){
159 Provides[] csServicesProvides = onapComponentSpec.getServices().getProvides();
160 assertNotNull(type + " ComponentSpec Services Provides is NULL", csServicesProvides);
161 assertTrue(type + " ComponentSpec Services Provides Section Size is 0", csServicesProvides.length > 0);
164 public void verifyDockerConfig(String type,OnapComponentSpec onapComponentSpec, Properties nodeTemplateProperties){
165 OnapAuxilary dockerConfig = nodeTemplateProperties.getDocker_config();
166 assertNotNull(type +" Blueprint Docker Config Section is NULL", dockerConfig);
170 public void verifyParameters(String type, OnapComponentSpec onapComponentSpec, Map<String, Node> nodeTemplates) {
171 Parameters[] csParameters = onapComponentSpec.getParameters();
172 assertNotNull(type +" ComponentSpec Parameters Section is NULL", csParameters);
173 assertTrue(type + " ComponentSpec Parameters Section Size is 0", csParameters.length > 0);
176 public void verifyAuxilary(String type, OnapComponentSpec onapComponentSpec){
177 OnapAuxilary csAuxilary = onapComponentSpec.getAuxilary();
178 assertNotNull(type +" ComponentSpec Auxilary Section is NULL", csAuxilary);
181 public void verifyHealthCheck(String type,OnapComponentSpec onapComponentSpec, Properties nodeTemplateProperties){
182 HealthCheck csAuxilaryHealthcheck = onapComponentSpec.getAuxilary().getHealthcheck();
183 assertNotNull(type +" ComponentSpec Auxilary Health Check Section is NULL", csAuxilaryHealthcheck);
184 HealthCheck healthCheck = nodeTemplateProperties.getDocker_config().getHealthcheck();
185 assertNotNull(type + " Blueprint:NodeTemplates:DockerConfig:Healthcheck Section is NULL", healthCheck);
186 assertEquals(type + " Blueprint:NodeTemplates:DockerConfig:Healthcheck:Interval Tag is not matching", healthCheck.getInterval(), csAuxilaryHealthcheck.getInterval());
187 assertEquals(type + " Blueprint:NodeTemplates:DockerConfig:Healthcheck:Timeout Tag is not matching", healthCheck.getTimeout(), csAuxilaryHealthcheck.getTimeout());
188 assertEquals(type + " Blueprint:NodeTemplates:DockerConfig:Healthcheck:Script Tag is not matching", healthCheck.getEndpoint(), csAuxilaryHealthcheck.getEndpoint());
189 assertEquals(type + " Blueprint:NodeTemplates:DockerConfig:Healthcheck:Type Tag is not matching", healthCheck.getType(), csAuxilaryHealthcheck.getType());
192 public void verifyVolumes(String type,OnapComponentSpec onapComponentSpec, Properties nodeTemplateProperties){
193 Volumes[] csAuxilaryVolumes = onapComponentSpec.getAuxilary().getVolumes();
194 assertNotNull(type +" ComponentSpec Auxilary Live Health Check Section is NULL", csAuxilaryVolumes);
195 Volumes[] onapVolumes = nodeTemplateProperties.getDocker_config().getVolumes();
196 assertNotNull(type + " Blueprint:NodeTemplates:DockerConfig:LiveHealthcheck Section is NULL", onapVolumes);
199 public void verifyArtifacts(String type,OnapComponentSpec onapComponentSpec, Map<String, LinkedHashMap<String, Object>> inputs,String bptype){
200 Artifacts[] csArtifacts = onapComponentSpec.getArtifacts();
201 assertNotNull(type + " ComponentSpec Artifacts Section is NULL", csArtifacts);
202 assertEquals(type + " Blueprint:Artifacts:image is not matching", ((String) inputs.get("image").get("default")), "\"" + csArtifacts[0].getUri() + "\"");
203 //assertEquals(type + " Blueprint:Artifacts:image is not matching", ((String) inputs.get("tag_version").get("default")), "\"" + csArtifacts[0].getUri() + "\"");