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