177d7bc230c06d4d27b6e15b8ec1b6084ab449fb
[policy/clamp.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2021 Nordix Foundation.
4  * ================================================================================
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  * SPDX-License-Identifier: Apache-2.0
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.policy.clamp.controlloop.participant.kubernetes.parameters;
22
23 import static org.assertj.core.api.Assertions.assertThat;
24
25 import java.util.Set;
26 import javax.validation.ConstraintViolation;
27 import javax.validation.Validation;
28 import javax.validation.ValidatorFactory;
29 import org.junit.jupiter.api.Test;
30
31 class ParticipantK8sParametersTest {
32
33     private CommonTestData commonTestData = new CommonTestData();
34     private ValidatorFactory validatorFactory = Validation.buildDefaultValidatorFactory();
35
36     @Test
37     void testParticipantPolicyParameters() {
38         final ParticipantK8sParameters participantParameters = commonTestData.getParticipantK8sParameters();
39         assertThat(validatorFactory.getValidator().validate(participantParameters)).isNullOrEmpty();
40     }
41
42     @Test
43     void testParticipantK8sParameters_NullTopicSinks() {
44         final ParticipantK8sParameters participantParameters = commonTestData.getParticipantK8sParameters();
45         participantParameters.getIntermediaryParameters().getClampControlLoopTopics().setTopicSinks(null);
46         assertThat(validatorFactory.getValidator().validate(participantParameters)).isNotEmpty();
47     }
48
49     @Test
50     void testParticipantK8sParameters_NullTopicSources() {
51         final ParticipantK8sParameters participantParameters = commonTestData.getParticipantK8sParameters();
52         participantParameters.getIntermediaryParameters().getClampControlLoopTopics().setTopicSources(null);
53         assertThat(validatorFactory.getValidator().validate(participantParameters)).isNotEmpty();
54     }
55
56     @Test
57     void testParticipantK8sParameters_BlankLocalChartDirParameter() {
58         final ParticipantK8sParameters participantParameters = commonTestData.getParticipantK8sParameters();
59         participantParameters.setLocalChartDirectory(" ");
60         Set<ConstraintViolation<ParticipantK8sParameters>> violations = validatorFactory.getValidator()
61             .validate(participantParameters);
62         assertThat(violations.size()).isEqualTo(1);
63     }
64
65     @Test
66     void testParticipantK8sParameters_BlankInfoFileParameter() {
67         final ParticipantK8sParameters participantParameters = commonTestData.getParticipantK8sParameters();
68         participantParameters.setInfoFileName("");
69         Set<ConstraintViolation<ParticipantK8sParameters>> violations = validatorFactory.getValidator()
70             .validate(participantParameters);
71         assertThat(violations.size()).isEqualTo(1);
72     }
73
74     @Test
75     void testNoIntermediaryParameters() {
76         final ParticipantK8sParameters participantParameters = commonTestData.getParticipantK8sParameters();
77         participantParameters.setIntermediaryParameters(null);
78         assertThat(validatorFactory.getValidator().validate(participantParameters)).isNotEmpty();
79     }
80
81     @Test
82     void testNoParticipantId() {
83         final ParticipantK8sParameters participantParameters = commonTestData.getParticipantK8sParameters();
84         participantParameters.getIntermediaryParameters().setParticipantId(null);
85         assertThat(validatorFactory.getValidator().validate(participantParameters)).isNotEmpty();
86     }
87
88 }