Skip to content

Commit b6abe40

Browse files
committed
#19, dsl tests
1 parent 9411c4e commit b6abe40

2 files changed

Lines changed: 187 additions & 0 deletions

File tree

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/*
2+
* Copyright 2021 https://github.com/openapi-processor/openapi-processor-gradle
3+
* PDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package io.openapiprocessor.gradle
7+
8+
import org.gradle.testkit.runner.GradleRunner
9+
import org.junit.Rule
10+
import org.junit.rules.TemporaryFolder
11+
import spock.lang.Specification
12+
import spock.lang.Unroll
13+
14+
import static org.gradle.testkit.runner.TaskOutcome.SUCCESS
15+
16+
class GroovyDslSpec extends Specification {
17+
18+
@Rule
19+
TemporaryFolder testProjectDir
20+
21+
File buildFile
22+
File openapiFile
23+
String projectDir
24+
25+
def setup() {
26+
projectDir = System.properties['PROJECT_DIR']
27+
buildFile = testProjectDir.newFile('build.gradle')
28+
29+
testProjectDir.newFolder ('src', 'api')
30+
openapiFile = testProjectDir.newFile ('src/api/openapi.yaml')
31+
}
32+
33+
@Unroll
34+
void "test groovy (method) dsl with with gradle #gradleVersion" () {
35+
openapiFile << """\
36+
property: value
37+
"""
38+
39+
buildFile << """\
40+
plugins {
41+
id("io.openapiprocessor.openapi-processor")
42+
}
43+
44+
openapiProcessor {
45+
apiPath("\$projectDir/src/api/openapi.yaml")
46+
47+
process("v1") {
48+
processor(project.files("$projectDir/processor-v1/build/libs/processor-v1.jar"))
49+
targetDir("\$buildDir/v1")
50+
51+
prop("v1", "value v1")
52+
}
53+
54+
}
55+
"""
56+
57+
when:
58+
def result = GradleRunner.create()
59+
.withGradleVersion(gradleVersion)
60+
.withProjectDir(testProjectDir.root)
61+
.withArguments('--stacktrace', 'processV1')
62+
.withPluginClasspath ([
63+
new File("${projectDir}/build/classes/groovy/main/"),
64+
new File("${projectDir}/build/classes/java/main/"),
65+
new File("${projectDir}/build/resources/main/")
66+
])
67+
.withDebug (true)
68+
.build()
69+
70+
then:
71+
result.task(':processV1').outcome == SUCCESS
72+
result.output.contains("processor v1 did run !")
73+
74+
where:
75+
// 5.5 is the minimum required version to run this test
76+
gradleVersion << [
77+
'5.5', '5.5.1',
78+
'5.6', '5.6.1', '5.6.2', '5.6.3', '5.6.4',
79+
'6.0', '6.0.1',
80+
'6.1', '6.1.1',
81+
'6.2', '6.2.1', '6.2.2',
82+
'6.3',
83+
'6.4', '6.4.1',
84+
'6.5', '6.5.1',
85+
'6.6', '6.6.1',
86+
'6.7', '6.7.1',
87+
'6.8', '6.8.1', '6.8.2', '6.8.3',
88+
'7.0'
89+
].reverse ()
90+
91+
}
92+
93+
}
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
/*
2+
* Copyright 2021 https://github.com/openapi-processor/openapi-processor-gradle
3+
* PDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package io.openapiprocessor.gradle
7+
8+
import org.gradle.testkit.runner.GradleRunner
9+
import org.junit.Rule
10+
import org.junit.rules.TemporaryFolder
11+
import spock.lang.Specification
12+
import spock.lang.Unroll
13+
14+
import static org.gradle.testkit.runner.TaskOutcome.SUCCESS
15+
16+
class KotlinDslSpec extends Specification {
17+
18+
@Rule
19+
TemporaryFolder testProjectDir
20+
21+
File buildFile
22+
File openapiFile
23+
String projectDir
24+
25+
def setup() {
26+
projectDir = System.properties['PROJECT_DIR']
27+
buildFile = testProjectDir.newFile('build.gradle.kts')
28+
29+
testProjectDir.newFolder ('src', 'api')
30+
openapiFile = testProjectDir.newFile ('src/api/openapi.yaml')
31+
}
32+
33+
@Unroll
34+
void "test kotlin dsl with with gradle #gradleVersion" () {
35+
openapiFile << """\
36+
property: value
37+
"""
38+
39+
buildFile << """\
40+
plugins {
41+
id("io.openapiprocessor.openapi-processor")
42+
}
43+
44+
openapiProcessor {
45+
apiPath("\$projectDir/src/api/openapi.yaml")
46+
47+
process("v1") {
48+
processor(files("$projectDir/processor-v1/build/libs/processor-v1.jar"))
49+
targetDir("\$buildDir/v1")
50+
51+
prop("v1", "value v1")
52+
}
53+
54+
}
55+
"""
56+
57+
when:
58+
def result = GradleRunner.create()
59+
.withGradleVersion(gradleVersion)
60+
.withProjectDir(testProjectDir.root)
61+
.withArguments('--stacktrace', 'processV1')
62+
.withPluginClasspath ([
63+
new File("${projectDir}/build/classes/groovy/main/"),
64+
new File("${projectDir}/build/classes/java/main/"),
65+
new File("${projectDir}/build/resources/main/")
66+
])
67+
.withDebug (true)
68+
.build()
69+
70+
then:
71+
result.task(':processV1').outcome == SUCCESS
72+
result.output.contains("processor v1 did run !")
73+
74+
where:
75+
// 5.5 is the minimum required version to run this test
76+
gradleVersion << [
77+
// // does not work with gradle before 6.5
78+
// '5.5', '5.5.1',
79+
// '5.6', '5.6.1', '5.6.2', '5.6.3', '5.6.4',
80+
// '6.0', '6.0.1',
81+
// '6.1', '6.1.1',
82+
// '6.2', '6.2.1', '6.2.2',
83+
// '6.3',
84+
// '6.4', '6.4.1',
85+
'6.5', '6.5.1',
86+
'6.6', '6.6.1',
87+
'6.7', '6.7.1',
88+
'6.8', '6.8.1', '6.8.2', '6.8.3',
89+
'7.0'
90+
].reverse ()
91+
92+
}
93+
94+
}

0 commit comments

Comments
 (0)