From 045e5354157b6991f07a1dca87e8d5994e5785fa Mon Sep 17 00:00:00 2001 From: Cheryl King Date: Sat, 21 Sep 2024 12:10:45 -0500 Subject: [PATCH] Add negative tests for versionless feature support --- liberty-maven-plugin/pom.xml | 2 +- .../invoker.properties | 1 + .../pom.xml | 110 ++++++++++++++++++ .../src/test/resources/server.xml | 7 ++ .../invoker.properties | 1 + .../pom.xml | 110 ++++++++++++++++++ .../src/test/resources/server.xml | 6 + .../checkErrorVersionlessFeature.bsh | 38 ++++++ .../src/test/resources/cleanTest.bsh | 9 +- 9 files changed, 282 insertions(+), 2 deletions(-) create mode 100644 liberty-maven-plugin/src/it/kernel-install-versionless-feature-fail-bad-platform-it/invoker.properties create mode 100644 liberty-maven-plugin/src/it/kernel-install-versionless-feature-fail-bad-platform-it/pom.xml create mode 100644 liberty-maven-plugin/src/it/kernel-install-versionless-feature-fail-bad-platform-it/src/test/resources/server.xml create mode 100644 liberty-maven-plugin/src/it/kernel-install-versionless-feature-fail-no-platform-it/invoker.properties create mode 100644 liberty-maven-plugin/src/it/kernel-install-versionless-feature-fail-no-platform-it/pom.xml create mode 100644 liberty-maven-plugin/src/it/kernel-install-versionless-feature-fail-no-platform-it/src/test/resources/server.xml create mode 100644 liberty-maven-plugin/src/test/resources/checkErrorVersionlessFeature.bsh diff --git a/liberty-maven-plugin/pom.xml b/liberty-maven-plugin/pom.xml index 0dbb48850..915c8dc25 100644 --- a/liberty-maven-plugin/pom.xml +++ b/liberty-maven-plugin/pom.xml @@ -37,7 +37,7 @@ io.openliberty.tools liberty-ant-tasks - 1.9.15 + 1.9.16-SNAPSHOT org.apache.maven diff --git a/liberty-maven-plugin/src/it/kernel-install-versionless-feature-fail-bad-platform-it/invoker.properties b/liberty-maven-plugin/src/it/kernel-install-versionless-feature-fail-bad-platform-it/invoker.properties new file mode 100644 index 000000000..62359c56d --- /dev/null +++ b/liberty-maven-plugin/src/it/kernel-install-versionless-feature-fail-bad-platform-it/invoker.properties @@ -0,0 +1 @@ +invoker.buildResult = failure \ No newline at end of file diff --git a/liberty-maven-plugin/src/it/kernel-install-versionless-feature-fail-bad-platform-it/pom.xml b/liberty-maven-plugin/src/it/kernel-install-versionless-feature-fail-bad-platform-it/pom.xml new file mode 100644 index 000000000..84431db1e --- /dev/null +++ b/liberty-maven-plugin/src/it/kernel-install-versionless-feature-fail-bad-platform-it/pom.xml @@ -0,0 +1,110 @@ + + + + 4.0.0 + + + io.openliberty.tools.it + tests + 1.0-SNAPSHOT + + + kernel-install-versionless-feature-fail-bad-platform-it + jar + + + + junit + junit + 4.13.1 + test + + + + commons-io + commons-io + 2.8.0 + + + + + + + io.openliberty.tools + liberty-maven-plugin + @pom.version@ + + + ${runtimeGroupId} + ${runtimeKernelId} + ${runtimeVersion} + zip + + test + src/test/resources/server.xml + + + + install-liberty-server + compile + + install-server + + + + create-server + pre-integration-test + + create + + + + install-feature + pre-integration-test + + install-feature + + + + true + + + + + + + org.apache.maven.plugins + maven-failsafe-plugin + 3.1.2 + + ${project.build.directory} + -enableassertions + + + + integration-test + + integration-test + + + + verify + verify + + verify + + + + + + org.apache.maven.plugins + maven-surefire-plugin + 3.1.2 + + true + + + + + + diff --git a/liberty-maven-plugin/src/it/kernel-install-versionless-feature-fail-bad-platform-it/src/test/resources/server.xml b/liberty-maven-plugin/src/it/kernel-install-versionless-feature-fail-bad-platform-it/src/test/resources/server.xml new file mode 100644 index 000000000..5976a6b36 --- /dev/null +++ b/liberty-maven-plugin/src/it/kernel-install-versionless-feature-fail-bad-platform-it/src/test/resources/server.xml @@ -0,0 +1,7 @@ + + + appSecurityClient-1.0 + jaxws + badname + + diff --git a/liberty-maven-plugin/src/it/kernel-install-versionless-feature-fail-no-platform-it/invoker.properties b/liberty-maven-plugin/src/it/kernel-install-versionless-feature-fail-no-platform-it/invoker.properties new file mode 100644 index 000000000..62359c56d --- /dev/null +++ b/liberty-maven-plugin/src/it/kernel-install-versionless-feature-fail-no-platform-it/invoker.properties @@ -0,0 +1 @@ +invoker.buildResult = failure \ No newline at end of file diff --git a/liberty-maven-plugin/src/it/kernel-install-versionless-feature-fail-no-platform-it/pom.xml b/liberty-maven-plugin/src/it/kernel-install-versionless-feature-fail-no-platform-it/pom.xml new file mode 100644 index 000000000..09fed6481 --- /dev/null +++ b/liberty-maven-plugin/src/it/kernel-install-versionless-feature-fail-no-platform-it/pom.xml @@ -0,0 +1,110 @@ + + + + 4.0.0 + + + io.openliberty.tools.it + tests + 1.0-SNAPSHOT + + + kernel-install-versionless-feature-fail-no-platform-it + jar + + + + junit + junit + 4.13.1 + test + + + + commons-io + commons-io + 2.8.0 + + + + + + + io.openliberty.tools + liberty-maven-plugin + @pom.version@ + + + ${runtimeGroupId} + ${runtimeKernelId} + ${runtimeVersion} + zip + + test + src/test/resources/server.xml + + + + install-liberty-server + compile + + install-server + + + + create-server + pre-integration-test + + create + + + + install-feature + pre-integration-test + + install-feature + + + + true + + + + + + + org.apache.maven.plugins + maven-failsafe-plugin + 3.1.2 + + ${project.build.directory} + -enableassertions + + + + integration-test + + integration-test + + + + verify + verify + + verify + + + + + + org.apache.maven.plugins + maven-surefire-plugin + 3.1.2 + + true + + + + + + diff --git a/liberty-maven-plugin/src/it/kernel-install-versionless-feature-fail-no-platform-it/src/test/resources/server.xml b/liberty-maven-plugin/src/it/kernel-install-versionless-feature-fail-no-platform-it/src/test/resources/server.xml new file mode 100644 index 000000000..9bbdc46d5 --- /dev/null +++ b/liberty-maven-plugin/src/it/kernel-install-versionless-feature-fail-no-platform-it/src/test/resources/server.xml @@ -0,0 +1,6 @@ + + + appSecurityClient-1.0 + servlet + + diff --git a/liberty-maven-plugin/src/test/resources/checkErrorVersionlessFeature.bsh b/liberty-maven-plugin/src/test/resources/checkErrorVersionlessFeature.bsh new file mode 100644 index 000000000..b4f56ecd0 --- /dev/null +++ b/liberty-maven-plugin/src/test/resources/checkErrorVersionlessFeature.bsh @@ -0,0 +1,38 @@ +//Check build.log content for certain tests +boolean flag = false; +String testname = basedir.getName(); +String expectedMessage = null; +switch (testname) { + case "kernel-install-versionless-feature-fail-bad-platform-it": + expectedMessage = "CWWKF1515E: The badname platform could not be found."; + break; + case "kernel-install-versionless-feature-fail-no-platform-it": + expectedMessage = "CWWKF1516E: The platform could not be determined. The following versionless features cannot be installed: [servlet]"; + 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 c9b4b7ff8..d8db6aa36 100644 --- a/liberty-maven-plugin/src/test/resources/cleanTest.bsh +++ b/liberty-maven-plugin/src/test/resources/cleanTest.bsh @@ -1,4 +1,11 @@ +//If need to check build.log for error message, call script +boolean flag = true; +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); +} //Runs clean in the test project directory Runtime.getRuntime().exec("../../../../mvnw clean", null, basedir); System.out.println("Cleaned target dir(s) for " + basedir); -return true; \ No newline at end of file +return flag; \ No newline at end of file