Changes for checkstyle 8.32
[policy/apex-pdp.git] / services / services-onappf / src / test / java / org / onap / policy / apex / services / onappf / parameters / TestApexStarterParameterGroup.java
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.apex.services.onappf.parameters;
22
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertFalse;
25 import static org.junit.Assert.assertTrue;
26
27 import java.util.Map;
28 import org.junit.Test;
29 import org.onap.policy.common.endpoints.parameters.RestServerParameters;
30 import org.onap.policy.common.endpoints.parameters.TopicParameterGroup;
31 import org.onap.policy.common.parameters.GroupValidationResult;
32
33 /**
34  * Class to perform unit test of {@link ApexStarterParameterGroup}.
35  *
36  * @author Ajith Sreekumar (ajith.sreekumar@est.tech)
37  */
38 public class TestApexStarterParameterGroup {
39     CommonTestData commonTestData = new CommonTestData();
40
41     @Test
42     public void testApexStarterParameterGroup_Named() {
43         final ApexStarterParameterGroup apexStarterParameters = new ApexStarterParameterGroup("my-name");
44         assertEquals("my-name", apexStarterParameters.getName());
45     }
46
47     @Test
48     public void testApexStarterParameterGroup() {
49         final ApexStarterParameterGroup apexStarterParameters = commonTestData.toObject(
50                 commonTestData.getApexStarterParameterGroupMap(CommonTestData.APEX_STARTER_GROUP_NAME),
51                 ApexStarterParameterGroup.class);
52         final RestServerParameters restServerParameters = apexStarterParameters.getRestServerParameters();
53         final PdpStatusParameters pdpStatusParameters = apexStarterParameters.getPdpStatusParameters();
54         final TopicParameterGroup topicParameterGroup  = apexStarterParameters.getTopicParameterGroup();
55         final GroupValidationResult validationResult = apexStarterParameters.validate();
56         assertTrue(validationResult.isValid());
57         assertEquals(CommonTestData.APEX_STARTER_GROUP_NAME, apexStarterParameters.getName());
58         assertEquals(CommonTestData.TIME_INTERVAL, pdpStatusParameters.getTimeIntervalMs());
59         assertEquals(CommonTestData.PDP_TYPE, pdpStatusParameters.getPdpType());
60         assertEquals(CommonTestData.DESCRIPTION, pdpStatusParameters.getDescription());
61         assertEquals(CommonTestData.SUPPORTED_POLICY_TYPES, pdpStatusParameters.getSupportedPolicyTypes());
62         assertEquals(CommonTestData.TOPIC_PARAMS, topicParameterGroup.getTopicSinks());
63         assertEquals(CommonTestData.TOPIC_PARAMS, topicParameterGroup.getTopicSources());
64         assertEquals(restServerParameters.getHost(), apexStarterParameters.getRestServerParameters().getHost());
65         assertEquals(restServerParameters.getPort(), apexStarterParameters.getRestServerParameters().getPort());
66         assertEquals(restServerParameters.getUserName(), apexStarterParameters.getRestServerParameters().getUserName());
67         assertEquals(restServerParameters.getPassword(), apexStarterParameters.getRestServerParameters().getPassword());
68         assertTrue(apexStarterParameters.getRestServerParameters().isHttps());
69         assertFalse(apexStarterParameters.getRestServerParameters().isAaf());
70     }
71
72     @Test
73     public void testApexStarterParameterGroup_NullName() {
74         final ApexStarterParameterGroup apexStarterParameters = commonTestData
75                 .toObject(commonTestData.getApexStarterParameterGroupMap(null), ApexStarterParameterGroup.class);
76         final GroupValidationResult validationResult = apexStarterParameters.validate();
77         assertFalse(validationResult.isValid());
78         assertEquals(null, apexStarterParameters.getName());
79         assertTrue(validationResult.getResult().contains("is null"));
80     }
81
82     @Test
83     public void testApexStarterParameterGroup_EmptyName() {
84         final ApexStarterParameterGroup apexStarterParameters = commonTestData
85                 .toObject(commonTestData.getApexStarterParameterGroupMap(""), ApexStarterParameterGroup.class);
86         final GroupValidationResult validationResult = apexStarterParameters.validate();
87         assertFalse(validationResult.isValid());
88         assertEquals("", apexStarterParameters.getName());
89         assertTrue(validationResult.getResult().contains(
90                 "field \"name\" type \"java.lang.String\" value \"\" INVALID, " + "must be a non-blank string"));
91     }
92
93     @Test
94     public void testApexStarterParameterGroup_SetName() {
95         final ApexStarterParameterGroup apexStarterParameters = commonTestData.toObject(
96                 commonTestData.getApexStarterParameterGroupMap(CommonTestData.APEX_STARTER_GROUP_NAME),
97                 ApexStarterParameterGroup.class);
98         apexStarterParameters.setName("ApexStarterNewGroup");
99         final GroupValidationResult validationResult = apexStarterParameters.validate();
100         assertTrue(validationResult.isValid());
101         assertEquals("ApexStarterNewGroup", apexStarterParameters.getName());
102     }
103
104     @Test
105     public void testApexStarterParameterGroup_EmptyPdpStatusParameters() {
106         final Map<String, Object> map =
107                 commonTestData.getApexStarterParameterGroupMap(CommonTestData.APEX_STARTER_GROUP_NAME);
108         map.put("pdpStatusParameters", commonTestData.getPdpStatusParametersMap(true));
109         final ApexStarterParameterGroup apexStarterParameters =
110                 commonTestData.toObject(map, ApexStarterParameterGroup.class);
111         final GroupValidationResult validationResult = apexStarterParameters.validate();
112         assertFalse(validationResult.isValid());
113         assertTrue(validationResult.getResult()
114                 .contains("\"org.onap.policy.apex.services.onappf.parameters.ApexStarterParameterGroup\" INVALID, "
115                         + "parameter group has status INVALID"));
116     }
117
118     @Test
119     public void testApexStarterParameterGroupp_EmptyRestServerParameters() {
120         final Map<String, Object> map =
121                 commonTestData.getApexStarterParameterGroupMap(CommonTestData.APEX_STARTER_GROUP_NAME);
122         map.put("restServerParameters", commonTestData.getRestServerParametersMap(true));
123
124         final ApexStarterParameterGroup apexStarterParameters =
125                 commonTestData.toObject(map, ApexStarterParameterGroup.class);
126         final GroupValidationResult validationResult = apexStarterParameters.validate();
127         assertFalse(validationResult.isValid());
128         assertTrue(validationResult.getResult()
129                 .contains("\"org.onap.policy.common.endpoints.parameters.RestServerParameters\" INVALID, "
130                         + "parameter group has status INVALID"));
131     }
132
133
134     @Test
135     public void testApexStarterParameterGroupp_EmptyTopicParameters() {
136         final Map<String, Object> map =
137                 commonTestData.getApexStarterParameterGroupMap(CommonTestData.APEX_STARTER_GROUP_NAME);
138         map.put("topicParameterGroup", commonTestData.getTopicParametersMap(true));
139
140         final ApexStarterParameterGroup apexStarterParameters =
141                 commonTestData.toObject(map, ApexStarterParameterGroup.class);
142         final GroupValidationResult validationResult = apexStarterParameters.validate();
143         assertFalse(validationResult.isValid());
144         assertTrue(validationResult.getResult()
145                 .contains("\"org.onap.policy.common.endpoints.parameters.TopicParameterGroup\" INVALID, "
146                         + "parameter group has status INVALID"));
147     }
148 }