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