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.dcae.main.parameters;
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertNull;
25 import static org.junit.Assert.assertTrue;
28 import org.junit.jupiter.api.Test;
29 import org.onap.policy.clamp.controlloop.participant.intermediary.parameters.ParticipantIntermediaryParameters;
30 import org.onap.policy.common.endpoints.parameters.TopicParameterGroup;
31 import org.onap.policy.common.parameters.ValidationResult;
34 * Class to perform unit test of {@link ParticipantParameterGroup}.
37 class TestParticipantDcaeParameters {
38 CommonTestData commonTestData = new CommonTestData();
41 void testParticipantParameterGroup_Named() {
42 final ParticipantDcaeParameters participantParameters = new ParticipantDcaeParameters("my-name");
43 assertEquals("my-name", participantParameters.getName());
47 void testParticipantParameterGroup() {
48 final ParticipantDcaeParameters participantParameters = commonTestData.toObject(
49 commonTestData.getParticipantParameterGroupMap(CommonTestData.PARTICIPANT_GROUP_NAME),
50 ParticipantDcaeParameters.class);
51 final ParticipantIntermediaryParameters participantIntermediaryParameters = participantParameters
52 .getIntermediaryParameters();
53 final TopicParameterGroup topicParameterGroup = participantParameters.getIntermediaryParameters()
54 .getClampControlLoopTopics();
55 final ValidationResult validationResult = participantParameters.validate();
56 assertTrue(validationResult.isValid());
57 assertEquals(CommonTestData.PARTICIPANT_GROUP_NAME, participantParameters.getName());
58 assertEquals(CommonTestData.TIME_INTERVAL, participantIntermediaryParameters.getReportingTimeInterval());
59 assertEquals(CommonTestData.DESCRIPTION, participantIntermediaryParameters.getDescription());
60 assertEquals(CommonTestData.TOPIC_PARAMS, topicParameterGroup.getTopicSinks());
61 assertEquals(CommonTestData.TOPIC_PARAMS, topicParameterGroup.getTopicSources());
65 void testParticipantParameterGroup_EmptyParticipantIntermediaryParameters() {
66 final Map<String, Object> map =
67 commonTestData.getParticipantParameterGroupMap(CommonTestData.PARTICIPANT_GROUP_NAME);
68 map.replace("intermediaryParameters", commonTestData.getIntermediaryParametersMap(true));
69 final ParticipantDcaeParameters participantParameters =
70 commonTestData.toObject(map, ParticipantDcaeParameters.class);
71 final ValidationResult validationResult = participantParameters.validate();
72 assertNull(validationResult.getResult());
76 void testParticipantParameterGroup_EmptyTopicParameters() {
77 final Map<String, Object> map =
78 commonTestData.getParticipantParameterGroupMap(CommonTestData.PARTICIPANT_GROUP_NAME);
79 final Map<String, Object> intermediaryParametersMap = commonTestData.getIntermediaryParametersMap(false);
80 intermediaryParametersMap.put("clampControlLoopTopics", commonTestData.getTopicParametersMap(true));
81 map.replace("intermediaryParameters", intermediaryParametersMap);
83 final ParticipantDcaeParameters participantParameters =
84 commonTestData.toObject(map, ParticipantDcaeParameters.class);
85 final ValidationResult validationResult = participantParameters.validate();
86 assertNull(validationResult.getResult());