2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2016-2018 Ericsson. All rights reserved.
4 * Modifications Copyright (C) 2019 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 goodParametersTest() {
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 noCarrierTechnology() {
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 noEventProcol() {
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 noCarrierTechnologyParClass() {
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 mismatchCarrierTechnologyParClass() {
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 wrongTypeCarrierTechnologyParClass() {
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) {
170 "error reading parameters from "
171 + "\"src/test/resources/parameters/prodConsWrongTypeCTParClass.json\"\n"
172 + "(ParameterRuntimeException):could not create default parameters for carrier technology "
173 + "\"SUPER_DOOPER\"\n" + "org.onap.policy.apex.service.engine.parameters.dummyclasses."
174 + "SuperTokenDelimitedEventProtocolParameters cannot be cast to "
175 + "org.onap.policy.apex.service.parameters.carriertechnology.CarrierTechnologyParameters",
181 public void okFileNameCarrierTechnology() {
182 final String[] args = {"-c", "src/test/resources/parameters/prodConsOKFileName.json"};
183 final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
186 final ApexParameters parameters = new ApexParameterHandler().getParameters(arguments);
187 final FileCarrierTechnologyParameters fileParams = (FileCarrierTechnologyParameters) parameters
188 .getEventOutputParameters().get("aProducer").getCarrierTechnologyParameters();
189 assertTrue(fileParams.getFileName().endsWith("target/aaa.json"));
190 assertEquals(false, fileParams.isStandardError());
191 assertEquals(false, fileParams.isStandardIo());
192 assertEquals(false, fileParams.isStreamingMode());
193 } catch (final ParameterException e) {
194 fail("This test should not throw an exception");
199 public void badFileNameCarrierTechnology() {
200 final String[] args = {"-c", "src/test/resources/parameters/prodConsBadFileName.json"};
201 final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
204 new ApexParameterHandler().getParameters(arguments);
205 fail("This test should throw an exception");
206 } catch (final ParameterException e) {
207 assertEquals("validation error(s) on parameters from "
208 + "\"src/test/resources/parameters/prodConsBadFileName.json\"\n"
209 + "parameter group \"APEX_PARAMETERS\" type "
210 + "\"org.onap.policy.apex.service.parameters.ApexParameters\" INVALID, "
211 + "parameter group has status INVALID\n"
212 + " parameter group map \"eventOutputParameters\" INVALID, "
213 + "parameter group map has status INVALID\n" + " parameter group \"aProducer\" type "
214 + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" "
215 + "INVALID, parameter group has status INVALID\n" + " parameter group \"FILE\" type "
216 + "\"org.onap.policy.apex.service.engine.event.impl."
217 + "filecarrierplugin.FileCarrierTechnologyParameters\" INVALID, "
218 + "parameter group has status INVALID\n" + " field \"fileName\" type "
219 + "\"java.lang.String\" value \"null\" INVALID, "
220 + "\"null\" invalid, must be specified as a non-empty string\n", e.getMessage());
225 public void badEventProtocolParClass() {
226 final String[] args = {"-c", "src/test/resources/parameters/prodConsBadEPParClass.json"};
227 final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
230 new ApexParameterHandler().getParameters(arguments);
231 fail("This test should throw an exception");
232 } catch (final ParameterException e) {
234 "error reading parameters from \"src/test/resources/parameters/prodConsBadEPParClass.json\"\n"
235 + "(ParameterRuntimeException):event protocol \"SUPER_TOK_DEL\" "
236 + "does not match plugin \"JSON\" in \"org.onap.policy.apex.service.engine.event.impl"
237 + ".jsonprotocolplugin.JsonEventProtocolParameters"
238 + "\", specify correct event protocol parameter plugin in parameter \"parameterClassName\"",
244 public void noEventProtocolParClass() {
245 final String[] args = {"-c", "src/test/resources/parameters/prodConsNoEPParClass.json"};
246 final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
249 new ApexParameterHandler().getParameters(arguments);
250 fail("This test should throw an exception");
251 } catch (final ParameterException e) {
252 assertEquals("error reading parameters from \"src/test/resources/parameters/prodConsNoEPParClass.json\"\n"
253 + "(ParameterRuntimeException):event protocol \"SUPER_TOK_DEL\" parameter "
254 + "\"parameterClassName\" value \"null\" invalid in JSON file", e.getMessage());
259 public void mismatchEventProtocolParClass() {
260 final String[] args = {"-c", "src/test/resources/parameters/prodConsMismatchEPParClass.json"};
261 final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
264 new ApexParameterHandler().getParameters(arguments);
265 fail("This test should throw an exception");
266 } catch (final ParameterException e) {
268 "error reading parameters from "
269 + "\"src/test/resources/parameters/prodConsMismatchEPParClass.json\"\n"
270 + "(ParameterRuntimeException):event protocol \"SUPER_TOK_BEL\" "
271 + "does not match plugin \"SUPER_TOK_DEL\" in "
272 + "\"org.onap.policy.apex.service.engine.parameters.dummyclasses."
273 + "SuperTokenDelimitedEventProtocolParameters\", "
274 + "specify correct event protocol parameter plugin in parameter \"parameterClassName\"",
280 public void wrongTypeEventProtocolParClass() {
281 final String[] args = {"-c", "src/test/resources/parameters/prodConsWrongTypeEPParClass.json"};
282 final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
285 new ApexParameterHandler().getParameters(arguments);
286 fail("This test should throw an exception");
287 } catch (final ParameterException e) {
288 assertEquals("error reading parameters from "
289 + "\"src/test/resources/parameters/prodConsWrongTypeEPParClass.json\"\n"
290 + "(ParameterRuntimeException):could not create default parameters for event protocol "
291 + "\"SUPER_TOK_DEL\"\n" + "org.onap.policy.apex.service.engine."
292 + "parameters.dummyclasses.SuperDooperCarrierTechnologyParameters "
293 + "cannot be cast to org.onap.policy.apex.service."
294 + "parameters.eventprotocol.EventProtocolParameters", e.getMessage());