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