summaryrefslogtreecommitdiffstats
path: root/mod/bpgenerator/onap/src/test/java/org/onap/blueprintgenerator/test/OnapTestUtils.java
blob: 01845abf795534caf63c2ac9223da5ee0e315e0d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
/*
 *
 *  * ============LICENSE_START=======================================================
 *  *  org.onap.dcae
 *  *  ================================================================================
 *  *  Copyright (c) 2020  AT&T Intellectual Property. All rights reserved.
 *  *  ================================================================================
 *  *  Licensed under the Apache License, Version 2.0 (the "License");
 *  *  you may not use this file except in compliance with the License.
 *  *  You may obtain a copy of the License at
 *  *
 *  *       http://www.apache.org/licenses/LICENSE-2.0
 *  *
 *  *  Unless required by applicable law or agreed to in writing, software
 *  *  distributed under the License is distributed on an "AS IS" BASIS,
 *  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  *  See the License for the specific language governing permissions and
 *  *  limitations under the License.
 *  *  ============LICENSE_END=========================================================
 *
 *
 */

package org.onap.blueprintgenerator.test;

import org.onap.blueprintgenerator.constants.Constants;
import org.onap.blueprintgenerator.model.base.Blueprint;
import org.onap.blueprintgenerator.model.common.Input;
import org.onap.blueprintgenerator.model.common.Node;
import org.onap.blueprintgenerator.model.common.Properties;
import org.onap.blueprintgenerator.model.componentspec.OnapAuxilary;
import org.onap.blueprintgenerator.model.componentspec.OnapComponentSpec;

import org.onap.blueprintgenerator.model.componentspec.common.Calls;
import org.onap.blueprintgenerator.model.componentspec.common.Provides;
import org.onap.blueprintgenerator.model.componentspec.common.HealthCheck;
import org.onap.blueprintgenerator.model.componentspec.common.Parameters;
import org.onap.blueprintgenerator.model.componentspec.common.Volumes;
import org.onap.blueprintgenerator.model.componentspec.common.Artifacts;
import org.onap.blueprintgenerator.model.dmaap.Streams;
import org.junit.Ignore;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.io.File;
import java.io.IOException;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

/**
 * @author : Ravi Mantena
 * @date 10/16/2020 Application: ONAP - Blueprint Generator Test Utilities used in Test Suite and
 * Test Cases
 */
@Component
@Ignore
public class OnapTestUtils extends BlueprintGeneratorTests {

    @Value("${imports.onap.types}")
    private String importsOnapTypes;

    @Value("${imports.onap.K8s.plugintypes}")
    private String importsOnapK8sPlugintypes;

    @Value("${imports.onap.K8s.dcaepolicyplugin}")
    private String importsOnapK8sDcaepolicyplugin;

    @Value("${imports.dmaap.dmaapplugin}")
    private String importsDmaapDmaapplugin;

    @Value("${import.Postgres}")
    private String importPostgres;

    @Value("${import.Clamp}")
    private String importClamp;

    /**
     * Creates Input
     *
     * @param componentSpecPath
     * @param outputPath
     * @param bluePrintName
     * @param importPath
     * @param bpType
     * @param serviceNameOverride
     * @return
     */
    public Input getInput(
        String componentSpecPath,
        String outputPath,
        String bluePrintName,
        String importPath,
        String bpType,
        String serviceNameOverride) {
        Input input = new Input();
        input.setComponentSpecPath(componentSpecPath);
        input.setBluePrintName(bluePrintName);
        input.setOutputPath(outputPath);
        input.setBpType(bpType);
        input.setServiceNameOverride(serviceNameOverride);
        input.setImportPath(importPath);
        return input;
    }

    /**
     * Creates Input from Component Spec Path
     *
     * @param componentSpecPath
     * @return
     */
    public Input getInput(String componentSpecPath) {
        Input input = new Input();
        input.setComponentSpecPath(componentSpecPath);
        return input;
    }

    /**
     * Verifies Tosca Def Version
     *
     * @param type
     * @param blueprint
     * @param toscaDefVersion
     */
    public void verifyToscaDefVersion(String type, Blueprint blueprint, String toscaDefVersion) {
        String bpToscaDefVersion = blueprint.getTosca_definitions_version();
        assertNotNull(type + " TOSCA Definition Version is NULL", bpToscaDefVersion);
        assertEquals(
            type + " TOSCA Definition Version is not Matching", bpToscaDefVersion, toscaDefVersion);
    }

    /**
     * Verifies Imports
     *
     * @param type
     * @param blueprint
     * @param validateimps
     */
    public void verifyBpImports(String type, Blueprint blueprint, boolean validateimps) {
        String[] bpImports = blueprint.getImports()
            .toArray(new String[blueprint.getImports().size()]);
        if (validateimps) {
            String[] testImports = {
                importsOnapTypes,
                importsOnapK8sPlugintypes,
                importsDmaapDmaapplugin,
                importPostgres,
                importClamp
            };
            assertArrayEquals(
                type
                    + " Blueprint Imports is not matching with default Dmaap K8s Blueprint imports",
                bpImports,
                testImports);
        } else {
            String[] testImports = {
                importsOnapTypes,
                importsOnapK8sPlugintypes,
                importsOnapK8sDcaepolicyplugin,
                importPostgres,
                importClamp
            };
            assertArrayEquals(
                type + " Blueprint Imports is not matching with default Onap K8s Blueprint imports",
                bpImports,
                testImports);
        }
    }

    /**
     * Verifies Imports from file
     *
     * @param type
     * @param blueprint
     * @param importPath
     */
    public void verifyBpImportsFromFile(String type, Blueprint blueprint, String importPath)
        throws IOException {
        Blueprint importFileRead = yamlObjectMapper
            .readValue(new File(importPath), Blueprint.class);
        String[] importFileImports =
            importFileRead.getImports().toArray(new String[importFileRead.getImports().size()]);
        String[] bpImports = blueprint.getImports()
            .toArray(new String[blueprint.getImports().size()]);
        assertArrayEquals(
            type + " Blueprint Imports is not matching with default Dmaap K8s Blueprint imports",
            bpImports,
            importFileImports);
    }

    /**
     * Verifies Streams Publishes
     *
     * @param type
     * @param onapComponentSpec
     * @param nodeTemplateProperties
     */
    public void verifyStreamsPublishes(
        String type, OnapComponentSpec onapComponentSpec, Properties nodeTemplateProperties) {
        List<Streams> streamsPublishes = nodeTemplateProperties.getStreams_publishes();
        if (!(streamsPublishes == null)) {
            assertNotNull(
                type + " Blueprint:NodeTemplates:Properties:StreamsPublishes is NULL",
                streamsPublishes);
            assertTrue(
                type + " Blueprint:NodeTemplates:Properties:StreamsPublishes Section Size is 0",
                streamsPublishes.size() > 0);
            assertEquals(
                type + " Blueprint:NodeTemplates:Properties:StreamsPublishes is Not Matching",
                streamsPublishes.get(0).getType(),
                Constants.MESSAGEROUTER_VALUE);
            assertEquals(
                type + " Blueprint:NodeTemplates:Properties:StreamsPublishes is Not Matching",
                streamsPublishes.get(1).getType(),
                Constants.MESSAGEROUTER_VALUE);
        }
    }

    /**
     * Verifies Streams Subscribes
     *
     * @param type
     * @param onapComponentSpec
     * @param nodeTemplateProperties
     */
    public void verifyStreamsSubscribes(
        String type, OnapComponentSpec onapComponentSpec, Properties nodeTemplateProperties) {
        List<Streams> streamsSubscribes = nodeTemplateProperties.getStreams_subscribes();
        if (!(streamsSubscribes == null)) {
            assertNotNull(
                type + " Blueprint:NodeTemplates:Properties:StreamsSubscribes is NULL",
                streamsSubscribes);
            assertTrue(
                type + " Blueprint:NodeTemplates:Properties:StreamsSubscribes Section Size is 0",
                streamsSubscribes.size() > 0);
            assertEquals(
                type + " Blueprint:NodeTemplates:Properties:StreamsSubscribes is Not Matching",
                streamsSubscribes.get(0).getType(),
                Constants.MESSAGE_ROUTER);
            assertEquals(
                type + " Blueprint:NodeTemplates:Properties:StreamsSubscribes is Not Matching",
                streamsSubscribes.get(1).getType(),
                Constants.DATA_ROUTER);
        }
    }

    /**
     * Verifies Services Calls
     *
     * @param type
     * @param onapComponentSpec
     */
    public void verifyServicesCalls(String type, OnapComponentSpec onapComponentSpec) {
        Calls[] csServicesCalls = onapComponentSpec.getServices().getCalls();
        assertNotNull(type + " ComponentSpec Services Calls is NULL", csServicesCalls);
        // assertTrue(type + " ComponentSpec Services Calls Section Size is 0", csServicesCalls.length >
        // 0);
    }

    /**
     * Verifies Services Provides
     *
     * @param type
     * @param onapComponentSpec
     */
    public void verifyServicesProvides(String type, OnapComponentSpec onapComponentSpec) {
        Provides[] csServicesProvides = onapComponentSpec.getServices().getProvides();
        assertNotNull(type + " ComponentSpec Services Provides is NULL", csServicesProvides);
        assertTrue(
            type + " ComponentSpec Services Provides Section Size is 0",
            csServicesProvides.length > 0);
    }

    /**
     * Verifies Docker Config
     *
     * @param type
     * @param onapComponentSpec
     * @param nodeTemplateProperties
     */
    public void verifyDockerConfig(
        String type, OnapComponentSpec onapComponentSpec, Properties nodeTemplateProperties) {
        OnapAuxilary dockerConfig = nodeTemplateProperties.getDocker_config();
        assertNotNull(type + " Blueprint Docker Config Section is NULL", dockerConfig);
    }

    /**
     * Verifies Parameters
     *
     * @param type
     * @param onapComponentSpec
     * @param nodeTemplates
     */
    public void verifyParameters(
        String type, OnapComponentSpec onapComponentSpec, Map<String, Node> nodeTemplates) {
        Parameters[] csParameters = onapComponentSpec.getParameters();
        assertNotNull(type + " ComponentSpec Parameters Section is NULL", csParameters);
        assertTrue(type + " ComponentSpec Parameters Section Size is 0", csParameters.length > 0);
    }

    /**
     * Verifies Auxilary
     *
     * @param type
     * @param onapComponentSpec
     */
    public void verifyAuxilary(String type, OnapComponentSpec onapComponentSpec) {
        OnapAuxilary csAuxilary = onapComponentSpec.getAuxilary();
        assertNotNull(type + " ComponentSpec Auxilary Section is NULL", csAuxilary);
    }

    /**
     * Verifies HealthCheck
     *
     * @param type
     * @param onapComponentSpec
     * @param nodeTemplateProperties
     */
    public void verifyHealthCheck(
        String type, OnapComponentSpec onapComponentSpec, Properties nodeTemplateProperties) {
        HealthCheck csAuxilaryHealthcheck = onapComponentSpec.getAuxilary().getHealthcheck();
        assertNotNull(
            type + " ComponentSpec Auxilary Health Check Section is NULL", csAuxilaryHealthcheck);
        HealthCheck healthCheck = nodeTemplateProperties.getDocker_config().getHealthcheck();
        assertNotNull(
            type + " Blueprint:NodeTemplates:DockerConfig:Healthcheck Section is NULL",
            healthCheck);
        assertEquals(
            type + " Blueprint:NodeTemplates:DockerConfig:Healthcheck:Interval Tag is not matching",
            healthCheck.getInterval(),
            csAuxilaryHealthcheck.getInterval());
        assertEquals(
            type + " Blueprint:NodeTemplates:DockerConfig:Healthcheck:Timeout Tag is not matching",
            healthCheck.getTimeout(),
            csAuxilaryHealthcheck.getTimeout());
        assertEquals(
            type + " Blueprint:NodeTemplates:DockerConfig:Healthcheck:Script Tag is not matching",
            healthCheck.getEndpoint(),
            csAuxilaryHealthcheck.getEndpoint());
        assertEquals(
            type + " Blueprint:NodeTemplates:DockerConfig:Healthcheck:Type Tag is not matching",
            healthCheck.getType(),
            csAuxilaryHealthcheck.getType());
    }

    /**
     * Verifies Volumes
     *
     * @param type
     * @param onapComponentSpec
     * @param nodeTemplateProperties
     */
    public void verifyVolumes(
        String type, OnapComponentSpec onapComponentSpec, Properties nodeTemplateProperties) {
        Volumes[] csAuxilaryVolumes = onapComponentSpec.getAuxilary().getVolumes();
        assertNotNull(
            type + " ComponentSpec Auxilary Live Health Check Section is NULL", csAuxilaryVolumes);
        Volumes[] onapVolumes = nodeTemplateProperties.getDocker_config().getVolumes();
        assertNotNull(
            type + " Blueprint:NodeTemplates:DockerConfig:LiveHealthcheck Section is NULL",
            onapVolumes);
    }

    /**
     * Verifies Artifacts
     *
     * @param type
     * @param onapComponentSpec
     * @param inputs
     * @param bptype
     */
    public void verifyArtifacts(
        String type,
        OnapComponentSpec onapComponentSpec,
        Map<String, LinkedHashMap<String, Object>> inputs,
        String bptype) {
        Artifacts[] csArtifacts = onapComponentSpec.getArtifacts();
        assertNotNull(type + " ComponentSpec Artifacts Section is NULL", csArtifacts);
        assertEquals(
            type + " Blueprint:Artifacts:image is not matching",
            ((String) inputs.get("image").get("default")),
            "\"" + csArtifacts[0].getUri() + "\"");
        // assertEquals(type + " Blueprint:Artifacts:image is not matching", ((String)
        // inputs.get("tag_version").get("default")), "\"" + csArtifacts[0].getUri() + "\"");

    }
}