Skip to content

Commit

Permalink
More positive and negative tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cherylking committed Sep 12, 2024
1 parent b476101 commit 0b4c021
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> args = new ArrayList<String>();
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<String> args = new ArrayList<String>()
args.add(task)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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")
Expand All @@ -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"))
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<server description="default server">
<featureManager>
<feature>servlet</feature>
<feature>mpHealth-4.0</feature>
</featureManager>
</server>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<server description="default server">
<featureManager>
<feature>ejb</feature>
</featureManager>
</server>
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
<server description="default server">
<featureManager>
<feature>beanValidation</feature>
<feature>servlet</feature>
<feature>servlet-4.0</feature>
<feature>jpa</feature>
<feature>ejb</feature>
<platform>javaee-8.0</platform>
</featureManager>
</server>

0 comments on commit 0b4c021

Please sign in to comment.