summaryrefslogtreecommitdiffstats
path: root/main/src/test
diff options
context:
space:
mode:
authoradheli.tavares <adheli.tavares@est.tech>2021-04-13 16:33:41 +0100
committeradheli.tavares <adheli.tavares@est.tech>2021-04-16 10:34:17 +0100
commitadfc3ee02f3194a143bcea430e5e3aeb99a23206 (patch)
treee54813c7d0d91b87a4d2c31f9b1e5d8ec7cdc477 /main/src/test
parent8c6123d8c19d95115dc865784ccb1dc87d24f35c (diff)
Refactor DistributionCommandLineArguments class
CMD Class to use the CMD Handler from Common. Issue-ID: POLICY-3129 Change-Id: I2219cdb7db5669de71c3b2b90c496321b61d14eb 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/distribution/main/parameters/TestDistributionParameterHandler.java200
-rw-r--r--main/src/test/java/org/onap/policy/distribution/main/startstop/TestDistributionCommandLineArguments.java26
2 files changed, 111 insertions, 115 deletions
diff --git a/main/src/test/java/org/onap/policy/distribution/main/parameters/TestDistributionParameterHandler.java b/main/src/test/java/org/onap/policy/distribution/main/parameters/TestDistributionParameterHandler.java
index 6eb4cf77..dcafe68c 100644
--- a/main/src/test/java/org/onap/policy/distribution/main/parameters/TestDistributionParameterHandler.java
+++ b/main/src/test/java/org/onap/policy/distribution/main/parameters/TestDistributionParameterHandler.java
@@ -1,7 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2020 Nordix Foundation
+ * Modifications Copyright (C) 2020-2021 Nordix Foundation.
* Modifications Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -31,6 +31,7 @@ import java.nio.file.Files;
import java.nio.file.Paths;
import org.junit.Test;
import org.onap.policy.common.parameters.ParameterRuntimeException;
+import org.onap.policy.common.utils.cmd.CommandLineException;
import org.onap.policy.distribution.main.PolicyDistributionException;
import org.onap.policy.distribution.main.startstop.DistributionCommandLineArguments;
import org.onap.policy.distribution.main.testclasses.DummyPolicyDecoderParameterGroup;
@@ -43,48 +44,41 @@ import org.onap.policy.distribution.main.testclasses.DummyPolicyForwarderParamet
*/
public class TestDistributionParameterHandler {
@Test
- public void testParameterHandlerNoParameterFile() throws PolicyDistributionException {
- verifyFailure("NoParameterFile.json",
- PolicyDistributionException.class,
- "FileNotFoundException");
+ public void testParameterHandlerNoParameterFile() throws PolicyDistributionException, CommandLineException {
+ verifyFailure("NoParameterFile.json", PolicyDistributionException.class, "FileNotFoundException");
}
@Test
- public void testParameterHandlerEmptyParameters() throws PolicyDistributionException {
- verifyFailure("EmptyParameters.json",
- PolicyDistributionException.class,
- "no parameters found in \"parameters/EmptyParameters.json\"");
+ public void testParameterHandlerEmptyParameters() throws PolicyDistributionException, CommandLineException {
+ verifyFailure("EmptyParameters.json", PolicyDistributionException.class,
+ "no parameters found in \"parameters/EmptyParameters.json\"");
}
@Test
- public void testParameterHandlerBadParameters() throws PolicyDistributionException {
- verifyFailure("BadParameters.json",
- PolicyDistributionException.class,
- "error reading parameters from \"parameters/BadParameters.json\"\n"
- + "(JsonSyntaxException):java.lang.IllegalStateException: "
- + "Expected a string but was BEGIN_ARRAY at line 2 column 15 path $.name");
+ public void testParameterHandlerBadParameters() throws PolicyDistributionException, CommandLineException {
+ verifyFailure("BadParameters.json", PolicyDistributionException.class,
+ "error reading parameters from \"parameters/BadParameters.json\"\n"
+ + "(JsonSyntaxException):java.lang.IllegalStateException: "
+ + "Expected a string but was BEGIN_ARRAY at line 2 column 15 path $.name");
}
@Test
- public void testParameterHandlerInvalidParameters() throws PolicyDistributionException {
- verifyFailure("InvalidParameters.json",
- PolicyDistributionException.class,
- "error reading parameters from \"parameters/InvalidParameters.json\"\n"
- + "(JsonSyntaxException):java.lang.IllegalStateException: "
- + "Expected a string but was BEGIN_ARRAY at line 2 column 15 path $.name");
+ public void testParameterHandlerInvalidParameters() throws PolicyDistributionException, CommandLineException {
+ verifyFailure("InvalidParameters.json", PolicyDistributionException.class,
+ "error reading parameters from \"parameters/InvalidParameters.json\"\n"
+ + "(JsonSyntaxException):java.lang.IllegalStateException: "
+ + "Expected a string but was BEGIN_ARRAY at line 2 column 15 path $.name");
}
@Test
- public void testParameterHandlerNoParameters() throws PolicyDistributionException {
- verifyFailure("NoParameters.json",
- ParameterRuntimeException.class,
- "map parameter \"receptionHandlerParameters\" is null");
+ public void testParameterHandlerNoParameters() throws PolicyDistributionException, CommandLineException {
+ verifyFailure("NoParameters.json", ParameterRuntimeException.class,
+ "map parameter \"receptionHandlerParameters\" is null");
}
@Test
- public void testParameterHandlerMinumumParameters() throws PolicyDistributionException {
- final String[] minArgumentString =
- { "-c", "parameters/MinimumParameters.json" };
+ public void testParameterHandlerMinumumParameters() throws PolicyDistributionException, CommandLineException {
+ final String[] minArgumentString = {"-c", "parameters/MinimumParameters.json"};
final DistributionCommandLineArguments minArguments = new DistributionCommandLineArguments();
minArguments.parse(minArgumentString);
@@ -94,9 +88,8 @@ public class TestDistributionParameterHandler {
}
@Test
- public void testDistributionParameterGroup() throws PolicyDistributionException {
- final String[] distributionConfigParameters =
- { "-c", "parameters/DistributionConfigParameters.json" };
+ public void testDistributionParameterGroup() throws PolicyDistributionException, CommandLineException {
+ final String[] distributionConfigParameters = {"-c", "parameters/DistributionConfigParameters.json"};
final DistributionCommandLineArguments arguments = new DistributionCommandLineArguments();
arguments.parse(distributionConfigParameters);
@@ -127,121 +120,116 @@ public class TestDistributionParameterHandler {
@Test
public void testDistributionParameterGroup_InvalidForwarderConfigurationClassName()
- throws PolicyDistributionException {
+ throws PolicyDistributionException, CommandLineException {
verifyFailure("DistributionConfigParameters_InvalidForwarderConfigurationClassName.json",
- PolicyDistributionException.class,
- "parameter \"parameterClassName\" value \"\" invalid in JSON file");
+ PolicyDistributionException.class, "parameter \"parameterClassName\" value \"\" invalid in JSON file");
}
@Test
public void testDistributionParameterGroup_UnknownForwarderConfigurationClassName()
- throws PolicyDistributionException {
+ throws PolicyDistributionException, CommandLineException {
verifyFailure("DistributionConfigParameters_UnknownForwarderConfigurationClassName.json",
- PolicyDistributionException.class,
- "parameter \"parameterClassName\" value \"org.onap.policy.Unknown\", could not find class");
+ PolicyDistributionException.class,
+ "parameter \"parameterClassName\" value \"org.onap.policy.Unknown\", could not find class");
}
@Test
- public void testDistributionParameterGroup_InvalidName() throws PolicyDistributionException {
- verifyFailure("DistributionConfigParameters_InvalidName.json",
- PolicyDistributionException.class,
- "field \"name\" type \"java.lang.String\" value \" \" INVALID, must be a non-blank string");
+ public void testDistributionParameterGroup_InvalidName() throws PolicyDistributionException, CommandLineException {
+ verifyFailure("DistributionConfigParameters_InvalidName.json", PolicyDistributionException.class,
+ "field \"name\" type \"java.lang.String\" value \" \" INVALID, must be a non-blank string");
}
@Test
- public void testDistributionParameterGroup_NoReceptionHandler() throws PolicyDistributionException {
- verifyFailure("DistributionConfigParameters_NoReceptionHandler.json",
- ParameterRuntimeException.class,
- "map parameter \"receptionHandlerParameters\" is null");
+ public void testDistributionParameterGroup_NoReceptionHandler()
+ throws PolicyDistributionException, CommandLineException {
+ verifyFailure("DistributionConfigParameters_NoReceptionHandler.json", ParameterRuntimeException.class,
+ "map parameter \"receptionHandlerParameters\" is null");
}
@Test
- public void testDistributionParameterGroup_EmptyReceptionHandler() throws PolicyDistributionException {
- verifyFailure("DistributionConfigParameters_EmptyReceptionHandler.json",
- PolicyDistributionException.class,
- "must have at least one reception handler\n");
+ public void testDistributionParameterGroup_EmptyReceptionHandler()
+ throws PolicyDistributionException, CommandLineException {
+ verifyFailure("DistributionConfigParameters_EmptyReceptionHandler.json", PolicyDistributionException.class,
+ "must have at least one reception handler\n");
}
@Test
- public void testDistributionParameterGroup_NoPolicyDecoder() throws PolicyDistributionException {
- verifyFailure("DistributionConfigParameters_NoPolicyDecoder.json",
- ParameterRuntimeException.class,
- "map parameter \"policyDecoders\" is null");
+ public void testDistributionParameterGroup_NoPolicyDecoder()
+ throws PolicyDistributionException, CommandLineException {
+ verifyFailure("DistributionConfigParameters_NoPolicyDecoder.json", ParameterRuntimeException.class,
+ "map parameter \"policyDecoders\" is null");
}
@Test
- public void testDistributionParameterGroup_NoPolicyForwarder() throws PolicyDistributionException {
- verifyFailure("DistributionConfigParameters_NoPolicyForwarder.json",
- ParameterRuntimeException.class,
- "map parameter \"policyForwarders\" is null");
+ public void testDistributionParameterGroup_NoPolicyForwarder()
+ throws PolicyDistributionException, CommandLineException {
+ verifyFailure("DistributionConfigParameters_NoPolicyForwarder.json", ParameterRuntimeException.class,
+ "map parameter \"policyForwarders\" is null");
}
@Test
- public void testDistributionParameterGroup_EmptyPolicyDecoder() throws PolicyDistributionException {
- verifyFailure("DistributionConfigParameters_EmptyPolicyDecoder.json",
- PolicyDistributionException.class,
- "must have at least one policy decoder\n");
+ public void testDistributionParameterGroup_EmptyPolicyDecoder()
+ throws PolicyDistributionException, CommandLineException {
+ verifyFailure("DistributionConfigParameters_EmptyPolicyDecoder.json", PolicyDistributionException.class,
+ "must have at least one policy decoder\n");
}
@Test
- public void testDistributionParameterGroup_EmptyPolicyForwarder() throws PolicyDistributionException {
- verifyFailure("DistributionConfigParameters_EmptyPolicyForwarder.json",
- PolicyDistributionException.class,
- "must have at least one policy forwarder\n");
+ public void testDistributionParameterGroup_EmptyPolicyForwarder()
+ throws PolicyDistributionException, CommandLineException {
+ verifyFailure("DistributionConfigParameters_EmptyPolicyForwarder.json", PolicyDistributionException.class,
+ "must have at least one policy forwarder\n");
}
@Test
public void testDistributionParameterGroup_InvalidReceptionHandlerParameters()
- throws PolicyDistributionException, IOException {
+ throws PolicyDistributionException, IOException, CommandLineException {
- String resultString = Files.readString(Paths.get(
- "src/test/resources/expectedValidationResults/InvalidReceptionHandlerParameters.txt"))
- .trim().replaceAll("\\r\\n", "\\\n");
+ String resultString = Files
+ .readString(
+ Paths.get("src/test/resources/expectedValidationResults/InvalidReceptionHandlerParameters.txt"))
+ .trim().replaceAll("\\r\\n", "\\\n");
verifyFailure("DistributionConfigParameters_InvalidReceptionHandlerParameters.json",
- PolicyDistributionException.class,
- resultString);
+ PolicyDistributionException.class, resultString);
}
@Test
public void testDistributionParameterGroup_InvalidDecoderAndForwarderParameters()
- throws PolicyDistributionException, IOException {
+ throws PolicyDistributionException, IOException, CommandLineException {
- String resultString = new String(Files.readString(Paths.get(
- "src/test/resources/expectedValidationResults/InvalidDecoderAndForwarderParameters.txt"))
- .trim().replaceAll("\\r\\n", "\\\n"));
+ String resultString = new String(Files
+ .readString(Paths
+ .get("src/test/resources/expectedValidationResults/InvalidDecoderAndForwarderParameters.txt"))
+ .trim().replaceAll("\\r\\n", "\\\n"));
verifyFailure("DistributionConfigParameters_InvalidDecoderAndForwarderParameters.json",
- PolicyDistributionException.class,
- resultString);
+ PolicyDistributionException.class, resultString);
}
@Test
public void testDistributionParameterGroup_InvalidRestServerParameters()
- throws PolicyDistributionException, IOException {
+ throws PolicyDistributionException, IOException, CommandLineException {
- String resultString = new String(Files.readString(Paths.get(
- "src/test/resources/expectedValidationResults/InvalidRestServerParameters.txt"))
+ String resultString = new String(Files
+ .readString(Paths.get("src/test/resources/expectedValidationResults/InvalidRestServerParameters.txt"))
.trim().replaceAll("\\r\\n", "\\\n"));
verifyFailure("DistributionConfigParameters_InvalidRestServerParameters.json",
- PolicyDistributionException.class,
- resultString);
+ PolicyDistributionException.class, resultString);
}
@Test
- public void testDistributionVersion() throws PolicyDistributionException {
- final String[] distributionConfigParameters =
- { "-v" };
+ public void testDistributionVersion() throws PolicyDistributionException, CommandLineException {
+ final String[] distributionConfigParameters = {"-v"};
final DistributionCommandLineArguments arguments = new DistributionCommandLineArguments();
final String version = arguments.parse(distributionConfigParameters);
assertTrue(version.startsWith("ONAP Policy Framework Distribution Service"));
}
@Test
- public void testDistributionHelp() throws PolicyDistributionException {
- final String[] distributionConfigParameters =
- { "-h" };
+ public void testDistributionHelp() throws PolicyDistributionException, CommandLineException {
+ final String[] distributionConfigParameters = {"-h"};
final DistributionCommandLineArguments arguments = new DistributionCommandLineArguments();
final String help = arguments.parse(distributionConfigParameters);
assertTrue(help.startsWith("usage:"));
@@ -249,45 +237,43 @@ public class TestDistributionParameterHandler {
@Test
public void testDistributionInvalidOption() throws PolicyDistributionException {
- final String[] distributionConfigParameters =
- { "-d" };
+ final String[] distributionConfigParameters = {"-d"};
final DistributionCommandLineArguments arguments = new DistributionCommandLineArguments();
- assertThatThrownBy(() ->
- arguments.parse(distributionConfigParameters)
- ).isInstanceOf(PolicyDistributionException.class)
- .hasMessageContaining("invalid command line arguments specified");
+ assertThatThrownBy(() -> arguments.parse(distributionConfigParameters))
+ .hasMessageContaining("invalid command line arguments specified");
}
@Test
- public void testDistributionParameterGroup_InvalidReceptionHandlerClass() throws PolicyDistributionException {
+ public void testDistributionParameterGroup_InvalidReceptionHandlerClass()
+ throws PolicyDistributionException, CommandLineException {
verifyFailure("DistributionConfigParameters_InvalidReceptionHandlerClass.json",
- PolicyDistributionException.class, "could not find class");
+ PolicyDistributionException.class, "could not find class");
}
@Test
- public void testDistributionParameterGroup_EmptyReceptionHandlerClass() throws PolicyDistributionException {
- verifyFailure("DistributionConfigParameters_EmptyReceptionHandlerClass.json",
- PolicyDistributionException.class, "invalid in JSON file");
+ public void testDistributionParameterGroup_EmptyReceptionHandlerClass()
+ throws PolicyDistributionException, CommandLineException {
+ verifyFailure("DistributionConfigParameters_EmptyReceptionHandlerClass.json", PolicyDistributionException.class,
+ "invalid in JSON file");
}
@Test
public void testDistributionParameterGroup_InvalidDecoderConfigurationClassName()
- throws PolicyDistributionException {
+ throws PolicyDistributionException, CommandLineException {
verifyFailure("DistributionConfigParameters_InvalidDecoderConfigurationClassName.json",
- PolicyDistributionException.class,
- "parameter \"parameterClassName\" value \"\" invalid in JSON file");
+ PolicyDistributionException.class, "parameter \"parameterClassName\" value \"\" invalid in JSON file");
}
@Test
public void testDistributionParameterGroup_UnknownDecoderConfigurationClassName()
- throws PolicyDistributionException {
+ throws PolicyDistributionException, CommandLineException {
verifyFailure("DistributionConfigParameters_UnknownDecoderConfigurationClassName.json",
- PolicyDistributionException.class,
- "parameter \"parameterClassName\" value \"org.onap.policy.Unknown\", could not find class");
+ PolicyDistributionException.class,
+ "parameter \"parameterClassName\" value \"org.onap.policy.Unknown\", could not find class");
}
private <T> void verifyFailure(String fileName, Class<T> clazz, String expectedMessage)
- throws PolicyDistributionException {
+ throws PolicyDistributionException, CommandLineException {
final String[] distributionConfigParameters = {"-c", "parameters/" + fileName};
final DistributionCommandLineArguments arguments = new DistributionCommandLineArguments();
@@ -296,6 +282,6 @@ public class TestDistributionParameterHandler {
DistributionParameterHandler paramHandler = new DistributionParameterHandler();
assertThatThrownBy(() -> paramHandler.getParameters(arguments)).isInstanceOf(clazz)
- .hasMessageContaining(expectedMessage);
+ .hasMessageContaining(expectedMessage);
}
}
diff --git a/main/src/test/java/org/onap/policy/distribution/main/startstop/TestDistributionCommandLineArguments.java b/main/src/test/java/org/onap/policy/distribution/main/startstop/TestDistributionCommandLineArguments.java
index 7e72b852..0a0e5fa0 100644
--- a/main/src/test/java/org/onap/policy/distribution/main/startstop/TestDistributionCommandLineArguments.java
+++ b/main/src/test/java/org/onap/policy/distribution/main/startstop/TestDistributionCommandLineArguments.java
@@ -20,11 +20,11 @@
package org.onap.policy.distribution.main.startstop;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.Assert.assertThrows;
import org.junit.Test;
-import org.onap.policy.distribution.main.PolicyDistributionException;
import org.onap.policy.distribution.main.PolicyDistributionRuntimeException;
/**
@@ -36,6 +36,12 @@ import org.onap.policy.distribution.main.PolicyDistributionRuntimeException;
public class TestDistributionCommandLineArguments {
@Test
+ public void testDistributionOnlyFileName() {
+ String[] testArgs = {"src/test/resources/parameters/DistributionConfigParameters.json"};
+ assertThrows(PolicyDistributionRuntimeException.class, () -> new DistributionCommandLineArguments(testArgs));
+ }
+
+ @Test
public void testDistributionCommandLineArgumentsException() {
String[] wrongParams = {"arg1", "nothing", "{\"someJson\":1}"};
assertThrows(PolicyDistributionRuntimeException.class, () -> new DistributionCommandLineArguments(wrongParams));
@@ -44,28 +50,32 @@ public class TestDistributionCommandLineArguments {
@Test
public void testValidateFileNameEmpty() {
String[] argsOnlyKeyNoValue = {"-c", ""};
- assertValidate(argsOnlyKeyNoValue, "policy distribution configuration file was not specified as an argument");
+ assertValidate(argsOnlyKeyNoValue, "policy-distribution configuration file was not specified as an argument");
}
@Test
public void testValidateFileNameDoesNotExist() {
String[] fileNameNotExistentArgs = {"-c", "someFileName.json"};
assertValidate(fileNameNotExistentArgs,
- "policy distribution configuration file \"someFileName.json\" does not exist");
+ "policy-distribution configuration file \"someFileName.json\" does not exist");
}
@Test
public void testValidateFileNameIsNotFile() {
String[] folderAsFileNameArgs = {"-c", "src/test/resources/parameters"};
assertValidate(folderAsFileNameArgs,
- "policy distribution configuration file \"src/test/resources/parameters\" is not a normal file");
+ "policy-distribution configuration file \"src/test/resources/parameters\" is not a normal file");
}
- protected void assertValidate(String[] testArgs, String expectedErrorMsg) {
+ @Test
+ public void testDistributionVersion() {
+ String[] testArgs = {"-v"};
DistributionCommandLineArguments sutArgs = new DistributionCommandLineArguments(testArgs);
+ assertThat(sutArgs.version()).startsWith("ONAP Policy Framework Distribution Service");
+ }
- assertThatThrownBy(() -> sutArgs.validate())
- .isInstanceOf(PolicyDistributionException.class)
- .hasMessage(expectedErrorMsg);
+ private void assertValidate(String[] testArgs, String expectedErrorMsg) {
+ DistributionCommandLineArguments sutArgs = new DistributionCommandLineArguments(testArgs);
+ assertThatThrownBy(() -> sutArgs.validate()).hasMessage(expectedErrorMsg);
}
}