From 0b4c021f32606eb143c6851979def052b3512fb0 Mon Sep 17 00:00:00 2001 From: Cheryl King Date: Thu, 12 Sep 2024 10:31:07 -0500 Subject: [PATCH] More positive and negative tests --- .../gradle/AbstractIntegrationTest.groovy | 19 ++++++ ...KernelInstallVersionlessFeatureTest.groovy | 60 ++++++++++++++++++- .../server_versionless_feature_2.xml | 6 ++ ...server_versionless_feature_no_platform.xml | 5 ++ ...onless_feature_with_versioned_feature.xml} | 3 +- 5 files changed, 89 insertions(+), 4 deletions(-) create mode 100644 src/test/resources/kernel-install-versionless-feature-test/server_versionless_feature_2.xml create mode 100644 src/test/resources/kernel-install-versionless-feature-test/server_versionless_feature_no_platform.xml rename src/test/resources/{kernel-install-feature-test/server_versionless_feature.xml => kernel-install-versionless-feature-test/server_versionless_feature_with_versioned_feature.xml} (73%) diff --git a/src/test/groovy/io/openliberty/tools/gradle/AbstractIntegrationTest.groovy b/src/test/groovy/io/openliberty/tools/gradle/AbstractIntegrationTest.groovy index 566faa066..331359c93 100644 --- a/src/test/groovy/io/openliberty/tools/gradle/AbstractIntegrationTest.groovy +++ b/src/test/groovy/io/openliberty/tools/gradle/AbstractIntegrationTest.groovy @@ -149,6 +149,25 @@ abstract class AbstractIntegrationTest { return result } + // Use this method when the task is supposed to fail. Then the returned BuildResult can be + // checked for any expected output. + protected static BuildResult runTasksFailResult(File projectDir, String... tasks) { + List args = new ArrayList(); + for (String task: tasks) { + args.add(task); + } + args.add("-i"); + args.add("-s"); + + BuildResult result = GradleRunner.create() + .withProjectDir(projectDir) + .forwardOutput() + .withArguments(args) + .buildAndFail(); + + return result; + } + protected static boolean runTaskCheckForUpToDate(File projectDir, String task, String argument) { List args = new ArrayList() args.add(task) diff --git a/src/test/groovy/io/openliberty/tools/gradle/KernelInstallVersionlessFeatureTest.groovy b/src/test/groovy/io/openliberty/tools/gradle/KernelInstallVersionlessFeatureTest.groovy index c6cc7f6e0..95614fe18 100644 --- a/src/test/groovy/io/openliberty/tools/gradle/KernelInstallVersionlessFeatureTest.groovy +++ b/src/test/groovy/io/openliberty/tools/gradle/KernelInstallVersionlessFeatureTest.groovy @@ -18,10 +18,13 @@ package io.openliberty.tools.gradle import static junit.framework.Assert.assertEquals import static org.junit.Assert.* +import org.junit.After import org.junit.Before import org.junit.BeforeClass import org.junit.Test +import org.gradle.testkit.runner.BuildResult + import io.openliberty.tools.common.plugins.util.InstallFeatureUtil class KernelInstallVersionlessFeatureTest extends AbstractIntegrationTest{ @@ -41,12 +44,17 @@ class KernelInstallVersionlessFeatureTest extends AbstractIntegrationTest{ copyServer("server_empty.xml") deleteDir(new File(buildDir, "build/wlp/lib/features")) } + + @After + public void after() { + copyServer("server_empty.xml") + } @Test /** * Install with only server.xml features */ - public void testInstallVersionlessFeaturesServer() { + public void testInstallVersionlessFeaturesWithPlatformServer() { copyBuildFiles(new File(resourceDir, "install_features_server.gradle"), buildDir) runTasks(buildDir, "libertyCreate") copyServer("server_versionless_feature.xml") @@ -58,8 +66,56 @@ class KernelInstallVersionlessFeatureTest extends AbstractIntegrationTest{ assertNotInstalled("couchdb-1.0") assertNotInstalled("distributedMap-1.0") } - + + @Test + /** + * Install with only server.xml features + */ + public void testInstallVersionlessFeaturesWithVersionedFeatureServer() { + copyBuildFiles(new File(resourceDir, "install_features_server.gradle"), buildDir) + runTasks(buildDir, "libertyCreate") + copyServer("server_versionless_feature_with_versioned_feature.xml") + runTasks(buildDir, "installFeature") + assertInstalled("beanValidation-2.0") + assertInstalled("servlet-4.0") + assertInstalled("jpa-2.2") + assertInstalled("ejb-3.2") + assertNotInstalled("couchdb-1.0") + assertNotInstalled("distributedMap-1.0") + } + + @Test + /** + * Install with only server.xml features + */ + public void testInstallVersionlessFeaturesServerNoPlatform() { + copyBuildFiles(new File(resourceDir, "install_features_server.gradle"), buildDir) + runTasks(buildDir, "libertyCreate") + copyServer("server_versionless_feature_no_platform.xml") + // expect failure - check for error message + BuildResult result = runTasksFailResult(buildDir, "installFeature") + String output = result.getOutput() + assertTrue(output.contains("CWWKF1516E: The platform could not be determined. The following versionless features cannot be installed: [ejb].")) + } + + //@Test + // Commented out because current failure returns + // "Cannot invoke "com.ibm.ws.kernel.feature.provisioning.ProvisioningFeatureDefinition.getSymbolicName()" because the return value of "java.util.HashMap.get(Object)" is null" + /** + * Install with only server.xml features + */ + public void testInstallVersionlessFeaturesServerNoCommonPlatform() { + copyBuildFiles(new File(resourceDir, "install_features_server.gradle"), buildDir) + runTasks(buildDir, "libertyCreate") + copyServer("server_versionless_feature_2.xml") + // expect failure - check for error message + BuildResult result = runTasksFailResult(buildDir, "installFeature") + String output = result.getOutput() + assertTrue(output.contains("CWWKF1516E: The platform could not be determined. The following versionless features cannot be installed: [servlet].")) + } + private copyServer(String serverFile) { + assertTrue(new File(resourceDir, serverFile).exists()) copyFile(new File(resourceDir, serverFile), new File(buildDir, "build/wlp/usr/servers/defaultServer/server.xml")) } diff --git a/src/test/resources/kernel-install-versionless-feature-test/server_versionless_feature_2.xml b/src/test/resources/kernel-install-versionless-feature-test/server_versionless_feature_2.xml new file mode 100644 index 000000000..af5bd9f63 --- /dev/null +++ b/src/test/resources/kernel-install-versionless-feature-test/server_versionless_feature_2.xml @@ -0,0 +1,6 @@ + + + servlet + mpHealth-4.0 + + diff --git a/src/test/resources/kernel-install-versionless-feature-test/server_versionless_feature_no_platform.xml b/src/test/resources/kernel-install-versionless-feature-test/server_versionless_feature_no_platform.xml new file mode 100644 index 000000000..54f137112 --- /dev/null +++ b/src/test/resources/kernel-install-versionless-feature-test/server_versionless_feature_no_platform.xml @@ -0,0 +1,5 @@ + + + ejb + + diff --git a/src/test/resources/kernel-install-feature-test/server_versionless_feature.xml b/src/test/resources/kernel-install-versionless-feature-test/server_versionless_feature_with_versioned_feature.xml similarity index 73% rename from src/test/resources/kernel-install-feature-test/server_versionless_feature.xml rename to src/test/resources/kernel-install-versionless-feature-test/server_versionless_feature_with_versioned_feature.xml index 2435856c5..a8d23aecd 100644 --- a/src/test/resources/kernel-install-feature-test/server_versionless_feature.xml +++ b/src/test/resources/kernel-install-versionless-feature-test/server_versionless_feature_with_versioned_feature.xml @@ -1,9 +1,8 @@ beanValidation - servlet + servlet-4.0 jpa ejb - javaee-8.0