From 56aa2c9599f9bf262b5d0c1f20364f6395adca39 Mon Sep 17 00:00:00 2001 From: user Date: Thu, 1 Jan 1970 00:00:00 +0000 Subject: [PATCH 1/2] Test framework should give meaningful output when it fails due to the testee JAR not being built --- .../epam/ticketservice/at/GenericCliProcessStepDefs.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/final/ticket-service-acceptance-tests/src/test/java/com/training/epam/ticketservice/at/GenericCliProcessStepDefs.java b/final/ticket-service-acceptance-tests/src/test/java/com/training/epam/ticketservice/at/GenericCliProcessStepDefs.java index a09c625d..fad247cc 100644 --- a/final/ticket-service-acceptance-tests/src/test/java/com/training/epam/ticketservice/at/GenericCliProcessStepDefs.java +++ b/final/ticket-service-acceptance-tests/src/test/java/com/training/epam/ticketservice/at/GenericCliProcessStepDefs.java @@ -8,12 +8,15 @@ import io.cucumber.java.en.Then; import io.cucumber.java.en.When; import java.io.IOException; +import java.io.File; +import java.io.FileNotFoundException; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeoutException; public class GenericCliProcessStepDefs { private static final int OUTPUT_TIMEOUT = 30000; + private static final String jarFile = "../ticket-service/target/ticket-service-0.0.1-SNAPSHOT.jar"; private ProcessUnderTest cliProcess; @@ -23,6 +26,9 @@ public GenericCliProcessStepDefs(ProcessUnderTest cliProcess) { @Given("the application is started") public void applicationStarted() throws IOException, InterruptedException { + if (!(new File(jarFile)).isFile()){ + throw new FileNotFoundException("The path " + jarFile + " does not exist. It should be your built JAR file."); + } cliProcess.run("java -jar -Dspring.profiles.active=ci ../ticket-service/target/ticket-service-0.0.1-SNAPSHOT.jar"); } From 0b84fc97a7a5def633160e1273ff68bf18a47795 Mon Sep 17 00:00:00 2001 From: user Date: Thu, 1 Jan 1970 00:00:00 +0000 Subject: [PATCH 2/2] Stop busy loopiny on EOF --- .../training/epam/ticketservice/at/ProcessUnderTest.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/final/ticket-service-acceptance-tests/src/test/java/com/training/epam/ticketservice/at/ProcessUnderTest.java b/final/ticket-service-acceptance-tests/src/test/java/com/training/epam/ticketservice/at/ProcessUnderTest.java index 66cf8f1f..20a2c0d6 100644 --- a/final/ticket-service-acceptance-tests/src/test/java/com/training/epam/ticketservice/at/ProcessUnderTest.java +++ b/final/ticket-service-acceptance-tests/src/test/java/com/training/epam/ticketservice/at/ProcessUnderTest.java @@ -68,7 +68,11 @@ private void clearOutput(long delayBeforeCleaning) throws IOException { private Void readOutputUntil(String expectedOutput) throws IOException { String actualString = ""; do { - actualString += (char) output.read(); + int c = output.read(); + if (c == -1) { + throw new IOException("Reached EOF before receiving '" + expectedOutput + "'"); + } + actualString += (char) c; if (actualString.length() > expectedOutput.length()) { actualString = actualString.substring(1); }