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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.apex.services.onappf.parameters;
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertFalse;
25 import static org.junit.Assert.assertTrue;
29 import org.junit.Test;
30 import org.onap.policy.common.parameters.GroupValidationResult;
33 * Class to perform unit test of {@link ApexStarterParameterGroup}.
35 * @author Ajith Sreekumar (ajith.sreekumar@est.tech)
37 public class TestApexStarterParameterGroup {
38 CommonTestData commonTestData = new CommonTestData();
41 public void testApexStarterParameterGroup_Named() {
42 final ApexStarterParameterGroup apexStarterParameters = new ApexStarterParameterGroup("my-name");
43 assertEquals("my-name", apexStarterParameters.getName());
47 public void testApexStarterParameterGroup() {
48 final ApexStarterParameterGroup apexStarterParameters = commonTestData.toObject(
49 commonTestData.getApexStarterParameterGroupMap(CommonTestData.APEX_STARTER_GROUP_NAME),
50 ApexStarterParameterGroup.class);
51 final RestServerParameters restServerParameters = apexStarterParameters.getRestServerParameters();
52 final PdpStatusParameters pdpStatusParameters = apexStarterParameters.getPdpStatusParameters();
53 final GroupValidationResult validationResult = apexStarterParameters.validate();
54 assertTrue(validationResult.isValid());
55 assertEquals(CommonTestData.APEX_STARTER_GROUP_NAME, apexStarterParameters.getName());
56 assertEquals(CommonTestData.TIME_INTERVAL, pdpStatusParameters.getTimeIntervalMs());
57 assertEquals(CommonTestData.PDP_TYPE, pdpStatusParameters.getPdpType());
58 assertEquals(CommonTestData.DESCRIPTION, pdpStatusParameters.getDescription());
59 assertEquals(CommonTestData.SUPPORTED_POLICY_TYPES, pdpStatusParameters.getSupportedPolicyTypes());
60 assertEquals(restServerParameters.getHost(), apexStarterParameters.getRestServerParameters().getHost());
61 assertEquals(restServerParameters.getPort(), apexStarterParameters.getRestServerParameters().getPort());
62 assertEquals(restServerParameters.getUserName(), apexStarterParameters.getRestServerParameters().getUserName());
63 assertEquals(restServerParameters.getPassword(), apexStarterParameters.getRestServerParameters().getPassword());
64 assertTrue(apexStarterParameters.getRestServerParameters().isHttps());
65 assertFalse(apexStarterParameters.getRestServerParameters().isAaf());
69 public void testApexStarterParameterGroup_NullName() {
70 final ApexStarterParameterGroup apexStarterParameters = commonTestData
71 .toObject(commonTestData.getApexStarterParameterGroupMap(null), ApexStarterParameterGroup.class);
72 final GroupValidationResult validationResult = apexStarterParameters.validate();
73 assertFalse(validationResult.isValid());
74 assertEquals(null, apexStarterParameters.getName());
75 assertTrue(validationResult.getResult().contains("is null"));
79 public void testApexStarterParameterGroup_EmptyName() {
80 final ApexStarterParameterGroup apexStarterParameters = commonTestData
81 .toObject(commonTestData.getApexStarterParameterGroupMap(""), ApexStarterParameterGroup.class);
82 final GroupValidationResult validationResult = apexStarterParameters.validate();
83 assertFalse(validationResult.isValid());
84 assertEquals("", apexStarterParameters.getName());
85 assertTrue(validationResult.getResult().contains(
86 "field \"name\" type \"java.lang.String\" value \"\" INVALID, " + "must be a non-blank string"));
90 public void testApexStarterParameterGroup_SetName() {
91 final ApexStarterParameterGroup apexStarterParameters = commonTestData.toObject(
92 commonTestData.getApexStarterParameterGroupMap(CommonTestData.APEX_STARTER_GROUP_NAME),
93 ApexStarterParameterGroup.class);
94 apexStarterParameters.setName("ApexStarterNewGroup");
95 final GroupValidationResult validationResult = apexStarterParameters.validate();
96 assertTrue(validationResult.isValid());
97 assertEquals("ApexStarterNewGroup", apexStarterParameters.getName());
101 public void testApexStarterParameterGroup_EmptyPdpStatusParameters() {
102 final Map<String, Object> map =
103 commonTestData.getApexStarterParameterGroupMap(CommonTestData.APEX_STARTER_GROUP_NAME);
104 map.put("pdpStatusParameters", commonTestData.getPdpStatusParametersMap(true));
105 final ApexStarterParameterGroup apexStarterParameters =
106 commonTestData.toObject(map, ApexStarterParameterGroup.class);
107 final GroupValidationResult validationResult = apexStarterParameters.validate();
108 assertFalse(validationResult.isValid());
109 assertTrue(validationResult.getResult()
110 .contains("\"org.onap.policy.apex.services.onappf.parameters.ApexStarterParameterGroup\" INVALID, "
111 + "parameter group has status INVALID"));
115 public void testApexStarterParameterGroupp_EmptyRestServerParameters() {
116 final Map<String, Object> map =
117 commonTestData.getApexStarterParameterGroupMap(CommonTestData.APEX_STARTER_GROUP_NAME);
118 map.put("restServerParameters", commonTestData.getRestServerParametersMap(true));
120 final ApexStarterParameterGroup apexStarterParameters =
121 commonTestData.toObject(map, ApexStarterParameterGroup.class);
122 final GroupValidationResult validationResult = apexStarterParameters.validate();
123 assertFalse(validationResult.isValid());
124 assertTrue(validationResult.getResult()
125 .contains("\"org.onap.policy.apex.services.onappf.parameters.RestServerParameters\" INVALID, "
126 + "parameter group has status INVALID"));