Skip to content

Commit

Permalink
Add test case for versionless features
Browse files Browse the repository at this point in the history
  • Loading branch information
cherylking committed Sep 11, 2024
1 parent b6ad004 commit fbd54fc
Show file tree
Hide file tree
Showing 9 changed files with 204 additions and 2 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
matrix:
# test against latest update of each major Java version, as well as specific updates of LTS versions:
RUNTIME: [ol, wlp]
RUNTIME_VERSION: [24.0.0.6]
RUNTIME_VERSION: [24.0.0.9]
java: [21, 17, 11, 8]
exclude:
- java: 8
Expand Down Expand Up @@ -101,7 +101,7 @@ jobs:
matrix:
# test against latest update of each major Java version, as well as specific updates of LTS versions:
RUNTIME: [ol, wlp]
RUNTIME_VERSION: [24.0.0.6]
RUNTIME_VERSION: [24.0.0.9]
java: [21, 17, 11, 8]
exclude:
- java: 8
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/*
* (C) Copyright IBM Corporation 2024.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.openliberty.tools.gradle

import static junit.framework.Assert.assertEquals
import static org.junit.Assert.*

import org.junit.Before
import org.junit.BeforeClass
import org.junit.Test

import io.openliberty.tools.common.plugins.util.InstallFeatureUtil

class KernelInstallVersionlessFeatureTest extends AbstractIntegrationTest{
static File resourceDir = new File("build/resources/test/kernel-install-versionless-feature-test")
static File buildDir = new File(integTestDir, "/kernel-install-versionless-feature-test")
static String buildFilename = "build.gradle"

@BeforeClass
public static void setup() {
createDir(buildDir)
createTestProject(buildDir, resourceDir, buildFilename)
}

@Before
public void before() {
runTasks(buildDir, "libertyCreate")
copyServer("server_empty.xml")
deleteDir(new File(buildDir, "build/wlp/lib/features"))
}

@Test
/**
* Install with only server.xml features
*/
public void testInstallVersionlessFeaturesServer() {
copyBuildFiles(new File(resourceDir, "install_features_server.gradle"), buildDir)
runTasks(buildDir, "libertyCreate")
copyServer("server_versionless_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")
}

private copyServer(String serverFile) {
copyFile(new File(resourceDir, serverFile), new File(buildDir, "build/wlp/usr/servers/defaultServer/server.xml"))
}

private void assertInstallStatus(String feature, boolean expectation) throws Exception {
String expectationString = (expectation ? "installed" : "not installed");
assertEquals("Feature " + feature + " was expected to be " + expectationString + " in the lib/features directory", expectation, existsInFeaturesDirectory(feature));
String featureInfo = getFeatureInfo();
assertEquals("Feature " + feature + " was expected to be " + expectationString + " according to productInfo featureInfo: " + featureInfo, expectation, featureInfo.contains(feature));
}

protected void assertInstalled(String feature) throws Exception {
assertInstallStatus(feature, true);
}

protected void assertNotInstalled(String feature) throws Exception {
assertInstallStatus(feature, false);
}

private boolean existsInFeaturesDirectory(String feature) {
File[] features;
File featuresDir = new File(buildDir, "build/wlp/lib/features")

features = featuresDir.listFiles(new FilenameFilter() {
public boolean accept(File dir, String name) {
return name.toLowerCase().equals("com.ibm.websphere.appserver." + feature.toLowerCase() + ".mf");
}
});

return features.size() >= 1;
}

private String getFeatureInfo() throws Exception {
File installDirectory = new File(buildDir, "build/wlp")
return InstallFeatureUtil.productInfo(installDirectory, "featureInfo");
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<server description="default server">
<featureManager>
<feature>beanValidation</feature>
<feature>servlet</feature>
<feature>jpa</feature>
<feature>ejb</feature>
<platform>javaee-8.0</platform>
</featureManager>
</server>
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
apply plugin: 'liberty'

buildscript {
repositories{
mavenLocal()
mavenCentral()
maven {
name = 'Sonatype Nexus Snapshots'
url = 'https://oss.sonatype.org/content/repositories/snapshots/'
}
}
dependencies {
classpath "io.openliberty.tools:liberty-gradle-plugin:$lgpVersion"
}
}

repositories {
mavenLocal()
mavenCentral()
}

liberty {
runtime = ['group': runtimeGroup,'name':kernelArtifactId,'version':runtimeVersion]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
apply plugin: 'liberty'

buildscript {
repositories{
mavenLocal()
mavenCentral()
maven {
name = 'Sonatype Nexus Snapshots'
url = 'https://oss.sonatype.org/content/repositories/snapshots/'
}
}
dependencies {
classpath "io.openliberty.tools:liberty-gradle-plugin:$lgpVersion"
}
}

repositories {
mavenLocal()
mavenCentral()
}

dependencies {
libertyRuntime group: 'com.ibm.websphere.appserver.runtime', name: 'wlp-kernel', version: runtimeVersion
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
buildscript {
repositories {
mavenLocal()
mavenCentral()
maven {
name = 'Sonatype Nexus Snapshots'
url = 'https://oss.sonatype.org/content/repositories/snapshots/'
}
}
dependencies {
classpath "io.openliberty.tools:liberty-gradle-plugin:$lgpVersion"
}
}

apply plugin: 'liberty'

repositories {
mavenCentral()
}

dependencies {
libertyRuntime group: runtimeGroup, name: kernelArtifactId, version: runtimeVersion
}

liberty {
server{
features {
acceptLicense = true
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<server description="default server">
<featureManager>

</featureManager>
</server>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<server description="default server">
<featureManager>
<feature>beanValidation</feature>
<feature>servlet</feature>
<feature>jpa</feature>
<feature>ejb</feature>
<platform>javaee-8.0</platform>
</featureManager>
</server>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
//Empty

0 comments on commit fbd54fc

Please sign in to comment.