2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2018 Ericsson. All rights reserved.
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.apex.service.engine.parameters;
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertFalse;
25 import static org.junit.Assert.assertNotNull;
26 import static org.junit.Assert.assertNull;
27 import static org.junit.Assert.assertTrue;
28 import static org.junit.Assert.fail;
30 import org.junit.Test;
31 import org.onap.policy.apex.service.engine.main.ApexCommandLineArguments;
32 import org.onap.policy.apex.service.parameters.ApexParameterHandler;
33 import org.onap.policy.apex.service.parameters.ApexParameters;
34 import org.onap.policy.common.parameters.ParameterException;
37 * Test the ApexParameters class.
39 public class ApexParametersTest {
42 public void javaPropertiesOk() throws ParameterException {
44 { "-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 javaPropertiesEmpty() throws ParameterException {
62 { "-c", "src/test/resources/parameters/javaPropertiesEmpty.json" };
63 final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
66 ApexParameters parameters = new ApexParameterHandler().getParameters(arguments);
67 assertFalse(parameters.checkJavaPropertiesSet());
68 } catch (final ParameterException pe) {
69 fail("This test should not throw an exception");
75 public void javaPropertiesBad() throws ParameterException {
77 { "-c", "src/test/resources/parameters/javaPropertiesBad.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 pe) {
84 assertTrue(pe.getMessage().contains("java properties array entries must have one key and one value"));
85 assertTrue(pe.getMessage().contains("java properties key is null or blank"));
86 assertTrue(pe.getMessage().contains("java properties value is null or blank"));
87 assertTrue(pe.getMessage().contains("java properties array entry is null"));
92 public void testGettersSetters() {
93 ApexParameters pars = new ApexParameters();
96 pars.setEngineServiceParameters(null);
97 assertNull(pars.getEngineServiceParameters());
99 pars.setEventInputParameters(null);
100 assertNull(pars.getEventInputParameters());
102 pars.setEventOutputParameters(null);
103 assertNull(pars.getEventOutputParameters());
105 assertFalse(pars.checkJavaPropertiesSet());
107 pars.setName("parName");
108 assertEquals("parName", pars.getName());