aboutsummaryrefslogtreecommitdiffstats
path: root/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/java/org/openecomp/sdc/validation/impl/util/HelmValidatorConfigReaderTest.java
blob: ba4728f8d524add40f14970bf2ca112c0d3e9418 (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
/*
 * ============LICENSE_START=======================================================
 *  Copyright (C) 2021 Nokia
 *  ================================================================================
 *  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.
 *
 *  SPDX-License-Identifier: Apache-2.0
 *  ============LICENSE_END=========================================================
 */

package org.openecomp.sdc.validation.impl.util;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.when;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.onap.config.api.Configuration;
import org.openecomp.sdc.validation.type.helmvalidator.HelmValidatorConfig;

@ExtendWith(MockitoExtension.class)
class HelmValidatorConfigReaderTest {

    private final static String CONFIG_NAMESPACE = "helmvalidator";
    @Mock
    private Configuration configuration;

    @ParameterizedTest
    @ValueSource(strings = {"v3", "3.4.5"})
    void shouldReadVersionFromConfig(String helmVersion) {
        //given
        when(configuration.getAsString(CONFIG_NAMESPACE, "hValidatorVersion")).thenReturn(helmVersion);
        HelmValidatorConfigReader helmValidatorConfigReader = new HelmValidatorConfigReader(configuration);
        //when
        HelmValidatorConfig helmValidatorConfig = helmValidatorConfigReader.getHelmValidatorConfig();
        //then
        assertEquals(helmVersion, helmValidatorConfig.getVersion());
    }

    @ParameterizedTest
    @ValueSource(strings = {"http://localhost:3211", "https://test-abc"})
    void shouldReadValidatorUrlFromConfig(String validatorUrl) {
        //given
        when(configuration.getAsString(CONFIG_NAMESPACE, "hValidatorUrl")).thenReturn(validatorUrl);
        HelmValidatorConfigReader helmValidatorConfigReader = new HelmValidatorConfigReader(configuration);
        //when
        HelmValidatorConfig helmValidatorConfig = helmValidatorConfigReader.getHelmValidatorConfig();
        //then
        assertEquals(validatorUrl, helmValidatorConfig.getValidatorUrl());
    }

    @ParameterizedTest
    @ValueSource(booleans = {true, false})
    void shouldReadEnabledValueFromConfig(boolean isEnabled) {
        //given
        when(configuration.getAsBooleanValue(CONFIG_NAMESPACE, "hValidatorEnabled")).thenReturn(isEnabled);
        HelmValidatorConfigReader helmValidatorConfigReader = new HelmValidatorConfigReader(configuration);
        //when
        HelmValidatorConfig helmValidatorConfig = helmValidatorConfigReader.getHelmValidatorConfig();
        //then
        Assertions.assertEquals(isEnabled, helmValidatorConfig.isEnabled());
    }

    @ParameterizedTest
    @ValueSource(booleans = {true, false})
    void shouldReadDeployableValueFromConfig(boolean isDeployable) {
        //given
        when(configuration.getAsBooleanValue(CONFIG_NAMESPACE, "hValidatorDeployable")).thenReturn(isDeployable);
        HelmValidatorConfigReader helmValidatorConfigReader = new HelmValidatorConfigReader(configuration);
        //when
        HelmValidatorConfig helmValidatorConfig = helmValidatorConfigReader.getHelmValidatorConfig();
        //then
        Assertions.assertEquals(isDeployable, helmValidatorConfig.isDeployable());
    }

    @ParameterizedTest
    @ValueSource(booleans = {true, false})
    void shouldReadLintableValueFromConfig(boolean isLintable) {
        //given
        when(configuration.getAsBooleanValue(CONFIG_NAMESPACE, "hValidatorLintable")).thenReturn(isLintable);
        HelmValidatorConfigReader helmValidatorConfigReader = new HelmValidatorConfigReader(configuration);
        //when
        HelmValidatorConfig helmValidatorConfig = helmValidatorConfigReader.getHelmValidatorConfig();
        //then
        Assertions.assertEquals(isLintable, helmValidatorConfig.isLintable());
    }

    @ParameterizedTest
    @ValueSource(booleans = {true, false})
    void shouldReadStrictLintableValueFromConfig(boolean isStrictLintable) {
        //given
        when(configuration.getAsBooleanValue(CONFIG_NAMESPACE, "hValidatorStrictLintable"))
            .thenReturn(isStrictLintable);
        HelmValidatorConfigReader helmValidatorConfigReader = new HelmValidatorConfigReader(configuration);
        //when
        HelmValidatorConfig helmValidatorConfig = helmValidatorConfigReader.getHelmValidatorConfig();
        //then
        Assertions.assertEquals(isStrictLintable, helmValidatorConfig.isStrictLintable());
    }
}