Skip to content

Commit

Permalink
test on gradle 8, fix sample doc
Browse files Browse the repository at this point in the history
Signed-off-by: Stewart Francis <[email protected]>

review comments
  • Loading branch information
stewartfrancis committed Dec 6, 2023
1 parent 626532b commit 765d372
Show file tree
Hide file tree
Showing 8 changed files with 152 additions and 151 deletions.
13 changes: 5 additions & 8 deletions samples/gradle-osgi-sample/README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
# Standalone project sample (gradle-war-sample)
# Standalone project sample (gradle-osgi-sample)
This sample shows how you can configure an existing OSGi project to build a CICS bundle. The OSGi project is configured (in `build.gradle`) to package its generated OSGi bundle jar as a bundle part into a CICS bundle and deploy the bundle to CICS.

# Set Up
Have your system programmer create your BUNDLE definition in CSD.
Your system programmer should create a BUNDLE definition in CSD and tell you the CSD group and BUNDLE definition name they have used. The BUNDLEDIR of the BUNDLE definition your system programmer creates should be set as follows: `<bundles-directory>/<bundle_id>_<bundle_version>`.
Have your system programmer create your BUNDLE definition in the CSD.
Your system programmer should create a BUNDLE definition in the CSD and tell you the CSD group and BUNDLE definition name they have used. The BUNDLEDIR of the BUNDLE definition your system programmer creates should be set as follows: `<bundles-directory>/<bundle_id>_<bundle_version>`.
So for this sample, if your system programmer configured bundles-directory as `/u/someuser/bundles/`, the BUNDLEDIR would be `/u/someuser/bundles/gradle-osgi-sample_1.0.0`.


## Using this sample project
[Clone the repository](https://github.com/IBM/cics-bundle-gradle.git) and import the sample, `samples/gradle-osgi-sample`, into your IDE.

Edit the variables in the `cicsBundle` block of the `standalone-war-demo/build.gradle` file, to match the correct CMCI URL, CSD group, CICSplex, region and BUNDLE definition name for your environment, and change your configuration to supply your CICS user ID and password via gradle.properties. If you're deploying the bundle into a single region environment (SMSSJ), remove the `cicsplex` and `region` fields.
Edit the variables in the `cicsBundle` block of the `build.gradle` file, to match the correct CMCI URL, CSD group, CICSplex, region and BUNDLE definition name for your environment, and change your configuration to supply your CICS user ID and password via `gradle.properties`. If you're deploying the bundle into a single region environment (SMSS), remove the `cicsplex` and `region` fields.

# Build
To build all projects and package the bundle part into a zipped CICS bundle, change to the `gradle-war-sample` directory and run:
To build all projects and package the bundle part into a zipped CICS bundle, run:
```
./gradlew build
```
Expand All @@ -24,6 +24,3 @@ To package and deploy the built bundle to your CICS region, run:
```

If you run into an `unable to find valid certification path to requested target` error during deployment, uncommenting the `insecure = true` line in the bundle project's `build.gradle` is a quick fix but it poses security concerns by disabling TLS/SSL checking for certificates. For recommended solutions in real use, refer to [Troubleshooting](https://github.com/IBM/cics-bundle-gradle#troubleshooting).

# What's next
Visit the servlet (http://myserver.site.domain.com:1234/standalone-war-demo-1.0.0 if you used our sample as-is) to see what you published.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
14 changes: 6 additions & 8 deletions src/test/groovy/com/ibm/cics/cbgp/AbstractTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -132,16 +132,16 @@ abstract class AbstractTest extends Specification {
FileUtils.copyFile(srcFile, destFile)
}

protected def runGradleAndSucceed(List args) {
return runGradle(args, false)
protected def runGradleAndSucceed(List args, String gradleVersion) {
return runGradle(args, false, gradleVersion)
}

protected def runGradleAndFail(List args) {
return runGradle(args, true)
protected def runGradleAndFail(List args, String gradleVersion) {
return runGradle(args, true, gradleVersion)
}

// Run the gradle build and print the test output
private def runGradle(List args, boolean failExpected) {
private def runGradle(List args, boolean failExpected, String gradleVersion) {
def result
args.add("--stacktrace")
args.add("--info")
Expand All @@ -152,7 +152,7 @@ abstract class AbstractTest extends Specification {
.withArguments(args)
.withPluginClasspath()
.withDebug(isDebug)
.withGradleVersion(getGradleVersion())
.withGradleVersion(gradleVersion)

if (!failExpected) {
result = gradleRunner.build()
Expand Down Expand Up @@ -249,6 +249,4 @@ abstract class AbstractTest extends Specification {
protected void checkBundleArchiveFile() {
assert archiveFile.exists(): "Missing archive file '${archiveFile.getPath()}'"
}

abstract String getGradleVersion();
}
89 changes: 55 additions & 34 deletions src/test/groovy/com/ibm/cics/cbgp/ErrorTests.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ import java.nio.charset.Charset
/**
* Test error path scenarios where invalid bundles fail to build and return appropriate error messages.
*/
abstract class ErrorTests extends AbstractTest {
class ErrorTests extends AbstractTest {

def "Test unsupported bundle part extension"() {
@Unroll
def "Test unsupported bundle part extension on Gradle #gradleVersion"(String gradleVersion) {

given:
rootProjectName = bundleProjectName = "empty"
Expand All @@ -38,14 +39,17 @@ abstract class ErrorTests extends AbstractTest {
""".stripIndent()

when:
def result = runGradleAndFail([BundlePlugin.DEPLOY_TASK_NAME])
def result = runGradleAndFail([BundlePlugin.DEPLOY_TASK_NAME], gradleVersion)

then:
checkBuildOutputStrings(result, ["Unsupported file extension 'har' for Java-based bundle part 'simple-har-1.7.7.har'. Supported extensions are: [ear, jar, war, eba]."])

where:
gradleVersion << GradleVersions.GRADLE_VERSIONS
}

@Unroll
def "Test cicsBundle extension missing #propertiesToRemove"(List<String> propertiesToRemove, List<String> expectedMessages) {
def "Test cicsBundle extension missing #propertiesToRemove on Gradle version #gradleVersion"(List<String> propertiesToRemove, List<String> expectedMessages, String gradleVersion) {

given:
rootProjectName = bundleProjectName = "standalone-war"
Expand All @@ -60,42 +64,59 @@ abstract class ErrorTests extends AbstractTest {
}
}
FileUtils.writeLines(buildFile, fileLines)
def result = runGradleAndFail([BundlePlugin.DEPLOY_TASK_NAME])
def result = runGradleAndFail([BundlePlugin.DEPLOY_TASK_NAME], gradleVersion)

then:
checkBuildOutputStrings(result, expectedMessages)

// Parameterize test so the same test can be used for various combinations of properties
where:
propertiesToRemove | expectedMessages
["defaultJVMServer"] | [AbstractJavaBundlePartBinding.JVMSERVER_EXCEPTION]
["url"] | [DeployBundleTask.MISSING_URL, DeployBundleTask.DEPLOY_CONFIG_EXCEPTION]
["bunddef"] | [DeployBundleTask.MISSING_BUNDDEF, DeployBundleTask.DEPLOY_CONFIG_EXCEPTION]
["csdgroup"] | [DeployBundleTask.MISSING_CSDGROUP, DeployBundleTask.DEPLOY_CONFIG_EXCEPTION]
["username"] | [DeployBundleTask.MISSING_USERNAME, DeployBundleTask.DEPLOY_CONFIG_EXCEPTION]
["password"] | [DeployBundleTask.MISSING_PASSWORD, DeployBundleTask.DEPLOY_CONFIG_EXCEPTION]
["cicsplex"] | [DeployBundleTask.MISSING_CICSPLEX_OR_REGION, DeployBundleTask.DEPLOY_CONFIG_EXCEPTION]
["region"] | [DeployBundleTask.MISSING_CICSPLEX_OR_REGION, DeployBundleTask.DEPLOY_CONFIG_EXCEPTION]
// if both cicsplex and region are missing, we shouldn't see an error message
["url", "cicsplex", "region", "bunddef", "csdgroup", "username", "password"] | [DeployBundleTask.MISSING_URL, DeployBundleTask.MISSING_BUNDDEF, DeployBundleTask.MISSING_CSDGROUP, DeployBundleTask.MISSING_USERNAME, DeployBundleTask.MISSING_PASSWORD, DeployBundleTask.DEPLOY_CONFIG_EXCEPTION]
["url", "bunddef", "csdgroup", "username", "password"] | [DeployBundleTask.MISSING_URL, DeployBundleTask.MISSING_BUNDDEF, DeployBundleTask.MISSING_CSDGROUP, DeployBundleTask.MISSING_USERNAME, DeployBundleTask.MISSING_PASSWORD, DeployBundleTask.DEPLOY_CONFIG_EXCEPTION]
[gradleVersion, propertiesToRemove, expectedMessages] << INPUTS
}
}

@Title("ErrorTests (Gradle 7.6.1)")
class Gradle761ErrorTests extends ErrorTests {

@Override
String getGradleVersion() {
return "7.6.1"
}
}

@Title("ErrorTests (Gradle 8.3)")
class Gradle83ErrorTests extends ErrorTests {

@Override
String getGradleVersion() {
return "8.3"
}
static final var INPUTS = GradleVersions.onAllVersions(
[
[
["defaultJVMServer"],
[AbstractJavaBundlePartBinding.JVMSERVER_EXCEPTION]
],
[
["url"],
[DeployBundleTask.MISSING_URL, DeployBundleTask.DEPLOY_CONFIG_EXCEPTION]
],
[
["bunddef"],
[DeployBundleTask.MISSING_BUNDDEF, DeployBundleTask.DEPLOY_CONFIG_EXCEPTION]
],
[
["csdgroup"],
[DeployBundleTask.MISSING_CSDGROUP, DeployBundleTask.DEPLOY_CONFIG_EXCEPTION]
],
[
["username"],
[DeployBundleTask.MISSING_USERNAME, DeployBundleTask.DEPLOY_CONFIG_EXCEPTION]
],
[
["password"],
[DeployBundleTask.MISSING_PASSWORD, DeployBundleTask.DEPLOY_CONFIG_EXCEPTION]
],
[
["cicsplex"],
[DeployBundleTask.MISSING_CICSPLEX_OR_REGION, DeployBundleTask.DEPLOY_CONFIG_EXCEPTION]
],
[
["region"],
[DeployBundleTask.MISSING_CICSPLEX_OR_REGION, DeployBundleTask.DEPLOY_CONFIG_EXCEPTION]
],
// if both cicsplex and region are missing, we shouldn't see an error message
[
["url", "cicsplex", "region", "bunddef", "csdgroup", "username", "password"],
[DeployBundleTask.MISSING_URL, DeployBundleTask.MISSING_BUNDDEF, DeployBundleTask.MISSING_CSDGROUP, DeployBundleTask.MISSING_USERNAME, DeployBundleTask.MISSING_PASSWORD, DeployBundleTask.DEPLOY_CONFIG_EXCEPTION]
],
[
["url", "bunddef", "csdgroup", "username", "password"],
[DeployBundleTask.MISSING_URL, DeployBundleTask.MISSING_BUNDDEF, DeployBundleTask.MISSING_CSDGROUP, DeployBundleTask.MISSING_USERNAME, DeployBundleTask.MISSING_PASSWORD, DeployBundleTask.DEPLOY_CONFIG_EXCEPTION]
]
]
)
}
28 changes: 4 additions & 24 deletions src/test/groovy/com/ibm/cics/cbgp/ExtraConfigTests.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ import spock.lang.Unroll
/**
* Test bundle parts which have been explicitly configured with extra values. E.g. overrides for name, jvmserver, etc.
*/
abstract class ExtraConfigTests extends AbstractTest {
class ExtraConfigTests extends AbstractTest {

@Unroll
def "Test extra config with #syntax syntax"(String syntax) {
def "Test extra config with #syntax syntax on Gradle version #gradleVersion"(String syntax, String gradleVersion) {

given:
rootProjectName = "extra-config-project"
Expand All @@ -50,7 +50,7 @@ abstract class ExtraConfigTests extends AbstractTest {
def jvmserverOverride = gradleProperties.getProperty("jvmsOsgi")

when:
def result = runGradleAndSucceed([BundlePlugin.DEPLOY_TASK_NAME])
def result = runGradleAndSucceed([BundlePlugin.DEPLOY_TASK_NAME], gradleVersion)

then:
checkBuildOutputStrings(result, [
Expand Down Expand Up @@ -109,26 +109,6 @@ abstract class ExtraConfigTests extends AbstractTest {

// Parameterize test so the same test can be used for both Closure and Map syntax
where:
syntax | _
"closure" | _
"map" | _
}
}

@Title("ExtraConfigTests (Gradle 7.6.1)")
class Gradle761ExtraConfigTests extends ErrorTests {

@Override
String getGradleVersion() {
return "7.6.1"
}
}

@Title("ExtraConfigTests (Gradle 8.3)")
class Gradle83ExtraConfigTests extends ErrorTests {

@Override
String getGradleVersion() {
return "8.3"
[gradleVersion, syntax] << GradleVersions.onAllVersions(["closure", "map"])
}
}
Loading

0 comments on commit 765d372

Please sign in to comment.