From b2061d994738d3bd7bf0eed1719d63a82fc509ab Mon Sep 17 00:00:00 2001 From: Matt Bowersox Date: Mon, 1 May 2023 17:11:12 -0500 Subject: [PATCH] Fix loose app tests for Windows (#814) * Fix loose app tests for Windows * Update GHA yml to run loose app tests on Windows --- .github/workflows/gradle.yml | 2 +- .../tools/gradle/TestLooseApplication.groovy | 16 ++++++++++++---- .../TestLooseApplicationWithWarTask.groovy | 14 ++++++++++++-- .../tools/gradle/TestLooseEarApplication.groovy | 12 ++++++++---- 4 files changed, 33 insertions(+), 11 deletions(-) diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml index 1c73252be..9100dee8b 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle.yml @@ -151,7 +151,7 @@ jobs: - name: Run tests with Gradle on Windows working-directory: C:/ci.gradle # LibertyTest is excluded because test0_run hangs - run: ./gradlew clean install check -P"test.exclude"="**/Polling*,**/TestLoose*,**/LibertyTest*,**/GenerateFeaturesTest*" -Druntime=${{ matrix.RUNTIME }} -DruntimeVersion="${{ matrix.RUNTIME_VERSION }}" --stacktrace --info --no-daemon + run: ./gradlew clean install check -P"test.exclude"="**/Polling*,**/LibertyTest*,**/GenerateFeaturesTest*" -Druntime=${{ matrix.RUNTIME }} -DruntimeVersion="${{ matrix.RUNTIME_VERSION }}" --stacktrace --info --no-daemon timeout-minutes: 75 # Copy build reports and upload artifact if build failed - name: Copy build/report/tests/test for upload diff --git a/src/test/groovy/io/openliberty/tools/gradle/TestLooseApplication.groovy b/src/test/groovy/io/openliberty/tools/gradle/TestLooseApplication.groovy index 0c521fc61..d22855369 100644 --- a/src/test/groovy/io/openliberty/tools/gradle/TestLooseApplication.groovy +++ b/src/test/groovy/io/openliberty/tools/gradle/TestLooseApplication.groovy @@ -18,6 +18,8 @@ import org.junit.Test; import org.w3c.dom.Document; import org.w3c.dom.NodeList; +import io.openliberty.tools.common.plugins.util.OSUtil + public class TestLooseApplication extends AbstractIntegrationTest{ static File resourceDir = new File("build/resources/test/sample.servlet") static File buildDir = new File(integTestDir, "/test-loose-application") @@ -87,16 +89,24 @@ public class TestLooseApplication extends AbstractIntegrationTest{ // Check that dependencies are located in the test build dir specified by copyLibsDirectory. Otherwise they would be located in the gradle cache somewhere. String nodeValue = nodes.item(0).getAttributes().getNamedItem("sourceOnDisk").getNodeValue(); - assert nodeValue.endsWith("/commons-text-1.1.jar") && nodeValue.contains("/test-loose-application/build/libs/") : 'archive sourceOnDisk attribute value not correct' + if (OSUtil.isWindows()) { + Assert.assertTrue('archive sourceOnDisk attribute value not correct', nodeValue.endsWith("\\commons-text-1.1.jar") && nodeValue.contains("\\test-loose-application\\build\\libs\\")) + } else { + Assert.assertTrue('archive sourceOnDisk attribute value not correct', nodeValue.endsWith("/commons-text-1.1.jar") && nodeValue.contains("/test-loose-application/build/libs/")) + } Assert.assertEquals("archive targetInArchive attribute value", "/WEB-INF/lib/commons-lang3-3.5.jar", nodes.item(1).getAttributes().getNamedItem("targetInArchive").getNodeValue()); // Check that dependencies are located in the test build dir specified by copyLibsDirectory. Otherwise they would be located in the gradle cache somewhere. nodeValue = nodes.item(1).getAttributes().getNamedItem("sourceOnDisk").getNodeValue(); - assert nodeValue.endsWith("/commons-lang3-3.5.jar") && nodeValue.contains("/test-loose-application/build/libs/") : 'archive sourceOnDisk attribute value not correct' + if (OSUtil.isWindows()) { + Assert.assertTrue('archive sourceOnDisk attribute value not correct', nodeValue.endsWith("\\commons-lang3-3.5.jar") && nodeValue.contains("\\test-loose-application\\build\\libs\\")) + } else { + Assert.assertTrue('archive sourceOnDisk attribute value not correct', ("/commons-lang3-3.5.jar") && nodeValue.contains("/test-loose-application/build/libs/")) + } } @Test @@ -114,6 +124,4 @@ public class TestLooseApplication extends AbstractIntegrationTest{ assert value != null : "keystore_password property not found" } - - } diff --git a/src/test/groovy/io/openliberty/tools/gradle/TestLooseApplicationWithWarTask.groovy b/src/test/groovy/io/openliberty/tools/gradle/TestLooseApplicationWithWarTask.groovy index 423f500f0..2ab0480ce 100644 --- a/src/test/groovy/io/openliberty/tools/gradle/TestLooseApplicationWithWarTask.groovy +++ b/src/test/groovy/io/openliberty/tools/gradle/TestLooseApplicationWithWarTask.groovy @@ -18,6 +18,8 @@ import org.junit.Test; import org.w3c.dom.Document; import org.w3c.dom.NodeList; +import io.openliberty.tools.common.plugins.util.OSUtil + public class TestLooseApplicationWithWarTask extends AbstractIntegrationTest{ static File resourceDir = new File("build/resources/test/sample.servlet") static File buildDir = new File(integTestDir, "/test-loose-application-with-war-tasks") @@ -86,15 +88,23 @@ public class TestLooseApplicationWithWarTask extends AbstractIntegrationTest{ // Check that dependencies are not located in the test build dir since copyLibsDirectory not set. They will be located in the gradle cache somewhere. String nodeValue = nodes.item(0).getAttributes().getNamedItem("sourceOnDisk").getNodeValue(); - assert nodeValue.endsWith("/commons-text-1.1.jar") && !nodeValue.contains("/test-loose-application-with-war-tasks/") : 'archive sourceOnDisk attribute value not correct' + if (OSUtil.isWindows()) { + Assert.assertTrue('archive sourceOnDisk attribute value not correct', nodeValue.endsWith("\\commons-text-1.1.jar") && !nodeValue.contains("\\test-loose-application-with-war-tasks\\")) + } else { + Assert.assertTrue('archive sourceOnDisk attribute value not correct', nodeValue.endsWith("/commons-text-1.1.jar") && !nodeValue.contains("/test-loose-application-with-war-tasks/")) + } Assert.assertEquals("archive targetInArchive attribute value", "/WEB-INF/lib/commons-lang3-3.5.jar", nodes.item(1).getAttributes().getNamedItem("targetInArchive").getNodeValue()); // Check that dependencies are not located in the test build dir since copyLibsDirectory not set. They will be located in the gradle cache somewhere. nodeValue = nodes.item(1).getAttributes().getNamedItem("sourceOnDisk").getNodeValue(); - assert nodeValue.endsWith("/commons-lang3-3.5.jar") && !nodeValue.contains("/test-loose-application-with-war-tasks/") : 'archive sourceOnDisk attribute value not correct' + if (OSUtil.isWindows()) { + Assert.assertTrue('archive sourceOnDisk attribute value not correct', nodeValue.endsWith("\\commons-lang3-3.5.jar") && !nodeValue.contains("\\test-loose-application-with-war-tasks\\")) + } else { + Assert.assertTrue('archive sourceOnDisk attribute value not correct', nodeValue.endsWith("/commons-lang3-3.5.jar") && !nodeValue.contains("/test-loose-application-with-war-tasks/")) + } } @Test diff --git a/src/test/groovy/io/openliberty/tools/gradle/TestLooseEarApplication.groovy b/src/test/groovy/io/openliberty/tools/gradle/TestLooseEarApplication.groovy index c21232905..3e44d40a2 100644 --- a/src/test/groovy/io/openliberty/tools/gradle/TestLooseEarApplication.groovy +++ b/src/test/groovy/io/openliberty/tools/gradle/TestLooseEarApplication.groovy @@ -22,6 +22,8 @@ import org.w3c.dom.Node; import java.net.HttpURLConnection; import java.net.URL; +import io.openliberty.tools.common.plugins.util.OSUtil + public class TestLooseEarApplication extends AbstractIntegrationTest{ static File resourceDir = new File("build/resources/test/loose-ear-test") static File buildDir = new File(integTestDir, "/test-loose-ear-application") @@ -109,10 +111,13 @@ public class TestLooseEarApplication extends AbstractIntegrationTest{ if (node.getAttributes().getNamedItem("targetInArchive").getNodeValue().equals("/WEB-INF/lib/commons-text-1.1.jar")) { // Check that dependencies are located in the test build dir specified by copyLibsDirectory. Otherwise they would be located in the gradle cache somewhere. String nodeValue = node.getAttributes().getNamedItem("sourceOnDisk").getNodeValue(); - Assert.assertTrue(nodeValue.endsWith("/commons-text-1.1.jar") && nodeValue.contains("/test-loose-ear-application/ejb-ear/build/libs/")) + if (OSUtil.isWindows()) { + Assert.assertTrue(nodeValue.endsWith("\\commons-text-1.1.jar") && nodeValue.contains("\\test-loose-ear-application\\ejb-ear\\build\\libs\\")) + } else { + Assert.assertTrue(nodeValue.endsWith("/commons-text-1.1.jar") && nodeValue.contains("/test-loose-ear-application/ejb-ear/build/libs/")) + } } } - } @Test @@ -129,5 +134,4 @@ public class TestLooseEarApplication extends AbstractIntegrationTest{ throw new AssertionError ("Fail on task libertyStart. "+ e) } } - -} +} \ No newline at end of file