Skip to content

Commit

Permalink
fix failing tests after Gradle plugin configuration consolidation
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesfredley committed Nov 11, 2024
1 parent e69382a commit 619b84f
Show file tree
Hide file tree
Showing 38 changed files with 130 additions and 187 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ abstract class ApplicationContextSpec extends Specification implements ProjectFi
for (String line : lines) {
if (line.contains(groupArtifactId)) {
String str = line.substring(line.indexOf(groupArtifactId) + groupArtifactId.length() + ":".length())
String version = str.substring(0, str.indexOf("\")"))
String version = str.substring(0, str.indexOf("\""))
return Optional.of(new SemanticVersion(version))
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ class BuildBuilder implements ProjectFixture, ContextFixture {

String renderBuildSrc() {
List<String> featureNames = this.features ?: []
featureNames.add("gradle-build-src")
TestFramework testFramework = this.testFramework ?: TestFramework.SPOCK
ApplicationType type = this.applicationType ?: ApplicationType.WEB
Project project = this.project ?: buildProject()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,23 @@ class GradleDependencyComparatorSpec extends Specification {
dependencies.sort(GradleDependency.COMPARATOR)

then:
"${str(dependencies[0])}" == 'implementation("io.micronaut:micronaut-http-client")'
"${str(dependencies[1])}" == 'implementation("io.micronaut:micronaut-runtime")'
"${str(dependencies[2])}" == 'implementation("io.micronaut:micronaut-validation")'
"${str(dependencies[3])}" == 'implementation("io.micronaut.sql:micronaut-jdbc-hikari")'
"${str(dependencies[4])}" == 'implementation("io.swagger.core.v3:swagger-annotations")'
"${str(dependencies[5])}" == 'implementation("jakarta.annotation:jakarta.annotation-api")'
"${str(dependencies[6])}" == 'compileOnly("io.micronaut.openapi:micronaut-openapi")'
"${str(dependencies[7])}" == 'console("org.grails:grails-console")'
"${str(dependencies[8])}" == 'runtimeOnly("ch.qos.logback:logback-classic")'
"${str(dependencies[9])}" == 'runtimeOnly("mysql:mysql-connector-java")'
"${str(dependencies[10])}" == 'testImplementation("org.testcontainers:junit-jupiter")'
"${str(dependencies[11])}" == 'testImplementation("org.testcontainers:mysql")'
"${str(dependencies[12])}" == 'testImplementation("org.testcontainers:testcontainers")'
"${str(dependencies[0])}" == 'implementation "io.micronaut:micronaut-http-client"'
"${str(dependencies[1])}" == 'implementation "io.micronaut:micronaut-runtime"'
"${str(dependencies[2])}" == 'implementation "io.micronaut:micronaut-validation"'
"${str(dependencies[3])}" == 'implementation "io.micronaut.sql:micronaut-jdbc-hikari"'
"${str(dependencies[4])}" == 'implementation "io.swagger.core.v3:swagger-annotations"'
"${str(dependencies[5])}" == 'implementation "jakarta.annotation:jakarta.annotation-api"'
"${str(dependencies[6])}" == 'compileOnly "io.micronaut.openapi:micronaut-openapi"'
"${str(dependencies[7])}" == 'console "org.grails:grails-console"'
"${str(dependencies[8])}" == 'runtimeOnly "ch.qos.logback:logback-classic"'
"${str(dependencies[9])}" == 'runtimeOnly "mysql:mysql-connector-java"'
"${str(dependencies[10])}" == 'testImplementation "org.testcontainers:junit-jupiter"'
"${str(dependencies[11])}" == 'testImplementation "org.testcontainers:mysql"'
"${str(dependencies[12])}" == 'testImplementation "org.testcontainers:testcontainers"'
}

private static String str(GradleDependency dependency) {
"${dependency.getConfiguration().toString()}(\"${dependency.groupId}:${dependency.artifactId}\")"
"${dependency.getConfiguration().toString()} \"${dependency.groupId}:${dependency.artifactId}\""
}

private static GradleDependency dep(Dependency.Builder dependency, GeneratorContext ctx) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,52 +34,10 @@ class GradleSpec extends ApplicationContextSpec implements CommandOutputFixture

void "test settings.gradle"() {
given:
final def output = generate(ApplicationType.WEB, new Options(TestFramework.SPOCK, JdkVersion.JDK_11))
final String settingsGradle = output["settings.gradle"]

expect:
settingsGradle.contains("pluginManagement")
settingsGradle.contains("repositories")
settingsGradle.contains("mavenLocal()")
settingsGradle.contains("maven { url \"https://repo.grails.org/grails/core/\" }")
settingsGradle.contains("gradlePluginPortal()")
settingsGradle.contains("id \"org.grails.grails-web\" version \"6.2.1\"")
settingsGradle.contains("id \"org.grails.grails-gsp\" version \"6.2.1\"")
settingsGradle.contains("id \"com.bertramlabs.asset-pipeline\" version \"4.3.0\"")
}

void "test settings.gradle for REST-API"() {
given:
final def output = generate(ApplicationType.REST_API, new Options(TestFramework.SPOCK, JdkVersion.JDK_11))
final String settingsGradle = output["settings.gradle"]

expect:
settingsGradle.contains("pluginManagement")
settingsGradle.contains("repositories")
settingsGradle.contains("mavenLocal()")
settingsGradle.contains("maven { url \"https://repo.grails.org/grails/core/\" }")
settingsGradle.contains("gradlePluginPortal()")
settingsGradle.contains("id \"org.grails.grails-web\" version \"6.2.1\"")
settingsGradle.contains("id \"org.grails.plugins.views-json\" version \"3.2.3\"")
!settingsGradle.contains("id \"org.grails.grails-gsp\" version \"6.2.1\"")
!settingsGradle.contains("id \"com.bertramlabs.asset-pipeline\" version \"4.3.0\"")
}

void "test settings.gradle for REST-API for markup-views"() {
given:
final def output = generate(ApplicationType.REST_API, new Options(TestFramework.SPOCK, JdkVersion.JDK_11), ["views-markup"])
final def output = generate(ApplicationType.WEB, new Options(TestFramework.SPOCK, JdkVersion.JDK_11), ["gradle-settings-file"])
final String settingsGradle = output["settings.gradle"]

expect:
settingsGradle.contains("pluginManagement")
settingsGradle.contains("repositories")
settingsGradle.contains("mavenLocal()")
settingsGradle.contains("maven { url \"https://repo.grails.org/grails/core/\" }")
settingsGradle.contains("gradlePluginPortal()")
settingsGradle.contains("id \"org.grails.grails-web\" version \"6.2.1\"")
settingsGradle.contains("id \"org.grails.plugins.views-markup\" version \"3.2.3\"")
!settingsGradle.contains("id \"org.grails.plugins.views-json\" version \"3.2.3\"")
!settingsGradle.contains("id \"org.grails.grails-gsp\" version \"6.2.1\"")
!settingsGradle.contains("id \"com.bertramlabs.asset-pipeline\" version \"4.3.0\"")
settingsGradle.contains("rootProject.name")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,9 @@ class AsciidoctorSpec extends ApplicationContextSpec implements CommandOutputFix
given:
final def output = generate(ApplicationType.WEB, new Options(TestFramework.SPOCK, JdkVersion.JDK_11), ["asciidoctor"])
final def buildGradle = output["build.gradle"]
final def settingGradle = output["settings.gradle"]

expect:
settingGradle.contains("id \"org.asciidoctor.jvm.convert\" version \"4.0.0-alpha.1\"")
buildGradle.contains("id \"org.asciidoctor.jvm.convert\" version \"4.0.0-alpha.1\"")
buildGradle.contains("apply from: \"gradle/asciidoc.gradle\"")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,6 @@ class AssetPipelineSpec extends ApplicationContextSpec implements CommandOutputF
features.contains("asset-pipeline-grails")
}

void "test buildSrc is present for buildscript dependencies"() {
given:
final def output = generate(ApplicationType.WEB, new Options(TestFramework.SPOCK, JdkVersion.JDK_11))
final def buildSrcBuildGradle = output["buildSrc/build.gradle"]

expect:
buildSrcBuildGradle != null
buildSrcBuildGradle.contains("implementation(\"com.bertramlabs.plugins:asset-pipeline-gradle:4.3.0\")")

}


void "test dependencies are present for gradle"() {
when:
final String template = new BuildBuilder(beanContext)
Expand All @@ -40,7 +28,7 @@ class AssetPipelineSpec extends ApplicationContextSpec implements CommandOutputF

then:
template.contains("id \"com.bertramlabs.asset-pipeline\"")
template.contains("runtimeOnly(\"com.bertramlabs.plugins:asset-pipeline-grails:4.3.0\")")
template.contains("runtimeOnly \"com.bertramlabs.plugins:asset-pipeline-grails:4.5.1\"")
template.contains('''
assets {
minifyJs = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class EHCacheSpec extends ApplicationContextSpec implements CommandOutputFixture
.render()

then:
template.contains('implementation("org.grails.plugins:cache-ehcache:3.0.0")')
template.contains('implementation "org.grails.plugins:cache-ehcache:3.0.0"')

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class EmbeddedMongoSpec extends ApplicationContextSpec implements CommandOutputF
.render()

then:
template.contains("testRuntimeOnly(\"org.grails.plugins:embedded-mongodb:2.0.1\")")
template.contains("testRuntimeOnly \"org.grails.plugins:embedded-mongodb:2.0.1\"")
}

void "test config"() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ class HibernateGormSpec extends ApplicationContextSpec implements CommandOutputF
.render()

then:
template.contains('implementation("org.grails.plugins:hibernate5")')
template.contains("runtimeOnly(\"org.apache.tomcat:tomcat-jdbc\")")
template.contains("runtimeOnly(\"com.h2database:h2\")")
template.contains('implementation "org.grails.plugins:hibernate5"')
template.contains("runtimeOnly \"org.apache.tomcat:tomcat-jdbc\"")
template.contains("runtimeOnly \"com.h2database:h2\"")
}

void "test dependencies are present for buildSrc"() {
Expand All @@ -41,17 +41,17 @@ class HibernateGormSpec extends ApplicationContextSpec implements CommandOutputF
.renderBuildSrc()

then:
template.contains('implementation("org.grails.plugins:hibernate5:8.1.0")')
template.contains('implementation "org.grails.plugins:hibernate5:8.1.0"')
}

void "test buildSrc is present for buildscript dependencies"() {
given:
final def output = generate(ApplicationType.WEB, new Options(TestFramework.SPOCK, JdkVersion.JDK_11))
final def buildSrcBuildGradle = output["buildSrc/build.gradle"]
final def buildGradle = output["build.gradle"]

expect:
buildSrcBuildGradle != null
buildSrcBuildGradle.contains("implementation(\"org.grails.plugins:hibernate5:8.1.0\")")
buildGradle != null
buildGradle.contains("classpath \"org.grails.plugins:hibernate5:8.1.0\"")

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class MongoGormSpec extends ApplicationContextSpec implements CommandOutputFixtu
.render()

then:
template.contains("implementation(\"org.grails.plugins:mongodb\")")
template.contains("implementation \"org.grails.plugins:mongodb\"")
}

void "test gorm mongodb with embedded-mongodb feature"() {
Expand All @@ -51,8 +51,8 @@ class MongoGormSpec extends ApplicationContextSpec implements CommandOutputFixtu
.render()

then:
template.contains("implementation(\"org.grails.plugins:mongodb\")")
template.contains("testRuntimeOnly(\"org.grails.plugins:embedded-mongodb:2.0.1\")")
template.contains("implementation \"org.grails.plugins:mongodb\"")
template.contains("testRuntimeOnly \"org.grails.plugins:embedded-mongodb:2.0.1\"")
}

void "test config"() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class MongoSyncSpec extends ApplicationContextSpec implements CommandOutputFixtu
.render()

then:
template.contains('implementation("org.mongodb:mongodb-driver-sync:4.11.3")')
template.contains('testImplementation("org.testcontainers:mongodb")')
template.contains('implementation "org.mongodb:mongodb-driver-sync:4.11.3"')
template.contains('testImplementation "org.testcontainers:mongodb"')
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class MySQLSpec extends ApplicationContextSpec {
.render()

then:
template.contains('runtimeOnly("mysql:mysql-connector-java")')
template.contains('runtimeOnly "mysql:mysql-connector-java"')
}

void "test there can only be one of DatabaseDriverFeature"() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class Neo4JGormSpec extends ApplicationContextSpec implements CommandOutputFixtu
.render()

then:
template.contains("implementation(\"org.grails.plugins:neo4j\")")
template.contains("implementation \"org.grails.plugins:neo4j\"")
}

void "test config"() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class PostgresSpec extends ApplicationContextSpec {
.render()

then:
template.contains('runtimeOnly("org.postgresql:postgresql")')
template.contains('runtimeOnly "org.postgresql:postgresql"')
}

void "test there can only be one of DatabaseDriverFeature"() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class SQLServerSpec extends ApplicationContextSpec {
.render()

then:
template.contains('runtimeOnly("com.microsoft.sqlserver:mssql-jdbc")')
template.contains('runtimeOnly "com.microsoft.sqlserver:mssql-jdbc"')
}

void "test there can only be one of DatabaseDriverFeature"() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ class TestContainersSpec extends ApplicationContextSpec {
.render()

then:
template.contains('testImplementation("org.testcontainers:mysql")')
template.contains('testImplementation("org.testcontainers:testcontainers")')
template.contains('testImplementation "org.testcontainers:mysql"')
template.contains('testImplementation "org.testcontainers:testcontainers"')
}

void "test postgres dependency is present for gradle"() {
Expand All @@ -27,8 +27,8 @@ class TestContainersSpec extends ApplicationContextSpec {
.render()

then:
template.contains('testImplementation("org.testcontainers:postgresql")')
template.contains('testImplementation("org.testcontainers:testcontainers")')
template.contains('testImplementation "org.testcontainers:postgresql"')
template.contains('testImplementation "org.testcontainers:testcontainers"')
}

void "test sqlserver dependency is present for gradle"() {
Expand All @@ -38,8 +38,8 @@ class TestContainersSpec extends ApplicationContextSpec {
.render()

then:
template.contains('testImplementation("org.testcontainers:mssqlserver")')
template.contains('testImplementation("org.testcontainers:testcontainers")')
template.contains('testImplementation "org.testcontainers:mssqlserver"')
template.contains('testImplementation "org.testcontainers:testcontainers"')
}

void "test mongo-sync dependency is present for gradle"() {
Expand All @@ -49,8 +49,8 @@ class TestContainersSpec extends ApplicationContextSpec {
.render()

then:
template.contains('testImplementation("org.testcontainers:mongodb")')
template.contains('testImplementation("org.testcontainers:testcontainers")')
template.contains('testImplementation "org.testcontainers:mongodb"')
template.contains('testImplementation "org.testcontainers:testcontainers"')
}

void "test mongo-gorm dependency is present for gradle"() {
Expand All @@ -60,8 +60,8 @@ class TestContainersSpec extends ApplicationContextSpec {
.render()

then:
template.contains('testImplementation("org.testcontainers:mongodb")')
template.contains('testImplementation("org.testcontainers:testcontainers")')
template.contains('testImplementation "org.testcontainers:mongodb"')
template.contains('testImplementation "org.testcontainers:testcontainers"')
}

void "test testcontainers core is present when no testcontainer modules are present for gradle"() {
Expand All @@ -71,7 +71,7 @@ class TestContainersSpec extends ApplicationContextSpec {
.render()

then:
template.contains('testImplementation("org.testcontainers:testcontainers")')
template.contains('testImplementation "org.testcontainers:testcontainers"')
}

void "testframework dependency is present for gradle for feature #feature and spock framework"() {
Expand All @@ -82,7 +82,7 @@ class TestContainersSpec extends ApplicationContextSpec {
.render()

then:
template.contains('testImplementation("org.testcontainers:spock")')
template.contains('testImplementation "org.testcontainers:spock"')

where:
feature << ["mongo-sync", "mysql", "postgres", "sqlserver"]
Expand All @@ -97,7 +97,7 @@ class TestContainersSpec extends ApplicationContextSpec {
.render()

then:
template.contains('testImplementation("org.testcontainers:junit-jupiter")')
template.contains('testImplementation "org.testcontainers:junit-jupiter"')

where:
feature << ["mongo-sync", "mysql", "postgres", "sqlserver"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ class GrailsBaseSpec extends BeanContextSpec implements CommandOutputFixture {
def buildGradle = output['build.gradle']

then:
buildGradle.contains("implementation(\"org.grails:grails-core\")")
buildGradle.contains("implementation(\"org.grails:grails-web-boot\")")
buildGradle.contains("implementation(\"org.grails:grails-logging\")")
buildGradle.contains("implementation \"org.grails:grails-core\"")
buildGradle.contains("implementation \"org.grails:grails-web-boot\"")
buildGradle.contains("implementation \"org.grails:grails-logging\"")
}

void "test src/main directories are present"() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ class GrailsConsoleSpec extends BeanContextSpec {
.render()

then:
template.contains("console(\"org.grails:grails-console\")")
template.contains("console \"org.grails:grails-console\"")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ class GrailsDefaultPluginsSpec extends ApplicationContextSpec implements Command
final String buildGradle = output["build.gradle"]

expect:
buildGradle.contains("implementation(\"org.grails:grails-plugin-rest\")")
buildGradle.contains("implementation(\"org.grails:grails-plugin-databinding\")")
buildGradle.contains("implementation(\"org.grails:grails-plugin-i18n\")")
buildGradle.contains("implementation(\"org.grails:grails-plugin-services\")")
buildGradle.contains("implementation(\"org.grails:grails-plugin-interceptors\")")
buildGradle.contains("implementation \"org.grails:grails-plugin-rest\"")
buildGradle.contains("implementation \"org.grails:grails-plugin-databinding\"")
buildGradle.contains("implementation \"org.grails:grails-plugin-i18n\"")
buildGradle.contains("implementation \"org.grails:grails-plugin-services\"")
buildGradle.contains("implementation \"org.grails:grails-plugin-interceptors\"")
}

void "test i18n message properties files are present"() {
Expand Down
Loading

0 comments on commit 619b84f

Please sign in to comment.