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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.clamp.controlloop.participant.kubernetes.parameters;
23 import static org.assertj.core.api.Assertions.assertThat;
26 import javax.validation.ConstraintViolation;
27 import javax.validation.Validation;
28 import javax.validation.ValidatorFactory;
29 import org.junit.jupiter.api.Test;
31 class ParticipantK8sParametersTest {
33 private CommonTestData commonTestData = new CommonTestData();
34 private ValidatorFactory validatorFactory = Validation.buildDefaultValidatorFactory();
37 void testParticipantPolicyParameters() {
38 final ParticipantK8sParameters participantParameters = commonTestData.getParticipantK8sParameters();
39 assertThat(validatorFactory.getValidator().validate(participantParameters)).isNullOrEmpty();
43 void testParticipantK8sParameters_NullTopicSinks() {
44 final ParticipantK8sParameters participantParameters = commonTestData.getParticipantK8sParameters();
45 participantParameters.getIntermediaryParameters().getClampControlLoopTopics().setTopicSinks(null);
46 assertThat(validatorFactory.getValidator().validate(participantParameters)).isNotEmpty();
50 void testParticipantK8sParameters_NullTopicSources() {
51 final ParticipantK8sParameters participantParameters = commonTestData.getParticipantK8sParameters();
52 participantParameters.getIntermediaryParameters().getClampControlLoopTopics().setTopicSources(null);
53 assertThat(validatorFactory.getValidator().validate(participantParameters)).isNotEmpty();
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);
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);
75 void testNoIntermediaryParameters() {
76 final ParticipantK8sParameters participantParameters = commonTestData.getParticipantK8sParameters();
77 participantParameters.setIntermediaryParameters(null);
78 assertThat(validatorFactory.getValidator().validate(participantParameters)).isNotEmpty();
82 void testNoParticipantId() {
83 final ParticipantK8sParameters participantParameters = commonTestData.getParticipantK8sParameters();
84 participantParameters.getIntermediaryParameters().setParticipantId(null);
85 assertThat(validatorFactory.getValidator().validate(participantParameters)).isNotEmpty();