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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 * SPDX-License-Identifier: Apache-2.0
20 * ============LICENSE_END=========================================================
23 package org.onap.policy.models.sim.pdp.parameters;
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.assertNull;
29 import static org.junit.jupiter.api.Assertions.assertTrue;
32 import org.junit.jupiter.api.Test;
33 import org.onap.policy.common.parameters.ValidationResult;
34 import org.onap.policy.common.parameters.topic.TopicParameterGroup;
37 * Class to perform unit test of {@link PdpSimulatorParameterGroup}.
39 * @author Ajith Sreekumar (ajith.sreekumar@est.tech)
41 class TestPdpSimulatorParameterGroup {
42 CommonTestData commonTestData = new CommonTestData();
45 void testPdpSimulatorParameterGroup_Named() {
46 final PdpSimulatorParameterGroup pdpSimulatorParameters = new PdpSimulatorParameterGroup("my-name");
47 assertEquals("my-name", pdpSimulatorParameters.getName());
51 void testPdpSimulatorParameterGroup() {
52 final PdpSimulatorParameterGroup pdpSimulatorParameters = commonTestData.toObject(
53 commonTestData.getPdpSimulatorParameterGroupMap(CommonTestData.PDP_SIMULATOR_GROUP_NAME),
54 PdpSimulatorParameterGroup.class);
55 final PdpStatusParameters pdpStatusParameters = pdpSimulatorParameters.getPdpStatusParameters();
56 final TopicParameterGroup topicParameterGroup = pdpSimulatorParameters.getTopicParameterGroup();
57 final ValidationResult validationResult = pdpSimulatorParameters.validate();
58 assertTrue(validationResult.isValid());
59 assertEquals(CommonTestData.PDP_SIMULATOR_GROUP_NAME, pdpSimulatorParameters.getName());
60 assertEquals(CommonTestData.TIME_INTERVAL, pdpStatusParameters.getTimeIntervalMs());
61 assertEquals(CommonTestData.PDP_TYPE, pdpStatusParameters.getPdpType());
62 assertEquals(CommonTestData.DESCRIPTION, pdpStatusParameters.getDescription());
63 assertEquals(CommonTestData.SUPPORTED_POLICY_TYPES, pdpStatusParameters.getSupportedPolicyTypes());
64 assertEquals(CommonTestData.TOPIC_PARAMS, topicParameterGroup.getTopicSinks());
65 assertEquals(CommonTestData.TOPIC_PARAMS, topicParameterGroup.getTopicSources());
69 void testPdpSimulatorParameterGroup_NullName() {
70 final PdpSimulatorParameterGroup pdpSimulatorParameters = commonTestData
71 .toObject(commonTestData.getPdpSimulatorParameterGroupMap(null), PdpSimulatorParameterGroup.class);
72 final ValidationResult validationResult = pdpSimulatorParameters.validate();
73 assertFalse(validationResult.isValid());
74 assertNull(pdpSimulatorParameters.getName());
75 assertTrue(validationResult.getResult().contains("is null"));
79 void testPdpSimulatorParameterGroup_EmptyName() {
80 final PdpSimulatorParameterGroup pdpSimulatorParameters = commonTestData
81 .toObject(commonTestData.getPdpSimulatorParameterGroupMap(""), PdpSimulatorParameterGroup.class);
82 final ValidationResult validationResult = pdpSimulatorParameters.validate();
83 assertFalse(validationResult.isValid());
84 assertEquals("", pdpSimulatorParameters.getName());
85 assertThat(validationResult.getResult()).contains(
86 "\"name\" value \"\" INVALID, " + "is blank");
90 void testPdpSimulatorParameterGroup_SetName() {
91 final PdpSimulatorParameterGroup pdpSimulatorParameters = commonTestData.toObject(
92 commonTestData.getPdpSimulatorParameterGroupMap(CommonTestData.PDP_SIMULATOR_GROUP_NAME),
93 PdpSimulatorParameterGroup.class);
94 pdpSimulatorParameters.setName("PdpSimulatorNewGroup");
95 final ValidationResult validationResult = pdpSimulatorParameters.validate();
96 assertTrue(validationResult.isValid());
97 assertEquals("PdpSimulatorNewGroup", pdpSimulatorParameters.getName());
101 void testPdpSimulatorParameterGroup_EmptyPdpStatusParameters() {
102 final Map<String, Object> map =
103 commonTestData.getPdpSimulatorParameterGroupMap(CommonTestData.PDP_SIMULATOR_GROUP_NAME);
104 map.put("pdpStatusParameters", commonTestData.getPdpStatusParametersMap(true));
105 final PdpSimulatorParameterGroup pdpSimulatorParameters =
106 commonTestData.toObject(map, PdpSimulatorParameterGroup.class);
107 final ValidationResult validationResult = pdpSimulatorParameters.validate();
108 assertFalse(validationResult.isValid());
109 assertThat(validationResult.getResult())
110 .contains("\"PdpSimulatorParameterGroup\" INVALID, item has status INVALID");
114 void testApexStarterParameterGroupp_EmptyTopicParameters() {
115 final Map<String, Object> map =
116 commonTestData.getPdpSimulatorParameterGroupMap(CommonTestData.PDP_SIMULATOR_GROUP_NAME);
117 map.put("topicParameterGroup", commonTestData.getTopicParametersMap(true));
119 final PdpSimulatorParameterGroup parGroup =
120 commonTestData.toObject(map, PdpSimulatorParameterGroup.class);
121 final ValidationResult validationResult = parGroup.validate();
122 assertFalse(validationResult.isValid());
123 assertThat(validationResult.getResult())
124 .contains("\"TopicParameterGroup\" INVALID, item has status INVALID");