Merge "Convert models to JUnit 5"
[policy/models.git] / models-sim / policy-models-sim-pdp / src / test / java / org / onap / policy / models / sim / pdp / parameters / TestPdpSimulatorParameterGroup.java
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2019 Nordix Foundation.
4  *  Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
5  *  Modifications Copyright (C) 2024 Nordix Foundation
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  * SPDX-License-Identifier: Apache-2.0
20  * ============LICENSE_END=========================================================
21  */
22
23 package org.onap.policy.models.sim.pdp.parameters;
24
25 import static org.assertj.core.api.Assertions.assertThat;
26 import static org.junit.jupiter.api.Assertions.assertEquals;
27 import static org.junit.jupiter.api.Assertions.assertFalse;
28 import static org.junit.jupiter.api.Assertions.assertTrue;
29
30 import java.util.Map;
31 import org.junit.jupiter.api.Test;
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 PdpSimulatorParameterGroup}.
37  *
38  * @author Ajith Sreekumar (ajith.sreekumar@est.tech)
39  */
40 class TestPdpSimulatorParameterGroup {
41     CommonTestData commonTestData = new CommonTestData();
42
43     @Test
44     void testPdpSimulatorParameterGroup_Named() {
45         final PdpSimulatorParameterGroup pdpSimulatorParameters = new PdpSimulatorParameterGroup("my-name");
46         assertEquals("my-name", pdpSimulatorParameters.getName());
47     }
48
49     @Test
50     void testPdpSimulatorParameterGroup() {
51         final PdpSimulatorParameterGroup pdpSimulatorParameters = commonTestData.toObject(
52                 commonTestData.getPdpSimulatorParameterGroupMap(CommonTestData.PDP_SIMULATOR_GROUP_NAME),
53                 PdpSimulatorParameterGroup.class);
54         final PdpStatusParameters pdpStatusParameters = pdpSimulatorParameters.getPdpStatusParameters();
55         final TopicParameterGroup topicParameterGroup  = pdpSimulatorParameters.getTopicParameterGroup();
56         final ValidationResult validationResult = pdpSimulatorParameters.validate();
57         assertTrue(validationResult.isValid());
58         assertEquals(CommonTestData.PDP_SIMULATOR_GROUP_NAME, pdpSimulatorParameters.getName());
59         assertEquals(CommonTestData.TIME_INTERVAL, pdpStatusParameters.getTimeIntervalMs());
60         assertEquals(CommonTestData.PDP_TYPE, pdpStatusParameters.getPdpType());
61         assertEquals(CommonTestData.DESCRIPTION, pdpStatusParameters.getDescription());
62         assertEquals(CommonTestData.SUPPORTED_POLICY_TYPES, pdpStatusParameters.getSupportedPolicyTypes());
63         assertEquals(CommonTestData.TOPIC_PARAMS, topicParameterGroup.getTopicSinks());
64         assertEquals(CommonTestData.TOPIC_PARAMS, topicParameterGroup.getTopicSources());
65     }
66
67     @Test
68     void testPdpSimulatorParameterGroup_NullName() {
69         final PdpSimulatorParameterGroup pdpSimulatorParameters = commonTestData
70                 .toObject(commonTestData.getPdpSimulatorParameterGroupMap(null), PdpSimulatorParameterGroup.class);
71         final ValidationResult validationResult = pdpSimulatorParameters.validate();
72         assertFalse(validationResult.isValid());
73         assertEquals(null, pdpSimulatorParameters.getName());
74         assertTrue(validationResult.getResult().contains("is null"));
75     }
76
77     @Test
78     void testPdpSimulatorParameterGroup_EmptyName() {
79         final PdpSimulatorParameterGroup pdpSimulatorParameters = commonTestData
80                 .toObject(commonTestData.getPdpSimulatorParameterGroupMap(""), PdpSimulatorParameterGroup.class);
81         final ValidationResult validationResult = pdpSimulatorParameters.validate();
82         assertFalse(validationResult.isValid());
83         assertEquals("", pdpSimulatorParameters.getName());
84         assertThat(validationResult.getResult()).contains(
85                 "\"name\" value \"\" INVALID, " + "is blank");
86     }
87
88     @Test
89     void testPdpSimulatorParameterGroup_SetName() {
90         final PdpSimulatorParameterGroup pdpSimulatorParameters = commonTestData.toObject(
91                 commonTestData.getPdpSimulatorParameterGroupMap(CommonTestData.PDP_SIMULATOR_GROUP_NAME),
92                 PdpSimulatorParameterGroup.class);
93         pdpSimulatorParameters.setName("PdpSimulatorNewGroup");
94         final ValidationResult validationResult = pdpSimulatorParameters.validate();
95         assertTrue(validationResult.isValid());
96         assertEquals("PdpSimulatorNewGroup", pdpSimulatorParameters.getName());
97     }
98
99     @Test
100     void testPdpSimulatorParameterGroup_EmptyPdpStatusParameters() {
101         final Map<String, Object> map =
102                 commonTestData.getPdpSimulatorParameterGroupMap(CommonTestData.PDP_SIMULATOR_GROUP_NAME);
103         map.put("pdpStatusParameters", commonTestData.getPdpStatusParametersMap(true));
104         final PdpSimulatorParameterGroup pdpSimulatorParameters =
105                 commonTestData.toObject(map, PdpSimulatorParameterGroup.class);
106         final ValidationResult validationResult = pdpSimulatorParameters.validate();
107         assertFalse(validationResult.isValid());
108         assertThat(validationResult.getResult())
109                 .contains("\"PdpSimulatorParameterGroup\" INVALID, item has status INVALID");
110     }
111
112     @Test
113     void testApexStarterParameterGroupp_EmptyTopicParameters() {
114         final Map<String, Object> map =
115                 commonTestData.getPdpSimulatorParameterGroupMap(CommonTestData.PDP_SIMULATOR_GROUP_NAME);
116         map.put("topicParameterGroup", commonTestData.getTopicParametersMap(true));
117
118         final PdpSimulatorParameterGroup parGroup =
119                 commonTestData.toObject(map, PdpSimulatorParameterGroup.class);
120         final ValidationResult validationResult = parGroup.validate();
121         assertFalse(validationResult.isValid());
122         assertThat(validationResult.getResult())
123                 .contains("\"TopicParameterGroup\" INVALID, item has status INVALID");
124     }
125
126 }