dcfbe94b7c015bdaa2f7c9ecf11af80a88450522
[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.simulator.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.assertTrue;
27
28 import org.junit.Test;
29 import org.onap.policy.common.parameters.GroupValidationResult;
30
31 /**
32  * Class to perform unit test of {@link ParticipantParameterGroup}.
33  */
34 public class TestParticipantSimulatorParameters {
35     CommonTestData commonTestData = new CommonTestData();
36
37     @Test
38     public void testParticipantParameterGroup_Named() {
39         final ParticipantSimulatorParameters participantParameters = new ParticipantSimulatorParameters("my-name");
40         assertEquals("my-name", participantParameters.getName());
41     }
42
43     @Test
44     public void testParticipantParameterGroup() {
45         final ParticipantSimulatorParameters participantParameters = commonTestData.toObject(
46                 commonTestData.getParticipantParameterGroupMap(CommonTestData.PARTICIPANT_GROUP_NAME),
47                 ParticipantSimulatorParameters.class);
48         assertThat(participantParameters.validate().isValid()).isTrue();
49         assertEquals(CommonTestData.PARTICIPANT_GROUP_NAME, participantParameters.getName());
50     }
51
52     @Test
53     public void testParticipantParameterGroup_NullName() {
54         final ParticipantSimulatorParameters participantParameters = commonTestData
55                 .toObject(commonTestData.getParticipantParameterGroupMap(null),
56                         ParticipantSimulatorParameters.class);
57         final GroupValidationResult validationResult = participantParameters.validate();
58         assertFalse(validationResult.isValid());
59         assertEquals(null, participantParameters.getName());
60         assertTrue(validationResult.getResult().contains("is null"));
61     }
62
63     @Test
64     public void testParticipantParameterGroup_EmptyName() {
65         final ParticipantSimulatorParameters participantParameters = commonTestData
66                 .toObject(commonTestData.getParticipantParameterGroupMap(""),
67                                 ParticipantSimulatorParameters.class);
68         final GroupValidationResult validationResult = participantParameters.validate();
69         assertFalse(validationResult.isValid());
70         assertEquals("", participantParameters.getName());
71         assertTrue(validationResult.getResult().contains(
72                 "field \"name\" type \"java.lang.String\" value \"\" INVALID, " + "must be a non-blank string"));
73     }
74
75     @Test
76     public void testParticipantParameterGroup_SetName() {
77         final ParticipantSimulatorParameters participantParameters = commonTestData.toObject(
78                 commonTestData.getParticipantParameterGroupMap(CommonTestData.PARTICIPANT_GROUP_NAME),
79                 ParticipantSimulatorParameters.class);
80         participantParameters.setName("ParticipantNewGroup");
81         assertThat(participantParameters.validate().isValid()).isTrue();
82         assertEquals("ParticipantNewGroup", participantParameters.getName());
83     }
84 }