db26a1a4396ec98c57ce824de3f123ca76213342
[policy/common.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2019 Nordix Foundation.
4  *  Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
5
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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  *
19  * SPDX-License-Identifier: Apache-2.0
20  * ============LICENSE_END=========================================================
21  */
22
23 package org.onap.policy.common.endpoints.parameters;
24
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;
29
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;
34
35 /**
36  * Class to perform unit test of {@link TopicParameterGroup}.
37  *
38  * @author Ajith Sreekumar (ajith.sreekumar@est.tech)
39  */
40 public class TopicParameterGroupTest {
41     private static CommonTestData testData = new CommonTestData();
42     private static final Coder coder = new StandardCoder();
43
44     @Test
45     public void test() {
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());
52     }
53
54     @Test
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());
61     }
62
63     @Test
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());
71     }
72
73     @Test
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"));
81     }
82 }