diff --git a/liberty-maven-plugin/src/it/dev-it/resources/exploded-war-project/pom.xml b/liberty-maven-plugin/src/it/dev-it/resources/exploded-war-project/pom.xml index 4654d6c19..2c385d115 100755 --- a/liberty-maven-plugin/src/it/dev-it/resources/exploded-war-project/pom.xml +++ b/liberty-maven-plugin/src/it/dev-it/resources/exploded-war-project/pom.xml @@ -164,6 +164,7 @@ resource2 + true Filtered directory end --> diff --git a/liberty-maven-plugin/src/it/dev-it/src/test/java/net/wasdev/wlp/test/dev/it/ExplodedLooseWarAppTest.java b/liberty-maven-plugin/src/it/dev-it/src/test/java/net/wasdev/wlp/test/dev/it/ExplodedLooseWarAppTest.java index dbe139af8..c7075aae0 100644 --- a/liberty-maven-plugin/src/it/dev-it/src/test/java/net/wasdev/wlp/test/dev/it/ExplodedLooseWarAppTest.java +++ b/liberty-maven-plugin/src/it/dev-it/src/test/java/net/wasdev/wlp/test/dev/it/ExplodedLooseWarAppTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * (c) Copyright IBM Corporation 2021. + * (c) Copyright IBM Corporation 2021, 2023 * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -32,123 +32,125 @@ public class ExplodedLooseWarAppTest extends BaseDevTest { private final String projectArtifact = "exploded-war-proj-1.0-SNAPSHOT"; private final String appsDir = "target/liberty/wlp/usr/servers/defaultServer/dropins/"; + private long lastModified; - @BeforeClass - public static void setUpBeforeClass() throws Exception { - setUpBeforeClass(null, "../resources/exploded-war-project"); - } - - @AfterClass - public static void cleanUpAfterClass() throws Exception { - BaseDevTest.cleanUpAfterClass(); - } - - @Ignore // TODO enable this test - @Test - public void configureWebXmlFiltering() throws Exception { - int appDeployedCount = countOccurrences("Running liberty:deploy", logFile); - // Add deployment descriptor filtering config to pom war plugin - replaceString("false", - "true", pom); - - // Verify exploded goal running and redeploy - assertTrue(getLogTail(), verifyLogMessageExists("Running liberty:deploy", 4000, logFile, ++appDeployedCount)); - assertTrue(getLogTail(), verifyLogMessageExists("Running maven-war-plugin:exploded", 2000)); - - // Verify loose app xml is correct - verifyExplodedLooseApp(); - - // Remove filtering config - replaceString("true", - "false", pom); - - // Verify redeploy - assertTrue(getLogTail(), verifyLogMessageExists("Running liberty:deploy", 2000)); - - // Verify loose app xml is back to how it was - verifyNonExplodedLooseApp(); - } - - @Ignore // TODO enable this test - @Test - public void configureFilteredResource() throws Exception { - // Add filtering config to pom war plugin (directory) - replaceString("", pom); - - replaceString("Filtered directory end -->", - "", pom); - - // Verify exploded goal running and redeploy - assertTrue(getLogTail(), verifyLogMessageExists("Running liberty:deploy", 2000)); - assertTrue(getLogTail(), verifyLogMessageExists("Running maven-war-plugin:exploded", 2000)); - - // Verify loose app xml is correct - verifyExplodedLooseApp(); - - // Remove filtering config - replaceString("", - "", - "Filtered directory end -->", pom); - - // Verify redeploy - assertTrue(getLogTail(), verifyLogMessageExists("Running liberty:deploy", 2000)); - - // Verify loose app xml is back to how it was - verifyNonExplodedLooseApp(); - } - - @Ignore // TODO enable this test - @Test - public void configureWarOverlay() throws Exception { - // Add filtering config to pom war plugin (directory) - replaceString("", pom); - - replaceString("Overlay configuration end -->", - "", pom); - - // Verify exploded goal running and redeploy - assertTrue(getLogTail(), verifyLogMessageExists("Running liberty:deploy", 2000)); - assertTrue(getLogTail(), verifyLogMessageExists("Running maven-war-plugin:exploded", 2000)); - - // Verify loose app xml is correct - verifyExplodedLooseApp(); - - // Remove filtering config - replaceString("", - "", - "Overlay configuration end -->", pom); - - // Verify redeploy - assertTrue(getLogTail(), verifyLogMessageExists("Running liberty:deploy", 2000)); - - // Verify loose app xml is back to how it was - verifyNonExplodedLooseApp(); - } - - private void verifyExplodedLooseApp() throws Exception { - String looseAppXml = tempProj.getAbsolutePath() + "/" + appsDir + projectArtifact + ".war.xml"; - - // Verify the target/ entry - String explodedWar = basicDevProj.getAbsolutePath() + "/target/" + projectArtifact; - assertTrue(getLogTail(), verifyFileExists(new File(looseAppXml), 3000)); - assertTrue(getLogTail(), verifyLogMessageExists("", 3000, new File(looseAppXml))); - } - - private void verifyNonExplodedLooseApp() throws Exception { - String looseAppXml = tempProj.getAbsolutePath() + "/" + appsDir + projectArtifact + ".war.xml"; - - // Verify the src/main/webapp entry - String srcMain = basicDevProj.getAbsolutePath() + "/src/main/webapp"; - assertTrue(getLogTail(), verifyLogMessageExists("", 3000, new File(looseAppXml))); - - // Verify the target/classes entry - String targetClasses = basicDevProj.getAbsolutePath() + "/target/classes"; - assertTrue(getLogTail(), verifyLogMessageExists("", 3000, new File(looseAppXml))); - } + @BeforeClass + public static void setUpBeforeClass() throws Exception { + setUpBeforeClass(null, "../resources/exploded-war-project"); + } + + @AfterClass + public static void cleanUpAfterClass() throws Exception { + BaseDevTest.cleanUpAfterClass(); + } + + @Test + public void configureWebXmlFiltering() throws Exception { + + // Add deployment descriptor filtering config to pom war plugin + replaceString("false", + "true", pom); + + verifyExplodedLooseApp(); + + // Remove filtering config + replaceString("true", + "false", pom); + + verifyNonExplodedLooseApp(); + } + + @Test + public void configureFilteredResource() throws Exception { + // Add filtering config to pom war plugin (directory) + replaceString("", pom); + + replaceString("Filtered directory end -->", + "", pom); + + verifyExplodedLooseApp(); + + replaceString("", + "", + "Filtered directory end -->", pom); + + verifyNonExplodedLooseApp(); + } + + @Test + public void configureWarOverlay() throws Exception { + + // Add filtering config to pom war plugin (directory) + replaceString("", pom); + + replaceString("Overlay configuration end -->", + "", pom); + + verifyExplodedLooseApp(); + + replaceString("", + "", + "Overlay configuration end -->", pom); + + verifyNonExplodedLooseApp(); + } + + private void waitForUpdate() throws Exception { + + boolean updated = false; + + File looseAppXml = getLooseAppXML(); + + // wait for update + for (int i = 0; i < 30; i++) { + if (looseAppXml.lastModified() > lastModified) { + updated = true; + break; + } else { + Thread.sleep(3000); + } + } + + if (!updated) { + throw new RuntimeException("Gave up waiting for modification for file: " + looseAppXml); + } + } + + private void verifyExplodedLooseApp() throws Exception { + + waitForUpdate(); + + File looseAppXml = getLooseAppXML(); + + String targetClasses = tempProj.getCanonicalPath() + File.separator + "target" + File.separator + "classes"; + assertTrue(getLogTail() + "\n------\n" + getLogTail(looseAppXml), verifyLogMessageExists("", 3000, looseAppXml)); + + // Verify the target/ entry + String explodedWar = tempProj.getCanonicalPath() + File.separator + "target" + File.separator + projectArtifact; + assertTrue(getLogTail() + "\n------\n" + getLogTail(looseAppXml), verifyLogMessageExists("", 3000, looseAppXml)); + } + + private void verifyNonExplodedLooseApp() throws Exception { + + waitForUpdate(); + + File looseAppXml = getLooseAppXML(); + + // Verify the target/classes entry + String targetClasses = tempProj.getCanonicalPath() + File.separator + "target" + File.separator + "classes"; + assertTrue(getLogTail() + "\n------\n" + getLogTail(looseAppXml), verifyLogMessageExists("", 3000, looseAppXml)); + + // Verify the dependency lib, we pick on the commons-lang3 dep and exclude the version + assertTrue(getLogTail() + "\n------\n" + getLogTail(looseAppXml), verifyLogMessageExists("targetInArchive=\"/WEB-INF/lib/commons-lang3", 3000, looseAppXml)); + } + + private File getLooseAppXML() throws Exception { + return new File(tempProj.getCanonicalPath() + File.separator + appsDir + projectArtifact + ".war.xml"); + } }