2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2018 Ericsson. All rights reserved.
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.distribution.main.parameters;
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertFalse;
25 import static org.junit.Assert.assertTrue;
27 import org.junit.Test;
28 import org.onap.policy.common.parameters.GroupValidationResult;
29 import org.onap.policy.distribution.reception.parameters.PluginHandlerParameters;
30 import org.onap.policy.distribution.reception.parameters.ReceptionHandlerParameters;
33 * Class to perform unit test of ReceptionHandlerParameters.
35 * @author Ram Krishna Verma (ram.krishna.verma@ericsson.com)
37 public class TestReceptionHandlerParameters {
38 CommonTestData commonTestData = new CommonTestData();
41 public void testReceptionHandlerParameters() {
42 final PluginHandlerParameters pHParameters = commonTestData.getPluginHandlerParameters(false);
43 final ReceptionHandlerParameters rHParameters = new ReceptionHandlerParameters(
44 CommonTestData.RECEPTION_HANDLER_TYPE, CommonTestData.RECEPTION_HANDLER_CLASS_NAME,
45 CommonTestData.RECEPTION_CONFIGURATION_PARAMETERS, pHParameters);
46 final GroupValidationResult validationResult = rHParameters.validate();
47 assertEquals(CommonTestData.RECEPTION_HANDLER_TYPE, rHParameters.getReceptionHandlerType());
48 assertEquals(CommonTestData.RECEPTION_HANDLER_CLASS_NAME, rHParameters.getReceptionHandlerClassName());
49 assertEquals(CommonTestData.RECEPTION_CONFIGURATION_PARAMETERS,
50 rHParameters.getReceptionHandlerConfigurationName());
51 assertEquals(pHParameters, rHParameters.getPluginHandlerParameters());
52 assertTrue(validationResult.isValid());
56 public void testReceptionHandlerParameters_NullReceptionHandlerType() {
57 final PluginHandlerParameters pHParameters = commonTestData.getPluginHandlerParameters(false);
58 final ReceptionHandlerParameters rHParameters =
59 new ReceptionHandlerParameters(null, CommonTestData.RECEPTION_HANDLER_CLASS_NAME,
60 CommonTestData.RECEPTION_CONFIGURATION_PARAMETERS, pHParameters);
61 final GroupValidationResult validationResult = rHParameters.validate();
62 assertEquals(null, rHParameters.getReceptionHandlerType());
63 assertEquals(CommonTestData.RECEPTION_HANDLER_CLASS_NAME, rHParameters.getReceptionHandlerClassName());
64 assertEquals(CommonTestData.RECEPTION_CONFIGURATION_PARAMETERS,
65 rHParameters.getReceptionHandlerConfigurationName());
66 assertEquals(pHParameters, rHParameters.getPluginHandlerParameters());
67 assertFalse(validationResult.isValid());
68 assertTrue(validationResult.getResult()
69 .contains("field \"receptionHandlerType\" type \"java.lang.String\" value \"null\" INVALID, "
70 + "must be a non-blank string"));
74 public void testReceptionHandlerParameters_NullReceptionHandlerClassName() {
75 final PluginHandlerParameters pHParameters = commonTestData.getPluginHandlerParameters(false);
76 final ReceptionHandlerParameters rHParameters =
77 new ReceptionHandlerParameters(CommonTestData.RECEPTION_HANDLER_TYPE, null,
78 CommonTestData.RECEPTION_CONFIGURATION_PARAMETERS, pHParameters);
79 final GroupValidationResult validationResult = rHParameters.validate();
80 assertEquals(CommonTestData.RECEPTION_HANDLER_TYPE, rHParameters.getReceptionHandlerType());
81 assertEquals(null, rHParameters.getReceptionHandlerClassName());
82 assertEquals(CommonTestData.RECEPTION_CONFIGURATION_PARAMETERS,
83 rHParameters.getReceptionHandlerConfigurationName());
84 assertEquals(pHParameters, rHParameters.getPluginHandlerParameters());
85 assertFalse(validationResult.isValid());
86 assertTrue(validationResult.getResult()
87 .contains("field \"receptionHandlerClassName\" type \"java.lang.String\" value \"null\" INVALID, "
88 + "must be a non-blank string containing full class name " + "of the reception handler"));
92 public void testReceptionHandlerParameters_EmptyReceptionHandlerType() {
93 final PluginHandlerParameters pHParameters = commonTestData.getPluginHandlerParameters(false);
94 final ReceptionHandlerParameters rHParameters =
95 new ReceptionHandlerParameters("", CommonTestData.RECEPTION_HANDLER_CLASS_NAME,
96 CommonTestData.RECEPTION_CONFIGURATION_PARAMETERS, pHParameters);
97 final GroupValidationResult validationResult = rHParameters.validate();
98 assertEquals("", rHParameters.getReceptionHandlerType());
99 assertEquals(CommonTestData.RECEPTION_HANDLER_CLASS_NAME, rHParameters.getReceptionHandlerClassName());
100 assertEquals(pHParameters, rHParameters.getPluginHandlerParameters());
101 assertFalse(validationResult.isValid());
102 assertTrue(validationResult.getResult()
103 .contains("field \"receptionHandlerType\" type \"java.lang.String\" value \"\" INVALID, "
104 + "must be a non-blank string"));
108 public void testReceptionHandlerParameters_EmptyReceptionHandlerClassName() {
109 final PluginHandlerParameters pHParameters = commonTestData.getPluginHandlerParameters(false);
110 final ReceptionHandlerParameters rHParameters =
111 new ReceptionHandlerParameters(CommonTestData.RECEPTION_HANDLER_TYPE, "",
112 CommonTestData.RECEPTION_CONFIGURATION_PARAMETERS, pHParameters);
113 final GroupValidationResult validationResult = rHParameters.validate();
114 assertEquals(CommonTestData.RECEPTION_HANDLER_TYPE, rHParameters.getReceptionHandlerType());
115 assertEquals("", rHParameters.getReceptionHandlerClassName());
116 assertEquals(CommonTestData.RECEPTION_CONFIGURATION_PARAMETERS,
117 rHParameters.getReceptionHandlerConfigurationName());
118 assertEquals(pHParameters, rHParameters.getPluginHandlerParameters());
119 assertFalse(validationResult.isValid());
120 assertTrue(validationResult.getResult()
121 .contains("field \"receptionHandlerClassName\" type \"java.lang.String\" value \"\" INVALID, "
122 + "must be a non-blank string containing full class name " + "of the reception handler"));
126 public void testReceptionHandlerParameters_EmptyPluginHandler() {
127 final PluginHandlerParameters pHParameters = commonTestData.getPluginHandlerParameters(true);
128 final ReceptionHandlerParameters rHParameters = new ReceptionHandlerParameters(
129 CommonTestData.RECEPTION_HANDLER_TYPE, CommonTestData.RECEPTION_HANDLER_CLASS_NAME,
130 CommonTestData.RECEPTION_CONFIGURATION_PARAMETERS, pHParameters);
131 GroupValidationResult result = rHParameters.validate();
132 assertFalse(result.isValid());
133 assertTrue(result.getResult().endsWith("must have at least one policy forwarder\n"));
137 public void testReceptionHandlerParameters_InvalidReceptionHandlerClass() {
138 final PluginHandlerParameters pHParameters = commonTestData.getPluginHandlerParameters(false);
140 final ReceptionHandlerParameters rHParameters = new ReceptionHandlerParameters(
141 CommonTestData.RECEPTION_HANDLER_TYPE, CommonTestData.RECEPTION_HANDLER_CLASS_NAME + "Invalid",
142 CommonTestData.RECEPTION_CONFIGURATION_PARAMETERS, pHParameters);
143 final GroupValidationResult validationResult = rHParameters.validate();
144 assertEquals(CommonTestData.RECEPTION_HANDLER_TYPE, rHParameters.getReceptionHandlerType());
145 assertEquals(CommonTestData.RECEPTION_HANDLER_CLASS_NAME + "Invalid",
146 rHParameters.getReceptionHandlerClassName());
147 assertEquals(CommonTestData.RECEPTION_CONFIGURATION_PARAMETERS,
148 rHParameters.getReceptionHandlerConfigurationName());
149 assertEquals(pHParameters, rHParameters.getPluginHandlerParameters());
150 assertFalse(validationResult.isValid());
151 assertTrue(validationResult.getResult().contains("reception handler class not found in classpath"));