Skip to content

Commit 9e726b3

Browse files
committed
Add test that exhibits the problem
1 parent e855f9c commit 9e726b3

File tree

1 file changed

+55
-1
lines changed

1 file changed

+55
-1
lines changed

src/test/kotlin/org/springdoc/openapi/gradle/plugin/OpenApiGradlePluginTest.kt

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,10 +335,64 @@ class OpenApiGradlePluginTest {
335335
}
336336
}
337337

338+
@Test
339+
fun `running the same build keeps the OpenAPI task up to date`() {
340+
buildFile.writeText(
341+
"""
342+
$baseBuildGradle
343+
openApi {}
344+
""".trimMargin()
345+
)
346+
347+
// Run the first build to generate the OpenAPI file
348+
assertEquals(TaskOutcome.SUCCESS, openApiDocsTask(runTheBuild()).outcome)
349+
assertOpenApiJsonFile(1)
350+
351+
// Rerunning the build does not regenerate the OpenAPI file
352+
assertEquals(TaskOutcome.UP_TO_DATE, openApiDocsTask(runTheBuild()).outcome)
353+
assertOpenApiJsonFile(1)
354+
}
355+
356+
@Test
357+
fun `changing the source code regenerates the OpenAPI`() {
358+
buildFile.writeText(
359+
"""
360+
$baseBuildGradle
361+
openApi {}
362+
""".trimMargin()
363+
)
364+
365+
// Run the first build to generate the OpenAPI file
366+
assertEquals(TaskOutcome.SUCCESS, openApiDocsTask(runTheBuild()).outcome)
367+
assertOpenApiJsonFile(1)
368+
369+
val addedFile = projectTestDir.resolve("src/main/java/com/example/demo/endpoints/AddedController.java")
370+
addedFile.createNewFile()
371+
addedFile.writeText("""
372+
package com.example.demo.endpoints;
373+
374+
import org.springframework.web.bind.annotation.GetMapping;
375+
import org.springframework.web.bind.annotation.RestController;
376+
377+
@RestController
378+
public class AddedController {
379+
380+
@GetMapping("/added")
381+
public String added() {
382+
return "Added file";
383+
}
384+
}
385+
""".trimIndent())
386+
387+
// Run the same build with added source file
388+
assertEquals(TaskOutcome.SUCCESS, openApiDocsTask(runTheBuild()).outcome)
389+
assertOpenApiJsonFile(2)
390+
}
391+
338392
private fun runTheBuild(vararg additionalArguments: String = emptyArray()) =
339393
GradleRunner.create()
340394
.withProjectDir(projectTestDir)
341-
.withArguments("clean", "generateOpenApiDocs", *additionalArguments)
395+
.withArguments("generateOpenApiDocs", *additionalArguments)
342396
.withPluginClasspath()
343397
.build()
344398

0 commit comments

Comments
 (0)