2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2018 Ericsson. All rights reserved.
4 * Modifications Copyright (C) 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.assertNotNull;
30 import static org.junit.Assert.assertNull;
31 import static org.junit.Assert.assertTrue;
33 import org.junit.Test;
34 import org.onap.policy.apex.service.engine.main.ApexCommandLineArguments;
35 import org.onap.policy.apex.service.parameters.ApexParameterHandler;
36 import org.onap.policy.apex.service.parameters.ApexParameters;
37 import org.onap.policy.common.parameters.ParameterException;
40 * Test the ApexParameters class.
42 public class ApexParametersTest {
45 public void testJavaPropertiesOk() throws ParameterException {
46 final String[] args = {"-p", "src/test/resources/parameters/javaPropertiesOK.json"};
47 final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
49 ApexParameters parameters = new ApexParameterHandler().getParameters(arguments);
50 assertTrue(parameters.checkJavaPropertiesSet());
51 assertEquals("property0", parameters.getJavaProperties()[0][0]);
52 assertEquals("property0Value", parameters.getJavaProperties()[0][1]);
53 assertEquals("property1", parameters.getJavaProperties()[1][0]);
54 assertEquals("property1Value", parameters.getJavaProperties()[1][1]);
59 public void testJavaPropertiesEmpty() throws ParameterException {
60 final String[] args = {"-p", "src/test/resources/parameters/javaPropertiesEmpty.json"};
61 final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
63 ApexParameters parameters = new ApexParameterHandler().getParameters(arguments);
64 assertFalse(parameters.checkJavaPropertiesSet());
69 public void testJavaPropertiesBad() throws ParameterException {
70 final String[] args = {"-p", "src/test/resources/parameters/javaPropertiesBad.json"};
71 final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
73 assertThatThrownBy(() -> new ApexParameterHandler().getParameters(arguments))
74 .hasMessageContaining("\"javaProperties\"")
75 .hasMessageContaining("entry 0", "entry 1", "entry 2", "entry 3", "entry 4", "entry 5")
76 .hasMessageContaining("must have one key and one value")
77 .hasMessageContaining("\"key\" value \"null\" INVALID, is blank")
78 .hasMessageContaining("\"value\" value \"null\" INVALID, is blank");
82 public void testGettersSetters() {
83 ApexParameters pars = new ApexParameters();
86 pars.setEngineServiceParameters(null);
87 assertNull(pars.getEngineServiceParameters());
89 pars.setEventInputParameters(null);
90 assertNull(pars.getEventInputParameters());
92 pars.setEventOutputParameters(null);
93 assertNull(pars.getEventOutputParameters());
95 assertFalse(pars.checkJavaPropertiesSet());
97 pars.setName("parName");
98 assertEquals("parName", pars.getName());