Polish
This commit is contained in:
@@ -41,6 +41,7 @@ import org.springframework.cloud.contract.verifier.config.ContractVerifierConfig
|
||||
* </ul>
|
||||
*
|
||||
* @author Jakub Kubrynski, codearte.io
|
||||
* @author Marcin Grzejszczak
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@@ -60,23 +61,20 @@ class SpringCloudContractVerifierGradlePlugin implements Plugin<Project> {
|
||||
@Override
|
||||
void apply(Project project) {
|
||||
this.project = project
|
||||
|
||||
project.plugins.apply(GroovyPlugin)
|
||||
|
||||
ContractVerifierConfigProperties extension = project.extensions.create(EXTENSION_NAME, ContractVerifierConfigProperties)
|
||||
|
||||
project.check.dependsOn(GENERATE_SERVER_TESTS_TASK_NAME)
|
||||
|
||||
setConfigurationDefaults(extension)
|
||||
createGenerateTestsTask(extension)
|
||||
createAndConfigureGenerateWireMockClientStubsFromDslTask(extension)
|
||||
Task stubsJar = createAndConfigureStubsJarTasks(extension)
|
||||
createAndConfigureCopyContractsTask(stubsJar, extension)
|
||||
createAndConfigureMavenPublishPlugin(stubsJar, extension)
|
||||
project.dependencies.add("testCompile", "com.github.tomakehurst:wiremock:2.1.7")
|
||||
project.dependencies.add("testCompile", "com.toomuchcoding.jsonassert:jsonassert:0.4.7")
|
||||
project.dependencies.add("testCompile", "org.assertj:assertj-core:2.3.0")
|
||||
addProjectDependencies(project)
|
||||
addIdeaTestSources(project, extension)
|
||||
}
|
||||
|
||||
private addIdeaTestSources(Project project, extension) {
|
||||
project.afterEvaluate {
|
||||
def hasIdea = project.plugins.findPlugin(IDEA_PLUGIN_CLASS)
|
||||
if (hasIdea) {
|
||||
@@ -90,6 +88,12 @@ class SpringCloudContractVerifierGradlePlugin implements Plugin<Project> {
|
||||
}
|
||||
}
|
||||
|
||||
private void addProjectDependencies(Project project) {
|
||||
project.dependencies.add("testCompile", "com.github.tomakehurst:wiremock:2.1.7")
|
||||
project.dependencies.add("testCompile", "com.toomuchcoding.jsonassert:jsonassert:0.4.7")
|
||||
project.dependencies.add("testCompile", "org.assertj:assertj-core:2.3.0")
|
||||
}
|
||||
|
||||
private void setConfigurationDefaults(ContractVerifierConfigProperties extension) {
|
||||
extension.with {
|
||||
generatedTestSourcesDir = project.file("${project.buildDir}/generated-test-sources/contracts")
|
||||
@@ -100,7 +104,7 @@ class SpringCloudContractVerifierGradlePlugin implements Plugin<Project> {
|
||||
}
|
||||
|
||||
private File defaultContractsDir() {
|
||||
project.file("${project.rootDir}/src/test/resources/contracts")
|
||||
return project.file("${project.rootDir}/src/test/resources/contracts")
|
||||
}
|
||||
|
||||
private void createGenerateTestsTask(ContractVerifierConfigProperties extension) {
|
||||
@@ -139,7 +143,6 @@ class SpringCloudContractVerifierGradlePlugin implements Plugin<Project> {
|
||||
}
|
||||
task.description = "Creates the stubs JAR task"
|
||||
task.group = GROUP_NAME
|
||||
|
||||
project.artifacts {
|
||||
archives task
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package org.springframework.cloud.contract.verifier.plugin
|
||||
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.Task
|
||||
import org.gradle.api.internal.project.AbstractProject
|
||||
import org.gradle.api.plugins.GroovyPlugin
|
||||
import org.gradle.api.publish.PublishingExtension
|
||||
import org.gradle.api.publish.maven.plugins.MavenPublishPlugin
|
||||
@@ -10,127 +10,133 @@ import org.springframework.cloud.contract.verifier.config.ContractVerifierConfig
|
||||
import spock.lang.Specification
|
||||
|
||||
class ContractVerifierSpec extends Specification {
|
||||
protected Project project
|
||||
AbstractProject project
|
||||
|
||||
def setup() {
|
||||
def dateString = new Date().format("yyyy-MM-dd_HH-mm-ss")
|
||||
def testFolder = new File("build/generated-tests/${getClass().simpleName}/${dateString}")
|
||||
testFolder.mkdirs()
|
||||
project = ProjectBuilder.builder().withProjectDir(testFolder).build()
|
||||
}
|
||||
def setup() {
|
||||
def dateString = new Date().format("yyyy-MM-dd_HH-mm-ss")
|
||||
def testFolder = new File("build/generated-tests/${getClass().simpleName}/${dateString}")
|
||||
testFolder.mkdirs()
|
||||
project = (AbstractProject) ProjectBuilder.builder().withProjectDir(testFolder).build()
|
||||
}
|
||||
|
||||
def "Applies groovy plugin"() {
|
||||
given:
|
||||
project.plugins.apply(SpringCloudContractVerifierGradlePlugin)
|
||||
def "should apply groovy plugin"() {
|
||||
given:
|
||||
project.plugins.apply(SpringCloudContractVerifierGradlePlugin)
|
||||
|
||||
expect:
|
||||
project.plugins.hasPlugin(GroovyPlugin)
|
||||
}
|
||||
expect:
|
||||
project.plugins.hasPlugin(GroovyPlugin)
|
||||
}
|
||||
|
||||
def "Creates contracts extension"() {
|
||||
given:
|
||||
project.plugins.apply(SpringCloudContractVerifierGradlePlugin)
|
||||
def "should create contracts extension"() {
|
||||
given:
|
||||
project.plugins.apply(SpringCloudContractVerifierGradlePlugin)
|
||||
|
||||
expect:
|
||||
project.extensions.findByType(ContractVerifierConfigProperties) != null
|
||||
}
|
||||
expect:
|
||||
project.extensions.findByType(ContractVerifierConfigProperties) != null
|
||||
}
|
||||
|
||||
def "Creates generateContractTests task"() {
|
||||
given:
|
||||
project.plugins.apply(SpringCloudContractVerifierGradlePlugin)
|
||||
def "should create generateContractTests task"() {
|
||||
given:
|
||||
project.plugins.apply(SpringCloudContractVerifierGradlePlugin)
|
||||
|
||||
expect:
|
||||
project.tasks.findByName("generateContractTests") != null
|
||||
}
|
||||
expect:
|
||||
project.tasks.findByName("generateContractTests") != null
|
||||
}
|
||||
|
||||
def "Configures generateContractTests task as a dependency of the check task"() {
|
||||
given:
|
||||
project.plugins.apply(SpringCloudContractVerifierGradlePlugin)
|
||||
def "should configure generateContractTests task as a dependency of the check task"() {
|
||||
given:
|
||||
project.plugins.apply(SpringCloudContractVerifierGradlePlugin)
|
||||
|
||||
expect:
|
||||
project.tasks.check.getDependsOn().contains("generateContractTests")
|
||||
}
|
||||
expect:
|
||||
project.tasks.check.getDependsOn().contains("generateContractTests")
|
||||
}
|
||||
|
||||
def "Creates generateWireMockClientStubs task"() {
|
||||
given:
|
||||
project.plugins.apply(SpringCloudContractVerifierGradlePlugin)
|
||||
def "should create generateWireMockClientStubs task"() {
|
||||
given:
|
||||
project.plugins.apply(SpringCloudContractVerifierGradlePlugin)
|
||||
|
||||
expect:
|
||||
project.tasks.findByName("generateWireMockClientStubs") != null
|
||||
}
|
||||
expect:
|
||||
project.tasks.findByName("generateWireMockClientStubs") != null
|
||||
}
|
||||
|
||||
def "Creates verifierStubsJar task"() {
|
||||
given:
|
||||
project.plugins.apply(SpringCloudContractVerifierGradlePlugin)
|
||||
def "should create verifierStubsJar task"() {
|
||||
given:
|
||||
project.plugins.apply(SpringCloudContractVerifierGradlePlugin)
|
||||
|
||||
expect:
|
||||
project.tasks.findByName("verifierStubsJar") != null
|
||||
}
|
||||
expect:
|
||||
project.tasks.findByName("verifierStubsJar") != null
|
||||
}
|
||||
|
||||
def "Configures generateWireMockClientStubs task as a dependency of the verifierStubsJar task"() {
|
||||
given:
|
||||
project.plugins.apply(SpringCloudContractVerifierGradlePlugin)
|
||||
def "should configure generateWireMockClientStubs task as a dependency of the verifierStubsJar task"() {
|
||||
given:
|
||||
project.plugins.apply(SpringCloudContractVerifierGradlePlugin)
|
||||
|
||||
expect:
|
||||
project.tasks.verifierStubsJar.getDependsOn().contains("generateWireMockClientStubs")
|
||||
}
|
||||
expect:
|
||||
project.tasks.verifierStubsJar.getDependsOn().contains("generateWireMockClientStubs")
|
||||
}
|
||||
|
||||
def "Creates copyContracts task"() {
|
||||
given:
|
||||
project.plugins.apply(SpringCloudContractVerifierGradlePlugin)
|
||||
def "should create copyContracts task"() {
|
||||
given:
|
||||
project.plugins.apply(SpringCloudContractVerifierGradlePlugin)
|
||||
|
||||
expect:
|
||||
project.tasks.findByName("copyContracts") != null
|
||||
}
|
||||
expect:
|
||||
project.tasks.findByName("copyContracts") != null
|
||||
}
|
||||
|
||||
def "Configures copyContracts task as a dependency of the verifierStubsJar task"() {
|
||||
given:
|
||||
project.plugins.apply(SpringCloudContractVerifierGradlePlugin)
|
||||
Task copyContracts = project.tasks.copyContracts
|
||||
assert copyContracts != null
|
||||
def "should configure copyContracts task as a dependency of the verifierStubsJar task"() {
|
||||
given:
|
||||
project.plugins.apply(SpringCloudContractVerifierGradlePlugin)
|
||||
Task copyContracts = project.tasks.copyContracts
|
||||
assert copyContracts != null
|
||||
|
||||
expect:
|
||||
project.tasks.verifierStubsJar.getDependsOn().contains(copyContracts)
|
||||
}
|
||||
expect:
|
||||
project.tasks.verifierStubsJar.getDependsOn().contains(copyContracts)
|
||||
}
|
||||
|
||||
/**
|
||||
* project.evaluate() is used here in order to trigger the evaluation lifecycle of a project.
|
||||
* This method is currently exposed via the internal API and is subject to change, however, Gradle
|
||||
* does not yet expose a way to test this portion of the lifecycle.
|
||||
*/
|
||||
def "Configures maven-publish plugin, if available"() {
|
||||
given:
|
||||
project.plugins.apply(MavenPublishPlugin)
|
||||
project.plugins.apply(SpringCloudContractVerifierGradlePlugin)
|
||||
project.evaluate() // Currently internal method to trigger afterEvaluate blocks.
|
||||
/**
|
||||
* project.evaluate() is used here in order to trigger the evaluation lifecycle of a project.
|
||||
* This method is currently exposed via the internal API and is subject to change, however, Gradle
|
||||
* does not yet expose a way to test this portion of the lifecycle.
|
||||
*/
|
||||
def "should configure maven-publish plugin, if available"() {
|
||||
given:
|
||||
project.plugins.apply(MavenPublishPlugin)
|
||||
project.plugins.apply(SpringCloudContractVerifierGradlePlugin)
|
||||
project.evaluate() // Currently internal method to trigger afterEvaluate blocks.
|
||||
|
||||
expect:
|
||||
def publications = project.extensions.getByType(PublishingExtension).publications
|
||||
publications.size() > 0
|
||||
publications.findByName("stubs") != null
|
||||
}
|
||||
expect:
|
||||
def publications = project.extensions.getByType(PublishingExtension).publications
|
||||
publications.size() > 0
|
||||
publications.findByName("stubs") != null
|
||||
}
|
||||
|
||||
def "Adds wiremock as a testCompile dependency"() {
|
||||
given:
|
||||
project.plugins.apply(SpringCloudContractVerifierGradlePlugin)
|
||||
def "should add wiremock as a testCompile dependency"() {
|
||||
given:
|
||||
project.plugins.apply(SpringCloudContractVerifierGradlePlugin)
|
||||
|
||||
expect:
|
||||
project.configurations.testCompile.dependencies.find { it.group == "com.github.tomakehurst" && it.name == "wiremock" } != null
|
||||
}
|
||||
expect:
|
||||
project.configurations.testCompile.dependencies.find {
|
||||
it.group == "com.github.tomakehurst" && it.name == "wiremock"
|
||||
} != null
|
||||
}
|
||||
|
||||
def "Adds jsonassert as a testCompile dependency"() {
|
||||
given:
|
||||
project.plugins.apply(SpringCloudContractVerifierGradlePlugin)
|
||||
def "should add jsonassert as a testCompile dependency"() {
|
||||
given:
|
||||
project.plugins.apply(SpringCloudContractVerifierGradlePlugin)
|
||||
|
||||
expect:
|
||||
project.configurations.testCompile.dependencies.find { it.group == "com.toomuchcoding.jsonassert" && it.name == "jsonassert" } != null
|
||||
}
|
||||
expect:
|
||||
project.configurations.testCompile.dependencies.find {
|
||||
it.group == "com.toomuchcoding.jsonassert" && it.name == "jsonassert"
|
||||
} != null
|
||||
}
|
||||
|
||||
def "Adds assertj-core as a testCompile dependency"() {
|
||||
given:
|
||||
project.plugins.apply(SpringCloudContractVerifierGradlePlugin)
|
||||
def "should add assertj-core as a testCompile dependency"() {
|
||||
given:
|
||||
project.plugins.apply(SpringCloudContractVerifierGradlePlugin)
|
||||
|
||||
expect:
|
||||
project.configurations.testCompile.dependencies.find { it.group == "org.assertj" && it.name == "assertj-core" } != null
|
||||
}
|
||||
expect:
|
||||
project.configurations.testCompile.dependencies.find {
|
||||
it.group == "org.assertj" && it.name == "assertj-core"
|
||||
} != null
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user