diff options
author | liamfallon <liam.fallon@est.tech> | 2018-12-15 09:47:58 +0000 |
---|---|---|
committer | liamfallon <liam.fallon@est.tech> | 2018-12-15 09:48:04 +0000 |
commit | 8e8f3458646ec97d058d7322917f56021de2dc7f (patch) | |
tree | b549a654cba7d87249751f85cf6b23d3b2b4cc48 /testsuites/integration | |
parent | 4b01ae1ca8bc592fbbbc4d5408d6c645487811dd (diff) |
Fix sonar test renaming issues
Renaming tests introduced Sonar issues:
- Tests where coverage was <80% flagged as they are new code
- Support test classes with names ending in "Test" flagged
becasue they did not contain test cases
Issue-ID: POLICY-1263
Change-Id: I17a4b27b2952a4978fab1c76579a013478b60ae1
Signed-off-by: liamfallon <liam.fallon@est.tech>
Diffstat (limited to 'testsuites/integration')
2 files changed, 31 insertions, 36 deletions
diff --git a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/file/TestFile2FileFiltered.java b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/file/TestFile2FileFiltered.java index 6c7af80fd..59d36374a 100644 --- a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/file/TestFile2FileFiltered.java +++ b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/file/TestFile2FileFiltered.java @@ -98,7 +98,7 @@ public class TestFile2FileFiltered { // Wait for the file to be filled long outFile0Size = 0; - for (int i = 0; i < 4; i++) { + for (int i = 0; i < 20; i++) { final String fileString = stripVariableLengthText(outFilePaths[0]); outFile0Size = fileString.length(); if (outFile0Size > 0 && outFile0Size >= expectedFileSizes[0]) { diff --git a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/restclient/TestRest2File.java b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/restclient/TestRest2File.java index 94bd6b2b3..216b566ff 100644 --- a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/restclient/TestRest2File.java +++ b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/restclient/TestRest2File.java @@ -20,7 +20,6 @@ package org.onap.policy.apex.testsuites.integration.uservice.adapt.restclient; -import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import java.io.ByteArrayOutputStream; @@ -113,17 +112,14 @@ public class TestRest2File { final ApexMain apexMain = new ApexMain(args); - ThreadUtilities.sleep(1000); + ThreadUtilities.sleep(5000); apexMain.shutdown(); final String outputEventText = TextFileUtils .getTextFileAsString("target/examples/events/SampleDomain/EventsOut.json"); - if (!outputEventText.contains( - "04\",\n" + " \"version\": \"0.0.1\",\n" + " \"nameSpace\": \"org.onap.policy.apex.sample.events\"")) { - LOGGER.error(outputEventText); - fail("test output did not contain required string"); - } + checkRequiredString(outputEventText, + "04\",\n" + " \"version\": \"0.0.1\",\n" + " \"nameSpace\": \"org.onap.policy.apex.sample.events\""); } /** @@ -141,7 +137,7 @@ public class TestRest2File { final String[] args = { "src/test/resources/prodcons/REST2FileJsonEmptyEvents.json" }; final ApexMain apexMain = new ApexMain(args); - ThreadUtilities.sleep(1000); + ThreadUtilities.sleep(5000); apexMain.shutdown(); final String outString = outContent.toString(); @@ -149,11 +145,8 @@ public class TestRest2File { System.setOut(stdout); System.setErr(stderr); - if (!outString.contains( - "received an empty event from URL \"http://localhost:32801/TestRest2File/apex/event/GetEmptyEvent\"")) { - LOGGER.error(outString); - fail("test output did not contain required string"); - } + checkRequiredString(outString, + "received an empty event from URL " + "\"http://localhost:32801/TestRest2File/apex/event/GetEmptyEvent\""); } /** @@ -171,7 +164,7 @@ public class TestRest2File { final String[] args = { "src/test/resources/prodcons/REST2FileJsonEventNoURL.json" }; final ApexMain apexMain = new ApexMain(args); - ThreadUtilities.sleep(1000); + ThreadUtilities.sleep(5000); apexMain.shutdown(); final String outString = outContent.toString(); @@ -179,10 +172,7 @@ public class TestRest2File { System.setOut(stdout); System.setErr(stderr); - if (!outString.contains(" no URL has been set for event sending on REST client")) { - LOGGER.error(outString); - fail("test output did not contain required string"); - } + checkRequiredString(outString, " no URL has been set for event sending on REST client"); } /** @@ -200,7 +190,7 @@ public class TestRest2File { final String[] args = { "src/test/resources/prodcons/REST2FileJsonEventBadURL.json" }; final ApexMain apexMain = new ApexMain(args); - ThreadUtilities.sleep(1000); + ThreadUtilities.sleep(5000); apexMain.shutdown(); final String outString = outContent.toString(); @@ -208,11 +198,8 @@ public class TestRest2File { System.setOut(stdout); System.setErr(stderr); - if (!outString.contains( - "reception of event from URL \"http://localhost:32801/TestRest2File/apex/event/Bad\" failed with status code 404")) { - LOGGER.error(outString); - fail("test output did not contain required string"); - } + checkRequiredString(outString, "reception of event from URL " + + "\"http://localhost:32801/TestRest2File/apex/event/Bad\" failed with status code 404"); } /** @@ -230,7 +217,7 @@ public class TestRest2File { final String[] args = { "src/test/resources/prodcons/REST2FileJsonEventBadHTTPMethod.json" }; final ApexMain apexMain = new ApexMain(args); - ThreadUtilities.sleep(1000); + ThreadUtilities.sleep(5000); apexMain.shutdown(); final String outString = outContent.toString(); @@ -238,11 +225,8 @@ public class TestRest2File { System.setOut(stdout); System.setErr(stderr); - if (!outString.contains("specified HTTP method of \"POST\" is invalid, " - + "only HTTP method \"GET\" is supported for event reception on REST client consumer")) { - LOGGER.error(outString); - fail("test output did not contain required string"); - } + checkRequiredString(outString, "specified HTTP method of \"POST\" is invalid, " + + "only HTTP method \"GET\" is supported for event reception on REST client consumer"); } /** @@ -260,7 +244,7 @@ public class TestRest2File { final String[] args = { "src/test/resources/prodcons/REST2FileJsonEventBadResponse.json" }; final ApexMain apexMain = new ApexMain(args); - ThreadUtilities.sleep(1000); + ThreadUtilities.sleep(5000); apexMain.shutdown(); final String outString = outContent.toString(); @@ -268,10 +252,21 @@ public class TestRest2File { System.setOut(stdout); System.setErr(stderr); - if (!outString.contains( - "reception of event from URL \"http://localhost:32801/TestRest2File/apex/event/GetEventBadResponse\" failed with status code 400 and message \"\"")) { - LOGGER.error(outString); - fail("test output did not contain required string"); + checkRequiredString(outString, + "reception of event from URL " + "\"http://localhost:32801/TestRest2File/apex/event/GetEventBadResponse\" " + + "failed with status code 400 and message \"\""); + } + + /** + * Check if a required string exists in the output. + * + * @param outputEventText the text to examine + * @param requiredString the string to search for + */ + private void checkRequiredString(String outputText, String requiredString) { + if (!outputText.contains(requiredString)) { + LOGGER.error("\n***output text:\n" + outputText + "\n***"); + fail("\n***test output did not contain required string:\n" + requiredString + "\n***"); } } } |