2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2016-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.main;
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertTrue;
25 import static org.junit.Assert.fail;
27 import org.junit.After;
28 import org.junit.Test;
29 import org.onap.policy.apex.model.basicmodel.concepts.ApexException;
32 * Test Apex Command Line Arguments.
34 * @author Liam Fallon (liam.fallon@ericsson.com)
36 public class ApexCommandLineArgumentsTest {
38 public void clearRelativeFileRoot() {
39 System.clearProperty("APEX_RELATIVE_FILE_ROOT");
43 public void testCommandLineArguments() {
44 final ApexCommandLineArguments apexArguments = new ApexCommandLineArguments();
46 final String[] args00 =
49 apexArguments.parse(args00);
50 apexArguments.validate();
51 fail("Test should throw an exception here");
52 } catch (final ApexException e) {
53 assertEquals("Apex configuration file was not specified as an argument", e.getMessage());
56 final String[] args01 =
59 final String result = apexArguments.parse(args01);
60 assertTrue(result.startsWith("usage: org.onap.policy.apex.service.engine.main.ApexMain [options...]"));
61 } catch (final ApexException e) {
63 fail("Test should not throw an exception");
66 final String[] args02 =
69 final String result = apexArguments.parse(args02);
70 assertTrue(result.startsWith("Apex Adaptive Policy Engine"));
71 } catch (final ApexException e) {
73 fail("Test should not throw an exception");
76 final String[] args03 =
79 final String result = apexArguments.parse(args03);
80 assertTrue(result.startsWith("usage: org.onap.policy.apex.service.engine.main.ApexMain [options...]"));
81 } catch (final ApexException e) {
83 fail("Test should not throw an exception");
86 final String[] args04 =
89 final String result = apexArguments.parse(args04);
90 assertTrue(result.startsWith("usage: org.onap.policy.apex.service.engine.main.ApexMain [options...]"));
91 } catch (final ApexException e) {
93 fail("Test should not throw an exception");
96 final String[] args05 =
99 apexArguments.parse(args05);
100 } catch (final ApexException e) {
101 assertEquals("invalid command line arguments specified : Unrecognized option: -a", e.getMessage());
104 final String[] args06 =
105 { "-c", "hello", "-m", "goodbye", "-h", "-v" };
107 final String result = apexArguments.parse(args06);
108 assertTrue(result.startsWith("usage: org.onap.policy.apex.service.engine.main.ApexMain [options...]"));
109 } catch (final ApexException e) {
110 assertEquals("invalid command line arguments specified : Unrecognized option: -a", e.getMessage());
113 final String[] args07 =
114 { "-c", "hello", "-m", "goodbye", "-h", "aaa" };
116 final String result = apexArguments.parse(args07);
117 assertTrue(result.startsWith("usage: org.onap.policy.apex.service.engine.main.ApexMain [options...]"));
118 } catch (final ApexException e) {
119 assertEquals("too many command line arguments specified : [-c, hello, -m, goodbye, -h, aaa]",
125 public void testCommandLineFileParameters() {
126 final ApexCommandLineArguments apexArguments = new ApexCommandLineArguments();
128 final String[] args00 =
131 apexArguments.parse(args00);
132 apexArguments.validate();
133 fail("Test should throw an exception here");
134 } catch (final ApexException e) {
135 assertEquals("Apex configuration file \"zooby\" does not exist", e.getMessage());
138 final String[] args01 =
141 apexArguments.parse(args01);
142 apexArguments.validate();
143 fail("Test should throw an exception here");
144 } catch (final ApexException e) {
145 assertEquals("invalid command line arguments specified : Missing argument for option: c", e.getMessage());
148 final String[] args02 =
149 { "-c", "src/test/resources/parameters/goodParams.json" };
151 apexArguments.parse(args02);
152 apexArguments.validate();
153 } catch (final ApexException e) {
155 fail("Test should not throw an exception");
158 final String[] args03 =
159 { "-c", "src/test/resources/parameters/goodParams.json", "-m", "zooby" };
161 apexArguments.parse(args03);
162 apexArguments.validate();
163 fail("Test should throw an exception here");
164 } catch (final ApexException e) {
165 assertEquals("Apex model file \"zooby\" does not exist", e.getMessage());
168 final String[] args04 =
171 apexArguments.parse(args04);
172 apexArguments.validate();
173 fail("Test should throw an exception here");
174 } catch (final ApexException e) {
175 assertEquals("invalid command line arguments specified : Missing argument for option: m", e.getMessage());
178 final String[] args05 =
179 { "-c", "src/test/resources/parameters/goodParams.json", "-m" };
181 apexArguments.parse(args05);
182 apexArguments.validate();
183 fail("Test should throw an exception here");
184 } catch (final ApexException e) {
185 assertEquals("invalid command line arguments specified : Missing argument for option: m", e.getMessage());
188 final String[] args06 =
189 { "-c", "src/test/resources/parameters/goodParams.json", "-m",
190 "src/test/resources/main/DummyModelFile.json" };
192 apexArguments.parse(args06);
193 apexArguments.validate();
194 } catch (final ApexException e) {
196 fail("Test should not throw an exception");
199 final String[] args07 =
200 { "-c", "parameters/goodParams.json", "-m", "main/DummyModelFile.json" };
202 apexArguments.parse(args07);
203 apexArguments.validate();
204 } catch (final ApexException e) {
206 fail("Test should not throw an exception");
211 public void testCommandLineRelativeRootParameters() {
212 final ApexCommandLineArguments apexArguments = new ApexCommandLineArguments();
214 final String[] args00 =
215 { "-c", "src/test/resources/parameters/goodParams.json", "-rfr", "zooby" };
217 apexArguments.parse(args00);
218 apexArguments.validate();
219 fail("Test should throw an exception here");
220 } catch (final ApexException e) {
221 assertTrue(e.getMessage().contains("zooby\" does not exist or is not a directory"));
224 final String[] args01 =
227 apexArguments.parse(args01);
228 apexArguments.validate();
229 fail("Test should throw an exception here");
230 } catch (final ApexException e) {
231 assertEquals("invalid command line arguments specified : Missing argument for option: rfr", e.getMessage());
234 final String[] args02 =
235 { "-c", "src/test/resources/parameters/goodParams.json", "-rfr", "pom.xml" };
237 apexArguments.parse(args02);
238 apexArguments.validate();
239 fail("Test should throw an exception here");
240 } catch (final ApexException e) {
241 assertTrue(e.getMessage().contains("pom.xml\" does not exist or is not a directory"));
244 final String[] args03 =
245 { "-c", "src/test/resources/parameters/goodParams.json", "-rfr", "target" };
247 apexArguments.parse(args03);
248 apexArguments.validate();
249 } catch (final ApexException e) {
250 fail("Test should not throw an exception here");
253 final String[] args04 =
254 { "-c", "src/test/resources/parameters/goodParamsRelative.json", "-rfr", "src/test/resources" };
256 apexArguments.parse(args04);
257 apexArguments.validate();
258 } catch (final ApexException e) {
259 fail("Test should not throw an exception here");