Skip to content

Commit

Permalink
Add integration tests to cover happy and unhappy paths
Browse files Browse the repository at this point in the history
  • Loading branch information
Julio Zynger committed Jun 4, 2020
1 parent 918a887 commit a41ef12
Showing 1 changed file with 208 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.zynger.floorplan

import com.google.common.truth.Truth.assertThat
import org.gradle.testkit.runner.BuildResult
import org.gradle.testkit.runner.GradleRunner
import org.junit.Rule
import org.junit.Test
Expand All @@ -13,6 +15,9 @@ class FloorPlanGradlePluginIntegrationTest {
private fun writeBuildGradle(build: String) {
testProjectRoot.newFile("build.gradle").run { writeText(build) }
}
private fun createSchemasDirectory() {
testProjectRoot.newFolder("schemas")
}

@Test
fun applyingBarePluginSucceeds() {
Expand All @@ -26,4 +31,207 @@ class FloorPlanGradlePluginIntegrationTest {
.withPluginClasspath()
.build()
}

@Test
fun testMissingSchemaLocationFailsBuild() {
writeBuildGradle(
"""plugins {
| id "com.zynger.floorplan"
|}
|
|floorPlan {
| outputLocation = "schemas"
| outputFormat {
| svg {
| enabled = true
| }
| }
|}""".trimMargin()
)
floorPlanRunner()
.buildAndFail()
.withFailureMessage("Missing schemaLocation property.")
}

@Test
fun testMissingOutputLocationFailsBuild() {
writeBuildGradle(
"""plugins {
| id "com.zynger.floorplan"
|}
|
|floorPlan {
| schemaLocation = "schemas"
| outputFormat {
| svg {
| enabled = true
| }
| }
|}""".trimMargin()
)
floorPlanRunner()
.buildAndFail()
.withFailureMessage("Missing outputLocation property.")
}

@Test
fun testMissingOutputFormatFailsBuild() {
createSchemasDirectory()
writeBuildGradle(
"""plugins {
| id "com.zynger.floorplan"
|}
|
|floorPlan {
| schemaLocation = "schemas"
| outputLocation = "schemas"
|}""".trimMargin()
)
floorPlanRunner()
.buildAndFail()
.withFailureMessage("There are no enabled output formats.")
}

@Test
fun testEmptyOutputFormatFailsBuild() {
createSchemasDirectory()
writeBuildGradle(
"""plugins {
| id "com.zynger.floorplan"
|}
|
|floorPlan {
| schemaLocation = "schemas"
| outputLocation = "schemas"
| outputFormat {
| }
|}""".trimMargin()
)
floorPlanRunner()
.buildAndFail()
.withFailureMessage("There are no enabled output formats.")
}

@Test
fun testAllDisabledOutputFormatFailsBuild() {
createSchemasDirectory()
writeBuildGradle(
"""plugins {
| id "com.zynger.floorplan"
|}
|
|floorPlan {
| schemaLocation = "schemas"
| outputLocation = "schemas"
| outputFormat {
| dbml {
| enabled = false
| }
| svg {
| enabled = false
| }
| }
|}""".trimMargin()
)
floorPlanRunner()
.buildAndFail()
.withFailureMessage("There are no enabled output formats.")
}

@Test
fun testMultipleEnabledOutputFormatFailsBuild() {
createSchemasDirectory()
writeBuildGradle(
"""plugins {
| id "com.zynger.floorplan"
|}
|
|floorPlan {
| schemaLocation = "schemas"
| outputLocation = "schemas"
| outputFormat {
| dbml {
| enabled = true
| }
| svg {
| enabled = true
| }
| }
|}""".trimMargin()
)
floorPlanRunner()
.buildAndFail()
.withFailureMessage("There can only be one enabled output format.")
}

@Test
fun testSingleOutputFormatEnabled() {
createSchemasDirectory()
writeBuildGradle(
"""plugins {
| id "com.zynger.floorplan"
|}
|
|floorPlan {
| schemaLocation = "schemas"
| outputLocation = "schemas"
| outputFormat {
| svg {
| enabled = true
| }
| }
|}""".trimMargin()
)
floorPlanRunner()
.build()
.withSuccessfulMessage()
}

@Test
fun testMultipleOutputFormatButSingleEnabled() {
createSchemasDirectory()
writeBuildGradle(
"""plugins {
| id "com.zynger.floorplan"
|}
|
|floorPlan {
| schemaLocation = "schemas"
| outputLocation = "schemas"
| outputFormat {
| dbml {
| enabled = false
| }
| svg {
| enabled = true
| }
| }
|}""".trimMargin()
)
floorPlanRunner()
.build()
.withSuccessfulMessage()
}

private fun floorPlanRunner(): GradleRunner {
return GradleRunner.create()
.withProjectDir(testProjectRoot.root)
.withPluginClasspath()
.withArguments(GRADLE_TASK_NAME)
}

private fun BuildResult.withSuccessfulMessage(): BuildResult {
assertThat(output).contains(BUILD_SUCCESSFUL)
return this
}

private fun BuildResult.withFailureMessage(message: String): BuildResult {
assertThat(output).contains(message)
return this
}

private companion object {
private const val GRADLE_TASK_NAME = "generateFloorPlan"
private const val BUILD_SUCCESSFUL = "BUILD SUCCESSFUL"
}
}

0 comments on commit a41ef12

Please sign in to comment.