2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2016-2018 Ericsson. All rights reserved.
4 * Modifications Copyright (C) 2019-2020 Nordix Foundation.
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
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 * SPDX-License-Identifier: Apache-2.0
19 * ============LICENSE_END=========================================================
22 package org.onap.policy.apex.service.engine.parameters;
24 import static org.junit.Assert.assertEquals;
25 import static org.junit.Assert.assertTrue;
26 import static org.junit.Assert.fail;
28 import org.junit.Test;
29 import org.onap.policy.apex.service.engine.event.impl.filecarrierplugin.FileCarrierTechnologyParameters;
30 import org.onap.policy.apex.service.engine.main.ApexCommandLineArguments;
31 import org.onap.policy.apex.service.parameters.ApexParameterHandler;
32 import org.onap.policy.apex.service.parameters.ApexParameters;
33 import org.onap.policy.common.parameters.ParameterException;
36 * Test for an empty parameter file.
38 * @author Liam Fallon (liam.fallon@ericsson.com)
40 public class ProducerConsumerTests {
42 public void testGoodParametersTest() {
43 final String[] args = {"-c", "src/test/resources/parameters/goodParams.json"};
44 final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
47 final ApexParameters parameters = new ApexParameterHandler().getParameters(arguments);
49 assertEquals("MyApexEngine", parameters.getEngineServiceParameters().getName());
50 assertEquals("0.0.1", parameters.getEngineServiceParameters().getVersion());
51 assertEquals(45, parameters.getEngineServiceParameters().getId());
52 assertEquals(19, parameters.getEngineServiceParameters().getInstanceCount());
53 assertEquals(65522, parameters.getEngineServiceParameters().getDeploymentPort());
54 assertEquals("FILE", parameters.getEventOutputParameters().get("FirstProducer")
55 .getCarrierTechnologyParameters().getLabel());
57 parameters.getEventOutputParameters().get("FirstProducer").getEventProtocolParameters().getLabel());
58 assertEquals("FILE", parameters.getEventOutputParameters().get("MyOtherProducer")
59 .getCarrierTechnologyParameters().getLabel());
60 assertEquals("JSON", parameters.getEventOutputParameters().get("MyOtherProducer")
61 .getEventProtocolParameters().getLabel());
62 assertEquals("FILE", parameters.getEventInputParameters().get("TheFileConsumer1")
63 .getCarrierTechnologyParameters().getLabel());
64 assertEquals("JSON", parameters.getEventInputParameters().get("TheFileConsumer1")
65 .getEventProtocolParameters().getLabel());
66 assertEquals("SUPER_DOOPER", parameters.getEventInputParameters().get("MySuperDooperConsumer1")
67 .getCarrierTechnologyParameters().getLabel());
68 assertEquals("SUPER_TOK_DEL", parameters.getEventInputParameters().get("MySuperDooperConsumer1")
69 .getEventProtocolParameters().getLabel());
70 } catch (final ParameterException e) {
71 fail("This test should not throw an exception");
76 public void testNoCarrierTechnology() {
77 final String[] args = {"-c", "src/test/resources/parameters/prodConsNoCT.json"};
78 final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
81 new ApexParameterHandler().getParameters(arguments);
82 fail("This test should throw an exception");
83 } catch (final ParameterException e) {
84 assertEquals("validation error(s) on parameters from \"src/test/resources/parameters/prodConsNoCT.json\"\n"
85 + "parameter group \"APEX_PARAMETERS\" type "
86 + "\"org.onap.policy.apex.service.parameters.ApexParameters\" INVALID, "
87 + "parameter group has status INVALID\n"
88 + " parameter group map \"eventInputParameters\" INVALID, "
89 + "parameter group map has status INVALID\n" + " parameter group \"aConsumer\" type "
90 + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" INVALID,"
91 + " parameter group has status INVALID\n" + " parameter group \"UNDEFINED\" INVALID, "
92 + "event handler carrierTechnologyParameters not specified or blank\n", e.getMessage());
97 public void testNoEventProcol() {
98 final String[] args = {"-c", "src/test/resources/parameters/prodConsNoEP.json"};
99 final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
102 new ApexParameterHandler().getParameters(arguments);
103 fail("This test should throw an exception");
104 } catch (final ParameterException e) {
105 assertEquals("validation error(s) on parameters from \"src/test/resources/parameters/prodConsNoEP.json\"\n"
106 + "parameter group \"APEX_PARAMETERS\" type "
107 + "\"org.onap.policy.apex.service.parameters.ApexParameters\" INVALID, "
108 + "parameter group has status INVALID\n"
109 + " parameter group map \"eventOutputParameters\" INVALID, "
110 + "parameter group map has status INVALID\n" + " parameter group \"aProducer\" type "
111 + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" INVALID"
112 + ", parameter group has status INVALID\n" + " parameter group \"UNDEFINED\" INVALID, "
113 + "event handler eventProtocolParameters not specified or blank\n"
114 + " parameter group map \"eventInputParameters\" INVALID, "
115 + "parameter group map has status INVALID\n" + " parameter group \"aConsumer\" type "
116 + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" INVALID"
117 + ", parameter group has status INVALID\n" + " parameter group \"FILE\" type "
118 + "\"org.onap.policy.apex.service.engine.event.impl."
119 + "filecarrierplugin.FileCarrierTechnologyParameters\" INVALID, "
120 + "parameter group has status INVALID\n"
121 + " field \"fileName\" type \"java.lang.String\" value \"null\" INVALID, "
122 + "\"null\" invalid, must be specified as a non-empty string\n", e.getMessage());
127 public void testNoCarrierTechnologyParClass() {
128 final String[] args = {"-c", "src/test/resources/parameters/prodConsNoCTParClass.json"};
129 final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
132 new ApexParameterHandler().getParameters(arguments);
133 fail("This test should throw an exception");
134 } catch (final ParameterException e) {
135 assertEquals("error reading parameters from \"src/test/resources/parameters/prodConsNoCTParClass.json\"\n"
136 + "(ParameterRuntimeException):carrier technology \"SUPER_DOOPER\" "
137 + "parameter \"parameterClassName\" value \"null\" invalid in JSON file", e.getMessage());
142 public void testMismatchCarrierTechnologyParClass() {
143 final String[] args = {"-c", "src/test/resources/parameters/prodConsMismatchCTParClass.json"};
144 final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
147 new ApexParameterHandler().getParameters(arguments);
148 fail("This test should throw an exception");
149 } catch (final ParameterException e) {
150 assertEquals("error reading parameters from "
151 + "\"src/test/resources/parameters/prodConsMismatchCTParClass.json\"\n"
152 + "(ParameterRuntimeException):carrier technology \"SUPER_LOOPER\" "
153 + "does not match plugin \"SUPER_DOOPER\" in \"" + "org.onap.policy.apex.service.engine."
154 + "parameters.dummyclasses.SuperDooperCarrierTechnologyParameters"
155 + "\", specify correct carrier technology parameter plugin "
156 + "in parameter \"parameterClassName\"", e.getMessage());
161 public void testWrongTypeCarrierTechnologyParClass() {
162 final String[] args = {"-c", "src/test/resources/parameters/prodConsWrongTypeCTParClass.json"};
163 final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
166 new ApexParameterHandler().getParameters(arguments);
167 fail("This test should throw an exception");
168 } catch (final ParameterException e) {
169 assertEquals("error reading parameters from "
170 + "\"src/test/resources/parameters/prodConsWrongTypeCTParClass.json\"\n"
171 + "(ParameterRuntimeException):could not create default parameters for carrier technology "
172 + "\"SUPER_DOOPER\"\n" + "class org.onap.policy.apex.service.engine.parameters.dummyclasses."
173 + "SuperTokenDelimitedEventProtocolParameters cannot be cast to class "
174 + "org.onap.policy.apex.service.parameters.carriertechnology.CarrierTechnologyParameters (org.onap."
175 + "policy.apex.service.engine.parameters.dummyclasses.SuperTokenDelimitedEventProtocolParameters "
176 + "and org.onap.policy.apex.service.parameters.carriertechnology.CarrierTechnologyParameters are in"
177 + " unnamed module of loader 'app')", e.getMessage());
182 public void testOkFileNameCarrierTechnology() {
183 final String[] args = {"-c", "src/test/resources/parameters/prodConsOKFileName.json"};
184 final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
187 final ApexParameters parameters = new ApexParameterHandler().getParameters(arguments);
188 final FileCarrierTechnologyParameters fileParams = (FileCarrierTechnologyParameters) parameters
189 .getEventOutputParameters().get("aProducer").getCarrierTechnologyParameters();
190 assertTrue(fileParams.getFileName().endsWith("target/aaa.json"));
191 assertEquals(false, fileParams.isStandardError());
192 assertEquals(false, fileParams.isStandardIo());
193 assertEquals(false, fileParams.isStreamingMode());
194 } catch (final ParameterException e) {
195 fail("This test should not throw an exception");
200 public void testBadFileNameCarrierTechnology() {
201 final String[] args = {"-c", "src/test/resources/parameters/prodConsBadFileName.json"};
202 final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
205 new ApexParameterHandler().getParameters(arguments);
206 fail("This test should throw an exception");
207 } catch (final ParameterException e) {
208 assertEquals("validation error(s) on parameters from "
209 + "\"src/test/resources/parameters/prodConsBadFileName.json\"\n"
210 + "parameter group \"APEX_PARAMETERS\" type "
211 + "\"org.onap.policy.apex.service.parameters.ApexParameters\" INVALID, "
212 + "parameter group has status INVALID\n"
213 + " parameter group map \"eventOutputParameters\" INVALID, "
214 + "parameter group map has status INVALID\n" + " parameter group \"aProducer\" type "
215 + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" "
216 + "INVALID, parameter group has status INVALID\n" + " parameter group \"FILE\" type "
217 + "\"org.onap.policy.apex.service.engine.event.impl."
218 + "filecarrierplugin.FileCarrierTechnologyParameters\" INVALID, "
219 + "parameter group has status INVALID\n" + " field \"fileName\" type "
220 + "\"java.lang.String\" value \"null\" INVALID, "
221 + "\"null\" invalid, must be specified as a non-empty string\n", e.getMessage());
226 public void testBadEventProtocolParClass() {
227 final String[] args = {"-c", "src/test/resources/parameters/prodConsBadEPParClass.json"};
228 final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
231 new ApexParameterHandler().getParameters(arguments);
232 fail("This test should throw an exception");
233 } catch (final ParameterException e) {
235 "error reading parameters from \"src/test/resources/parameters/prodConsBadEPParClass.json\"\n"
236 + "(ParameterRuntimeException):event protocol \"SUPER_TOK_DEL\" "
237 + "does not match plugin \"JSON\" in \"org.onap.policy.apex.service.engine.event.impl"
238 + ".jsonprotocolplugin.JsonEventProtocolParameters"
239 + "\", specify correct event protocol parameter plugin in parameter \"parameterClassName\"",
245 public void testNoEventProtocolParClass() {
246 final String[] args = {"-c", "src/test/resources/parameters/prodConsNoEPParClass.json"};
247 final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
250 new ApexParameterHandler().getParameters(arguments);
251 fail("This test should throw an exception");
252 } catch (final ParameterException e) {
253 assertEquals("error reading parameters from \"src/test/resources/parameters/prodConsNoEPParClass.json\"\n"
254 + "(ParameterRuntimeException):event protocol \"SUPER_TOK_DEL\" parameter "
255 + "\"parameterClassName\" value \"null\" invalid in JSON file", e.getMessage());
260 public void testMismatchEventProtocolParClass() {
261 final String[] args = {"-c", "src/test/resources/parameters/prodConsMismatchEPParClass.json"};
262 final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
265 new ApexParameterHandler().getParameters(arguments);
266 fail("This test should throw an exception");
267 } catch (final ParameterException e) {
269 "error reading parameters from "
270 + "\"src/test/resources/parameters/prodConsMismatchEPParClass.json\"\n"
271 + "(ParameterRuntimeException):event protocol \"SUPER_TOK_BEL\" "
272 + "does not match plugin \"SUPER_TOK_DEL\" in "
273 + "\"org.onap.policy.apex.service.engine.parameters.dummyclasses."
274 + "SuperTokenDelimitedEventProtocolParameters\", "
275 + "specify correct event protocol parameter plugin in parameter \"parameterClassName\"",
281 public void testWrongTypeEventProtocolParClass() {
282 final String[] args = {"-c", "src/test/resources/parameters/prodConsWrongTypeEPParClass.json"};
283 final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
286 new ApexParameterHandler().getParameters(arguments);
287 fail("This test should throw an exception");
288 } catch (final ParameterException e) {
289 assertEquals("error reading parameters from "
290 + "\"src/test/resources/parameters/prodConsWrongTypeEPParClass.json\"\n"
291 + "(ParameterRuntimeException):could not create default parameters for event protocol "
292 + "\"SUPER_TOK_DEL\"\n" + "class org.onap.policy.apex.service.engine."
293 + "parameters.dummyclasses.SuperDooperCarrierTechnologyParameters "
294 + "cannot be cast to class org.onap.policy.apex.service."
295 + "parameters.eventprotocol.EventProtocolParameters (org.onap.policy.apex.service.engine.parameters"
296 + ".dummyclasses.SuperDooperCarrierTechnologyParameters and org.onap.policy.apex.service.parameters"
297 + ".eventprotocol.EventProtocolParameters are in unnamed module of loader 'app')", e.getMessage());