diff options
author | adheli.tavares <adheli.tavares@est.tech> | 2021-04-13 16:38:04 +0100 |
---|---|---|
committer | adheli.tavares <adheli.tavares@est.tech> | 2021-04-16 10:47:03 +0100 |
commit | 51a62bd019f1f59ee9db4872f332f1d228cef4d5 (patch) | |
tree | 938cd5b6d76064d2ed158925bf0ea53cd502e1ea /main/src/test | |
parent | c5f7f467107eb58b272dff3724d69d9a41c6c97d (diff) |
Refactor ApiCommandLineArguments class
CMD Class to use CMD Handler from Common.
Issue-ID: POLICY-3129
Change-Id: I7a1b960b1e3ecc6df0f7dde6b3301d640f4feb11
Signed-off-by: adheli.tavares <adheli.tavares@est.tech>
Diffstat (limited to 'main/src/test')
-rw-r--r-- | main/src/test/java/org/onap/policy/api/main/parameters/TestApiParameterHandler.java | 25 | ||||
-rw-r--r-- | main/src/test/java/org/onap/policy/api/main/startstop/TestApiCommandLineArguments.java | 34 |
2 files changed, 30 insertions, 29 deletions
diff --git a/main/src/test/java/org/onap/policy/api/main/parameters/TestApiParameterHandler.java b/main/src/test/java/org/onap/policy/api/main/parameters/TestApiParameterHandler.java index 34379085..5e1b7eb2 100644 --- a/main/src/test/java/org/onap/policy/api/main/parameters/TestApiParameterHandler.java +++ b/main/src/test/java/org/onap/policy/api/main/parameters/TestApiParameterHandler.java @@ -2,6 +2,7 @@ * ============LICENSE_START======================================================= * Copyright (C) 2018 Samsung Electronics Co., Ltd. All rights reserved. * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * Modifications 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. @@ -31,6 +32,7 @@ import java.nio.file.Paths; import org.junit.Test; import org.onap.policy.api.main.exception.PolicyApiException; import org.onap.policy.api.main.startstop.ApiCommandLineArguments; +import org.onap.policy.common.utils.cmd.CommandLineException; /** * Class to perform unit test of ApiParameterHandler. @@ -38,7 +40,7 @@ import org.onap.policy.api.main.startstop.ApiCommandLineArguments; */ public class TestApiParameterHandler { @Test - public void testParameterHandlerNoParameterFile() throws PolicyApiException { + public void testParameterHandlerNoParameterFile() throws PolicyApiException, CommandLineException { final String[] noArgumentString = {"-c", "parameters/NoParameterFile.json"}; final ApiCommandLineArguments noArguments = new ApiCommandLineArguments(); noArguments.parse(noArgumentString); @@ -52,7 +54,7 @@ public class TestApiParameterHandler { } @Test - public void testParameterHandlerEmptyParameters() throws PolicyApiException { + public void testParameterHandlerEmptyParameters() throws PolicyApiException, CommandLineException { final String[] emptyArgumentString = {"-c", "parameters/EmptyParameters.json"}; final ApiCommandLineArguments emptyArguments = new ApiCommandLineArguments(); emptyArguments.parse(emptyArgumentString); @@ -66,7 +68,7 @@ public class TestApiParameterHandler { } @Test - public void testParameterHandlerBadParameters() throws PolicyApiException { + public void testParameterHandlerBadParameters() throws PolicyApiException, CommandLineException { final String[] badArgumentString = {"-c", "parameters/BadParameters.json"}; final ApiCommandLineArguments badArguments = new ApiCommandLineArguments(); badArguments.parse(badArgumentString); @@ -82,7 +84,7 @@ public class TestApiParameterHandler { } @Test - public void testParameterHandlerInvalidParameters() throws PolicyApiException { + public void testParameterHandlerInvalidParameters() throws PolicyApiException, CommandLineException { final String[] invalidArgumentString = {"-c", "parameters/InvalidParameters.json"}; final ApiCommandLineArguments invalidArguments = new ApiCommandLineArguments(); invalidArguments.parse(invalidArgumentString); @@ -98,7 +100,7 @@ public class TestApiParameterHandler { } @Test - public void testParameterHandlerNoParameters() throws PolicyApiException { + public void testParameterHandlerNoParameters() throws PolicyApiException, CommandLineException { final String[] noArgumentString = {"-c", "parameters/NoParameters.json"}; final ApiCommandLineArguments noArguments = new ApiCommandLineArguments(); noArguments.parse(noArgumentString); @@ -116,7 +118,7 @@ public class TestApiParameterHandler { } @Test - public void testParameterHandlerMinumumParameters() throws PolicyApiException { + public void testParameterHandlerMinumumParameters() throws PolicyApiException, CommandLineException { final String[] minArgumentString = {"-c", "parameters/MinimumParameters.json"}; final ApiCommandLineArguments minArguments = new ApiCommandLineArguments(); minArguments.parse(minArgumentString); @@ -125,7 +127,7 @@ public class TestApiParameterHandler { } @Test - public void testApiParameterGroup() throws PolicyApiException { + public void testApiParameterGroup() throws PolicyApiException, CommandLineException { final String[] apiConfigParameters = {"-c", "parameters/ApiConfigParameters_Https.json"}; final ApiCommandLineArguments arguments = new ApiCommandLineArguments(); arguments.parse(apiConfigParameters); @@ -135,7 +137,7 @@ public class TestApiParameterHandler { } @Test - public void testApiParameterGroup_InvalidName() throws PolicyApiException { + public void testApiParameterGroup_InvalidName() throws PolicyApiException, CommandLineException { final String[] apiConfigParameters = {"-c", "parameters/ApiConfigParameters_InvalidName.json"}; final ApiCommandLineArguments arguments = new ApiCommandLineArguments(); arguments.parse(apiConfigParameters); @@ -150,7 +152,8 @@ public class TestApiParameterHandler { } @Test - public void testApiParameterGroup_InvalidRestServerParameters() throws PolicyApiException, IOException { + public void testApiParameterGroup_InvalidRestServerParameters() + throws PolicyApiException, IOException, CommandLineException { final String[] apiConfigParameters = {"-c", "parameters/ApiConfigParameters_InvalidRestServerParameters.json"}; final ApiCommandLineArguments arguments = new ApiCommandLineArguments(); arguments.parse(apiConfigParameters); @@ -167,7 +170,7 @@ public class TestApiParameterHandler { } @Test - public void testApiVersion() throws PolicyApiException { + public void testApiVersion() throws PolicyApiException, CommandLineException { final String[] apiConfigParameters = {"-v"}; final ApiCommandLineArguments arguments = new ApiCommandLineArguments(); final String version = arguments.parse(apiConfigParameters); @@ -175,7 +178,7 @@ public class TestApiParameterHandler { } @Test - public void testApiHelp() throws PolicyApiException { + public void testApiHelp() throws PolicyApiException, CommandLineException { final String[] apiConfigParameters = {"-h"}; final ApiCommandLineArguments arguments = new ApiCommandLineArguments(); final String help = arguments.parse(apiConfigParameters); diff --git a/main/src/test/java/org/onap/policy/api/main/startstop/TestApiCommandLineArguments.java b/main/src/test/java/org/onap/policy/api/main/startstop/TestApiCommandLineArguments.java index 8adfacc5..8d3c42c9 100644 --- a/main/src/test/java/org/onap/policy/api/main/startstop/TestApiCommandLineArguments.java +++ b/main/src/test/java/org/onap/policy/api/main/startstop/TestApiCommandLineArguments.java @@ -3,6 +3,7 @@ * ONAP Policy API * ================================================================================ * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * Modifications 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. @@ -22,10 +23,10 @@ package org.onap.policy.api.main.startstop; +import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; import org.junit.Test; -import org.onap.policy.api.main.exception.PolicyApiException; import org.onap.policy.api.main.exception.PolicyApiRuntimeException; public class TestApiCommandLineArguments { @@ -33,38 +34,35 @@ public class TestApiCommandLineArguments { @Test(expected = PolicyApiRuntimeException.class) public void testApiCommandLineArgumentsStringArray() { - String [] args = {"---d"}; + String[] args = {"---d"}; new ApiCommandLineArguments(args); } @Test public void testNonExistentFileValidateReadableFile() { apiCmdArgs.setConfigurationFilePath("src/test/resources/filetest/nonexist.json "); - assertThatThrownBy( - apiCmdArgs::validate - ) - .isInstanceOf(PolicyApiException.class) - .hasMessageContaining("file \"src/test/resources/filetest/nonexist.json \" does not exist"); + assertThatThrownBy(apiCmdArgs::validate) + .hasMessageContaining("file \"src/test/resources/filetest/nonexist.json \" does not exist"); } @Test public void testEmptyFileNameValidateReadableFile() { apiCmdArgs.setConfigurationFilePath(""); - assertThatThrownBy( - apiCmdArgs::validate - ) - .isInstanceOf(PolicyApiException.class) - .hasMessageContaining("policy api configuration file was not specified as an argument"); + assertThatThrownBy(apiCmdArgs::validate) + .hasMessageContaining("policy-api configuration file was not specified as an argument"); } @Test public void testInvalidUrlValidateReadableFile() { apiCmdArgs.setConfigurationFilePath("src/test\\resources/filetest\\n"); - assertThatThrownBy( - apiCmdArgs::validate - ) - .isInstanceOf(PolicyApiException.class) - .hasMessageContaining( - "policy api configuration file \"src/test\\resources/filetest\\n\" does not exist"); + assertThatThrownBy(apiCmdArgs::validate).hasMessageContaining( + "policy-api configuration file \"src/test\\resources/filetest\\n\" does not exist"); + } + + @Test + public void testVersion() { + String[] testArgs = {"-v"}; + ApiCommandLineArguments cmdArgs = new ApiCommandLineArguments(testArgs); + assertThat(cmdArgs.version()).startsWith("ONAP Policy Framework Api Service"); } } |