2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019 Nordix Foundation.
4 * Modifications Copyright (C) 2019, 2021 AT&T Intellectual Property.
5 * Modifications Copyright (C) 2021 Bell Canada. All rights reserved.
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.pap.main.parameters;
25 import static org.assertj.core.api.Assertions.assertThat;
26 import static org.junit.Assert.assertEquals;
27 import static org.junit.Assert.assertFalse;
28 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;
33 import org.onap.policy.common.utils.coder.Coder;
34 import org.onap.policy.common.utils.coder.StandardCoder;
37 * Class to perform unit test of {@link PapParameterGroup}.
39 * @author Ram Krishna Verma (ram.krishna.verma@est.tech)
41 public class TestPapParameterGroup {
42 private static final Coder coder = new StandardCoder();
44 CommonTestData commonTestData = new CommonTestData();
47 public void testPapParameterGroup_Named() {
48 final PapParameterGroup papParameters = new PapParameterGroup("my-name");
49 assertEquals("my-name", papParameters.getName());
53 public void testPapParameterGroup() {
54 final PapParameterGroup papParameters = commonTestData.getPapParameterGroup(1);
55 final TopicParameterGroup topicParameterGroup = papParameters.getTopicParameterGroup();
56 final ValidationResult validationResult = papParameters.validate();
57 assertTrue(validationResult.isValid());
58 assertEquals(CommonTestData.PAP_GROUP_NAME, papParameters.getName());
59 assertEquals(topicParameterGroup.getTopicSinks(), papParameters.getTopicParameterGroup().getTopicSinks());
60 assertEquals(topicParameterGroup.getTopicSources(), papParameters.getTopicParameterGroup().getTopicSources());
64 public void testPapParameterGroup_NullName() throws Exception {
65 String json = commonTestData.getPapParameterGroupAsString(1).replace("\"PapGroup\"", "null");
66 final PapParameterGroup papParameters = coder.decode(json, PapParameterGroup.class);
67 final ValidationResult validationResult = papParameters.validate();
68 assertFalse(validationResult.isValid());
69 assertEquals(null, papParameters.getName());
70 assertThat(validationResult.getResult()).contains("is null");
74 public void testPapParameterGroup_EmptyName() throws Exception {
75 String json = commonTestData.getPapParameterGroupAsString(1).replace(CommonTestData.PAP_GROUP_NAME, "");
76 final PapParameterGroup papParameters = coder.decode(json, PapParameterGroup.class);
77 final ValidationResult validationResult = papParameters.validate();
78 assertFalse(validationResult.isValid());
79 assertEquals("", papParameters.getName());
80 assertThat(validationResult.getResult()).contains("\"name\" value \"\" INVALID, " + "is blank");
84 public void testPapParameterGroup_SetName() {
85 final PapParameterGroup papParameters = commonTestData.getPapParameterGroup(1);
86 papParameters.setName("PapNewGroup");
87 final ValidationResult validationResult = papParameters.validate();
88 assertTrue(validationResult.isValid());
89 assertEquals("PapNewGroup", papParameters.getName());