2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019 Nordix Foundation.
4 * Modifications Copyright (C) 2019 AT&T Intellectual Property. 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.common.endpoints.parameters;
25 import static org.junit.Assert.assertEquals;
26 import static org.junit.Assert.assertFalse;
27 import static org.junit.Assert.assertNull;
28 import static org.junit.Assert.assertTrue;
30 import org.junit.Test;
31 import org.onap.policy.common.parameters.GroupValidationResult;
32 import org.onap.policy.common.utils.coder.Coder;
33 import org.onap.policy.common.utils.coder.StandardCoder;
36 * Class to perform unit test of {@link TopicParameterGroup}.
38 * @author Ajith Sreekumar (ajith.sreekumar@est.tech)
40 public class TopicParameterGroupTest {
41 private static CommonTestData testData = new CommonTestData();
42 private static final Coder coder = new StandardCoder();
46 final TopicParameterGroup topicParameterGroup =
47 testData.toObject(testData.getTopicParameterGroupMap(false), TopicParameterGroup.class);
48 final GroupValidationResult validationResult = topicParameterGroup.validate();
49 assertTrue(validationResult.isValid());
50 assertEquals(CommonTestData.TOPIC_PARAMS, topicParameterGroup.getTopicSinks());
51 assertEquals(CommonTestData.TOPIC_PARAMS, topicParameterGroup.getTopicSources());
55 public void testValidate() {
56 final TopicParameterGroup topicParameterGroup =
57 testData.toObject(testData.getTopicParameterGroupMap(false), TopicParameterGroup.class);
58 final GroupValidationResult result = topicParameterGroup.validate();
59 assertNull(result.getResult());
60 assertTrue(result.isValid());
64 public void test_valid() throws Exception {
65 String json = testData.getParameterGroupAsString(
66 "src/test/resources/org/onap/policy/common/endpoints/parameters/TopicParameters_valid.json");
67 TopicParameterGroup topicParameterGroup = coder.decode(json, TopicParameterGroup.class);
68 final GroupValidationResult result = topicParameterGroup.validate();
69 assertNull(result.getResult());
70 assertTrue(result.isValid());
74 public void test_invalid() throws Exception {
75 String json = testData.getParameterGroupAsString(
76 "src/test/resources/org/onap/policy/common/endpoints/parameters/TopicParameters_invalid.json");
77 TopicParameterGroup topicParameterGroup = coder.decode(json, TopicParameterGroup.class);
78 final GroupValidationResult result = topicParameterGroup.validate();
79 assertFalse(result.isValid());
80 assertTrue(result.getResult().contains("parameter group has status INVALID"));