Skip to content

Commit

Permalink
Re-enable exploded loose tests
Browse files Browse the repository at this point in the history
Signed-off-by: Scott Kurz <[email protected]>
  • Loading branch information
scottkurz committed Aug 17, 2023
1 parent 800876f commit 70576a9
Show file tree
Hide file tree
Showing 2 changed files with 122 additions and 119 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@
<webResources>
<resource>
<directory>resource2</directory>
<filtering>true</filtering>
</resource>
</webResources>
Filtered directory end -->
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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("<filteringDeploymentDescriptors>false</filteringDeploymentDescriptors>",
"<filteringDeploymentDescriptors>true</filteringDeploymentDescriptors>", 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("<filteringDeploymentDescriptors>true</filteringDeploymentDescriptors>",
"<filteringDeploymentDescriptors>false</filteringDeploymentDescriptors>", 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("<!-- Filtered directory start",
"<!-- Filtered directory start -->", pom);

replaceString("Filtered directory end -->",
"<!-- 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 start -->",
"<!-- Filtered directory start ", pom);

replaceString("<!-- Filtered directory end -->",
"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("<!-- Overlay configuration start",
"<!-- Overlay configuration start -->", pom);

replaceString("Overlay configuration end -->",
"<!-- 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 start -->",
"<!-- Overlay configuration start", pom);

replaceString("<!-- Overlay configuration end -->",
"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/<projectArtifact> entry
String explodedWar = basicDevProj.getAbsolutePath() + "/target/" + projectArtifact;
assertTrue(getLogTail(), verifyFileExists(new File(looseAppXml), 3000));
assertTrue(getLogTail(), verifyLogMessageExists("<dir sourceOnDisk=\"" + explodedWar + "\" targetInArchive=\"/\"/>", 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("<dir sourceOnDisk=\"" + srcMain + "\" targetInArchive=\"/\"/>", 3000, new File(looseAppXml)));

// Verify the target/classes entry
String targetClasses = basicDevProj.getAbsolutePath() + "/target/classes";
assertTrue(getLogTail(), verifyLogMessageExists("<dir sourceOnDisk=\"" + targetClasses + "\" targetInArchive=\"/WEB-INF/classes\"/>", 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("<filteringDeploymentDescriptors>false</filteringDeploymentDescriptors>",
"<filteringDeploymentDescriptors>true</filteringDeploymentDescriptors>", pom);

verifyExplodedLooseApp();

// Remove filtering config
replaceString("<filteringDeploymentDescriptors>true</filteringDeploymentDescriptors>",
"<filteringDeploymentDescriptors>false</filteringDeploymentDescriptors>", pom);

verifyNonExplodedLooseApp();
}

@Test
public void configureFilteredResource() throws Exception {
// Add filtering config to pom war plugin (directory)
replaceString("<!-- Filtered directory start",
"<!-- Filtered directory start -->", pom);

replaceString("Filtered directory end -->",
"<!-- Filtered directory end -->", pom);

verifyExplodedLooseApp();

replaceString("<!-- Filtered directory start -->",
"<!-- Filtered directory start ", pom);

replaceString("<!-- Filtered directory end -->",
"Filtered directory end -->", pom);

verifyNonExplodedLooseApp();
}

@Test
public void configureWarOverlay() throws Exception {

// Add filtering config to pom war plugin (directory)
replaceString("<!-- Overlay configuration start",
"<!-- Overlay configuration start -->", pom);

replaceString("Overlay configuration end -->",
"<!-- Overlay configuration end -->", pom);

verifyExplodedLooseApp();

replaceString("<!-- Overlay configuration start -->",
"<!-- Overlay configuration start", pom);

replaceString("<!-- Overlay configuration end -->",
"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("<dir sourceOnDisk=\"" + targetClasses + "\" targetInArchive=\"/WEB-INF/classes\"/>", 3000, looseAppXml));

// Verify the target/<projectArtifact> entry
String explodedWar = tempProj.getCanonicalPath() + File.separator + "target" + File.separator + projectArtifact;
assertTrue(getLogTail() + "\n------\n" + getLogTail(looseAppXml), verifyLogMessageExists("<dir sourceOnDisk=\"" + explodedWar + "\" targetInArchive=\"/\"/>", 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("<dir sourceOnDisk=\"" + targetClasses + "\" targetInArchive=\"/WEB-INF/classes\"/>", 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");
}
}

0 comments on commit 70576a9

Please sign in to comment.