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 * Modification Copyright 2022. Nordix Foundation.
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
20 * SPDX-License-Identifier: Apache-2.0
21 * ============LICENSE_END=========================================================
24 package org.onap.policy.pap.main.parameters;
26 import static org.assertj.core.api.Assertions.assertThat;
27 import static org.junit.Assert.assertEquals;
28 import static org.junit.Assert.assertFalse;
29 import static org.junit.Assert.assertTrue;
31 import org.junit.Test;
32 import org.onap.policy.common.endpoints.parameters.TopicParameterGroup;
33 import org.onap.policy.common.parameters.ValidationResult;
34 import org.onap.policy.common.utils.coder.Coder;
35 import org.onap.policy.common.utils.coder.CoderException;
36 import org.onap.policy.common.utils.coder.StandardCoder;
39 * Class to perform unit test of {@link PapParameterGroup}.
41 * @author Ram Krishna Verma (ram.krishna.verma@est.tech)
43 public class TestPapParameterGroup {
44 private static final Coder coder = new StandardCoder();
46 CommonTestData commonTestData = new CommonTestData();
49 public void testPapParameterGroup_Named() {
50 final PapParameterGroup papParameters = new PapParameterGroup("my-name");
51 assertEquals("my-name", papParameters.getName());
55 public void testPapParameterGroup() {
56 final PapParameterGroup papParameters = commonTestData.getPapParameterGroup(1);
57 validateParameters(papParameters);
61 public void testPapParameterGroup_Postgres() throws CoderException {
62 String json = commonTestData.getPapPostgresParameterGroupAsString(1);
63 final PapParameterGroup papPostgresParameters = coder.decode(json, PapParameterGroup.class);
64 validateParameters(papPostgresParameters);
68 public void testPapParameterGroup_NullName() throws Exception {
69 String json = commonTestData.getPapParameterGroupAsString(1).replace("\"PapGroup\"", "null");
70 final PapParameterGroup papParameters = coder.decode(json, PapParameterGroup.class);
71 final ValidationResult validationResult = papParameters.validate();
72 assertFalse(validationResult.isValid());
73 assertEquals(null, papParameters.getName());
74 assertThat(validationResult.getResult()).contains("is null");
78 public void testPapParameterGroup_EmptyName() throws Exception {
79 String json = commonTestData.getPapParameterGroupAsString(1).replace(CommonTestData.PAP_GROUP_NAME, "");
80 final PapParameterGroup papParameters = coder.decode(json, PapParameterGroup.class);
81 final ValidationResult validationResult = papParameters.validate();
82 assertFalse(validationResult.isValid());
83 assertEquals("", papParameters.getName());
84 assertThat(validationResult.getResult()).contains("\"name\" value \"\" INVALID, " + "is blank");
88 public void testPapParameterGroup_SetName() {
89 final PapParameterGroup papParameters = commonTestData.getPapParameterGroup(1);
90 papParameters.setName("PapNewGroup");
91 final ValidationResult validationResult = papParameters.validate();
92 assertTrue(validationResult.isValid());
93 assertEquals("PapNewGroup", papParameters.getName());
97 * Validates the pap parameters.
99 * @param parameterGroup parameter group being tested
101 public void validateParameters(PapParameterGroup parameterGroup) {
102 final TopicParameterGroup topicParameterGroup = parameterGroup.getTopicParameterGroup();
103 final ValidationResult validationResult = parameterGroup.validate();
104 assertTrue(validationResult.isValid());
105 assertEquals(CommonTestData.PAP_GROUP_NAME, parameterGroup.getName());
106 assertEquals(topicParameterGroup.getTopicSinks(), parameterGroup.getTopicParameterGroup().getTopicSinks());
107 assertEquals(topicParameterGroup.getTopicSources(), parameterGroup.getTopicParameterGroup().getTopicSources());