From 29fcfcd3a2c120061eb16ed1aa8bc75d43f5aa2f Mon Sep 17 00:00:00 2001 From: Arun Venmany Date: Wed, 20 Nov 2024 20:17:25 +0530 Subject: [PATCH] moving spring boot failure test to new file Signed-off-by: Arun Venmany --- .../checkErrorSpringBootApplicationNode.bsh | 35 +++++++++++++++++++ .../src/test/resources/cleanTest.bsh | 7 +++- 2 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 liberty-maven-plugin/src/test/resources/checkErrorSpringBootApplicationNode.bsh diff --git a/liberty-maven-plugin/src/test/resources/checkErrorSpringBootApplicationNode.bsh b/liberty-maven-plugin/src/test/resources/checkErrorSpringBootApplicationNode.bsh new file mode 100644 index 000000000..0cce49584 --- /dev/null +++ b/liberty-maven-plugin/src/test/resources/checkErrorSpringBootApplicationNode.bsh @@ -0,0 +1,35 @@ +//Check build.log content for certain tests +boolean flag = false; +String testname = basedir.getName(); +String expectedMessage = null; +switch (testname) { + case "springboot-3-appsdirectory-apps-fail-it": + expectedMessage = "Found multiple springBootApplication elements specified in the server configuration. Only one springBootApplication can be configured per Liberty server."; + break; + default: + return false; +} +File buildlog = new File(basedir,"build.log"); +if (buildlog.exists()) { + try { + InputStream buildOutput = new FileInputStream(buildlog); + InputStreamReader in = new InputStreamReader(buildOutput); + java.util.Scanner s = new java.util.Scanner(in); + while (s.hasNextLine() && !flag) { + String line = s.nextLine(); + if (line.contains(expectedMessage)) { + flag = true; + System.out.println("Correct error message found for test "+testname); + } + } + s.close(); + in.close(); + buildOutput.close(); + } catch (Exception e) { + System.out.println("Error checking build.log " + e.getMessage()); + } +} +if (!flag) { + System.out.println("FAILED: Expected error message ("+expectedMessage+") not found in "+buildlog.getAbsolutePath()); +} +return flag; \ No newline at end of file diff --git a/liberty-maven-plugin/src/test/resources/cleanTest.bsh b/liberty-maven-plugin/src/test/resources/cleanTest.bsh index 7d0f5a8b9..b766886fa 100644 --- a/liberty-maven-plugin/src/test/resources/cleanTest.bsh +++ b/liberty-maven-plugin/src/test/resources/cleanTest.bsh @@ -1,10 +1,15 @@ //If need to check build.log for error message, call script boolean flag = true; -if (basedir.getName().contains("versionless-feature-fail-") || basedir.getName().contains("springboot-3-appsdirectory-apps-fail-")) { +if (basedir.getName().contains("versionless-feature-fail-")) { String errorScript = new File(basedir, "checkErrorVersionlessFeature.bsh").getAbsolutePath(); System.out.println("Running post-build script: "+ errorScript); flag = source(errorScript); } +if (basedir.getName().contains("springboot-3-appsdirectory-apps-fail-")) { + String errorScript = new File(basedir, "checkErrorSpringBootApplicationNode.bsh").getAbsolutePath(); + System.out.println("Running post-build script: "+ errorScript); + flag = source(errorScript); +} //Runs clean in the test project directory Runtime.getRuntime().exec("../../../../mvnw clean", null, basedir); System.out.println("Cleaned target dir(s) for " + basedir);