2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2018 Ericsson. All rights reserved.
4 * Modifications Copyright (C) 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.assertFalse;
26 import static org.junit.Assert.assertNotNull;
27 import static org.junit.Assert.assertNull;
28 import static org.junit.Assert.assertTrue;
29 import static org.junit.Assert.fail;
31 import org.junit.Test;
32 import org.onap.policy.apex.service.engine.main.ApexCommandLineArguments;
33 import org.onap.policy.apex.service.parameters.ApexParameterHandler;
34 import org.onap.policy.apex.service.parameters.ApexParameters;
35 import org.onap.policy.common.parameters.ParameterException;
38 * Test the ApexParameters class.
40 public class ApexParametersTest {
43 public void testJavaPropertiesOk() throws ParameterException {
44 final String[] args = {"-c", "src/test/resources/parameters/javaPropertiesOK.json"};
45 final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
48 ApexParameters parameters = new ApexParameterHandler().getParameters(arguments);
49 assertTrue(parameters.checkJavaPropertiesSet());
50 assertEquals("property0", parameters.getJavaProperties()[0][0]);
51 assertEquals("property0Value", parameters.getJavaProperties()[0][1]);
52 assertEquals("property1", parameters.getJavaProperties()[1][0]);
53 assertEquals("property1Value", parameters.getJavaProperties()[1][1]);
54 } catch (final ParameterException e) {
55 fail("This test should not throw an exception");
60 public void testJavaPropertiesEmpty() throws ParameterException {
61 final String[] args = {"-c", "src/test/resources/parameters/javaPropertiesEmpty.json"};
62 final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
65 ApexParameters parameters = new ApexParameterHandler().getParameters(arguments);
66 assertFalse(parameters.checkJavaPropertiesSet());
67 } catch (final ParameterException pe) {
68 fail("This test should not throw an exception");
73 public void testJavaPropertiesBad() throws ParameterException {
74 final String[] args = {"-c", "src/test/resources/parameters/javaPropertiesBad.json"};
75 final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
78 new ApexParameterHandler().getParameters(arguments);
79 fail("This test should throw an exception");
80 } catch (final ParameterException pe) {
81 assertTrue(pe.getMessage().contains("java properties array entries must have one key and one value"));
82 assertTrue(pe.getMessage().contains("java properties key is null or blank"));
83 assertTrue(pe.getMessage().contains("java properties value is null or blank"));
84 assertTrue(pe.getMessage().contains("java properties array entry is null"));
89 public void testGettersSetters() {
90 ApexParameters pars = new ApexParameters();
93 pars.setEngineServiceParameters(null);
94 assertNull(pars.getEngineServiceParameters());
96 pars.setEventInputParameters(null);
97 assertNull(pars.getEventInputParameters());
99 pars.setEventOutputParameters(null);
100 assertNull(pars.getEventOutputParameters());
102 assertFalse(pars.checkJavaPropertiesSet());
104 pars.setName("parName");
105 assertEquals("parName", pars.getName());