2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019 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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.models.sim.pdp.parameters;
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertFalse;
25 import static org.junit.Assert.assertTrue;
28 import org.junit.Test;
29 import org.onap.policy.common.endpoints.parameters.TopicParameterGroup;
30 import org.onap.policy.common.parameters.GroupValidationResult;
33 * Class to perform unit test of {@link PdpSimulatorParameterGroup}.
35 * @author Ajith Sreekumar (ajith.sreekumar@est.tech)
37 public class TestPdpSimulatorParameterGroup {
38 CommonTestData commonTestData = new CommonTestData();
41 public void testPdpSimulatorParameterGroup_Named() {
42 final PdpSimulatorParameterGroup pdpSimulatorParameters = new PdpSimulatorParameterGroup("my-name");
43 assertEquals("my-name", pdpSimulatorParameters.getName());
47 public void testPdpSimulatorParameterGroup() {
48 final PdpSimulatorParameterGroup pdpSimulatorParameters = commonTestData.toObject(
49 commonTestData.getPdpSimulatorParameterGroupMap(CommonTestData.PDP_SIMULATOR_GROUP_NAME),
50 PdpSimulatorParameterGroup.class);
51 final PdpStatusParameters pdpStatusParameters = pdpSimulatorParameters.getPdpStatusParameters();
52 final TopicParameterGroup topicParameterGroup = pdpSimulatorParameters.getTopicParameterGroup();
53 final GroupValidationResult validationResult = pdpSimulatorParameters.validate();
54 assertTrue(validationResult.isValid());
55 assertEquals(CommonTestData.PDP_SIMULATOR_GROUP_NAME, pdpSimulatorParameters.getName());
56 assertEquals(CommonTestData.TIME_INTERVAL, pdpStatusParameters.getTimeIntervalMs());
57 assertEquals(CommonTestData.PDP_TYPE, pdpStatusParameters.getPdpType());
58 assertEquals(CommonTestData.DESCRIPTION, pdpStatusParameters.getDescription());
59 assertEquals(CommonTestData.SUPPORTED_POLICY_TYPES, pdpStatusParameters.getSupportedPolicyTypes());
60 assertEquals(CommonTestData.TOPIC_PARAMS, topicParameterGroup.getTopicSinks());
61 assertEquals(CommonTestData.TOPIC_PARAMS, topicParameterGroup.getTopicSources());
65 public void testPdpSimulatorParameterGroup_NullName() {
66 final PdpSimulatorParameterGroup pdpSimulatorParameters = commonTestData
67 .toObject(commonTestData.getPdpSimulatorParameterGroupMap(null), PdpSimulatorParameterGroup.class);
68 final GroupValidationResult validationResult = pdpSimulatorParameters.validate();
69 assertFalse(validationResult.isValid());
70 assertEquals(null, pdpSimulatorParameters.getName());
71 assertTrue(validationResult.getResult().contains("is null"));
75 public void testPdpSimulatorParameterGroup_EmptyName() {
76 final PdpSimulatorParameterGroup pdpSimulatorParameters = commonTestData
77 .toObject(commonTestData.getPdpSimulatorParameterGroupMap(""), PdpSimulatorParameterGroup.class);
78 final GroupValidationResult validationResult = pdpSimulatorParameters.validate();
79 assertFalse(validationResult.isValid());
80 assertEquals("", pdpSimulatorParameters.getName());
81 assertTrue(validationResult.getResult().contains(
82 "field \"name\" type \"java.lang.String\" value \"\" INVALID, " + "must be a non-blank string"));
86 public void testPdpSimulatorParameterGroup_SetName() {
87 final PdpSimulatorParameterGroup pdpSimulatorParameters = commonTestData.toObject(
88 commonTestData.getPdpSimulatorParameterGroupMap(CommonTestData.PDP_SIMULATOR_GROUP_NAME),
89 PdpSimulatorParameterGroup.class);
90 pdpSimulatorParameters.setName("PdpSimulatorNewGroup");
91 final GroupValidationResult validationResult = pdpSimulatorParameters.validate();
92 assertTrue(validationResult.isValid());
93 assertEquals("PdpSimulatorNewGroup", pdpSimulatorParameters.getName());
97 public void testPdpSimulatorParameterGroup_EmptyPdpStatusParameters() {
98 final Map<String, Object> map =
99 commonTestData.getPdpSimulatorParameterGroupMap(CommonTestData.PDP_SIMULATOR_GROUP_NAME);
100 map.put("pdpStatusParameters", commonTestData.getPdpStatusParametersMap(true));
101 final PdpSimulatorParameterGroup pdpSimulatorParameters =
102 commonTestData.toObject(map, PdpSimulatorParameterGroup.class);
103 final GroupValidationResult validationResult = pdpSimulatorParameters.validate();
104 assertFalse(validationResult.isValid());
105 assertTrue(validationResult.getResult()
106 .contains("\"org.onap.policy.models.sim.pdp.parameters.PdpSimulatorParameterGroup\" INVALID, "
107 + "parameter group has status INVALID"));
111 public void testApexStarterParameterGroupp_EmptyTopicParameters() {
112 final Map<String, Object> map =
113 commonTestData.getPdpSimulatorParameterGroupMap(CommonTestData.PDP_SIMULATOR_GROUP_NAME);
114 map.put("topicParameterGroup", commonTestData.getTopicParametersMap(true));
116 final PdpSimulatorParameterGroup parGroup =
117 commonTestData.toObject(map, PdpSimulatorParameterGroup.class);
118 final GroupValidationResult validationResult = parGroup.validate();
119 assertFalse(validationResult.isValid());
120 assertTrue(validationResult.getResult()
121 .contains("\"org.onap.policy.common.endpoints.parameters.TopicParameterGroup\" INVALID, "
122 + "parameter group has status INVALID"));