aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwaynedunican <wayne.dunican@est.tech>2020-07-01 08:39:47 +0100
committerwaynedunican <wayne.dunican@est.tech>2020-07-02 14:51:37 +0100
commitffd7bb269fd65df1b976f416a0502d665bd3aa61 (patch)
tree5bf25b3d29f51e63b2bfcc699a465ca074f4bbe6
parentcfab9d394022e32ea16c91fcdaadff8e209b1c68 (diff)
Replace try/catch blocks with assertj - dist
Replaced try/catch blocks in policy/distribution test cases with assertj assertions Issue-ID: POLICY-2451 Change-Id: Ib7ecd13e39abd471bf1424d8a3db22c72ad1e3b8 Signed-off-by: waynedunican <wayne.dunican@est.tech>
-rw-r--r--main/src/test/java/org/onap/policy/distribution/main/parameters/TestDistributionParameterGroup.java20
-rw-r--r--main/src/test/java/org/onap/policy/distribution/main/parameters/TestDistributionParameterHandler.java248
-rw-r--r--main/src/test/java/org/onap/policy/distribution/main/parameters/TestPluginHandlerParameters.java28
-rw-r--r--main/src/test/java/org/onap/policy/distribution/main/rest/TestDistributionRestServer.java21
-rw-r--r--main/src/test/java/org/onap/policy/distribution/main/rest/TestDistributionStatistics.java22
-rw-r--r--main/src/test/java/org/onap/policy/distribution/main/rest/TestHttpsDistributionRestServer.java14
-rw-r--r--main/src/test/java/org/onap/policy/distribution/main/rest/TestHttpsStatisticDistributionRestServer.java18
-rw-r--r--plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/file/FilePolicyForwarderTest.java33
-rw-r--r--plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/policy/file/PolicyDecoderFileInCsarToPolicyTest.java41
-rw-r--r--plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/file/TestFileSystemReceptionHandler.java25
-rw-r--r--plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/file/TestFileSystemReceptionHandlerConfigurationParameterGroup.java27
-rw-r--r--plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/sdc/TestSdcReceptionHandler.java55
-rw-r--r--plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/sdc/TestSdcReceptionHandlerConfigurationParameterGroup.java27
13 files changed, 209 insertions, 370 deletions
diff --git a/main/src/test/java/org/onap/policy/distribution/main/parameters/TestDistributionParameterGroup.java b/main/src/test/java/org/onap/policy/distribution/main/parameters/TestDistributionParameterGroup.java
index 317b1a13..3c206261 100644
--- a/main/src/test/java/org/onap/policy/distribution/main/parameters/TestDistributionParameterGroup.java
+++ b/main/src/test/java/org/onap/policy/distribution/main/parameters/TestDistributionParameterGroup.java
@@ -2,6 +2,7 @@
* ============LICENSE_START=======================================================
* Copyright (C) 2018 Ericsson. All rights reserved.
* Modifications Copyright (C) 2019 AT&T Intellectual Property. 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.
@@ -21,15 +22,17 @@
package org.onap.policy.distribution.main.parameters;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
+import java.io.IOException;
import java.util.Map;
import org.junit.Test;
import org.onap.policy.common.endpoints.parameters.RestServerParameters;
import org.onap.policy.common.parameters.GroupValidationResult;
+import org.onap.policy.common.parameters.ParameterRuntimeException;
import org.onap.policy.distribution.main.testclasses.DummyPolicyForwarderParameterGroup;
import org.onap.policy.distribution.main.testclasses.DummyReceptionHandlerParameterGroup;
import org.onap.policy.distribution.reception.parameters.PolicyDecoderConfigurationParameterGroup;
@@ -177,16 +180,11 @@ public class TestDistributionParameterGroup {
commonTestData.getPolicyForwarderConfigurationParameters(false);
final Map<String, PolicyDecoderConfigurationParameterGroup> decoderConfigurations =
commonTestData.getPolicyDecoderConfigurationParameters(false);
- try {
- final DistributionParameterGroup distributionParameters =
- new DistributionParameterGroup(CommonTestData.DISTRIBUTION_GROUP_NAME, restServerParameters, null,
- receptionHandlerConfigurations, forwarderConfigurations, decoderConfigurations);
- distributionParameters.validate();
- fail("test should throw an exception here");
- } catch (final Exception e) {
- assertTrue(e.getMessage().contains("map parameter \"receptionHandlerParameters\" is null"));
- }
-
+ final DistributionParameterGroup distributionParameters =
+ new DistributionParameterGroup(CommonTestData.DISTRIBUTION_GROUP_NAME, restServerParameters, null,
+ receptionHandlerConfigurations, forwarderConfigurations, decoderConfigurations);
+ assertThatThrownBy(distributionParameters::validate).isInstanceOf(ParameterRuntimeException.class)
+ .hasMessageContaining("map parameter \"receptionHandlerParameters\" is null");
}
@Test
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 f97f2713..a789569b 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,6 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 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.
@@ -20,14 +21,15 @@
package org.onap.policy.distribution.main.parameters;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
import java.io.IOException;
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.distribution.main.PolicyDistributionException;
import org.onap.policy.distribution.main.startstop.DistributionCommandLineArguments;
import org.onap.policy.distribution.main.testclasses.DummyPolicyDecoderParameterGroup;
@@ -46,13 +48,9 @@ public class TestDistributionParameterHandler {
final DistributionCommandLineArguments noArguments = new DistributionCommandLineArguments();
noArguments.parse(noArgumentString);
-
- try {
- new DistributionParameterHandler().getParameters(noArguments);
- fail("test should throw an exception here");
- } catch (final Exception e) {
- assertTrue(e.getMessage().contains("FileNotFoundException"));
- }
+ assertThatThrownBy(() ->
+ new DistributionParameterHandler().getParameters(noArguments)
+ ).isInstanceOf(PolicyDistributionException.class).hasMessageContaining("FileNotFoundException");
}
@Test
@@ -63,12 +61,10 @@ public class TestDistributionParameterHandler {
final DistributionCommandLineArguments emptyArguments = new DistributionCommandLineArguments();
emptyArguments.parse(emptyArgumentString);
- try {
- new DistributionParameterHandler().getParameters(emptyArguments);
- fail("test should throw an exception here");
- } catch (final Exception e) {
- assertEquals("no parameters found in \"parameters/EmptyParameters.json\"", e.getMessage());
- }
+ assertThatThrownBy(() ->
+ new DistributionParameterHandler().getParameters(emptyArguments)
+ ).isInstanceOf(PolicyDistributionException.class)
+ .hasMessageContaining("no parameters found in \"parameters/EmptyParameters.json\"");
}
@Test
@@ -79,14 +75,12 @@ public class TestDistributionParameterHandler {
final DistributionCommandLineArguments badArguments = new DistributionCommandLineArguments();
badArguments.parse(badArgumentString);
- try {
- new DistributionParameterHandler().getParameters(badArguments);
- fail("test should throw an exception here");
- } catch (final Exception e) {
- assertEquals("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", e.getMessage());
- }
+ assertThatThrownBy(() ->
+ new DistributionParameterHandler().getParameters(badArguments)
+ ).isInstanceOf(PolicyDistributionException.class)
+ .hasMessageContaining("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
@@ -97,14 +91,12 @@ public class TestDistributionParameterHandler {
final DistributionCommandLineArguments invalidArguments = new DistributionCommandLineArguments();
invalidArguments.parse(invalidArgumentString);
- try {
- new DistributionParameterHandler().getParameters(invalidArguments);
- fail("test should throw an exception here");
- } catch (final Exception e) {
- assertEquals("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", e.getMessage());
- }
+ assertThatThrownBy(() ->
+ new DistributionParameterHandler().getParameters(invalidArguments)
+ ).isInstanceOf(PolicyDistributionException.class)
+ .hasMessageContaining("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
@@ -115,12 +107,10 @@ public class TestDistributionParameterHandler {
final DistributionCommandLineArguments noArguments = new DistributionCommandLineArguments();
noArguments.parse(noArgumentString);
- try {
- new DistributionParameterHandler().getParameters(noArguments);
- fail("test should throw an exception here");
- } catch (final Exception e) {
- assertEquals("map parameter \"receptionHandlerParameters\" is null", e.getMessage());
- }
+ assertThatThrownBy(() ->
+ new DistributionParameterHandler().getParameters(noArguments)
+ ).isInstanceOf(ParameterRuntimeException.class)
+ .hasMessageContaining("map parameter \"receptionHandlerParameters\" is null");
}
@Test
@@ -176,12 +166,10 @@ public class TestDistributionParameterHandler {
final DistributionCommandLineArguments arguments = new DistributionCommandLineArguments();
arguments.parse(distributionConfigParameters);
- try {
- new DistributionParameterHandler().getParameters(arguments);
- fail("test should throw an exception here");
- } catch (final Exception e) {
- assertTrue(e.getMessage().contains("parameter \"parameterClassName\" value \"\" invalid in JSON file"));
- }
+ assertThatThrownBy(() ->
+ new DistributionParameterHandler().getParameters(arguments)
+ ).isInstanceOf(PolicyDistributionException.class)
+ .hasMessageContaining("parameter \"parameterClassName\" value \"\" invalid in JSON file");
}
@Test
@@ -193,13 +181,11 @@ public class TestDistributionParameterHandler {
final DistributionCommandLineArguments arguments = new DistributionCommandLineArguments();
arguments.parse(distributionConfigParameters);
- try {
- new DistributionParameterHandler().getParameters(arguments);
- fail("test should throw an exception here");
- } catch (final Exception e) {
- assertTrue(e.getMessage().contains(
- "parameter \"parameterClassName\" value \"org.onap.policy.Unknown\", could not find class"));
- }
+ assertThatThrownBy(() ->
+ new DistributionParameterHandler().getParameters(arguments)
+ ).isInstanceOf(PolicyDistributionException.class)
+ .hasMessageContaining("parameter \"parameterClassName\" value \"org.onap.policy.Unknown\", "
+ + "could not find class");
}
@Test
@@ -210,13 +196,11 @@ public class TestDistributionParameterHandler {
final DistributionCommandLineArguments arguments = new DistributionCommandLineArguments();
arguments.parse(distributionConfigParameters);
- try {
- new DistributionParameterHandler().getParameters(arguments);
- fail("test should throw an exception here");
- } catch (final Exception e) {
- assertTrue(e.getMessage().contains(
- "field \"name\" type \"java.lang.String\" value \" \" INVALID, must be a non-blank string"));
- }
+ assertThatThrownBy(() ->
+ new DistributionParameterHandler().getParameters(arguments)
+ ).isInstanceOf(PolicyDistributionException.class)
+ .hasMessageContaining("field \"name\" type \"java.lang.String\" value \" "
+ + "\" INVALID, must be a non-blank string");
}
@Test
@@ -227,12 +211,10 @@ public class TestDistributionParameterHandler {
final DistributionCommandLineArguments arguments = new DistributionCommandLineArguments();
arguments.parse(distributionConfigParameters);
- try {
- new DistributionParameterHandler().getParameters(arguments);
- fail("test should throw an exception here");
- } catch (final Exception e) {
- assertTrue(e.getMessage().contains("map parameter \"receptionHandlerParameters\" is null"));
- }
+ assertThatThrownBy(() ->
+ new DistributionParameterHandler().getParameters(arguments)
+ ).isInstanceOf(ParameterRuntimeException.class)
+ .hasMessageContaining("map parameter \"receptionHandlerParameters\" is null");
}
@Test
@@ -243,12 +225,10 @@ public class TestDistributionParameterHandler {
final DistributionCommandLineArguments arguments = new DistributionCommandLineArguments();
arguments.parse(distributionConfigParameters);
- try {
- new DistributionParameterHandler().getParameters(arguments);
- fail("test should throw an exception here");
- } catch (final Exception e) {
- assertTrue(e.getMessage().contains("must have at least one reception handler\n"));
- }
+ assertThatThrownBy(() ->
+ new DistributionParameterHandler().getParameters(arguments)
+ ).isInstanceOf(PolicyDistributionException.class)
+ .hasMessageContaining("must have at least one reception handler\n");
}
@Test
@@ -259,12 +239,10 @@ public class TestDistributionParameterHandler {
final DistributionCommandLineArguments arguments = new DistributionCommandLineArguments();
arguments.parse(distributionConfigParameters);
- try {
- new DistributionParameterHandler().getParameters(arguments);
- fail("test should throw an exception here");
- } catch (final Exception e) {
- assertTrue(e.getMessage().contains("map parameter \"policyDecoders\" is null"));
- }
+ assertThatThrownBy(() ->
+ new DistributionParameterHandler().getParameters(arguments)
+ ).isInstanceOf(ParameterRuntimeException.class)
+ .hasMessageContaining("map parameter \"policyDecoders\" is null");
}
@Test
@@ -275,12 +253,10 @@ public class TestDistributionParameterHandler {
final DistributionCommandLineArguments arguments = new DistributionCommandLineArguments();
arguments.parse(distributionConfigParameters);
- try {
- new DistributionParameterHandler().getParameters(arguments);
- fail("test should throw an exception here");
- } catch (final Exception e) {
- assertTrue(e.getMessage().contains("map parameter \"policyForwarders\" is null"));
- }
+ assertThatThrownBy(() ->
+ new DistributionParameterHandler().getParameters(arguments)
+ ).isInstanceOf(ParameterRuntimeException.class)
+ .hasMessageContaining("map parameter \"policyForwarders\" is null");
}
@Test
@@ -291,12 +267,10 @@ public class TestDistributionParameterHandler {
final DistributionCommandLineArguments arguments = new DistributionCommandLineArguments();
arguments.parse(distributionConfigParameters);
- try {
- new DistributionParameterHandler().getParameters(arguments);
- fail("test should throw an exception here");
- } catch (final Exception e) {
- assertTrue(e.getMessage().contains("must have at least one policy decoder\n"));
- }
+ assertThatThrownBy(() ->
+ new DistributionParameterHandler().getParameters(arguments)
+ ).isInstanceOf(PolicyDistributionException.class)
+ .hasMessageContaining("must have at least one policy decoder\n");
}
@Test
@@ -307,12 +281,10 @@ public class TestDistributionParameterHandler {
final DistributionCommandLineArguments arguments = new DistributionCommandLineArguments();
arguments.parse(distributionConfigParameters);
- try {
- new DistributionParameterHandler().getParameters(arguments);
- fail("test should throw an exception here");
- } catch (final Exception e) {
- assertTrue(e.getMessage().endsWith("must have at least one policy forwarder\n"));
- }
+ assertThatThrownBy(() ->
+ new DistributionParameterHandler().getParameters(arguments)
+ ).isInstanceOf(PolicyDistributionException.class)
+ .hasMessageContaining("must have at least one policy forwarder\n");
}
@Test
@@ -324,15 +296,13 @@ public class TestDistributionParameterHandler {
final DistributionCommandLineArguments arguments = new DistributionCommandLineArguments();
arguments.parse(distributionConfigParameters);
- try {
- new DistributionParameterHandler().getParameters(arguments);
- fail("test should throw an exception here");
- } catch (final Exception e) {
- final String expectedResult = new String(Files.readAllBytes(
- Paths.get("src/test/resources/expectedValidationResults/InvalidReceptionHandlerParameters.txt")))
- .replaceAll("\\s+", "");
- assertEquals(expectedResult, e.getMessage().replaceAll("\\s+", ""));
- }
+ String resultString = Files.readString(Paths.get(
+ "src/test/resources/expectedValidationResults/InvalidReceptionHandlerParameters.txt"))
+ .trim().replaceAll("\\r\\n", "\\\n");
+ assertThatThrownBy(() ->
+ new DistributionParameterHandler().getParameters(arguments)
+ ).isInstanceOf(PolicyDistributionException.class)
+ .hasMessageContaining(resultString);
}
@Test
@@ -343,16 +313,12 @@ public class TestDistributionParameterHandler {
final DistributionCommandLineArguments arguments = new DistributionCommandLineArguments();
arguments.parse(distributionConfigParameters);
-
- try {
- new DistributionParameterHandler().getParameters(arguments);
- fail("test should throw an exception here");
- } catch (final Exception e) {
- final String expectedResult = new String(Files.readAllBytes(
- Paths.get("src/test/resources/expectedValidationResults/InvalidDecoderAndForwarderParameters.txt")))
- .replaceAll("\\s+", "");
- assertEquals(expectedResult, e.getMessage().replaceAll("\\s+", ""));
- }
+ String resultString = new String(Files.readString(Paths.get(
+ "src/test/resources/expectedValidationResults/InvalidDecoderAndForwarderParameters.txt"))
+ .trim().replaceAll("\\r\\n", "\\\n"));
+ assertThatThrownBy(() -> new DistributionParameterHandler().getParameters(arguments))
+ .isInstanceOf(PolicyDistributionException.class)
+ .hasMessageContaining((resultString));
}
@Test
@@ -364,15 +330,12 @@ public class TestDistributionParameterHandler {
final DistributionCommandLineArguments arguments = new DistributionCommandLineArguments();
arguments.parse(distributionConfigParameters);
- try {
- new DistributionParameterHandler().getParameters(arguments);
- fail("test should throw an exception here");
- } catch (final Exception e) {
- final String expectedResult = new String(Files.readAllBytes(
- Paths.get("src/test/resources/expectedValidationResults/InvalidRestServerParameters.txt")))
- .replaceAll("\\s+", "");
- assertEquals(expectedResult, e.getMessage().replaceAll("\\s+", ""));
- }
+ String resultString = new String(Files.readString(Paths.get(
+ "src/test/resources/expectedValidationResults/InvalidRestServerParameters.txt"))
+ .trim().replaceAll("\\r\\n", "\\\n"));
+ assertThatThrownBy(() -> new DistributionParameterHandler().getParameters(arguments))
+ .isInstanceOf(PolicyDistributionException.class)
+ .hasMessageContaining(resultString);
}
@Test
@@ -398,11 +361,10 @@ public class TestDistributionParameterHandler {
final String[] distributionConfigParameters =
{ "-d" };
final DistributionCommandLineArguments arguments = new DistributionCommandLineArguments();
- try {
- arguments.parse(distributionConfigParameters);
- } catch (final Exception exp) {
- assertTrue(exp.getMessage().startsWith("invalid command line arguments specified"));
- }
+ assertThatThrownBy(() ->
+ arguments.parse(distributionConfigParameters)
+ ).isInstanceOf(PolicyDistributionException.class)
+ .hasMessageContaining("invalid command line arguments specified");
}
@Test
@@ -413,11 +375,9 @@ public class TestDistributionParameterHandler {
final DistributionCommandLineArguments arguments = new DistributionCommandLineArguments();
arguments.parse(distributionConfigParameters);
- try {
- new DistributionParameterHandler().getParameters(arguments);
- } catch (final Exception e) {
- assertTrue(e.getMessage().contains("could not find class"));
- }
+ assertThatThrownBy(() -> new DistributionParameterHandler().getParameters(arguments))
+ .isInstanceOf(PolicyDistributionException.class)
+ .hasMessageContaining("could not find class");
}
@Test
@@ -428,11 +388,9 @@ public class TestDistributionParameterHandler {
final DistributionCommandLineArguments arguments = new DistributionCommandLineArguments();
arguments.parse(distributionConfigParameters);
- try {
- new DistributionParameterHandler().getParameters(arguments);
- } catch (final Exception e) {
- assertTrue(e.getMessage().contains("invalid in JSON file"));
- }
+ assertThatThrownBy(() -> new DistributionParameterHandler().getParameters(arguments))
+ .isInstanceOf(PolicyDistributionException.class)
+ .hasMessageContaining("invalid in JSON file");
}
@Test
@@ -444,12 +402,9 @@ public class TestDistributionParameterHandler {
final DistributionCommandLineArguments arguments = new DistributionCommandLineArguments();
arguments.parse(distributionConfigParameters);
- try {
- new DistributionParameterHandler().getParameters(arguments);
- fail("test should throw an exception here");
- } catch (final Exception e) {
- assertTrue(e.getMessage().contains("parameter \"parameterClassName\" value \"\" invalid in JSON file"));
- }
+ assertThatThrownBy(() -> new DistributionParameterHandler().getParameters(arguments))
+ .isInstanceOf(PolicyDistributionException.class)
+ .hasMessageContaining("parameter \"parameterClassName\" value \"\" invalid in JSON file");
}
@Test
@@ -461,12 +416,9 @@ public class TestDistributionParameterHandler {
final DistributionCommandLineArguments arguments = new DistributionCommandLineArguments();
arguments.parse(distributionConfigParameters);
- try {
- new DistributionParameterHandler().getParameters(arguments);
- fail("test should throw an exception here");
- } catch (final Exception e) {
- assertTrue(e.getMessage().contains(
- "parameter \"parameterClassName\" value \"org.onap.policy.Unknown\", could not find class"));
- }
+ assertThatThrownBy(() -> new DistributionParameterHandler().getParameters(arguments))
+ .isInstanceOf(PolicyDistributionException.class)
+ .hasMessageContaining("parameter \"parameterClassName\" value"
+ + " \"org.onap.policy.Unknown\", could not find class");
}
}
diff --git a/main/src/test/java/org/onap/policy/distribution/main/parameters/TestPluginHandlerParameters.java b/main/src/test/java/org/onap/policy/distribution/main/parameters/TestPluginHandlerParameters.java
index 9eeae354..73ec0ba3 100644
--- a/main/src/test/java/org/onap/policy/distribution/main/parameters/TestPluginHandlerParameters.java
+++ b/main/src/test/java/org/onap/policy/distribution/main/parameters/TestPluginHandlerParameters.java
@@ -1,6 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 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.
@@ -20,14 +21,15 @@
package org.onap.policy.distribution.main.parameters;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
import java.util.Map;
import org.junit.Test;
import org.onap.policy.common.parameters.GroupValidationResult;
+import org.onap.policy.common.parameters.ParameterRuntimeException;
import org.onap.policy.distribution.forwarding.parameters.PolicyForwarderParameters;
import org.onap.policy.distribution.reception.parameters.PluginHandlerParameters;
import org.onap.policy.distribution.reception.parameters.PolicyDecoderParameters;
@@ -55,26 +57,18 @@ public class TestPluginHandlerParameters {
@Test
public void testPluginHandlerParameters_NullPolicyDecoders() {
- try {
- final Map<String, PolicyForwarderParameters> policyForwarders = commonTestData.getPolicyForwarders(false);
- final PluginHandlerParameters pHParameters = new PluginHandlerParameters(null, policyForwarders);
- pHParameters.validate();
- fail("test should throw an exception here");
- } catch (final Exception e) {
- assertTrue(e.getMessage().contains("map parameter \"policyDecoders\" is null"));
- }
+ final Map<String, PolicyForwarderParameters> policyForwarders = commonTestData.getPolicyForwarders(false);
+ final PluginHandlerParameters pHParameters = new PluginHandlerParameters(null, policyForwarders);
+ assertThatThrownBy(pHParameters::validate).isInstanceOf(ParameterRuntimeException.class)
+ .hasMessage("map parameter \"policyDecoders\" is null");
}
@Test
public void testPluginHandlerParameters_NullPolicyForwarders() {
- try {
- final Map<String, PolicyDecoderParameters> policyDecoders = commonTestData.getPolicyDecoders(false);
- final PluginHandlerParameters pHParameters = new PluginHandlerParameters(policyDecoders, null);
- pHParameters.validate();
- fail("test should throw an exception here");
- } catch (final Exception e) {
- assertTrue(e.getMessage().contains("map parameter \"policyForwarders\" is null"));
- }
+ final Map<String, PolicyDecoderParameters> policyDecoders = commonTestData.getPolicyDecoders(false);
+ final PluginHandlerParameters pHParameters = new PluginHandlerParameters(policyDecoders, null);
+ assertThatThrownBy(pHParameters::validate).isInstanceOf(ParameterRuntimeException.class)
+ .hasMessage("map parameter \"policyForwarders\" is null");
}
@Test
diff --git a/main/src/test/java/org/onap/policy/distribution/main/rest/TestDistributionRestServer.java b/main/src/test/java/org/onap/policy/distribution/main/rest/TestDistributionRestServer.java
index 5adc0bdf..62bd8aad 100644
--- a/main/src/test/java/org/onap/policy/distribution/main/rest/TestDistributionRestServer.java
+++ b/main/src/test/java/org/onap/policy/distribution/main/rest/TestDistributionRestServer.java
@@ -3,7 +3,7 @@
* Copyright (C) 2018 Ericsson. All rights reserved.
* Copyright (C) 2019 Nordix Foundation.
* Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 2019-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.
@@ -23,9 +23,9 @@
package org.onap.policy.distribution.main.rest;
+import static org.assertj.core.api.Assertions.assertThatCode;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
import java.io.IOException;
import javax.ws.rs.client.Client;
@@ -43,8 +43,6 @@ import org.onap.policy.common.utils.network.NetworkUtil;
import org.onap.policy.distribution.main.PolicyDistributionException;
import org.onap.policy.distribution.main.parameters.CommonTestData;
import org.onap.policy.distribution.main.startstop.Main;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
/**
* Class to perform unit test of HealthCheckMonitor.
@@ -53,7 +51,6 @@ import org.slf4j.LoggerFactory;
*/
public class TestDistributionRestServer {
- private static final Logger LOGGER = LoggerFactory.getLogger(TestDistributionRestServer.class);
private static final String NOT_ALIVE = "not alive";
private static final String ALIVE = "alive";
private static final String SELF = NetworkUtil.getHostname();
@@ -62,15 +59,12 @@ public class TestDistributionRestServer {
@Test
public void testHealthCheckSuccess() {
final String reportString = "Report [name=Policy SSD, url=" + SELF + ", healthy=true, code=200, message=alive]";
- try {
+ assertThatCode(() -> {
final Main main = startDistributionService();
final HealthCheckReport report = performHealthCheck();
validateReport(NAME, SELF, true, 200, ALIVE, reportString, report);
stopDistributionService(main);
- } catch (final Exception exp) {
- LOGGER.error("testHealthCheckSuccess failed", exp);
- fail("Test should not throw an exception");
- }
+ }).doesNotThrowAnyException();
}
@Test
@@ -80,17 +74,14 @@ public class TestDistributionRestServer {
final RestServerParameters restServerParams = new CommonTestData().getRestServerParameters(false);
restServerParams.setName(CommonTestData.DISTRIBUTION_GROUP_NAME);
final RestServer restServer = new RestServer(restServerParams, null, DistributionRestController.class);
- try {
+ assertThatCode(() -> {
restServer.start();
final HealthCheckReport report = performHealthCheck();
validateReport(NAME, SELF, false, 500, NOT_ALIVE, reportString, report);
assertTrue(restServer.isAlive());
assertTrue(restServer.toString().startsWith("RestServer [servers="));
restServer.shutdown();
- } catch (final Exception exp) {
- LOGGER.error("testHealthCheckFailure failed", exp);
- fail("Test should not throw an exception");
- }
+ }).doesNotThrowAnyException();
}
private Main startDistributionService() {
diff --git a/main/src/test/java/org/onap/policy/distribution/main/rest/TestDistributionStatistics.java b/main/src/test/java/org/onap/policy/distribution/main/rest/TestDistributionStatistics.java
index ebaa18b9..f394e02b 100644
--- a/main/src/test/java/org/onap/policy/distribution/main/rest/TestDistributionStatistics.java
+++ b/main/src/test/java/org/onap/policy/distribution/main/rest/TestDistributionStatistics.java
@@ -3,6 +3,7 @@
* Copyright (C) 2018 Ericsson. All rights reserved.
* Copyright (C) 2019 Nordix Foundation.
* Modifications Copyright (C) 2019 AT&T Intellectual Property. 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.
@@ -22,8 +23,8 @@
package org.onap.policy.distribution.main.rest;
+import static org.assertj.core.api.Assertions.assertThatCode;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
import java.io.IOException;
import javax.ws.rs.client.Client;
@@ -41,8 +42,6 @@ import org.onap.policy.distribution.main.PolicyDistributionException;
import org.onap.policy.distribution.main.parameters.CommonTestData;
import org.onap.policy.distribution.main.startstop.Main;
import org.onap.policy.distribution.reception.statistics.DistributionStatisticsManager;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
/**
* Class to perform unit test of {@link DistributionRestController}.
@@ -51,12 +50,9 @@ import org.slf4j.LoggerFactory;
*/
public class TestDistributionStatistics {
- private static final Logger LOGGER = LoggerFactory.getLogger(TestDistributionStatistics.class);
-
-
@Test
public void testDistributionStatistics_200() {
- try {
+ assertThatCode(() -> {
final Main main = startDistributionService();
StatisticsReport report = getDistributionStatistics();
validateReport(report, 0, 200);
@@ -65,10 +61,7 @@ public class TestDistributionStatistics {
validateReport(report, 1, 200);
stopDistributionService(main);
DistributionStatisticsManager.resetAllStatistics();
- } catch (final Exception exp) {
- LOGGER.error("testDistributionStatistics_200 failed", exp);
- fail("Test should not throw an exception");
- }
+ }).doesNotThrowAnyException();
}
@Test
@@ -76,16 +69,13 @@ public class TestDistributionStatistics {
final RestServerParameters restServerParams = new CommonTestData().getRestServerParameters(false);
restServerParams.setName(CommonTestData.DISTRIBUTION_GROUP_NAME);
final RestServer restServer = new RestServer(restServerParams, null, DistributionRestController.class);
- try {
+ assertThatCode(() -> {
restServer.start();
final StatisticsReport report = getDistributionStatistics();
validateReport(report, 0, 500);
restServer.shutdown();
DistributionStatisticsManager.resetAllStatistics();
- } catch (final Exception exp) {
- LOGGER.error("testDistributionStatistics_500 failed", exp);
- fail("Test should not throw an exception");
- }
+ }).doesNotThrowAnyException();
}
private Main startDistributionService() {
diff --git a/main/src/test/java/org/onap/policy/distribution/main/rest/TestHttpsDistributionRestServer.java b/main/src/test/java/org/onap/policy/distribution/main/rest/TestHttpsDistributionRestServer.java
index 0d511088..dd8d4516 100644
--- a/main/src/test/java/org/onap/policy/distribution/main/rest/TestHttpsDistributionRestServer.java
+++ b/main/src/test/java/org/onap/policy/distribution/main/rest/TestHttpsDistributionRestServer.java
@@ -1,7 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2018 Intel. All rights reserved.
- * Modifications Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 2019-2020 Nordix Foundation.
* Modifications Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -22,8 +22,8 @@
package org.onap.policy.distribution.main.rest;
+import static org.assertj.core.api.Assertions.assertThatCode;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
import java.security.SecureRandom;
import java.security.cert.X509Certificate;
@@ -42,8 +42,6 @@ import org.onap.policy.common.endpoints.report.HealthCheckReport;
import org.onap.policy.common.utils.network.NetworkUtil;
import org.onap.policy.distribution.main.PolicyDistributionException;
import org.onap.policy.distribution.main.startstop.Main;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
/**
* Class to perform unit test of HealthCheckMonitor.
@@ -52,7 +50,6 @@ import org.slf4j.LoggerFactory;
*/
public class TestHttpsDistributionRestServer {
- private static final Logger LOGGER = LoggerFactory.getLogger(TestHttpsDistributionRestServer.class);
private static final String ALIVE = "alive";
private static final String SELF = NetworkUtil.getHostname();
private static final String NAME = "Policy SSD";
@@ -61,15 +58,12 @@ public class TestHttpsDistributionRestServer {
@Test
public void testHttpsHealthCheckSuccess() {
final String reportString = "Report [name=Policy SSD, url=" + SELF + ", healthy=true, code=200, message=alive]";
- try {
+ assertThatCode(() -> {
final Main main = startDistributionService();
final HealthCheckReport report = performHealthCheck();
validateReport(NAME, SELF, true, 200, ALIVE, reportString, report);
stopDistributionService(main);
- } catch (final Exception exp) {
- LOGGER.error("testHttpsHealthCheckSuccess failed", exp);
- fail("Test should not throw an exception");
- }
+ }).doesNotThrowAnyException();
}
private Main startDistributionService() {
diff --git a/main/src/test/java/org/onap/policy/distribution/main/rest/TestHttpsStatisticDistributionRestServer.java b/main/src/test/java/org/onap/policy/distribution/main/rest/TestHttpsStatisticDistributionRestServer.java
index 8d29c8ef..76462565 100644
--- a/main/src/test/java/org/onap/policy/distribution/main/rest/TestHttpsStatisticDistributionRestServer.java
+++ b/main/src/test/java/org/onap/policy/distribution/main/rest/TestHttpsStatisticDistributionRestServer.java
@@ -3,6 +3,7 @@
* Copyright (C) 2018 Intel. All rights reserved.
* Copyright (C) 2019 Nordix Foundation.
* Modifications Copyright (C) 2020 AT&T Intellectual Property. 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.
@@ -22,11 +23,9 @@
package org.onap.policy.distribution.main.rest;
+import static org.assertj.core.api.Assertions.assertThatCode;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
-import java.security.KeyManagementException;
-import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.security.cert.X509Certificate;
import java.util.Properties;
@@ -43,8 +42,6 @@ import org.junit.Test;
import org.onap.policy.common.utils.network.NetworkUtil;
import org.onap.policy.distribution.main.PolicyDistributionException;
import org.onap.policy.distribution.main.startstop.Main;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
/**
* Class to perform unit test of HealthCheckMonitor.
@@ -53,21 +50,16 @@ import org.slf4j.LoggerFactory;
*/
public class TestHttpsStatisticDistributionRestServer {
- private static final Logger LOGGER = LoggerFactory.getLogger(TestHttpsStatisticDistributionRestServer.class);
private static String KEYSTORE = System.getProperty("user.dir") + "/src/test/resources/ssl/policy-keystore";
@Test
- public void testHttpsDistributionStatistic()
- throws PolicyDistributionException, InterruptedException, KeyManagementException, NoSuchAlgorithmException {
- try {
+ public void testHttpsDistributionStatistic() {
+ assertThatCode(() -> {
final Main main = startDistributionService();
final StatisticsReport report = performStatisticCheck();
validateReport(200, 0, 0, 0, 0, 0, 0, report);
stopDistributionService(main);
- } catch (final Exception exp) {
- LOGGER.error("testHttpsDistributionStatistic failed", exp);
- fail("Test should not throw an exception");
- }
+ }).doesNotThrowAnyException();
}
private Main startDistributionService() {
diff --git a/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/file/FilePolicyForwarderTest.java b/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/file/FilePolicyForwarderTest.java
index 72dba64d..fb00dae1 100644
--- a/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/file/FilePolicyForwarderTest.java
+++ b/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/file/FilePolicyForwarderTest.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* Copyright (C) 2019 Intel Corp. All rights reserved.
* Modifications Copyright (C) 2019-2020 AT&T Intellectual Property.
- * Modifications Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 2019-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.
@@ -22,8 +22,8 @@
package org.onap.policy.distribution.forwarding.file;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
import java.io.IOException;
import java.nio.file.Files;
@@ -40,6 +40,7 @@ import org.junit.runner.RunWith;
import org.mockito.Mockito;
import org.mockito.junit.MockitoJUnitRunner;
import org.onap.policy.common.parameters.ParameterService;
+import org.onap.policy.distribution.forwarding.PolicyForwardingException;
import org.onap.policy.models.tosca.authorative.concepts.ToscaEntity;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
@@ -77,20 +78,16 @@ public class FilePolicyForwarderTest {
}
@Test
- public void testForwardPolicy() {
+ public void testForwardPolicy() throws PolicyForwardingException {
final Collection<ToscaEntity> policies = new ArrayList<>();
final ToscaPolicy policy = createPolicy(policies, "test", "test");
final FilePolicyForwarder forwarder = new FilePolicyForwarder();
forwarder.configure(GROUP_NAME);
- try {
- forwarder.forward(policies);
- final Path path = Paths.get(tempFolder.getRoot().getAbsolutePath().toString(), policy.getName());
- assertTrue(Files.exists(path));
- } catch (final Exception exp) {
- fail("Test must not throw an exception");
- }
+ forwarder.forward(policies);
+ final Path path = Paths.get(tempFolder.getRoot().getAbsolutePath().toString(), policy.getName());
+ assertTrue(Files.exists(path));
}
@Test
@@ -107,12 +104,8 @@ public class FilePolicyForwarderTest {
final FilePolicyForwarder forwarder = new FilePolicyForwarder();
forwarder.configure(GROUP_NAME);
- try {
- forwarder.forward(policies);
- fail("Test must throw an exception");
- } catch (final Exception exp) {
- assertTrue(exp.getMessage().contains("Error sending policy"));
- }
+ assertThatThrownBy(() -> forwarder.forward(policies)).isInstanceOf(PolicyForwardingException.class)
+ .hasMessageContaining("Error sending policy");
}
@Test
@@ -124,12 +117,8 @@ public class FilePolicyForwarderTest {
final ToscaEntity policy = new UnsupportedPolicy();
policies.add(policy);
- try {
- forwarder.forward(policies);
- fail("Test must throw an exception");
- } catch (final Exception exp) {
- assertTrue(exp.getMessage().contains("Cannot forward policy"));
- }
+ assertThatThrownBy(() -> forwarder.forward(policies)).isInstanceOf(PolicyForwardingException.class)
+ .hasMessageContaining("Cannot forward policy");
}
class UnsupportedPolicy extends ToscaEntity {
diff --git a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/policy/file/PolicyDecoderFileInCsarToPolicyTest.java b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/policy/file/PolicyDecoderFileInCsarToPolicyTest.java
index 8e1585a0..05bd0780 100644
--- a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/policy/file/PolicyDecoderFileInCsarToPolicyTest.java
+++ b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/policy/file/PolicyDecoderFileInCsarToPolicyTest.java
@@ -1,7 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 2019-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.
@@ -21,12 +21,11 @@
package org.onap.policy.distribution.reception.decoding.policy.file;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
import java.io.File;
-import java.io.IOException;
import java.util.Collection;
import org.junit.AfterClass;
import org.junit.BeforeClass;
@@ -34,8 +33,8 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.runners.MockitoJUnitRunner;
import org.onap.policy.common.parameters.ParameterService;
-import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.distribution.model.Csar;
+import org.onap.policy.distribution.reception.decoding.PolicyDecodingException;
import org.onap.policy.distribution.reception.decoding.hpa.CommonTestData;
import org.onap.policy.models.tosca.authorative.concepts.ToscaEntity;
@@ -68,7 +67,7 @@ public class PolicyDecoderFileInCsarToPolicyTest {
}
@Test
- public void testDecodePolicy() {
+ public void testDecodePolicy() throws PolicyDecodingException {
final PolicyDecoderFileInCsarToPolicy decoder = new PolicyDecoderFileInCsarToPolicy();
decoder.configure(PolicyDecoderFileInCsarToPolicyParameterGroup.class.getSimpleName());
@@ -76,13 +75,9 @@ public class PolicyDecoderFileInCsarToPolicyTest {
final File file = new File("src/test/resources/service-Sampleservice.csar");
final Csar csar = new Csar(file.getAbsolutePath());
- try {
- assertTrue(decoder.canHandle(csar));
- final Collection<ToscaEntity> policyHolders = decoder.decode(csar);
- assertEquals(2, policyHolders.size());
- } catch (final Exception exp) {
- fail("Test must not throw an exception");
- }
+ assertTrue(decoder.canHandle(csar));
+ final Collection<ToscaEntity> policyHolders = decoder.decode(csar);
+ assertEquals(2, policyHolders.size());
}
@Test
@@ -94,14 +89,9 @@ public class PolicyDecoderFileInCsarToPolicyTest {
final File file = new File("unknown.csar");
final Csar csar = new Csar(file.getAbsolutePath());
- try {
- assertTrue(decoder.canHandle(csar));
- decoder.decode(csar);
- fail("Test must throw an exception");
- } catch (final Exception exp) {
- assertTrue(exp.getCause() instanceof IOException);
- assertTrue(exp.getMessage().contains("Failed decoding the policy"));
- }
+ assertTrue(decoder.canHandle(csar));
+ assertThatThrownBy(() -> decoder.decode(csar)).isInstanceOf(PolicyDecodingException.class)
+ .hasMessageContaining("Failed decoding the policy");
}
@@ -114,13 +104,8 @@ public class PolicyDecoderFileInCsarToPolicyTest {
final File file = new File("src/test/resources/service-Sampleservice-test.csar");
final Csar csar = new Csar(file.getAbsolutePath());
- try {
- assertTrue(decoder.canHandle(csar));
- decoder.decode(csar);
- fail("Test must throw an exception");
- } catch (final Exception exp) {
- assertTrue(exp.getCause() instanceof CoderException);
- assertTrue(exp.getMessage().contains("Failed decoding the policy"));
- }
+ assertTrue(decoder.canHandle(csar));
+ assertThatThrownBy(() -> decoder.decode(csar)).isInstanceOf(PolicyDecodingException.class)
+ .hasMessageContaining("Failed decoding the policy");
}
}
diff --git a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/file/TestFileSystemReceptionHandler.java b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/file/TestFileSystemReceptionHandler.java
index 7f97c5cf..c9debdd9 100644
--- a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/file/TestFileSystemReceptionHandler.java
+++ b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/file/TestFileSystemReceptionHandler.java
@@ -2,6 +2,7 @@
* ============LICENSE_START=======================================================
* Copyright (C) 2018 Intel. All rights reserved.
* Copyright (C) 2019 Nordix Foundation.
+ * 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.
@@ -21,7 +22,7 @@
package org.onap.policy.distribution.reception.handling.file;
-import static org.junit.Assert.fail;
+import static org.assertj.core.api.Assertions.assertThatCode;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
@@ -93,27 +94,19 @@ public class TestFileSystemReceptionHandler {
final FileSystemReceptionHandler sypHandler = Mockito.spy(fileSystemHandler);
Mockito.doNothing().when(sypHandler).initFileWatcher(Mockito.isA(String.class),
Mockito.anyInt());
- try {
- sypHandler.initializeReception(pssdConfigParameters.getName());
- } catch (final Exception exp) {
- LOGGER.error("testInit failed", exp);
- fail("Test should not throw any exception");
- }
+ assertThatCode(() -> sypHandler.initializeReception(pssdConfigParameters.getName()))
+ .doesNotThrowAnyException();
}
@Test
public final void testDestroy() throws IOException {
- try {
- final FileSystemReceptionHandler sypHandler = Mockito.spy(fileSystemHandler);
- Mockito.doNothing().when(sypHandler).initFileWatcher(Mockito.isA(String.class),
- Mockito.anyInt());
+ final FileSystemReceptionHandler sypHandler = Mockito.spy(fileSystemHandler);
+ Mockito.doNothing().when(sypHandler).initFileWatcher(Mockito.isA(String.class),
+ Mockito.anyInt());
+ assertThatCode(() -> {
sypHandler.initializeReception(pssdConfigParameters.getName());
sypHandler.destroy();
- } catch (final Exception exp) {
- LOGGER.error("testDestroy failed", exp);
- fail("Test should not throw any exception");
- }
-
+ }).doesNotThrowAnyException();
}
@Test
diff --git a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/file/TestFileSystemReceptionHandlerConfigurationParameterGroup.java b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/file/TestFileSystemReceptionHandlerConfigurationParameterGroup.java
index 6c57a132..03455b84 100644
--- a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/file/TestFileSystemReceptionHandlerConfigurationParameterGroup.java
+++ b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/file/TestFileSystemReceptionHandlerConfigurationParameterGroup.java
@@ -2,6 +2,7 @@
* ============LICENSE_START=======================================================
* Copyright (C) 2018 Intel. All rights reserved.
* Copyright (C) 2019 Nordix Foundation.
+ * 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.
@@ -24,7 +25,6 @@ package org.onap.policy.distribution.reception.handling.file;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
@@ -47,15 +47,13 @@ public class TestFileSystemReceptionHandlerConfigurationParameterGroup {
public void testFileSystemConfiguration() throws IOException {
FileSystemReceptionHandlerConfigurationParameterGroup configParameters = null;
String validPath = null;
- try {
- validPath = tempFolder.getRoot().getAbsolutePath();
- configParameters = new FileSystemReceptionHandlerConfigurationParameterGroup();
- configParameters.setWatchPath(validPath);
- configParameters.setMaxThread(2);
- } catch (final Exception e) {
- fail("test should not thrown an exception here: " + e.getMessage());
- }
+ validPath = tempFolder.getRoot().getAbsolutePath();
+
+ configParameters = new FileSystemReceptionHandlerConfigurationParameterGroup();
+ configParameters.setWatchPath(validPath);
+ configParameters.setMaxThread(2);
+
final GroupValidationResult validationResult = configParameters.validate();
assertTrue(validationResult.isValid());
assertEquals(validPath, configParameters.getWatchPath());
@@ -65,15 +63,12 @@ public class TestFileSystemReceptionHandlerConfigurationParameterGroup {
@Test
public void testInvalidFileSystemConfiguration() throws IOException {
FileSystemReceptionHandlerConfigurationParameterGroup configParameters = null;
- try {
- final Gson gson = new GsonBuilder().create();
- configParameters = gson.fromJson(new FileReader("src/test/resources/handling-sdcInvalid.json"),
- FileSystemReceptionHandlerConfigurationParameterGroup.class);
- } catch (final Exception e) {
- fail("test should not thrown an exception here: " + e.getMessage());
- }
+ final Gson gson = new GsonBuilder().create();
+ configParameters = gson.fromJson(new FileReader("src/test/resources/handling-sdcInvalid.json"),
+ FileSystemReceptionHandlerConfigurationParameterGroup.class);
final GroupValidationResult validationResult = configParameters.validate();
assertFalse(validationResult.isValid());
+
}
@Test
diff --git a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/sdc/TestSdcReceptionHandler.java b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/sdc/TestSdcReceptionHandler.java
index f51b6da0..58933c1f 100644
--- a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/sdc/TestSdcReceptionHandler.java
+++ b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/sdc/TestSdcReceptionHandler.java
@@ -2,6 +2,7 @@
* ============LICENSE_START=======================================================
* Copyright (C) 2018 Intel. All rights reserved.
* Copyright (C) 2019 Nordix Foundation.
+ * 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.
@@ -21,9 +22,9 @@
package org.onap.policy.distribution.reception.handling.sdc;
+import static org.assertj.core.api.Assertions.assertThatCode;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
import static org.mockito.Matchers.any;
import com.google.gson.Gson;
@@ -60,8 +61,6 @@ import org.onap.sdc.api.notification.INotificationData;
import org.onap.sdc.api.results.IDistributionClientDownloadResult;
import org.onap.sdc.api.results.IDistributionClientResult;
import org.onap.sdc.utils.DistributionActionResultEnum;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
/**
* Class to perform unit test of {@link SdcReceptionHandler}.
@@ -71,7 +70,6 @@ import org.slf4j.LoggerFactory;
@RunWith(MockitoJUnitRunner.class)
public class TestSdcReceptionHandler {
- private static final Logger LOGGER = LoggerFactory.getLogger(TestSdcReceptionHandler.class);
private static final String DUMMY_SERVICE_CSAR = "dummyService.csar";
@Mock
@@ -141,12 +139,8 @@ public class TestSdcReceptionHandler {
@Test
public final void testInitializeSdcClient() {
- try {
- sypHandler.initializeReception(pssdConfigParameters.getName());
- } catch (final Exception exp) {
- LOGGER.error("testInitializeSdcClient failed", exp);
- fail("Test should not throw any exception");
- }
+ assertThatCode(() -> sypHandler.initializeReception(pssdConfigParameters.getName()))
+ .doesNotThrowAnyException();
}
@Test
@@ -154,61 +148,38 @@ public class TestSdcReceptionHandler {
Mockito.when(successfulClientInitResult.getDistributionActionResult())
.thenReturn(DistributionActionResultEnum.FAIL).thenReturn(DistributionActionResultEnum.SUCCESS);
- try {
- sypHandler.initializeReception(pssdConfigParameters.getName());
- } catch (final Exception exp) {
- LOGGER.error("testInitializeSdcClient_Failure failed", exp);
- fail("Test should not throw any exception");
- }
+ assertThatCode(() -> sypHandler.initializeReception(pssdConfigParameters.getName()))
+ .doesNotThrowAnyException();
}
@Test
public final void testStartSdcClient_Failure() {
- try {
+ assertThatCode(() -> {
Mockito.when(distributionClient.start()).thenReturn(failureClientInitResult)
- .thenReturn(successfulClientInitResult);
+ .thenReturn(successfulClientInitResult);
sypHandler.initializeReception(pssdConfigParameters.getName());
- } catch (final Exception exp) {
- LOGGER.error("testStartSdcClient_Failure failed", exp);
- fail("Test should not throw any exception");
- }
+ }).doesNotThrowAnyException();
}
@Test
public final void testStopSdcClient() {
- try {
+ assertThatCode(() -> {
sypHandler.initializeReception(pssdConfigParameters.getName());
sypHandler.destroy();
- } catch (final Exception exp) {
- LOGGER.error("testStopSdcClient failed", exp);
- fail("Test should not throw any exception");
- }
-
+ }).doesNotThrowAnyException();
}
@Test
public final void testStopSdcClient_Failure() throws PluginInitializationException {
-
sypHandler.initializeReception(pssdConfigParameters.getName());
Mockito.when(distributionClient.stop()).thenReturn(failureClientInitResult)
.thenReturn(successfulClientInitResult);
- try {
- sypHandler.destroy();
- } catch (final Exception exp) {
- LOGGER.error("testStopSdcClient_Failure failed", exp);
- fail("Test should not throw any exception");
- }
+ assertThatCode(() -> sypHandler.destroy()).doesNotThrowAnyException();
}
@Test
public final void testStopSdcClientWithoutStart() {
- try {
- sypHandler.destroy();
- } catch (final Exception exp) {
- LOGGER.error("testStopSdcClientWithoutStart", exp);
- fail("Test should not throw any exception");
- }
-
+ assertThatCode(() -> sypHandler.destroy()).doesNotThrowAnyException();
}
@Test
diff --git a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/sdc/TestSdcReceptionHandlerConfigurationParameterGroup.java b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/sdc/TestSdcReceptionHandlerConfigurationParameterGroup.java
index 62a61eb5..d981369c 100644
--- a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/sdc/TestSdcReceptionHandlerConfigurationParameterGroup.java
+++ b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/sdc/TestSdcReceptionHandlerConfigurationParameterGroup.java
@@ -1,7 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2018 Intel. All rights reserved.
- * Modifications Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 2019-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.
@@ -24,7 +24,6 @@ package org.onap.policy.distribution.reception.handling.sdc;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
@@ -45,13 +44,10 @@ public class TestSdcReceptionHandlerConfigurationParameterGroup {
@Test
public void testSdcConfiguration() throws IOException {
SdcReceptionHandlerConfigurationParameterGroup configParameters = null;
- try {
- final Gson gson = new GsonBuilder().create();
- configParameters = gson.fromJson(new FileReader("src/test/resources/handling-sdc.json"),
- SdcReceptionHandlerConfigurationParameterGroup.class);
- } catch (final Exception e) {
- fail("test should not thrown an exception here: " + e.getMessage());
- }
+ final Gson gson = new GsonBuilder().create();
+ configParameters = gson.fromJson(new FileReader("src/test/resources/handling-sdc.json"),
+ SdcReceptionHandlerConfigurationParameterGroup.class);
+
final GroupValidationResult validationResult = configParameters.validate();
assertTrue(validationResult.isValid());
final SdcConfiguration config = new SdcConfiguration(configParameters);
@@ -75,15 +71,14 @@ public class TestSdcReceptionHandlerConfigurationParameterGroup {
@Test
public void testInvalidSdcConfiguration() throws IOException {
SdcReceptionHandlerConfigurationParameterGroup configParameters = null;
- try {
- final Gson gson = new GsonBuilder().create();
- configParameters = gson.fromJson(new FileReader("src/test/resources/handling-sdcInvalid.json"),
- SdcReceptionHandlerConfigurationParameterGroup.class);
- } catch (final Exception e) {
- fail("test should not thrown an exception here: " + e.getMessage());
- }
+
+ final Gson gson = new GsonBuilder().create();
+ configParameters = gson.fromJson(new FileReader("src/test/resources/handling-sdcInvalid.json"),
+ SdcReceptionHandlerConfigurationParameterGroup.class);
+
final GroupValidationResult validationResult = configParameters.validate();
assertFalse(validationResult.isValid());
+
}
@Test