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;
29 import org.junit.Test;
30 import org.onap.policy.common.endpoints.parameters.TopicParameterGroup;
31 import org.onap.policy.common.parameters.GroupValidationResult;
34 * Class to perform unit test of {@link PdpSimulatorParameterGroup}.
36 * @author Ajith Sreekumar (ajith.sreekumar@est.tech)
38 public class TestPdpSimulatorParameterGroup {
39 CommonTestData commonTestData = new CommonTestData();
42 public void testPdpSimulatorParameterGroup_Named() {
43 final PdpSimulatorParameterGroup pdpSimulatorParameters = new PdpSimulatorParameterGroup("my-name");
44 assertEquals("my-name", pdpSimulatorParameters.getName());
48 public void testPdpSimulatorParameterGroup() {
49 final PdpSimulatorParameterGroup pdpSimulatorParameters = commonTestData.toObject(
50 commonTestData.getPdpSimulatorParameterGroupMap(CommonTestData.PDP_SIMULATOR_GROUP_NAME),
51 PdpSimulatorParameterGroup.class);
52 final PdpStatusParameters pdpStatusParameters = pdpSimulatorParameters.getPdpStatusParameters();
53 final TopicParameterGroup topicParameterGroup = pdpSimulatorParameters.getTopicParameterGroup();
54 final GroupValidationResult validationResult = pdpSimulatorParameters.validate();
55 assertTrue(validationResult.isValid());
56 assertEquals(CommonTestData.PDP_SIMULATOR_GROUP_NAME, pdpSimulatorParameters.getName());
57 assertEquals(CommonTestData.TIME_INTERVAL, pdpStatusParameters.getTimeIntervalMs());
58 assertEquals(CommonTestData.PDP_TYPE, pdpStatusParameters.getPdpType());
59 assertEquals(CommonTestData.DESCRIPTION, pdpStatusParameters.getDescription());
60 assertEquals(CommonTestData.SUPPORTED_POLICY_TYPES, pdpStatusParameters.getSupportedPolicyTypes());
61 assertEquals(CommonTestData.TOPIC_PARAMS, topicParameterGroup.getTopicSinks());
62 assertEquals(CommonTestData.TOPIC_PARAMS, topicParameterGroup.getTopicSources());
66 public void testPdpSimulatorParameterGroup_NullName() {
67 final PdpSimulatorParameterGroup pdpSimulatorParameters = commonTestData
68 .toObject(commonTestData.getPdpSimulatorParameterGroupMap(null), PdpSimulatorParameterGroup.class);
69 final GroupValidationResult validationResult = pdpSimulatorParameters.validate();
70 assertFalse(validationResult.isValid());
71 assertEquals(null, pdpSimulatorParameters.getName());
72 assertTrue(validationResult.getResult().contains("is null"));
76 public void testPdpSimulatorParameterGroup_EmptyName() {
77 final PdpSimulatorParameterGroup pdpSimulatorParameters = commonTestData
78 .toObject(commonTestData.getPdpSimulatorParameterGroupMap(""), PdpSimulatorParameterGroup.class);
79 final GroupValidationResult validationResult = pdpSimulatorParameters.validate();
80 assertFalse(validationResult.isValid());
81 assertEquals("", pdpSimulatorParameters.getName());
82 assertTrue(validationResult.getResult().contains(
83 "field \"name\" type \"java.lang.String\" value \"\" INVALID, " + "must be a non-blank string"));
87 public void testPdpSimulatorParameterGroup_SetName() {
88 final PdpSimulatorParameterGroup pdpSimulatorParameters = commonTestData.toObject(
89 commonTestData.getPdpSimulatorParameterGroupMap(CommonTestData.PDP_SIMULATOR_GROUP_NAME),
90 PdpSimulatorParameterGroup.class);
91 pdpSimulatorParameters.setName("PdpSimulatorNewGroup");
92 final GroupValidationResult validationResult = pdpSimulatorParameters.validate();
93 assertTrue(validationResult.isValid());
94 assertEquals("PdpSimulatorNewGroup", pdpSimulatorParameters.getName());
98 public void testPdpSimulatorParameterGroup_EmptyPdpStatusParameters() {
99 final Map<String, Object> map =
100 commonTestData.getPdpSimulatorParameterGroupMap(CommonTestData.PDP_SIMULATOR_GROUP_NAME);
101 map.put("pdpStatusParameters", commonTestData.getPdpStatusParametersMap(true));
102 final PdpSimulatorParameterGroup pdpSimulatorParameters =
103 commonTestData.toObject(map, PdpSimulatorParameterGroup.class);
104 final GroupValidationResult validationResult = pdpSimulatorParameters.validate();
105 assertFalse(validationResult.isValid());
106 assertTrue(validationResult.getResult()
107 .contains("\"org.onap.policy.models.sim.pdp.parameters.PdpSimulatorParameterGroup\" INVALID, "
108 + "parameter group 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 GroupValidationResult validationResult = parGroup.validate();
120 assertFalse(validationResult.isValid());
121 assertTrue(validationResult.getResult()
122 .contains("\"org.onap.policy.common.endpoints.parameters.TopicParameterGroup\" INVALID, "
123 + "parameter group has status INVALID"));