Skip to content

Commit a30520c

Browse files
committed
add tests for openApiGenerate task with configuration cache support
1 parent 9398514 commit a30520c

2 files changed

Lines changed: 68 additions & 25 deletions

File tree

modules/openapi-generator-gradle-plugin/src/test/kotlin/GenerateTaskConfigurationCacheTest.kt

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,49 @@ class GenerateTaskConfigurationCacheTest : TestBase() {
6363
assertEquals(expectedRelativeFilePathSet, projectDirCC.toRelativeFilePathSet())
6464
}
6565

66+
@Test(dataProvider = "gradle_version_provider")
67+
fun `openApiGenerate should handle up-to-date with configuration cache`(gradleVersion: String, format: String) {
68+
val propertyFormat = PropertyFormat.valueOf(format)
69+
// Arrange
70+
withProject(inputSpecExtensionContents(propertyFormat))
71+
72+
// Act - First run: Should be SUCCESS and store the configuration cache
73+
val result1 = build {
74+
withProjectDir(projectDirCC)
75+
withArguments("--configuration-cache", "openApiGenerate")
76+
withGradleVersion(gradleVersion)
77+
}
78+
79+
// Assert first run
80+
assertEquals(TaskOutcome.SUCCESS, result1.task(":openApiGenerate")?.outcome)
81+
assertTrue(result1.output.contains("Configuration cache entry stored."))
82+
83+
// Act - Second run: Should be UP-TO-DATE and reuse the cache
84+
val result2 = build {
85+
withProjectDir(projectDirCC)
86+
withArguments("--configuration-cache", "openApiGenerate")
87+
withGradleVersion(gradleVersion)
88+
}
89+
90+
// Assert second run
91+
assertEquals(TaskOutcome.UP_TO_DATE, result2.task(":openApiGenerate")?.outcome)
92+
assertTrue(result2.output.contains("Configuration cache entry reused."))
93+
94+
// Act - Third run: Modify spec file and task should re-execute
95+
val specFile = projectDirCC.resolve("spec.yaml")
96+
specFile.appendText("\n# Trigger change")
97+
98+
val result3 = build {
99+
withProjectDir(projectDirCC)
100+
withArguments("--configuration-cache", "openApiGenerate")
101+
withGradleVersion(gradleVersion)
102+
}
103+
104+
// Assert third run
105+
assertEquals(TaskOutcome.SUCCESS, result3.task(":openApiGenerate")?.outcome)
106+
assertTrue(result3.output.contains("Configuration cache entry reused."))
107+
}
108+
66109
private fun getJavaVersion(): Int {
67110
val version = System.getProperty("java.version")
68111
val parts = version.split('.')

modules/openapi-generator-gradle-plugin/src/test/kotlin/TestBase.kt

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,31 +7,6 @@ import java.io.File
77
import java.io.InputStream
88
import java.nio.file.Files.createTempDirectory
99

10-
/**
11-
* Defines how file/directory properties are referenced in Gradle build scripts.
12-
* - STRING: Uses .absolutePath (e.g., file("spec.yaml").absolutePath)
13-
* - FILE: Uses direct file() reference (e.g., file("spec.yaml"))
14-
*
15-
* Note: File format tests only run with the newest Gradle version (8.7) for performance.
16-
* All properties in a single test use the same format (no mixing).
17-
*/
18-
enum class PropertyFormat {
19-
STRING,
20-
FILE
21-
}
22-
23-
/**
24-
* Converts a file path to a Gradle property reference based on format.
25-
* @param format The property format to use
26-
* @return Formatted property value (either file("path").absolutePath or file("path"))
27-
*/
28-
fun String.toPropertyReference(format: PropertyFormat): String {
29-
return when (format) {
30-
PropertyFormat.STRING -> """file("$this").absolutePath"""
31-
PropertyFormat.FILE -> """file("$this")"""
32-
}
33-
}
34-
3510
abstract class TestBase {
3611
protected open lateinit var temp: File
3712

@@ -74,4 +49,29 @@ abstract class TestBase {
7449
.forwardOutput()
7550
.apply(configure)
7651
.build()!!
52+
}
53+
54+
/**
55+
* Defines how file/directory properties are referenced in Gradle build scripts.
56+
* - STRING: Uses .absolutePath (e.g., file("spec.yaml").absolutePath)
57+
* - FILE: Uses direct file() reference (e.g., file("spec.yaml"))
58+
*
59+
* Note: File format tests only run with the newest Gradle version (8.7) for performance.
60+
* All properties in a single test use the same format (no mixing).
61+
*/
62+
enum class PropertyFormat {
63+
STRING,
64+
FILE
65+
}
66+
67+
/**
68+
* Converts a file path to a Gradle property reference based on format.
69+
* @param format The property format to use
70+
* @return Formatted property value (either file("path").absolutePath or file("path"))
71+
*/
72+
fun String.toPropertyReference(format: PropertyFormat): String {
73+
return when (format) {
74+
PropertyFormat.STRING -> """file("$this").absolutePath"""
75+
PropertyFormat.FILE -> """file("$this")"""
76+
}
7777
}

0 commit comments

Comments
 (0)