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.Test;
28 import org.onap.policy.apex.model.basicmodel.concepts.ApexException;
31 * Test Apex Command Line Arguments.
32 * @author Liam Fallon (liam.fallon@ericsson.com)
34 public class TestApexCommandLineArguments {
37 public void testCommandLineArguments() {
38 final ApexCommandLineArguments apexArguments = new ApexCommandLineArguments();
40 final String[] args00 = {""};
42 apexArguments.parse(args00);
43 apexArguments.validate();
44 fail("Test should throw an exception here");
45 } catch (final ApexException e) {
46 assertEquals("Apex configuration file was not specified as an argument", e.getMessage());
49 final String[] args01 = {"-h"};
51 final String result = apexArguments.parse(args01);
52 assertTrue(result.startsWith("usage: org.onap.policy.apex.service.engine.main.ApexMain [options...]"));
53 } catch (final ApexException e) {
55 fail("Test should not throw an exception");
58 final String[] args02 = {"-v"};
60 final String result = apexArguments.parse(args02);
61 assertTrue(result.startsWith("Apex Adaptive Policy Engine"));
62 } catch (final ApexException e) {
64 fail("Test should not throw an exception");
67 final String[] args03 = {"-v", "-h"};
69 final String result = apexArguments.parse(args03);
70 assertTrue(result.startsWith("usage: org.onap.policy.apex.service.engine.main.ApexMain [options...]"));
71 } catch (final ApexException e) {
73 fail("Test should not throw an exception");
76 final String[] args04 = {"-h", "-v"};
78 final String result = apexArguments.parse(args04);
79 assertTrue(result.startsWith("usage: org.onap.policy.apex.service.engine.main.ApexMain [options...]"));
80 } catch (final ApexException e) {
82 fail("Test should not throw an exception");
85 final String[] args05 = {"-a"};
87 apexArguments.parse(args05);
88 } catch (final ApexException e) {
89 assertEquals("invalid command line arguments specified : Unrecognized option: -a", e.getMessage());
92 final String[] args06 = {"-c", "hello", "-m", "goodbye", "-h", "-v"};
94 final String result = apexArguments.parse(args06);
95 assertTrue(result.startsWith("usage: org.onap.policy.apex.service.engine.main.ApexMain [options...]"));
96 } catch (final ApexException e) {
97 assertEquals("invalid command line arguments specified : Unrecognized option: -a", e.getMessage());
100 final String[] args07 = {"-c", "hello", "-m", "goodbye", "-h", "aaa"};
102 final String result = apexArguments.parse(args07);
103 assertTrue(result.startsWith("usage: org.onap.policy.apex.service.engine.main.ApexMain [options...]"));
104 } catch (final ApexException e) {
105 assertEquals("too many command line arguments specified : [-c, hello, -m, goodbye, -h, aaa]",
111 public void testCommandLineFileParameters() {
112 final ApexCommandLineArguments apexArguments = new ApexCommandLineArguments();
114 final String[] args00 = {"-c", "zooby"};
116 apexArguments.parse(args00);
117 apexArguments.validate();
118 fail("Test should throw an exception here");
119 } catch (final ApexException e) {
120 assertEquals("Apex configuration file \"zooby\" does not exist", e.getMessage());
123 final String[] args01 = {"-c"};
125 apexArguments.parse(args01);
126 apexArguments.validate();
127 fail("Test should throw an exception here");
128 } catch (final ApexException e) {
129 assertEquals("invalid command line arguments specified : Missing argument for option: c", e.getMessage());
132 final String[] args02 = {"-c", "src/test/resources/parameters/goodParams.json"};
134 apexArguments.parse(args02);
135 apexArguments.validate();
136 } catch (final ApexException e) {
138 fail("Test should not throw an exception");
141 final String[] args03 = {"-c", "src/test/resources/parameters/goodParams.json", "-m", "zooby"};
143 apexArguments.parse(args03);
144 apexArguments.validate();
145 fail("Test should throw an exception here");
146 } catch (final ApexException e) {
147 assertEquals("Apex model file \"zooby\" does not exist", e.getMessage());
150 final String[] args04 = {"-m"};
152 apexArguments.parse(args04);
153 apexArguments.validate();
154 fail("Test should throw an exception here");
155 } catch (final ApexException e) {
156 assertEquals("invalid command line arguments specified : Missing argument for option: m", e.getMessage());
159 final String[] args05 = {"-c", "src/test/resources/parameters/goodParams.json", "-m"};
161 apexArguments.parse(args05);
162 apexArguments.validate();
163 fail("Test should throw an exception here");
164 } catch (final ApexException e) {
165 assertEquals("invalid command line arguments specified : Missing argument for option: m", e.getMessage());
168 final String[] args06 = {"-c", "src/test/resources/parameters/goodParams.json", "-m",
169 "src/test/resources/main/DummyModelFile.json"};
171 apexArguments.parse(args06);
172 apexArguments.validate();
173 } catch (final ApexException e) {
175 fail("Test should not throw an exception");
178 final String[] args07 = {"-c", "parameters/goodParams.json", "-m", "main/DummyModelFile.json"};
180 apexArguments.parse(args07);
181 apexArguments.validate();
182 } catch (final ApexException e) {
184 fail("Test should not throw an exception");