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