@@ -17,290 +17,46 @@ class GroovyBridgeMethodsTest : TestBase() {
1717 override var temp: File = createTempDirectory(javaClass.simpleName).toFile()
1818
1919 @Test
20- fun `GenerateTask should accept inputSpecAsString property style in Groovy DSL` () {
21- // Arrange
22- val buildContents = """
23- plugins {
24- id 'org.openapi.generator'
25- }
26- openApiGenerate {
27- generatorName = "kotlin"
28- inputSpecAsString = "spec.yaml"
29- outputDirAsString = "build/kotlin"
30- apiPackage = "org.openapitools.example.api"
31- invokerPackage = "org.openapitools.example.invoker"
32- modelPackage = "org.openapitools.example.model"
33- }
34- """ .trimIndent()
35-
36- withProjectFiles(buildContents)
37-
38- // Act
39- val result = GradleRunner .create()
40- .withProjectDir(temp)
41- .withArguments(" openApiGenerate" )
42- .withPluginClasspath()
43- .build()
44-
45- // Assert
46- assertTrue(
47- result.output.contains(" Successfully generated code to" ),
48- " Expected successful generation using inputSpecAsString property style"
49- )
50- assertEquals(
51- TaskOutcome .SUCCESS , result.task(" :openApiGenerate" )?.outcome,
52- " Expected a successful run with inputSpecAsString property"
53- )
54- }
55-
56- @Test
57- fun `GenerateTask should accept setInputSpecAsString method style in Groovy DSL` () {
20+ fun `Custom GenerateTask should accept all AsString bridge methods` () {
5821 // Arrange
5922 val buildContents = """
6023 plugins {
6124 id 'org.openapi.generator'
6225 }
63- openApiGenerate {
26+
27+ tasks.register('customGenerate', org.openapitools.generator.gradle.plugin.tasks.GenerateTask) {
6428 generatorName = "kotlin"
6529 setInputSpecAsString("spec.yaml")
66- setOutputDirAsString("build/kotlin")
67- apiPackage = "org.openapitools.example.api"
68- invokerPackage = "org.openapitools.example.invoker"
69- modelPackage = "org.openapitools.example.model"
70- }
71- """ .trimIndent()
72-
73- withProjectFiles(buildContents)
74-
75- // Act
76- val result = GradleRunner .create()
77- .withProjectDir(temp)
78- .withArguments(" openApiGenerate" )
79- .withPluginClasspath()
80- .build()
81-
82- // Assert
83- assertTrue(
84- result.output.contains(" Successfully generated code to" ),
85- " Expected successful generation using setInputSpecAsString method style"
86- )
87- assertEquals(
88- TaskOutcome .SUCCESS , result.task(" :openApiGenerate" )?.outcome,
89- " Expected a successful run with setInputSpecAsString method"
90- )
91- }
92-
93- @Test
94- fun `GenerateTask should accept all file and directory AsString properties` () {
95- // Arrange
96- val buildContents = """
97- plugins {
98- id 'org.openapi.generator'
99- }
100- openApiGenerate {
101- generatorName = "kotlin"
102- inputSpecAsString = "spec.yaml"
103- outputDirAsString = "build/kotlin"
104- templateDirAsString = "templates"
105- configFileAsString = "config.json"
106- apiPackage = "org.openapitools.example.api"
107- invokerPackage = "org.openapitools.example.invoker"
108- modelPackage = "org.openapitools.example.model"
109- }
110- """ .trimIndent()
111-
112- withProjectFiles(buildContents, includeConfig = true , includeTemplates = true )
113-
114- // Act
115- val result = GradleRunner .create()
116- .withProjectDir(temp)
117- .withArguments(" openApiGenerate" )
118- .withPluginClasspath()
119- .build()
120-
121- // Assert
122- assertTrue(
123- result.output.contains(" Successfully generated code to" ),
124- " Expected successful generation using all AsString properties"
125- )
126- assertEquals(
127- TaskOutcome .SUCCESS , result.task(" :openApiGenerate" )?.outcome,
128- " Expected a successful run with all AsString properties"
129- )
130- }
131-
132- @Test
133- fun `GenerateTask should handle remote inputSpec with inputSpecAsString` () {
134- // Arrange
135- val specUrl = " https://raw.githubusercontent.com/OpenAPITools/openapi-generator/b6b8c0db872fb4a418ae496e89c7e656e14be165/modules/openapi-generator-gradle-plugin/src/test/resources/specs/petstore-v3.0.yaml"
136- val buildContents = """
137- plugins {
138- id 'org.openapi.generator'
139- }
140- openApiGenerate {
141- generatorName = "kotlin"
142- inputSpecAsString = "$specUrl "
143- outputDirAsString = "build/kotlin"
144- apiPackage = "org.openapitools.example.api"
145- invokerPackage = "org.openapitools.example.invoker"
146- modelPackage = "org.openapitools.example.model"
30+ setOutputDirAsString("build/custom-kotlin")
31+ setTemplateDirAsString("templates")
32+ apiPackage = "org.openapitools.custom.api"
33+ invokerPackage = "org.openapitools.custom.invoker"
34+ modelPackage = "org.openapitools.custom.model"
14735 }
14836 """ .trimIndent()
14937
150- File (temp, " build.gradle " ).writeText(buildContents )
38+ withProjectFiles(buildContents, includeTemplates = true )
15139
15240 // Act
15341 val result = GradleRunner .create()
15442 .withProjectDir(temp)
155- .withArguments(" openApiGenerate " )
43+ .withArguments(" customGenerate " )
15644 .withPluginClasspath()
15745 .build()
15846
15947 // Assert
16048 assertTrue(
16149 result.output.contains(" Successfully generated code to" ),
162- " Expected successful generation using remote URL with inputSpecAsString"
163- )
164- assertEquals(
165- TaskOutcome .SUCCESS , result.task(" :openApiGenerate" )?.outcome,
166- " Expected a successful run with remote inputSpecAsString"
167- )
168- }
169-
170- @Test
171- fun `ValidateTask should accept inputSpecAsString property style in Groovy DSL` () {
172- // Arrange
173- val buildContents = """
174- plugins {
175- id 'org.openapi.generator'
176- }
177- openApiValidate {
178- inputSpecAsString = "spec.yaml"
179- }
180- """ .trimIndent()
181-
182- withProjectFiles(buildContents)
183-
184- // Act
185- val result = GradleRunner .create()
186- .withProjectDir(temp)
187- .withArguments(" openApiValidate" )
188- .withPluginClasspath()
189- .build()
190-
191- // Assert
192- assertTrue(
193- result.output.contains(" Spec is valid" ),
194- " Expected successful validation using inputSpecAsString property style"
195- )
196- assertEquals(
197- TaskOutcome .SUCCESS , result.task(" :openApiValidate" )?.outcome,
198- " Expected a successful validation with inputSpecAsString property"
199- )
200- }
201-
202- @Test
203- fun `ValidateTask should accept setInputSpecAsString method style in Groovy DSL` () {
204- // Arrange
205- val buildContents = """
206- plugins {
207- id 'org.openapi.generator'
208- }
209- openApiValidate {
210- setInputSpecAsString("spec.yaml")
211- }
212- """ .trimIndent()
213-
214- withProjectFiles(buildContents)
215-
216- // Act
217- val result = GradleRunner .create()
218- .withProjectDir(temp)
219- .withArguments(" openApiValidate" )
220- .withPluginClasspath()
221- .build()
222-
223- // Assert
224- assertTrue(
225- result.output.contains(" Spec is valid" ),
226- " Expected successful validation using setInputSpecAsString method style"
227- )
228- assertEquals(
229- TaskOutcome .SUCCESS , result.task(" :openApiValidate" )?.outcome,
230- " Expected a successful validation with setInputSpecAsString method"
231- )
232- }
233-
234- @Test
235- fun `MetaTask should accept outputFolderAsString property style in Groovy DSL` () {
236- // Arrange
237- val buildContents = """
238- plugins {
239- id 'org.openapi.generator'
240- }
241- openApiMeta {
242- generatorName = "TestGenerator"
243- packageName = "org.openapitools.example"
244- outputFolderAsString = "build/meta"
245- }
246- """ .trimIndent()
247-
248- File (temp, " build.gradle" ).writeText(buildContents)
249-
250- // Act
251- val result = GradleRunner .create()
252- .withProjectDir(temp)
253- .withArguments(" openApiMeta" )
254- .withPluginClasspath()
255- .build()
256-
257- // Assert
258- assertTrue(
259- result.output.contains(" Created generator" ),
260- " Expected successful meta generation using outputFolderAsString property style"
261- )
262- assertEquals(
263- TaskOutcome .SUCCESS , result.task(" :openApiMeta" )?.outcome,
264- " Expected a successful run with outputFolderAsString property"
265- )
266- }
267-
268- @Test
269- fun `MetaTask should accept setOutputFolderAsString method style in Groovy DSL` () {
270- // Arrange
271- val buildContents = """
272- plugins {
273- id 'org.openapi.generator'
274- }
275- openApiMeta {
276- generatorName = "TestGenerator"
277- packageName = "org.openapitools.example"
278- setOutputFolderAsString("build/meta")
279- }
280- """ .trimIndent()
281-
282- File (temp, " build.gradle" ).writeText(buildContents)
283-
284- // Act
285- val result = GradleRunner .create()
286- .withProjectDir(temp)
287- .withArguments(" openApiMeta" )
288- .withPluginClasspath()
289- .build()
290-
291- // Assert
292- assertTrue(
293- result.output.contains(" Created generator" ),
294- " Expected successful meta generation using setOutputFolderAsString method style"
50+ " Expected successful generation in custom task using AsString methods"
29551 )
29652 assertEquals(
297- TaskOutcome .SUCCESS , result.task(" :openApiMeta " )?.outcome,
298- " Expected a successful run with setOutputFolderAsString method "
53+ TaskOutcome .SUCCESS , result.task(" :customGenerate " )?.outcome,
54+ " Expected a successful run with custom task using AsString methods "
29955 )
30056 }
30157
30258 @Test
303- fun `Custom GenerateTask should accept all AsString bridge methods` () {
59+ fun `Custom GenerateTask should accept all AsString bridge methods in groovy DSL ` () {
30460 // Arrange
30561 val buildContents = """
30662 plugins {
@@ -309,9 +65,9 @@ class GroovyBridgeMethodsTest : TestBase() {
30965
31066 tasks.register('customGenerate', org.openapitools.generator.gradle.plugin.tasks.GenerateTask) {
31167 generatorName = "kotlin"
312- setInputSpecAsString( "spec.yaml")
313- setOutputDirAsString( "build/custom-kotlin")
314- setTemplateDirAsString( "templates")
68+ inputSpecAsString = "spec.yaml"
69+ outputDirAsString = "build/custom-kotlin"
70+ templateDirAsString = "templates"
31571 apiPackage = "org.openapitools.custom.api"
31672 invokerPackage = "org.openapitools.custom.invoker"
31773 modelPackage = "org.openapitools.custom.model"
0 commit comments