Remove GroupValidationResult
[policy/pap.git] / main / src / test / java / org / onap / policy / pap / main / parameters / TestPapParameterGroup.java
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2019 Nordix Foundation.
4  *  Modifications Copyright (C) 2019, 2021 AT&T Intellectual Property.
5  * ================================================================================
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *      http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  * SPDX-License-Identifier: Apache-2.0
19  * ============LICENSE_END=========================================================
20  */
21
22 package org.onap.policy.pap.main.parameters;
23
24 import static org.assertj.core.api.Assertions.assertThat;
25 import static org.junit.Assert.assertEquals;
26 import static org.junit.Assert.assertFalse;
27 import static org.junit.Assert.assertTrue;
28
29 import org.junit.Test;
30 import org.onap.policy.common.endpoints.parameters.RestServerParameters;
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;
35
36 /**
37  * Class to perform unit test of {@link PapParameterGroup}.
38  *
39  * @author Ram Krishna Verma (ram.krishna.verma@est.tech)
40  */
41 public class TestPapParameterGroup {
42     private static final Coder coder = new StandardCoder();
43
44     CommonTestData commonTestData = new CommonTestData();
45
46     @Test
47     public void testPapParameterGroup_Named() {
48         final PapParameterGroup papParameters = new PapParameterGroup("my-name");
49         assertEquals("my-name", papParameters.getName());
50     }
51
52     @Test
53     public void testPapParameterGroup() {
54         final PapParameterGroup papParameters = commonTestData.getPapParameterGroup(1);
55         final RestServerParameters restServerParameters = papParameters.getRestServerParameters();
56         final TopicParameterGroup topicParameterGroup = papParameters.getTopicParameterGroup();
57         final ValidationResult validationResult = papParameters.validate();
58         assertTrue(validationResult.isValid());
59         assertEquals(CommonTestData.PAP_GROUP_NAME, papParameters.getName());
60         assertEquals(restServerParameters.getHost(), papParameters.getRestServerParameters().getHost());
61         assertEquals(restServerParameters.getPort(), papParameters.getRestServerParameters().getPort());
62         assertEquals(restServerParameters.getUserName(), papParameters.getRestServerParameters().getUserName());
63         assertEquals(restServerParameters.getPassword(), papParameters.getRestServerParameters().getPassword());
64         assertTrue(papParameters.getRestServerParameters().isHttps());
65         assertFalse(papParameters.getRestServerParameters().isAaf());
66         assertEquals(topicParameterGroup.getTopicSinks(), papParameters.getTopicParameterGroup().getTopicSinks());
67         assertEquals(topicParameterGroup.getTopicSources(), papParameters.getTopicParameterGroup().getTopicSources());
68     }
69
70     @Test
71     public void testPapParameterGroup_NullName() throws Exception {
72         String json = commonTestData.getPapParameterGroupAsString(1).replace("\"PapGroup\"", "null");
73         final PapParameterGroup papParameters = coder.decode(json, PapParameterGroup.class);
74         final ValidationResult validationResult = papParameters.validate();
75         assertFalse(validationResult.isValid());
76         assertEquals(null, papParameters.getName());
77         assertThat(validationResult.getResult()).contains("is null");
78     }
79
80     @Test
81     public void testPapParameterGroup_EmptyName() throws Exception {
82         String json = commonTestData.getPapParameterGroupAsString(1).replace(CommonTestData.PAP_GROUP_NAME, "");
83         final PapParameterGroup papParameters = coder.decode(json, PapParameterGroup.class);
84         final ValidationResult validationResult = papParameters.validate();
85         assertFalse(validationResult.isValid());
86         assertEquals("", papParameters.getName());
87         assertThat(validationResult.getResult()).contains("\"name\" value \"\" INVALID, " + "is blank");
88     }
89
90     @Test
91     public void testPapParameterGroup_SetName() {
92         final PapParameterGroup papParameters = commonTestData.getPapParameterGroup(1);
93         papParameters.setName("PapNewGroup");
94         final ValidationResult validationResult = papParameters.validate();
95         assertTrue(validationResult.isValid());
96         assertEquals("PapNewGroup", papParameters.getName());
97     }
98
99     @Test
100     public void testApiParameterGroup_EmptyRestServerParameters() throws Exception {
101         String json = commonTestData.getPapParameterGroupAsString(1);
102         json = commonTestData.nullifyField(json, "restServerParameters");
103         final PapParameterGroup papParameters = commonTestData.getPapParameterGroup(0);
104         final ValidationResult validationResult = papParameters.validate();
105         assertFalse(validationResult.isValid());
106         assertThat(validationResult.getResult())
107                 .contains("\"RestServerParameters\" INVALID, item has status INVALID");
108     }
109 }