4a946b111b0904bd83039b5bc7be95d92a61589d
[policy/apex-pdp.git] /
1 /*-
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
8  * 
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  * 
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.
16  * 
17  * SPDX-License-Identifier: Apache-2.0
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.policy.apex.service.engine.parameters;
22
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;
29
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;
35
36 /**
37  * Test the ApexParameters class.
38  */
39 public class ApexParametersTest {
40
41     @Test
42     public void javaPropertiesOk() throws ParameterException {
43         final String[] args =
44             { "-c", "src/test/resources/parameters/javaPropertiesOK.json" };
45         final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
46
47         try {
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");
56         }
57     }
58
59     @Test
60     public void javaPropertiesEmpty() throws ParameterException {
61         final String[] args =
62             { "-c", "src/test/resources/parameters/javaPropertiesEmpty.json" };
63         final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
64
65         try {
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");
70         }
71     }
72     
73
74     @Test
75     public void javaPropertiesBad() throws ParameterException {
76         final String[] args =
77             { "-c", "src/test/resources/parameters/javaPropertiesBad.json" };
78         final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
79
80         try {
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"));
88         }
89     }
90     
91     @Test
92     public void testGettersSetters() {
93         ApexParameters pars = new ApexParameters();
94         assertNotNull(pars);
95         
96         pars.setEngineServiceParameters(null);
97         assertNull(pars.getEngineServiceParameters());
98         
99         pars.setEventInputParameters(null);
100         assertNull(pars.getEventInputParameters());
101         
102         pars.setEventOutputParameters(null);
103         assertNull(pars.getEventOutputParameters());
104         
105         assertFalse(pars.checkJavaPropertiesSet());
106         
107         pars.setName("parName");
108         assertEquals("parName", pars.getName());
109     }
110 }