eaf0b2a9c38076bb69ea60e00b4f6067ff50b29d
[policy/common.git] /
1 /*-
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
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
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.
16  *
17  * SPDX-License-Identifier: Apache-2.0
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.policy.common.endpoints.parameters;
22
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertFalse;
25 import static org.junit.Assert.assertNull;
26 import static org.junit.Assert.assertTrue;
27
28 import org.junit.Test;
29 import org.onap.policy.common.parameters.GroupValidationResult;
30 import org.onap.policy.common.utils.coder.Coder;
31 import org.onap.policy.common.utils.coder.StandardCoder;
32
33 /**
34  * Class to perform unit test of {@link TopicParameterGroup}.
35  *
36  * @author Ajith Sreekumar (ajith.sreekumar@est.tech)
37  */
38 public class TopicParameterGroupTest {
39     private static CommonTestData testData = new CommonTestData();
40     private static final Coder coder = new StandardCoder();
41
42     @Test
43     public void test() throws Exception {
44         final TopicParameterGroup topicParameterGroup =
45                 testData.toObject(testData.getTopicParameterGroupMap(false), TopicParameterGroup.class);
46         final GroupValidationResult validationResult = topicParameterGroup.validate();
47         assertTrue(validationResult.isValid());
48         assertEquals(CommonTestData.TOPIC_PARAMS, topicParameterGroup.getTopicSinks());
49         assertEquals(CommonTestData.TOPIC_PARAMS, topicParameterGroup.getTopicSources());
50     }
51
52     @Test
53     public void testValidate() throws Exception {
54         final TopicParameterGroup topicParameterGroup =
55             testData.toObject(testData.getTopicParameterGroupMap(false), TopicParameterGroup.class);
56         final GroupValidationResult result = topicParameterGroup.validate();
57         assertNull(result.getResult());
58         assertTrue(result.isValid());
59     }
60
61     @Test
62     public void test_valid() throws Exception {
63         String json = testData.getParameterGroupAsString(
64             "src/test/resources/org/onap/policy/common/endpoints/parameters/TopicParameters_valid.json");
65         TopicParameterGroup topicParameterGroup = coder.decode(json, TopicParameterGroup.class);
66         final GroupValidationResult result = topicParameterGroup.validate();
67         assertNull(result.getResult());
68         assertTrue(result.isValid());
69     }
70
71     @Test
72     public void test_invalid() throws Exception {
73         String json = testData.getParameterGroupAsString(
74             "src/test/resources/org/onap/policy/common/endpoints/parameters/TopicParameters_invalid.json");
75         TopicParameterGroup topicParameterGroup = coder.decode(json, TopicParameterGroup.class);
76         final GroupValidationResult result = topicParameterGroup.validate();
77         assertFalse(result.isValid());
78         assertTrue(result.getResult().contains("parameter group has status INVALID"));
79     }
80 }