aboutsummaryrefslogtreecommitdiffstats
path: root/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/main/ApexCommandLineArgumentsTest.java
diff options
context:
space:
mode:
Diffstat (limited to 'services/services-engine/src/test/java/org/onap/policy/apex/service/engine/main/ApexCommandLineArgumentsTest.java')
-rw-r--r--services/services-engine/src/test/java/org/onap/policy/apex/service/engine/main/ApexCommandLineArgumentsTest.java201
1 files changed, 58 insertions, 143 deletions
diff --git a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/main/ApexCommandLineArgumentsTest.java b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/main/ApexCommandLineArgumentsTest.java
index 40375b1f6..09fbe91fe 100644
--- a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/main/ApexCommandLineArgumentsTest.java
+++ b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/main/ApexCommandLineArgumentsTest.java
@@ -1,28 +1,28 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2020 Nordix Foundation
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- *
+ *
* SPDX-License-Identifier: Apache-2.0
* ============LICENSE_END=========================================================
*/
package org.onap.policy.apex.service.engine.main;
-import static org.junit.Assert.assertEquals;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
import org.junit.After;
import org.junit.Test;
@@ -30,7 +30,7 @@ import org.onap.policy.apex.model.basicmodel.concepts.ApexException;
/**
* Test Apex Command Line Arguments.
- *
+ *
* @author Liam Fallon (liam.fallon@ericsson.com)
*/
public class ApexCommandLineArgumentsTest {
@@ -40,223 +40,138 @@ public class ApexCommandLineArgumentsTest {
}
@Test
- public void testCommandLineArguments() {
+ public void testCommandLineArguments() throws ApexException {
final ApexCommandLineArguments apexArguments = new ApexCommandLineArguments();
final String[] args00 =
{ "" };
- try {
+ assertThatThrownBy(() -> {
apexArguments.parse(args00);
apexArguments.validate();
- fail("Test should throw an exception here");
- } catch (final ApexException e) {
- assertEquals("Apex configuration file was not specified as an argument", e.getMessage());
- }
-
+ }).hasMessage("Apex configuration file was not specified as an argument");
final String[] args01 =
{ "-h" };
- try {
- final String result = apexArguments.parse(args01);
- assertTrue(result.startsWith("usage: org.onap.policy.apex.service.engine.main.ApexMain [options...]"));
- } catch (final ApexException e) {
- e.printStackTrace();
- fail("Test should not throw an exception");
- }
+
+ final String result = apexArguments.parse(args01);
+ assertTrue(result.startsWith("usage: org.onap.policy.apex.service.engine.main.ApexMain [options...]"));
final String[] args02 =
{ "-v" };
- try {
- final String result = apexArguments.parse(args02);
- assertTrue(result.startsWith("Apex Adaptive Policy Engine"));
- } catch (final ApexException e) {
- e.printStackTrace();
- fail("Test should not throw an exception");
- }
+ final String result02 = apexArguments.parse(args02);
+ assertTrue(result02.startsWith("Apex Adaptive Policy Engine"));
final String[] args03 =
{ "-v", "-h" };
- try {
- final String result = apexArguments.parse(args03);
- assertTrue(result.startsWith("usage: org.onap.policy.apex.service.engine.main.ApexMain [options...]"));
- } catch (final ApexException e) {
- e.printStackTrace();
- fail("Test should not throw an exception");
- }
+
+ final String result03 = apexArguments.parse(args03);
+ assertTrue(result03.startsWith("usage: org.onap.policy.apex.service.engine.main.ApexMain [options...]"));
final String[] args04 =
{ "-h", "-v" };
- try {
- final String result = apexArguments.parse(args04);
- assertTrue(result.startsWith("usage: org.onap.policy.apex.service.engine.main.ApexMain [options...]"));
- } catch (final ApexException e) {
- e.printStackTrace();
- fail("Test should not throw an exception");
- }
+
+ final String result04 = apexArguments.parse(args04);
+ assertTrue(result04.startsWith("usage: org.onap.policy.apex.service.engine.main.ApexMain [options...]"));
final String[] args05 =
{ "-a" };
- try {
- apexArguments.parse(args05);
- } catch (final ApexException e) {
- assertEquals("invalid command line arguments specified : Unrecognized option: -a", e.getMessage());
- }
-
+ assertThatThrownBy(() -> apexArguments.parse(args05))
+ .hasMessage("invalid command line arguments specified : Unrecognized option: -a");
final String[] args06 =
{ "-c", "hello", "-m", "goodbye", "-h", "-v" };
- try {
- final String result = apexArguments.parse(args06);
- assertTrue(result.startsWith("usage: org.onap.policy.apex.service.engine.main.ApexMain [options...]"));
- } catch (final ApexException e) {
- assertEquals("invalid command line arguments specified : Unrecognized option: -a", e.getMessage());
- }
+ final String result06 = apexArguments.parse(args06);
+ assertTrue(result06.startsWith("usage: org.onap.policy.apex.service.engine.main.ApexMain [options...]"));
final String[] args07 =
{ "-c", "hello", "-m", "goodbye", "-h", "aaa" };
- try {
- final String result = apexArguments.parse(args07);
- assertTrue(result.startsWith("usage: org.onap.policy.apex.service.engine.main.ApexMain [options...]"));
- } catch (final ApexException e) {
- assertEquals("too many command line arguments specified : [-c, hello, -m, goodbye, -h, aaa]",
- e.getMessage());
- }
+ assertThatThrownBy(() -> apexArguments.parse(args07))
+ .hasMessage("too many command line arguments specified : [-c, hello, -m, goodbye, -h, aaa]");
}
@Test
- public void testCommandLineFileParameters() {
+ public void testCommandLineFileParameters() throws ApexException {
final ApexCommandLineArguments apexArguments = new ApexCommandLineArguments();
final String[] args00 =
{ "-c", "zooby" };
- try {
+ assertThatThrownBy(() -> {
apexArguments.parse(args00);
apexArguments.validate();
- fail("Test should throw an exception here");
- } catch (final ApexException e) {
- assertEquals("Apex configuration file \"zooby\" does not exist", e.getMessage());
- }
-
+ }).hasMessage("Apex configuration file \"zooby\" does not exist");
final String[] args01 =
{ "-c" };
- try {
+ assertThatThrownBy(() -> {
apexArguments.parse(args01);
apexArguments.validate();
- fail("Test should throw an exception here");
- } catch (final ApexException e) {
- assertEquals("invalid command line arguments specified : Missing argument for option: c", e.getMessage());
- }
-
+ }).hasMessage("invalid command line arguments specified : Missing argument for option: c");
final String[] args02 =
{ "-c", "src/test/resources/parameters/goodParams.json" };
- try {
- apexArguments.parse(args02);
- apexArguments.validate();
- } catch (final ApexException e) {
- e.printStackTrace();
- fail("Test should not throw an exception");
- }
+ apexArguments.parse(args02);
+ apexArguments.validate();
final String[] args03 =
{ "-c", "src/test/resources/parameters/goodParams.json", "-m", "zooby" };
- try {
+ assertThatThrownBy(() -> {
apexArguments.parse(args03);
apexArguments.validate();
- fail("Test should throw an exception here");
- } catch (final ApexException e) {
- assertEquals("Apex model file \"zooby\" does not exist", e.getMessage());
- }
-
+ }).hasMessage("Apex model file \"zooby\" does not exist");
final String[] args04 =
{ "-m" };
- try {
+ assertThatThrownBy(() -> {
apexArguments.parse(args04);
apexArguments.validate();
- fail("Test should throw an exception here");
- } catch (final ApexException e) {
- assertEquals("invalid command line arguments specified : Missing argument for option: m", e.getMessage());
- }
-
+ }).hasMessage("invalid command line arguments specified : Missing argument for option: m");
final String[] args05 =
{ "-c", "src/test/resources/parameters/goodParams.json", "-m" };
- try {
+ assertThatThrownBy(() -> {
apexArguments.parse(args05);
apexArguments.validate();
- fail("Test should throw an exception here");
- } catch (final ApexException e) {
- assertEquals("invalid command line arguments specified : Missing argument for option: m", e.getMessage());
- }
-
+ }).hasMessage("invalid command line arguments specified : Missing argument for option: m");
final String[] args06 =
{ "-c", "src/test/resources/parameters/goodParams.json", "-m",
"src/test/resources/main/DummyModelFile.json" };
- try {
- apexArguments.parse(args06);
- apexArguments.validate();
- } catch (final ApexException e) {
- e.printStackTrace();
- fail("Test should not throw an exception");
- }
+ apexArguments.parse(args06);
+ apexArguments.validate();
final String[] args07 =
{ "-c", "parameters/goodParams.json", "-m", "main/DummyModelFile.json" };
- try {
- apexArguments.parse(args07);
- apexArguments.validate();
- } catch (final ApexException e) {
- e.printStackTrace();
- fail("Test should not throw an exception");
- }
+
+ apexArguments.parse(args07);
+ apexArguments.validate();
}
@Test
- public void testCommandLineRelativeRootParameters() {
+ public void testCommandLineRelativeRootParameters() throws ApexException {
final ApexCommandLineArguments apexArguments = new ApexCommandLineArguments();
final String[] args00 =
{ "-c", "src/test/resources/parameters/goodParams.json", "-rfr", "zooby" };
- try {
+ assertThatThrownBy(() -> {
apexArguments.parse(args00);
apexArguments.validate();
- fail("Test should throw an exception here");
- } catch (final ApexException e) {
- assertTrue(e.getMessage().contains("zooby\" does not exist or is not a directory"));
- }
-
+ }).hasMessageContaining("zooby\" does not exist or is not a directory");
final String[] args01 =
{ "-rfr" };
- try {
+ assertThatThrownBy(() -> {
apexArguments.parse(args01);
apexArguments.validate();
- fail("Test should throw an exception here");
- } catch (final ApexException e) {
- assertEquals("invalid command line arguments specified : Missing argument for option: rfr", e.getMessage());
- }
-
+ }).hasMessage("invalid command line arguments specified : Missing argument for option: rfr");
final String[] args02 =
{ "-c", "src/test/resources/parameters/goodParams.json", "-rfr", "pom.xml" };
- try {
+ assertThatThrownBy(() -> {
apexArguments.parse(args02);
apexArguments.validate();
- fail("Test should throw an exception here");
- } catch (final ApexException e) {
- assertTrue(e.getMessage().contains("pom.xml\" does not exist or is not a directory"));
- }
-
+ }).hasMessageContaining("pom.xml\" does not exist or is not a directory");
final String[] args03 =
{ "-c", "src/test/resources/parameters/goodParams.json", "-rfr", "target" };
- try {
- apexArguments.parse(args03);
- apexArguments.validate();
- } catch (final ApexException e) {
- fail("Test should not throw an exception here");
- }
+
+ apexArguments.parse(args03);
+ apexArguments.validate();
final String[] args04 =
{ "-c", "src/test/resources/parameters/goodParamsRelative.json", "-rfr", "src/test/resources" };
- try {
- apexArguments.parse(args04);
- apexArguments.validate();
- } catch (final ApexException e) {
- fail("Test should not throw an exception here");
- }
+
+ apexArguments.parse(args04);
+ apexArguments.validate();
+
}
}