diff --git a/liberty-maven-plugin/src/it/kernel-install-feature-test/base-install-feature-test/src/test/java/net/wasdev/wlp/test/feature/it/BaseInstallFeature.java b/liberty-maven-plugin/src/it/kernel-install-feature-test/base-install-feature-test/src/test/java/net/wasdev/wlp/test/feature/it/BaseInstallFeature.java index d2519a046..e80c2e200 100644 --- a/liberty-maven-plugin/src/it/kernel-install-feature-test/base-install-feature-test/src/test/java/net/wasdev/wlp/test/feature/it/BaseInstallFeature.java +++ b/liberty-maven-plugin/src/it/kernel-install-feature-test/base-install-feature-test/src/test/java/net/wasdev/wlp/test/feature/it/BaseInstallFeature.java @@ -15,29 +15,23 @@ *******************************************************************************/ package net.wasdev.wlp.test.feature.it; -import java.io.BufferedReader; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + import java.io.File; -import java.io.FileNotFoundException; -import java.io.FileReader; +import java.io.FileInputStream; import java.io.FilenameFilter; -import java.io.IOException; -import java.nio.charset.StandardCharsets; -import java.util.ArrayList; -import java.util.List; - -import io.openliberty.tools.common.plugins.util.InstallFeatureUtil; - -import static org.junit.Assert.assertEquals; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.util.Scanner; -import org.apache.commons.io.input.ReversedLinesFileReader; import org.junit.Before; +import io.openliberty.tools.common.plugins.util.InstallFeatureUtil; + public class BaseInstallFeature { - static File logFile; - static File logErrorFile; - - protected File[] features; + protected File[] features; @Before public void setUp() throws Exception { @@ -69,7 +63,10 @@ protected boolean existsInFeaturesDirectory(String feature) { boolean found = false; for (File file : features) { if ((file.getName().equals("com.ibm.websphere.appserver." + feature + ".mf")) || - (file.getName().equals("io.openliberty.versionless." + feature + ".mf"))) { + (file.getName().equals("io.openliberty.versionless." + feature + ".mf")) || + (file.getName().equals("io.openliberty.jakarta." + feature + ".mf")) || + (file.getName().equals("io.openliberty." + feature + ".mf"))) + { found = true; break; } @@ -82,130 +79,22 @@ protected String getFeatureInfo() throws Exception { return InstallFeatureUtil.productInfo(installDirectory, "featureInfo"); } - /** - * Count number of lines that contain the given string - */ - protected static int countOccurrences(String str, File file) throws FileNotFoundException, IOException { - int occurrences = 0; - BufferedReader br = new BufferedReader(new FileReader(file)); - String line = br.readLine(); - try { - while (line != null) { - if (line.contains(str)) { - occurrences++; - } - line = br.readLine(); - } - } finally { - br.close(); - } - return occurrences; - } - - protected static boolean readFile(String str, File file) throws FileNotFoundException, IOException { - BufferedReader br = new BufferedReader(new FileReader(file)); - String line = br.readLine(); - try { - while (line != null) { - if (line.contains(str)) { - return true; - } - line = br.readLine(); - } - } finally { - br.close(); - } - return false; - } - - protected static boolean verifyLogMessageDoesNotExist(String message, int timeout) - throws InterruptedException, FileNotFoundException, IOException { - return verifyLogMessageDoesNotExist(message, timeout, logFile); - } - - protected static boolean verifyLogMessageDoesNotExist(String message, int timeout, File log) - throws InterruptedException, FileNotFoundException, IOException { - int waited = 0; - int sleep = 10; - while (waited <= timeout) { - Thread.sleep(sleep); - waited += sleep; - if (countOccurrences(message, log) > 0) { - return false; - } - } - return true; - } - - protected static boolean verifyLogMessageExists(String message, int timeout) - throws InterruptedException, FileNotFoundException, IOException { - return verifyLogMessageExists(message, timeout, logFile); - } - - protected static boolean verifyLogMessageExists(String message, int timeout, File log) - throws InterruptedException, FileNotFoundException, IOException { - int waited = 0; - int sleep = 10; - while (waited <= timeout) { - Thread.sleep(sleep); - waited += sleep; - if (readFile(message, log)) { - return true; - } - } - return false; - } - - protected static boolean verifyLogMessageExists(String message, int timeout, File log, int occurrences) - throws InterruptedException, FileNotFoundException, IOException { - int waited = 0; - int sleep = 10; - while (waited <= timeout) { - Thread.sleep(sleep); - waited += sleep; - if (countOccurrences(message, log) == occurrences) { - return true; - } - } - return false; - } - - protected static boolean verifyLogMessageExists(String message, int timeout, int occurrences) - throws InterruptedException, FileNotFoundException, IOException { - return verifyLogMessageExists(message, timeout, logFile, occurrences); - } - - protected static String getLogTail() throws IOException { - return getLogTail(logFile); - } - - protected static String getLogTail(File log) throws IOException { - int numLines = 100; - ReversedLinesFileReader object = null; - try { - object = new ReversedLinesFileReader(log, StandardCharsets.UTF_8); - List reversedLines = new ArrayList(); + public boolean buildLogCheck(String msg) throws Exception { + File buildLog = new File("../build.log"); + assertTrue(buildLog.exists()); - for (int i = 0; i < numLines; i++) { - String line = object.readLine(); - if (line == null) { - break; + try (InputStream buildOutput = new FileInputStream(buildLog); InputStreamReader in = new InputStreamReader(buildOutput); Scanner s = new Scanner(in);) { + while (s.hasNextLine()) { + String line = s.nextLine(); + if(line.contains(msg)) { + return true; + } } - reversedLines.add(line); - } - StringBuilder result = new StringBuilder(); - for (int i = reversedLines.size() - 1; i >=0; i--) { - result.append(reversedLines.get(i) + "\n"); - } - return "Last "+numLines+" lines of log at "+log.getAbsolutePath()+":\n" + - "===================== START =======================\n" + - result.toString() + - "====================== END ========================\n"; - } finally { - if (object != null) { - object.close(); - } - } - } + } catch (Exception e) { + System.out.println("Error checking build.log " + e.getMessage()); + } + + return false; + } } diff --git a/liberty-maven-plugin/src/it/kernel-install-feature-test/install-features-versionless-bad-platform-server-it/invoker.properties b/liberty-maven-plugin/src/it/kernel-install-feature-test/install-features-versionless-bad-platform-server-it/invoker.properties new file mode 100644 index 000000000..0e3d716a9 --- /dev/null +++ b/liberty-maven-plugin/src/it/kernel-install-feature-test/install-features-versionless-bad-platform-server-it/invoker.properties @@ -0,0 +1,3 @@ +# The expected result of the build, possible values are "success" (default) and "failure" +# can be indexed +invoker.buildResult = failure \ No newline at end of file diff --git a/liberty-maven-plugin/src/it/kernel-install-feature-test/install-features-versionless-bad-platform-server-it/pom.xml b/liberty-maven-plugin/src/it/kernel-install-feature-test/install-features-versionless-bad-platform-server-it/pom.xml new file mode 100644 index 000000000..c87691cea --- /dev/null +++ b/liberty-maven-plugin/src/it/kernel-install-feature-test/install-features-versionless-bad-platform-server-it/pom.xml @@ -0,0 +1,63 @@ + + + + 4.0.0 + + + io.openliberty.tools.it + kernel-install-feature-tests + 1.0-SNAPSHOT + + + install-features-versionless-bad-platform-server-it + jar + + + + + 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-server-features + pre-integration-test + + install-feature + + + + true + + + + + + + + + diff --git a/liberty-maven-plugin/src/it/kernel-install-feature-test/install-features-versionless-no-platform-server-it/src/test/java/net/wasdev/wlp/test/feature/it/InstallFeaturesVersionlessServerTest.java b/liberty-maven-plugin/src/it/kernel-install-feature-test/install-features-versionless-bad-platform-server-it/src/test/java/net/wasdev/wlp/test/feature/it/InstallFeaturesVersionlessBadPlatformServerTest.java similarity index 80% rename from liberty-maven-plugin/src/it/kernel-install-feature-test/install-features-versionless-no-platform-server-it/src/test/java/net/wasdev/wlp/test/feature/it/InstallFeaturesVersionlessServerTest.java rename to liberty-maven-plugin/src/it/kernel-install-feature-test/install-features-versionless-bad-platform-server-it/src/test/java/net/wasdev/wlp/test/feature/it/InstallFeaturesVersionlessBadPlatformServerTest.java index 92c6c437c..0c5d4b23d 100644 --- a/liberty-maven-plugin/src/it/kernel-install-feature-test/install-features-versionless-no-platform-server-it/src/test/java/net/wasdev/wlp/test/feature/it/InstallFeaturesVersionlessServerTest.java +++ b/liberty-maven-plugin/src/it/kernel-install-feature-test/install-features-versionless-bad-platform-server-it/src/test/java/net/wasdev/wlp/test/feature/it/InstallFeaturesVersionlessBadPlatformServerTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * (c) Copyright IBM Corporation 2018. + * (c) Copyright IBM Corporation 2024. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,7 +19,7 @@ import org.junit.Test; import java.io.File; -public class InstallFeaturesVersionlessServerTest extends BaseInstallFeature { +public class InstallFeaturesVersionlessBadPlatformServerTest extends BaseInstallFeature { @Test public void testInstalledFeatures() throws Exception { @@ -32,7 +32,7 @@ public void testInstalledFeatures() throws Exception { assertNotInstalled("couchdb-1.0"); assertNotInstalled("distributedMap-1.0"); - assertTrue(getLogTail(), verifyLogMessageExists("CWWKF1516E: The platform could not be determined. The following versionless features cannot be installed: [servlet]", 30000)); + assertTrue(buildLogCheck("CWWKF1515E: The badname platform could not be found.")); } } diff --git a/liberty-maven-plugin/src/it/kernel-install-feature-test/install-features-versionless-bad-platform-server-it/src/test/resources/server.xml b/liberty-maven-plugin/src/it/kernel-install-feature-test/install-features-versionless-bad-platform-server-it/src/test/resources/server.xml new file mode 100644 index 000000000..748d9dc27 --- /dev/null +++ b/liberty-maven-plugin/src/it/kernel-install-feature-test/install-features-versionless-bad-platform-server-it/src/test/resources/server.xml @@ -0,0 +1,7 @@ + + + appSecurityClient-1.0 + servlet + badname + + diff --git a/liberty-maven-plugin/src/it/kernel-install-feature-test/install-features-versionless-no-platform-server-it/src/test/java/net/wasdev/wlp/test/feature/it/InstallFeaturesVersionlessNoPlatformServerTest.java b/liberty-maven-plugin/src/it/kernel-install-feature-test/install-features-versionless-no-platform-server-it/src/test/java/net/wasdev/wlp/test/feature/it/InstallFeaturesVersionlessNoPlatformServerTest.java new file mode 100644 index 000000000..17585fa83 --- /dev/null +++ b/liberty-maven-plugin/src/it/kernel-install-feature-test/install-features-versionless-no-platform-server-it/src/test/java/net/wasdev/wlp/test/feature/it/InstallFeaturesVersionlessNoPlatformServerTest.java @@ -0,0 +1,38 @@ +/******************************************************************************* + * (c) Copyright IBM Corporation 2024. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + *******************************************************************************/ +package net.wasdev.wlp.test.feature.it; + +import static org.junit.Assert.*; +import org.junit.Test; +import java.io.File; + +public class InstallFeaturesVersionlessNoPlatformServerTest extends BaseInstallFeature { + + @Test + public void testInstalledFeatures() throws Exception { + + + assertInstalled("appSecurityClient-1.0"); + assertNotInstalled("servlet"); + assertNotInstalled("servlet-4.0"); + assertNotInstalled("beanValidation-2.0"); + assertNotInstalled("couchdb-1.0"); + assertNotInstalled("distributedMap-1.0"); + + assertTrue(buildLogCheck("CWWKF1516E: The platform could not be determined. The following versionless features cannot be installed: [servlet]")); + } + +} diff --git a/liberty-maven-plugin/src/it/kernel-install-feature-test/install-features-versionless-with-versioned-server-it/pom.xml b/liberty-maven-plugin/src/it/kernel-install-feature-test/install-features-versionless-with-versioned-server-it/pom.xml new file mode 100644 index 000000000..cbe96d86c --- /dev/null +++ b/liberty-maven-plugin/src/it/kernel-install-feature-test/install-features-versionless-with-versioned-server-it/pom.xml @@ -0,0 +1,75 @@ + + + + 4.0.0 + + + io.openliberty.tools.it + kernel-install-feature-tests + 1.0-SNAPSHOT + + + install-features-versionless-with-versioned-server-it + jar + + + + + 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-server-features + pre-integration-test + + install-feature + + + + true + + + + + install-server-features-again + pre-integration-test + + install-feature + + + + true + + + + + + + + + diff --git a/liberty-maven-plugin/src/it/kernel-install-feature-test/install-features-versionless-with-versioned-server-it/src/test/java/net/wasdev/wlp/test/feature/it/InstallFeaturesVersionlessWithVersionedServerTest.java b/liberty-maven-plugin/src/it/kernel-install-feature-test/install-features-versionless-with-versioned-server-it/src/test/java/net/wasdev/wlp/test/feature/it/InstallFeaturesVersionlessWithVersionedServerTest.java new file mode 100644 index 000000000..a421c7674 --- /dev/null +++ b/liberty-maven-plugin/src/it/kernel-install-feature-test/install-features-versionless-with-versioned-server-it/src/test/java/net/wasdev/wlp/test/feature/it/InstallFeaturesVersionlessWithVersionedServerTest.java @@ -0,0 +1,42 @@ +/******************************************************************************* + * (c) Copyright IBM Corporation 2024. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + *******************************************************************************/ +package net.wasdev.wlp.test.feature.it; + +import static org.junit.Assert.*; +import org.junit.Test; +import java.io.File; + +public class InstallFeaturesVersionlessWithVersionedServerTest extends BaseInstallFeature { + + @Test + public void testInstalledFeatures() throws Exception { + + + assertInstalled("beanValidation"); + assertInstalled("jsp"); + assertInstalled("enterpriseBeans-4.0"); + assertInstalled("ejb"); + assertInstalled("jdbc"); + assertInstalled("servlet-5.0"); + + assertTrue(buildLogCheck("The following features have been installed: jdbc enterpriseBeansRemote-4.0 jsp connectors-2.0 enterpriseBeansPersistentTimer-4.0 enterpriseBeansLite-4.0 xmlBinding-3.0 mdb-4.0 jdbc-4.2 enterpriseBeans-4.0 expressionLanguage-4.0 pages-3.0 servlet-5.0 beanValidation-3.0 beanValidation jndi-1.0 ejb enterpriseBeansHome-4.0")); + + + + + } + +} diff --git a/liberty-maven-plugin/src/it/kernel-install-feature-test/install-features-versionless-with-versioned-server-it/src/test/resources/server.xml b/liberty-maven-plugin/src/it/kernel-install-feature-test/install-features-versionless-with-versioned-server-it/src/test/resources/server.xml new file mode 100644 index 000000000..5b24a3577 --- /dev/null +++ b/liberty-maven-plugin/src/it/kernel-install-feature-test/install-features-versionless-with-versioned-server-it/src/test/resources/server.xml @@ -0,0 +1,9 @@ + + + beanValidation + servlet-5.0 + jsp + ejb + jdbc + +