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 * @author Liam Fallon (liam.fallon@ericsson.com)
33 public class TestApexCommandLineArguments {
36 public void testCommandLineArguments() {
37 final ApexCommandLineArguments apexArguments = new ApexCommandLineArguments();
39 final String[] args00 = {""};
41 apexArguments.parse(args00);
42 apexArguments.validate();
43 fail("Test should throw an exception here");
44 } catch (final ApexException e) {
45 assertEquals("Apex configuration file was not specified as an argument", e.getMessage());
48 final String[] args01 = {"-h"};
50 final String result = apexArguments.parse(args01);
51 assertTrue(result.startsWith("usage: org.onap.policy.apex.service.engine.main.ApexMain [options...]"));
52 } catch (final ApexException e) {
54 fail("Test should not throw an exception");
57 final String[] args02 = {"-v"};
59 final String result = apexArguments.parse(args02);
60 assertTrue(result.startsWith("Apex Adaptive Policy Engine"));
61 } catch (final ApexException e) {
63 fail("Test should not throw an exception");
66 final String[] args03 = {"-v", "-h"};
68 final String result = apexArguments.parse(args03);
69 assertTrue(result.startsWith("usage: org.onap.policy.apex.service.engine.main.ApexMain [options...]"));
70 } catch (final ApexException e) {
72 fail("Test should not throw an exception");
75 final String[] args04 = {"-h", "-v"};
77 final String result = apexArguments.parse(args04);
78 assertTrue(result.startsWith("usage: org.onap.policy.apex.service.engine.main.ApexMain [options...]"));
79 } catch (final ApexException e) {
81 fail("Test should not throw an exception");
84 final String[] args05 = {"-a"};
86 apexArguments.parse(args05);
87 } catch (final ApexException e) {
88 assertEquals("invalid command line arguments specified : Unrecognized option: -a", e.getMessage());
91 final String[] args06 = {"-c", "hello", "-m", "goodbye", "-h", "-v"};
93 final String result = apexArguments.parse(args06);
94 assertTrue(result.startsWith("usage: org.onap.policy.apex.service.engine.main.ApexMain [options...]"));
95 } catch (final ApexException e) {
96 assertEquals("invalid command line arguments specified : Unrecognized option: -a", e.getMessage());
99 final String[] args07 = {"-c", "hello", "-m", "goodbye", "-h", "aaa"};
101 final String result = apexArguments.parse(args07);
102 assertTrue(result.startsWith("usage: org.onap.policy.apex.service.engine.main.ApexMain [options...]"));
103 } catch (final ApexException e) {
104 assertEquals("too many command line arguments specified : [-c, hello, -m, goodbye, -h, aaa]",
110 public void testCommandLineFileParameters() {
111 final ApexCommandLineArguments apexArguments = new ApexCommandLineArguments();
113 final String[] args00 = {"-c", "zooby"};
115 apexArguments.parse(args00);
116 apexArguments.validate();
117 fail("Test should throw an exception here");
118 } catch (final ApexException e) {
119 assertEquals("Apex configuration file \"zooby\" does not exist", e.getMessage());
122 final String[] args01 = {"-c"};
124 apexArguments.parse(args01);
125 apexArguments.validate();
126 fail("Test should throw an exception here");
127 } catch (final ApexException e) {
128 assertEquals("invalid command line arguments specified : Missing argument for option: c", e.getMessage());
131 final String[] args02 = {"-c", "src/test/resources/parameters/goodParams.json"};
133 apexArguments.parse(args02);
134 apexArguments.validate();
135 } catch (final ApexException e) {
137 fail("Test should not throw an exception");
140 final String[] args03 = {"-c", "src/test/resources/parameters/goodParams.json", "-m", "zooby"};
142 apexArguments.parse(args03);
143 apexArguments.validate();
144 fail("Test should throw an exception here");
145 } catch (final ApexException e) {
146 assertEquals("Apex model file \"zooby\" does not exist", e.getMessage());
149 final String[] args04 = {"-m"};
151 apexArguments.parse(args04);
152 apexArguments.validate();
153 fail("Test should throw an exception here");
154 } catch (final ApexException e) {
155 assertEquals("invalid command line arguments specified : Missing argument for option: m", e.getMessage());
158 final String[] args05 = {"-c", "src/test/resources/parameters/goodParams.json", "-m"};
160 apexArguments.parse(args05);
161 apexArguments.validate();
162 fail("Test should throw an exception here");
163 } catch (final ApexException e) {
164 assertEquals("invalid command line arguments specified : Missing argument for option: m", e.getMessage());
167 final String[] args06 = {"-c", "src/test/resources/parameters/goodParams.json", "-m",
168 "src/test/resources/main/DummyModelFile.json"};
170 apexArguments.parse(args06);
171 apexArguments.validate();
172 } catch (final ApexException e) {
174 fail("Test should not throw an exception");
177 final String[] args07 = {"-c", "parameters/goodParams.json", "-m", "main/DummyModelFile.json"};
179 apexArguments.parse(args07);
180 apexArguments.validate();
181 } catch (final ApexException e) {
183 fail("Test should not throw an exception");