summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAjith Sreekumar <ajith.sreekumar@bell.ca>2021-06-24 12:48:56 +0000
committerGerrit Code Review <gerrit@onap.org>2021-06-24 12:48:56 +0000
commitc2f0aac6784db56706931a5fa409e18a3dc872cd (patch)
treefdfa2490b56400cb18805fe4071df41da7408e20
parentf5b583897fd4170519e37e369559cd21d67c5bb3 (diff)
parenteaba0c9e1141ec6fa248b89934780bb14d5865fe (diff)
Merge "Increase code coverage in clamp-common"
-rw-r--r--common/src/main/java/org/onap/policy/clamp/controlloop/common/startstop/CommonCommandLineArguments.java2
-rw-r--r--common/src/test/java/org/onap/policy/clamp/controlloop/common/startstop/CommonCommandLineArgumentsTest.java80
-rw-r--r--pom.xml6
3 files changed, 87 insertions, 1 deletions
diff --git a/common/src/main/java/org/onap/policy/clamp/controlloop/common/startstop/CommonCommandLineArguments.java b/common/src/main/java/org/onap/policy/clamp/controlloop/common/startstop/CommonCommandLineArguments.java
index ebc9028f4..525da259f 100644
--- a/common/src/main/java/org/onap/policy/clamp/controlloop/common/startstop/CommonCommandLineArguments.java
+++ b/common/src/main/java/org/onap/policy/clamp/controlloop/common/startstop/CommonCommandLineArguments.java
@@ -139,7 +139,7 @@ public class CommonCommandLineArguments {
}
if (!theFile.canRead()) {
throw new ControlLoopException(Response.Status.NOT_ACCEPTABLE,
- fileTag + FILE_MESSAGE_PREAMBLE + fileName + "\" is ureadable");
+ fileTag + FILE_MESSAGE_PREAMBLE + fileName + "\" is unreadable");
}
}
}
diff --git a/common/src/test/java/org/onap/policy/clamp/controlloop/common/startstop/CommonCommandLineArgumentsTest.java b/common/src/test/java/org/onap/policy/clamp/controlloop/common/startstop/CommonCommandLineArgumentsTest.java
new file mode 100644
index 000000000..2d30592e4
--- /dev/null
+++ b/common/src/test/java/org/onap/policy/clamp/controlloop/common/startstop/CommonCommandLineArgumentsTest.java
@@ -0,0 +1,80 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2021 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.clamp.controlloop.common.startstop;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatCode;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+import org.apache.commons.cli.Options;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+
+public class CommonCommandLineArgumentsTest {
+
+ public static CommonCommandLineArguments cli;
+
+ @BeforeAll
+ static void setup() {
+ cli = new CommonCommandLineArguments(new Options());
+ }
+
+ @Test
+ void testConstructor() {
+ assertThat(cli).isNotNull();
+ }
+
+ @Test
+ void testHelp() {
+ assertThat(cli.help("DummyClass", new Options()))
+ .contains("DummyClass [options...]\noptions");
+ }
+
+ @Test
+ void testVersion() {
+ assertThatCode(() -> cli.version()).doesNotThrowAnyException();
+ }
+
+ @Test
+ void testValidateEmptyFileName() {
+ assertThatThrownBy(() -> cli.validate(""))
+ .hasMessageContaining("file was not specified as an argument");
+ }
+
+ @Test
+ void testValidateFileUrlNull() {
+ assertThatThrownBy(() -> cli.validate("abcd"))
+ .hasMessageContaining("does not exist");
+ }
+
+ @Test
+ void testValidateFileFound() {
+ String configFile = "demo/config/RuntimeConfig.json";
+ assertThatCode(() -> cli.validate(configFile)).doesNotThrowAnyException();
+ }
+
+ @Test
+ void testValidateNotNormalFile() {
+ String badFile = "demo/config";
+ assertThatThrownBy(() -> cli.validate(badFile)).hasMessageContaining("is not a normal file");
+ }
+
+}
diff --git a/pom.xml b/pom.xml
index b9d0efd98..8661998ab 100644
--- a/pom.xml
+++ b/pom.xml
@@ -69,6 +69,12 @@
<scope>test</scope>
</dependency>
<dependency>
+ <groupId>org.junit.jupiter</groupId>
+ <artifactId>junit-jupiter-engine</artifactId>
+ <version>5.7.1</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
<groupId>commons-cli</groupId>
<artifactId>commons-cli</artifactId>
</dependency>