2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2016-2018 Ericsson. All rights reserved.
4 * Modifications Copyright (C) 2019-2020 Nordix Foundation.
5 * Modifications Copyright (C) 2020 Bell Canada. All rights reserved.
6 * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
20 * SPDX-License-Identifier: Apache-2.0
21 * ============LICENSE_END=========================================================
24 package org.onap.policy.apex.service.engine.parameters;
26 import static org.assertj.core.api.Assertions.assertThatThrownBy;
27 import static org.junit.Assert.assertEquals;
28 import static org.junit.Assert.assertFalse;
29 import static org.junit.Assert.assertTrue;
31 import java.nio.file.NoSuchFileException;
32 import java.util.Arrays;
33 import org.junit.Test;
34 import org.onap.policy.apex.service.engine.event.impl.filecarrierplugin.consumer.ApexFileEventConsumer;
35 import org.onap.policy.apex.service.engine.event.impl.filecarrierplugin.producer.ApexFileEventProducer;
36 import org.onap.policy.apex.service.engine.main.ApexCommandLineArguments;
37 import org.onap.policy.apex.service.engine.parameters.dummyclasses.SuperDooperCarrierTechnologyParameters;
38 import org.onap.policy.apex.service.engine.parameters.dummyclasses.SuperDooperEventProducer;
39 import org.onap.policy.apex.service.engine.parameters.dummyclasses.SuperDooperEventSubscriber;
40 import org.onap.policy.apex.service.parameters.ApexParameterHandler;
41 import org.onap.policy.apex.service.parameters.ApexParameters;
42 import org.onap.policy.apex.service.parameters.carriertechnology.CarrierTechnologyParameters;
43 import org.onap.policy.apex.service.parameters.eventprotocol.EventProtocolParameters;
44 import org.onap.policy.common.parameters.ParameterException;
47 * Test for an empty parameter file.
49 * @author Liam Fallon (liam.fallon@ericsson.com)
51 public class ParameterTests {
53 public void testInvalidParametersNoFileTest() throws ParameterException {
54 final String[] args = {"-p", "src/test/resources/parameters/invalidNoFile.json"};
55 final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
57 assertThatThrownBy(() -> new ApexParameterHandler().getParameters(arguments))
58 .hasRootCauseInstanceOf(NoSuchFileException.class);
62 public void testInvalidParametersEmptyTest() {
63 final String[] args = {"-p", "src/test/resources/parameters/empty.json"};
64 final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
66 assertThatThrownBy(() -> new ApexParameterHandler().getParameters(arguments))
67 .hasMessageStartingWith("error reading parameters from \"src/test/resources/parameters/empty.json");
71 public void testInvalidParametersNoParamsTest() {
72 final String[] args = {"-p", "src/test/resources/parameters/noParams.json"};
73 final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
75 assertThatThrownBy(() -> new ApexParameterHandler().getParameters(arguments))
76 .hasMessageContaining("src/test/resources/parameters/noParams.json")
77 .hasMessageContaining("ApexParameters")
78 .hasMessageContaining("\"engineServiceParameters\" value \"null\" INVALID, is null")
79 .hasMessageContaining("\"eventOutputParameters\" value \"{}\" INVALID, minimum number of elements: 1")
80 .hasMessageContaining("\"eventInputParameters\" value \"{}\" INVALID, minimum number of elements: 1");
84 public void testInvalidParametersBlankParamsTest() {
85 final String[] args = {"-p", "src/test/resources/parameters/blankParams.json"};
86 final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
88 assertThatThrownBy(() -> new ApexParameterHandler().getParameters(arguments))
89 .hasMessageContaining("src/test/resources/parameters/blankParams.json")
90 .hasMessageContaining("ApexParameters")
91 .hasMessageContaining("EngineServiceParameters")
92 .hasMessageContaining("\"id\" value \"-1\" INVALID, is below the minimum")
93 .hasMessageContaining("\"policyModel\" value \"null\" INVALID, is null")
94 .hasMessageContaining("\"eventOutputParameters\" value \"{}\" INVALID, minimum number of elements")
95 .hasMessageContaining("\"eventInputParameters\" value \"{}\" INVALID, minimum number of elements");
99 public void testInvalidParametersTest() {
100 final String[] args = {"-p", "src/test/resources/parameters/badParams.json"};
101 final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
103 assertThatThrownBy(() -> new ApexParameterHandler().getParameters(arguments))
104 .hasMessageContaining("src/test/resources/parameters/badParams.json")
105 .hasMessageContaining("ApexParameters")
106 .hasMessageContaining("EngineServiceParameters")
107 .hasMessageContaining("\"name\" value \"hello there\" INVALID, does not match")
108 .hasMessageContaining("\"id\" value \"-45\" INVALID, is below the minimum")
109 .hasMessageContaining("\"instanceCount\" value \"-345\" INVALID, is below the minimum")
110 .hasMessageContaining("\"deploymentPort\" value \"65536\" INVALID, exceeds the maximum")
111 .hasMessageContaining("eventOutputParameters", "FirstProducer", "EventHandlerParameters",
112 "FileCarrierTechnologyParameters")
113 .hasMessageContaining("\"fileName\" value \"null\" INVALID, is blank")
114 .hasMessageContaining("eventInputParameters", "TheFileConsumer1", "EventHandlerParameters",
115 "FileCarrierTechnologyParameters")
116 .hasMessageContaining("\"fileName\" value \"null\" INVALID, is blank");
120 public void testGoodParametersTest() throws ParameterException {
121 final String[] args = {"-p", "src/test/resources/parameters/goodParams.json"};
122 final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
124 final ApexParameters parameters = new ApexParameterHandler().getParameters(arguments);
126 assertEquals(2, parameters.getEventInputParameters().size());
127 assertEquals(2, parameters.getEventOutputParameters().size());
128 assertTrue(parameters.getEventOutputParameters().containsKey("FirstProducer"));
129 assertTrue(parameters.getEventOutputParameters().containsKey("MyOtherProducer"));
130 assertEquals("FILE", parameters.getEventOutputParameters().get("FirstProducer")
131 .getCarrierTechnologyParameters().getLabel());
132 assertEquals("FILE", parameters.getEventOutputParameters().get("MyOtherProducer")
133 .getCarrierTechnologyParameters().getLabel());
134 assertEquals(ApexFileEventProducer.class.getName(), parameters.getEventOutputParameters()
135 .get("MyOtherProducer").getCarrierTechnologyParameters().getEventProducerPluginClass());
136 assertEquals(ApexFileEventConsumer.class.getName(), parameters.getEventOutputParameters()
137 .get("MyOtherProducer").getCarrierTechnologyParameters().getEventConsumerPluginClass());
139 parameters.getEventOutputParameters().get("FirstProducer").getEventProtocolParameters().getLabel());
140 assertEquals("JSON", parameters.getEventOutputParameters().get("MyOtherProducer")
141 .getEventProtocolParameters().getLabel());
143 assertTrue(parameters.getEventInputParameters().containsKey("TheFileConsumer1"));
144 assertTrue(parameters.getEventInputParameters().containsKey("MySuperDooperConsumer1"));
145 assertEquals("FILE", parameters.getEventInputParameters().get("TheFileConsumer1")
146 .getCarrierTechnologyParameters().getLabel());
147 assertEquals("SUPER_DOOPER", parameters.getEventInputParameters().get("MySuperDooperConsumer1")
148 .getCarrierTechnologyParameters().getLabel());
149 assertEquals("JSON", parameters.getEventInputParameters().get("TheFileConsumer1")
150 .getEventProtocolParameters().getLabel());
151 assertEquals("SUPER_TOK_DEL", parameters.getEventInputParameters().get("MySuperDooperConsumer1")
152 .getEventProtocolParameters().getLabel());
153 assertEquals(ApexFileEventProducer.class.getName(), parameters.getEventInputParameters()
154 .get("TheFileConsumer1").getCarrierTechnologyParameters().getEventProducerPluginClass());
155 assertEquals(ApexFileEventConsumer.class.getName(), parameters.getEventInputParameters()
156 .get("TheFileConsumer1").getCarrierTechnologyParameters().getEventConsumerPluginClass());
157 assertEquals(SuperDooperEventProducer.class.getName(), parameters.getEventInputParameters()
158 .get("MySuperDooperConsumer1").getCarrierTechnologyParameters().getEventProducerPluginClass());
159 assertEquals(SuperDooperEventSubscriber.class.getName(), parameters.getEventInputParameters()
160 .get("MySuperDooperConsumer1").getCarrierTechnologyParameters().getEventConsumerPluginClass());
164 public void testSuperDooperParametersTest() throws ParameterException {
165 final String[] args = {"-p", "src/test/resources/parameters/superDooperParams.json"};
166 final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
168 final ApexParameters parameters = new ApexParameterHandler().getParameters(arguments);
170 assertEquals("MyApexEngine", parameters.getEngineServiceParameters().getName());
171 assertEquals("0.0.1", parameters.getEngineServiceParameters().getVersion());
172 assertEquals(45, parameters.getEngineServiceParameters().getId());
173 assertEquals(345, parameters.getEngineServiceParameters().getInstanceCount());
174 assertEquals(65522, parameters.getEngineServiceParameters().getDeploymentPort());
176 final CarrierTechnologyParameters prodCarrierTech =
177 parameters.getEventOutputParameters().get("FirstProducer").getCarrierTechnologyParameters();
178 final EventProtocolParameters prodEventProt =
179 parameters.getEventOutputParameters().get("FirstProducer").getEventProtocolParameters();
180 final CarrierTechnologyParameters consCarrierTech =
181 parameters.getEventInputParameters().get("MySuperDooperConsumer1").getCarrierTechnologyParameters();
182 final EventProtocolParameters consEventProt =
183 parameters.getEventInputParameters().get("MySuperDooperConsumer1").getEventProtocolParameters();
185 assertEquals("SUPER_DOOPER", prodCarrierTech.getLabel());
186 assertEquals("SUPER_TOK_DEL", prodEventProt.getLabel());
187 assertEquals("SUPER_DOOPER", consCarrierTech.getLabel());
188 assertEquals("JSON", consEventProt.getLabel());
190 assertTrue(prodCarrierTech instanceof SuperDooperCarrierTechnologyParameters);
192 final SuperDooperCarrierTechnologyParameters superDooperParameters =
193 (SuperDooperCarrierTechnologyParameters) prodCarrierTech;
194 assertEquals("somehost:12345", superDooperParameters.getBootstrapServers());
195 assertEquals("0", superDooperParameters.getAcks());
196 assertEquals(25, superDooperParameters.getRetries());
197 assertEquals(98765, superDooperParameters.getBatchSize());
198 assertEquals(21, superDooperParameters.getLingerTime());
199 assertEquals(50505050, superDooperParameters.getBufferMemory());
200 assertEquals("first-group-id", superDooperParameters.getGroupId());
201 assertFalse(superDooperParameters.isEnableAutoCommit());
202 assertEquals(441, superDooperParameters.getAutoCommitTime());
203 assertEquals(987, superDooperParameters.getSessionTimeout());
204 assertEquals("producer-out", superDooperParameters.getProducerTopic());
205 assertEquals(101, superDooperParameters.getConsumerPollTime());
206 assertEquals("some.key.serailizer", superDooperParameters.getKeySerializer());
207 assertEquals("some.value.serailizer", superDooperParameters.getValueSerializer());
208 assertEquals("some.key.deserailizer", superDooperParameters.getKeyDeserializer());
209 assertEquals("some.value.deserailizer", superDooperParameters.getValueDeserializer());
211 final String[] consumerTopics = {"consumer-out-0", "consumer-out-1", "consumer-out-2"};
212 assertEquals(Arrays.asList(consumerTopics), superDooperParameters.getConsumerTopicList());