Fixed references to WireMock in the project so that it is correctly capitalized.
This commit is contained in:
@@ -8,7 +8,7 @@ Consumer Driven Contracts verifier for Java
|
||||
|
||||
Just to make long story short - AccuREST is a tool for Consumer Driven Contract (CDC) development. AccuREST ships easy DSL for describing REST contracts for JVM-based applications. The contract DSL is used by AccuREST for two things:
|
||||
|
||||
generating Wiremock's JSON stub definitions, allowing rapid development of the consumer side,
|
||||
generating WireMock's JSON stub definitions, allowing rapid development of the consumer side,
|
||||
generating Spock's acceptance tests for the server - to verify if your API implementation is compliant with the contract.
|
||||
By using AccuREST you can move TDD to an architecture level.
|
||||
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
package io.codearte.accurest.wiremock
|
||||
|
||||
import groovy.transform.CompileStatic
|
||||
import io.codearte.accurest.dsl.WireMockStubStrategy
|
||||
|
||||
@CompileStatic
|
||||
class DslToWireMockClientConverter extends DslToWireMockConverter {
|
||||
|
||||
@Override
|
||||
String convertContent(String dslBody) {
|
||||
return new WireMockStubStrategy(createGroovyDSLfromStringContent(dslBody)).toWireMockClientStub()
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,7 @@ import groovy.transform.CompileStatic
|
||||
import io.codearte.accurest.dsl.GroovyDsl
|
||||
|
||||
@CompileStatic
|
||||
abstract class DslToWiremockConverter implements SingleFileConverter {
|
||||
abstract class DslToWireMockConverter implements SingleFileConverter {
|
||||
|
||||
@Override
|
||||
boolean canHandleFileName(String fileName) {
|
||||
@@ -1,13 +0,0 @@
|
||||
package io.codearte.accurest.wiremock
|
||||
|
||||
import groovy.transform.CompileStatic
|
||||
import io.codearte.accurest.dsl.WiremockStubStrategy
|
||||
|
||||
@CompileStatic
|
||||
class DslToWiremockClientConverter extends DslToWiremockConverter {
|
||||
|
||||
@Override
|
||||
String convertContent(String dslBody) {
|
||||
return new WiremockStubStrategy(createGroovyDSLfromStringContent(dslBody)).toWiremockClientStub()
|
||||
}
|
||||
}
|
||||
@@ -8,15 +8,15 @@ import nl.flotsam.xeger.Xeger
|
||||
|
||||
import static org.apache.commons.lang3.StringEscapeUtils.escapeJava
|
||||
|
||||
class WiremockToDslConverter {
|
||||
static String fromWiremockStub(String wiremockStringStub) {
|
||||
return new WiremockToDslConverter().convertFromWiremockStub(wiremockStringStub)
|
||||
class WireMockToDslConverter {
|
||||
static String fromWireMockStub(String wireMockStringStub) {
|
||||
return new WireMockToDslConverter().convertFromWireMockStub(wireMockStringStub)
|
||||
}
|
||||
|
||||
private String convertFromWiremockStub(String wiremockStringStub) {
|
||||
Object wiremockStub = new JsonSlurper().parseText(wiremockStringStub)
|
||||
def request = wiremockStub.request
|
||||
def response = wiremockStub.response
|
||||
private String convertFromWireMockStub(String wireMockStringStub) {
|
||||
Object wireMockStub = new JsonSlurper().parseText(wireMockStringStub)
|
||||
def request = wireMockStub.request
|
||||
def response = wireMockStub.response
|
||||
def bodyPatterns = request.bodyPatterns
|
||||
String urlPattern = request.urlPattern
|
||||
return """\
|
||||
@@ -146,8 +146,8 @@ class WiremockToDslConverter {
|
||||
if (!it.name.endsWith('json')) {
|
||||
return
|
||||
}
|
||||
String dslFromWiremockStub = fromWiremockStub(it.text)
|
||||
String dslWrappedWithFactoryMethod = wrapWithFactoryMethod(dslFromWiremockStub)
|
||||
String dslFromWireMockStub = fromWireMockStub(it.text)
|
||||
String dslWrappedWithFactoryMethod = wrapWithFactoryMethod(dslFromWireMockStub)
|
||||
File newGroovyFile = new File(it.parent, it.name.replaceAll('json', 'groovy'))
|
||||
println("Creating new groovy file [$newGroovyFile.path]")
|
||||
newGroovyFile.text = dslWrappedWithFactoryMethod
|
||||
@@ -158,10 +158,10 @@ class WiremockToDslConverter {
|
||||
}
|
||||
}
|
||||
|
||||
static String wrapWithFactoryMethod(String dslFromWiremockStub) {
|
||||
static String wrapWithFactoryMethod(String dslFromWireMockStub) {
|
||||
return """\
|
||||
${GroovyDsl.name}.make {
|
||||
$dslFromWiremockStub
|
||||
$dslFromWireMockStub
|
||||
}
|
||||
"""
|
||||
}
|
||||
@@ -3,11 +3,11 @@ package io.codearte.accurest.wiremock
|
||||
import groovy.json.JsonSlurper
|
||||
import spock.lang.Specification
|
||||
|
||||
class DslToWiremockClientConverterSpec extends Specification {
|
||||
class DslToWireMockClientConverterSpec extends Specification {
|
||||
|
||||
def "should convert DSL file to Wiremock JSON"() {
|
||||
def "should convert DSL file to WireMock JSON"() {
|
||||
given:
|
||||
def converter = new DslToWiremockClientConverter()
|
||||
def converter = new DslToWireMockClientConverter()
|
||||
and:
|
||||
String dslBody = """
|
||||
io.codearte.accurest.dsl.GroovyDsl.make {
|
||||
@@ -28,9 +28,9 @@ class DslToWiremockClientConverterSpec extends Specification {
|
||||
}
|
||||
|
||||
|
||||
def "should convert DSL file with a nested list to Wiremock JSON"() {
|
||||
def "should convert DSL file with a nested list to WireMock JSON"() {
|
||||
given:
|
||||
def converter = new DslToWiremockClientConverter()
|
||||
def converter = new DslToWireMockClientConverter()
|
||||
and:
|
||||
String dslBody = """
|
||||
io.codearte.accurest.dsl.GroovyDsl.make {
|
||||
@@ -4,11 +4,11 @@ import com.github.tomakehurst.wiremock.stubbing.StubMapping
|
||||
import io.codearte.accurest.dsl.GroovyDsl
|
||||
import spock.lang.Specification
|
||||
|
||||
class WiremockToDslConverterSpec extends Specification {
|
||||
class WireMockToDslConverterSpec extends Specification {
|
||||
|
||||
def 'should produce a Groovy DSL from Wiremock stub'() {
|
||||
def 'should produce a Groovy DSL from WireMock stub'() {
|
||||
given:
|
||||
String wiremockStub = '''\
|
||||
String wireMockStub = '''\
|
||||
{
|
||||
"request": {
|
||||
"method": "GET",
|
||||
@@ -32,7 +32,7 @@ class WiremockToDslConverterSpec extends Specification {
|
||||
}
|
||||
'''
|
||||
and:
|
||||
stubMappingIsValidWiremockStub(wiremockStub)
|
||||
stubMappingIsValidWireMockStub(wireMockStub)
|
||||
and:
|
||||
GroovyDsl expectedGroovyDsl = GroovyDsl.make {
|
||||
request {
|
||||
@@ -65,7 +65,7 @@ class WiremockToDslConverterSpec extends Specification {
|
||||
}
|
||||
}
|
||||
when:
|
||||
String groovyDsl = WiremockToDslConverter.fromWiremockStub(wiremockStub)
|
||||
String groovyDsl = WireMockToDslConverter.fromWireMockStub(wireMockStub)
|
||||
then:
|
||||
new GroovyShell(this.class.classLoader).evaluate(
|
||||
""" io.codearte.accurest.dsl.GroovyDsl.make {
|
||||
@@ -74,9 +74,9 @@ class WiremockToDslConverterSpec extends Specification {
|
||||
}
|
||||
|
||||
|
||||
def 'should convert Wiremock stub with response body containing simple JSON'() {
|
||||
def 'should convert WireMock stub with response body containing simple JSON'() {
|
||||
given:
|
||||
String wiremockStub = '''\
|
||||
String wireMockStub = '''\
|
||||
{
|
||||
"request": {
|
||||
"method": "DELETE",
|
||||
@@ -97,7 +97,7 @@ class WiremockToDslConverterSpec extends Specification {
|
||||
}
|
||||
'''
|
||||
and:
|
||||
stubMappingIsValidWiremockStub(wiremockStub)
|
||||
stubMappingIsValidWireMockStub(wireMockStub)
|
||||
and:
|
||||
GroovyDsl expectedGroovyDsl = GroovyDsl.make {
|
||||
request {
|
||||
@@ -119,7 +119,7 @@ class WiremockToDslConverterSpec extends Specification {
|
||||
}
|
||||
}
|
||||
when:
|
||||
String groovyDsl = WiremockToDslConverter.fromWiremockStub(wiremockStub)
|
||||
String groovyDsl = WireMockToDslConverter.fromWireMockStub(wireMockStub)
|
||||
then:
|
||||
new GroovyShell(this.class.classLoader).evaluate(
|
||||
""" io.codearte.accurest.dsl.GroovyDsl.make {
|
||||
@@ -127,9 +127,9 @@ class WiremockToDslConverterSpec extends Specification {
|
||||
}""") == expectedGroovyDsl
|
||||
}
|
||||
|
||||
def 'should convert Wiremock stub with response body containing integer'() {
|
||||
def 'should convert WireMock stub with response body containing integer'() {
|
||||
given:
|
||||
String wiremockStub = '''\
|
||||
String wireMockStub = '''\
|
||||
{
|
||||
"request": {
|
||||
"method": "POST",
|
||||
@@ -150,7 +150,7 @@ class WiremockToDslConverterSpec extends Specification {
|
||||
}
|
||||
'''
|
||||
and:
|
||||
stubMappingIsValidWiremockStub(wiremockStub)
|
||||
stubMappingIsValidWireMockStub(wireMockStub)
|
||||
and:
|
||||
GroovyDsl expectedGroovyDsl = GroovyDsl.make {
|
||||
request {
|
||||
@@ -170,7 +170,7 @@ class WiremockToDslConverterSpec extends Specification {
|
||||
}
|
||||
}
|
||||
when:
|
||||
String groovyDsl = WiremockToDslConverter.fromWiremockStub(wiremockStub)
|
||||
String groovyDsl = WireMockToDslConverter.fromWireMockStub(wireMockStub)
|
||||
then:
|
||||
new GroovyShell(this.class.classLoader).evaluate(
|
||||
""" io.codearte.accurest.dsl.GroovyDsl.make {
|
||||
@@ -178,9 +178,9 @@ class WiremockToDslConverterSpec extends Specification {
|
||||
}""") == expectedGroovyDsl
|
||||
}
|
||||
|
||||
def 'should convert Wiremock stub with response body as a list'() {
|
||||
def 'should convert WireMock stub with response body as a list'() {
|
||||
given:
|
||||
String wiremockStub = '''\
|
||||
String wireMockStub = '''\
|
||||
{
|
||||
"request": {
|
||||
"method": "POST",
|
||||
@@ -201,7 +201,7 @@ class WiremockToDslConverterSpec extends Specification {
|
||||
}
|
||||
'''
|
||||
and:
|
||||
stubMappingIsValidWiremockStub(wiremockStub)
|
||||
stubMappingIsValidWireMockStub(wireMockStub)
|
||||
and:
|
||||
GroovyDsl expectedGroovyDsl = GroovyDsl.make {
|
||||
request {
|
||||
@@ -224,7 +224,7 @@ class WiremockToDslConverterSpec extends Specification {
|
||||
}
|
||||
}
|
||||
when:
|
||||
String groovyDsl = WiremockToDslConverter.fromWiremockStub(wiremockStub)
|
||||
String groovyDsl = WireMockToDslConverter.fromWireMockStub(wireMockStub)
|
||||
then:
|
||||
new GroovyShell(this.class.classLoader).evaluate(
|
||||
""" io.codearte.accurest.dsl.GroovyDsl.make {
|
||||
@@ -233,9 +233,9 @@ class WiremockToDslConverterSpec extends Specification {
|
||||
}
|
||||
|
||||
|
||||
def 'should convert Wiremock stub with response body containing a nested list'() {
|
||||
def 'should convert WireMock stub with response body containing a nested list'() {
|
||||
given:
|
||||
String wiremockStub = '''\
|
||||
String wireMockStub = '''\
|
||||
{
|
||||
"request": {
|
||||
"method": "POST",
|
||||
@@ -253,7 +253,7 @@ class WiremockToDslConverterSpec extends Specification {
|
||||
}
|
||||
'''
|
||||
and:
|
||||
stubMappingIsValidWiremockStub(wiremockStub)
|
||||
stubMappingIsValidWireMockStub(wireMockStub)
|
||||
and:
|
||||
GroovyDsl expectedGroovyDsl = GroovyDsl.make {
|
||||
request {
|
||||
@@ -290,7 +290,7 @@ class WiremockToDslConverterSpec extends Specification {
|
||||
}
|
||||
}
|
||||
when:
|
||||
String groovyDsl = WiremockToDslConverter.fromWiremockStub(wiremockStub)
|
||||
String groovyDsl = WireMockToDslConverter.fromWireMockStub(wireMockStub)
|
||||
then:
|
||||
new GroovyShell(this.class.classLoader).evaluate(
|
||||
""" io.codearte.accurest.dsl.GroovyDsl.make {
|
||||
@@ -298,9 +298,9 @@ class WiremockToDslConverterSpec extends Specification {
|
||||
}""") == expectedGroovyDsl
|
||||
}
|
||||
|
||||
def 'should convert Wiremock stub with request body checking equality to Json'() {
|
||||
def 'should convert WireMock stub with request body checking equality to Json'() {
|
||||
given:
|
||||
String wiremockStub = '''\
|
||||
String wireMockStub = '''\
|
||||
{
|
||||
"request": {
|
||||
"method": "POST",
|
||||
@@ -315,7 +315,7 @@ class WiremockToDslConverterSpec extends Specification {
|
||||
}
|
||||
'''
|
||||
and:
|
||||
stubMappingIsValidWiremockStub(wiremockStub)
|
||||
stubMappingIsValidWireMockStub(wireMockStub)
|
||||
and:
|
||||
GroovyDsl expectedGroovyDsl = GroovyDsl.make {
|
||||
request {
|
||||
@@ -328,7 +328,7 @@ class WiremockToDslConverterSpec extends Specification {
|
||||
}
|
||||
}
|
||||
when:
|
||||
String groovyDsl = WiremockToDslConverter.fromWiremockStub(wiremockStub)
|
||||
String groovyDsl = WireMockToDslConverter.fromWireMockStub(wireMockStub)
|
||||
then:
|
||||
GroovyDsl evaluatedGroovyDsl = new GroovyShell(this.class.classLoader).evaluate(
|
||||
""" io.codearte.accurest.dsl.GroovyDsl.make {
|
||||
@@ -338,9 +338,9 @@ class WiremockToDslConverterSpec extends Specification {
|
||||
evaluatedGroovyDsl == expectedGroovyDsl
|
||||
}
|
||||
|
||||
def 'should convert Wiremock stub with request body checking matching to Json'() {
|
||||
def 'should convert WireMock stub with request body checking matching to Json'() {
|
||||
given:
|
||||
String wiremockStub = '''\
|
||||
String wireMockStub = '''\
|
||||
{
|
||||
"request": {
|
||||
"method": "POST",
|
||||
@@ -355,7 +355,7 @@ class WiremockToDslConverterSpec extends Specification {
|
||||
}
|
||||
'''
|
||||
and:
|
||||
stubMappingIsValidWiremockStub(wiremockStub)
|
||||
stubMappingIsValidWireMockStub(wireMockStub)
|
||||
and:
|
||||
GroovyDsl expectedGroovyDsl = GroovyDsl.make {
|
||||
request {
|
||||
@@ -368,7 +368,7 @@ class WiremockToDslConverterSpec extends Specification {
|
||||
}
|
||||
}
|
||||
when:
|
||||
String groovyDsl = WiremockToDslConverter.fromWiremockStub(wiremockStub)
|
||||
String groovyDsl = WireMockToDslConverter.fromWireMockStub(wireMockStub)
|
||||
then:
|
||||
GroovyDsl evaluatedGroovyDsl = new GroovyShell(this.class.classLoader).evaluate(
|
||||
""" io.codearte.accurest.dsl.GroovyDsl.make {
|
||||
@@ -378,9 +378,9 @@ class WiremockToDslConverterSpec extends Specification {
|
||||
evaluatedGroovyDsl == expectedGroovyDsl
|
||||
}
|
||||
|
||||
def 'should convert Wiremock stub with request body with equalToJson'() {
|
||||
def 'should convert WireMock stub with request body with equalToJson'() {
|
||||
given:
|
||||
String wiremockStub = '''\
|
||||
String wireMockStub = '''\
|
||||
{
|
||||
"request" : {
|
||||
"url" : "/test",
|
||||
@@ -396,7 +396,7 @@ class WiremockToDslConverterSpec extends Specification {
|
||||
}
|
||||
'''
|
||||
and:
|
||||
stubMappingIsValidWiremockStub(wiremockStub)
|
||||
stubMappingIsValidWireMockStub(wireMockStub)
|
||||
and:
|
||||
GroovyDsl expectedGroovyDsl = GroovyDsl.make {
|
||||
request {
|
||||
@@ -409,7 +409,7 @@ class WiremockToDslConverterSpec extends Specification {
|
||||
}
|
||||
}
|
||||
when:
|
||||
String groovyDsl = WiremockToDslConverter.fromWiremockStub(wiremockStub)
|
||||
String groovyDsl = WireMockToDslConverter.fromWireMockStub(wireMockStub)
|
||||
then:
|
||||
GroovyDsl evaluatedGroovyDsl = new GroovyShell(this.class.classLoader).evaluate(
|
||||
""" io.codearte.accurest.dsl.GroovyDsl.make {
|
||||
@@ -419,9 +419,9 @@ class WiremockToDslConverterSpec extends Specification {
|
||||
evaluatedGroovyDsl == expectedGroovyDsl
|
||||
}
|
||||
|
||||
def 'should convert Wiremock stub with request body with equalTo'() {
|
||||
def 'should convert WireMock stub with request body with equalTo'() {
|
||||
given:
|
||||
String wiremockStub = '''\
|
||||
String wireMockStub = '''\
|
||||
{
|
||||
"request" : {
|
||||
"url" : "/test",
|
||||
@@ -436,7 +436,7 @@ class WiremockToDslConverterSpec extends Specification {
|
||||
}
|
||||
'''
|
||||
and:
|
||||
stubMappingIsValidWiremockStub(wiremockStub)
|
||||
stubMappingIsValidWireMockStub(wireMockStub)
|
||||
and:
|
||||
GroovyDsl expectedGroovyDsl = GroovyDsl.make {
|
||||
request {
|
||||
@@ -449,7 +449,7 @@ class WiremockToDslConverterSpec extends Specification {
|
||||
}
|
||||
}
|
||||
when:
|
||||
String groovyDsl = WiremockToDslConverter.fromWiremockStub(wiremockStub)
|
||||
String groovyDsl = WireMockToDslConverter.fromWireMockStub(wireMockStub)
|
||||
then:
|
||||
GroovyDsl evaluatedGroovyDsl = new GroovyShell(this.class.classLoader).evaluate(
|
||||
""" io.codearte.accurest.dsl.GroovyDsl.make {
|
||||
@@ -459,9 +459,9 @@ class WiremockToDslConverterSpec extends Specification {
|
||||
evaluatedGroovyDsl == expectedGroovyDsl
|
||||
}
|
||||
|
||||
def 'should convert Wiremock stub with request body with matches'() {
|
||||
def 'should convert WireMock stub with request body with matches'() {
|
||||
given:
|
||||
String wiremockStub = '''\
|
||||
String wireMockStub = '''\
|
||||
{
|
||||
"request" : {
|
||||
"url" : "/test",
|
||||
@@ -476,7 +476,7 @@ class WiremockToDslConverterSpec extends Specification {
|
||||
}
|
||||
'''
|
||||
and:
|
||||
stubMappingIsValidWiremockStub(wiremockStub)
|
||||
stubMappingIsValidWireMockStub(wireMockStub)
|
||||
and:
|
||||
GroovyDsl expectedGroovyDsl = GroovyDsl.make {
|
||||
request {
|
||||
@@ -489,7 +489,7 @@ class WiremockToDslConverterSpec extends Specification {
|
||||
}
|
||||
}
|
||||
when:
|
||||
String groovyDsl = WiremockToDslConverter.fromWiremockStub(wiremockStub)
|
||||
String groovyDsl = WireMockToDslConverter.fromWireMockStub(wireMockStub)
|
||||
then:
|
||||
GroovyDsl evaluatedGroovyDsl = new GroovyShell(this.class.classLoader).evaluate(
|
||||
""" io.codearte.accurest.dsl.GroovyDsl.make {
|
||||
@@ -499,7 +499,7 @@ class WiremockToDslConverterSpec extends Specification {
|
||||
evaluatedGroovyDsl == expectedGroovyDsl
|
||||
}
|
||||
|
||||
void stubMappingIsValidWiremockStub(String mappingDefinition) {
|
||||
void stubMappingIsValidWireMockStub(String mappingDefinition) {
|
||||
StubMapping.buildFrom(mappingDefinition)
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ class AccurestConfigProperties {
|
||||
File generatedTestSourcesDir
|
||||
|
||||
/**
|
||||
* Dir where the generated Wiremock stubs from Groovy DSL should be placed.
|
||||
* Dir where the generated WireMock stubs from Groovy DSL should be placed.
|
||||
* You can then mention them in your packaging task to create jar with stubs
|
||||
*/
|
||||
File stubsOutputDir
|
||||
|
||||
@@ -13,7 +13,7 @@ import static io.codearte.accurest.util.ContentUtils.extractValue
|
||||
import static io.codearte.accurest.util.JsonConverter.transformValues
|
||||
|
||||
@TypeChecked
|
||||
abstract class BaseWiremockStubStrategy {
|
||||
abstract class BaseWireMockStubStrategy {
|
||||
|
||||
private static Closure transform = {
|
||||
it instanceof DslProperty ? transformValues(it.clientValue, transform) : it
|
||||
@@ -21,11 +21,11 @@ import static io.codearte.accurest.util.RegexpBuilders.buildJSONRegexpMatch
|
||||
|
||||
@TypeChecked
|
||||
@PackageScope
|
||||
class WiremockRequestStubStrategy extends BaseWiremockStubStrategy {
|
||||
class WireMockRequestStubStrategy extends BaseWireMockStubStrategy {
|
||||
|
||||
private final Request request
|
||||
|
||||
WiremockRequestStubStrategy(GroovyDsl groovyDsl) {
|
||||
WireMockRequestStubStrategy(GroovyDsl groovyDsl) {
|
||||
this.request = groovyDsl.request
|
||||
}
|
||||
|
||||
@@ -11,12 +11,12 @@ import static io.codearte.accurest.util.ContentUtils.recognizeContentTypeFromHea
|
||||
|
||||
@TypeChecked
|
||||
@PackageScope
|
||||
class WiremockResponseStubStrategy extends BaseWiremockStubStrategy {
|
||||
class WireMockResponseStubStrategy extends BaseWireMockStubStrategy {
|
||||
|
||||
private final Request request
|
||||
private final Response response
|
||||
|
||||
WiremockResponseStubStrategy(GroovyDsl groovyDsl) {
|
||||
WireMockResponseStubStrategy(GroovyDsl groovyDsl) {
|
||||
this.response = groovyDsl.response
|
||||
this.request = groovyDsl.request
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package io.codearte.accurest.dsl
|
||||
|
||||
import groovy.json.JsonOutput
|
||||
import groovy.transform.CompileStatic
|
||||
|
||||
@CompileStatic
|
||||
class WireMockStubStrategy {
|
||||
|
||||
private final WireMockRequestStubStrategy wireMockRequestStubStrategy
|
||||
private final WireMockResponseStubStrategy wireMockResponseStubStrategy
|
||||
|
||||
WireMockStubStrategy(GroovyDsl groovyDsl) {
|
||||
this.wireMockRequestStubStrategy = new WireMockRequestStubStrategy(groovyDsl)
|
||||
this.wireMockResponseStubStrategy = new WireMockResponseStubStrategy(groovyDsl)
|
||||
}
|
||||
|
||||
String toWireMockClientStub() {
|
||||
return JsonOutput.prettyPrint(JsonOutput.toJson([request : wireMockRequestStubStrategy.buildClientRequestContent(),
|
||||
response: wireMockResponseStubStrategy.buildClientResponseContent()]))
|
||||
}
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
package io.codearte.accurest.dsl
|
||||
|
||||
import groovy.json.JsonOutput
|
||||
import groovy.transform.CompileStatic
|
||||
|
||||
@CompileStatic
|
||||
class WiremockStubStrategy {
|
||||
|
||||
private final WiremockRequestStubStrategy wiremockRequestStubStrategy
|
||||
private final WiremockResponseStubStrategy wiremockResponseStubStrategy
|
||||
|
||||
WiremockStubStrategy(GroovyDsl groovyDsl) {
|
||||
this.wiremockRequestStubStrategy = new WiremockRequestStubStrategy(groovyDsl)
|
||||
this.wiremockResponseStubStrategy = new WiremockResponseStubStrategy(groovyDsl)
|
||||
}
|
||||
|
||||
String toWiremockClientStub() {
|
||||
return JsonOutput.prettyPrint(JsonOutput.toJson([request : wiremockRequestStubStrategy.buildClientRequestContent(),
|
||||
response: wiremockResponseStubStrategy.buildClientResponseContent()]))
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,7 @@ package io.codearte.accurest.dsl
|
||||
import groovy.json.JsonSlurper
|
||||
import spock.lang.Specification
|
||||
|
||||
class WiremockGroovyDslResponseSpec extends Specification {
|
||||
class WireMockGroovyDslResponseSpec extends Specification {
|
||||
|
||||
def 'should generate response without body for client side'() {
|
||||
given:
|
||||
@@ -13,7 +13,7 @@ class WiremockGroovyDslResponseSpec extends Specification {
|
||||
}
|
||||
}
|
||||
expect:
|
||||
new WiremockResponseStubStrategy(dsl).buildClientResponseContent() == new JsonSlurper().parseText(expectedStub)
|
||||
new WireMockResponseStubStrategy(dsl).buildClientResponseContent() == new JsonSlurper().parseText(expectedStub)
|
||||
where:
|
||||
expectedStub << ['''
|
||||
{
|
||||
@@ -39,7 +39,7 @@ class WiremockGroovyDslResponseSpec extends Specification {
|
||||
}
|
||||
}
|
||||
expect:
|
||||
new WiremockResponseStubStrategy(dsl).buildClientResponseContent() == new JsonSlurper().parseText('''
|
||||
new WireMockResponseStubStrategy(dsl).buildClientResponseContent() == new JsonSlurper().parseText('''
|
||||
{
|
||||
"headers": {
|
||||
"Content-Type": "text/xml"
|
||||
@@ -4,9 +4,9 @@ import groovy.json.JsonBuilder
|
||||
import groovy.json.JsonSlurper
|
||||
import spock.lang.Issue
|
||||
|
||||
class WiremockGroovyDslSpec extends WiremockSpec {
|
||||
class WireMockGroovyDslSpec extends WireMockSpec {
|
||||
|
||||
def 'should convert groovy dsl stub to wiremock stub for the client side'() {
|
||||
def 'should convert groovy dsl stub to wireMock stub for the client side'() {
|
||||
given:
|
||||
GroovyDsl groovyDsl = GroovyDsl.make {
|
||||
request {
|
||||
@@ -33,9 +33,9 @@ class WiremockGroovyDslSpec extends WiremockSpec {
|
||||
}
|
||||
}
|
||||
when:
|
||||
String wiremockStub = new WiremockStubStrategy(groovyDsl).toWiremockClientStub()
|
||||
String wireMockStub = new WireMockStubStrategy(groovyDsl).toWireMockClientStub()
|
||||
then:
|
||||
new JsonSlurper().parseText(wiremockStub) == new JsonSlurper().parseText('''
|
||||
new JsonSlurper().parseText(wireMockStub) == new JsonSlurper().parseText('''
|
||||
{
|
||||
"request": {
|
||||
"method": "GET",
|
||||
@@ -51,11 +51,11 @@ class WiremockGroovyDslSpec extends WiremockSpec {
|
||||
}
|
||||
''')
|
||||
and:
|
||||
stubMappingIsValidWiremockStub(wiremockStub)
|
||||
stubMappingIsValidWireMockStub(wireMockStub)
|
||||
}
|
||||
|
||||
@Issue("#79")
|
||||
def 'should convert groovy dsl stub to wiremock stub for the client side with a body containing a map'() {
|
||||
def 'should convert groovy dsl stub to wireMock stub for the client side with a body containing a map'() {
|
||||
given:
|
||||
GroovyDsl groovyDsl = GroovyDsl.make {
|
||||
request {
|
||||
@@ -78,9 +78,9 @@ class WiremockGroovyDslSpec extends WiremockSpec {
|
||||
}
|
||||
}
|
||||
when:
|
||||
String wiremockStub = new WiremockStubStrategy(groovyDsl).toWiremockClientStub()
|
||||
String wireMockStub = new WireMockStubStrategy(groovyDsl).toWireMockClientStub()
|
||||
then:
|
||||
new JsonSlurper().parseText(wiremockStub) == new JsonSlurper().parseText('''
|
||||
new JsonSlurper().parseText(wireMockStub) == new JsonSlurper().parseText('''
|
||||
{
|
||||
"request": {
|
||||
"method": "GET",
|
||||
@@ -98,7 +98,7 @@ class WiremockGroovyDslSpec extends WiremockSpec {
|
||||
}
|
||||
''')
|
||||
and:
|
||||
stubMappingIsValidWiremockStub(wiremockStub)
|
||||
stubMappingIsValidWireMockStub(wireMockStub)
|
||||
}
|
||||
|
||||
@Issue("#86")
|
||||
@@ -122,9 +122,9 @@ class WiremockGroovyDslSpec extends WiremockSpec {
|
||||
}
|
||||
}
|
||||
when:
|
||||
String wiremockStub = new WiremockStubStrategy(groovyDsl).toWiremockClientStub()
|
||||
String wireMockStub = new WireMockStubStrategy(groovyDsl).toWireMockClientStub()
|
||||
then:
|
||||
new JsonSlurper().parseText(wiremockStub) == new JsonSlurper().parseText('''
|
||||
new JsonSlurper().parseText(wireMockStub) == new JsonSlurper().parseText('''
|
||||
{
|
||||
"request": {
|
||||
"method": "POST",
|
||||
@@ -147,10 +147,10 @@ class WiremockGroovyDslSpec extends WiremockSpec {
|
||||
}
|
||||
''')
|
||||
and:
|
||||
stubMappingIsValidWiremockStub(wiremockStub)
|
||||
stubMappingIsValidWireMockStub(wireMockStub)
|
||||
}
|
||||
|
||||
def 'should convert groovy dsl stub with Body as String to wiremock stub for the client side'() {
|
||||
def 'should convert groovy dsl stub with Body as String to wireMock stub for the client side'() {
|
||||
given:
|
||||
GroovyDsl groovyDsl = GroovyDsl.make {
|
||||
request {
|
||||
@@ -174,9 +174,9 @@ class WiremockGroovyDslSpec extends WiremockSpec {
|
||||
}
|
||||
}
|
||||
when:
|
||||
String wiremockStub = new WiremockStubStrategy(groovyDsl).toWiremockClientStub()
|
||||
String wireMockStub = new WireMockStubStrategy(groovyDsl).toWireMockClientStub()
|
||||
then:
|
||||
new JsonSlurper().parseText(wiremockStub) == new JsonSlurper().parseText('''
|
||||
new JsonSlurper().parseText(wireMockStub) == new JsonSlurper().parseText('''
|
||||
{
|
||||
"request": {
|
||||
"method": "GET",
|
||||
@@ -192,10 +192,10 @@ class WiremockGroovyDslSpec extends WiremockSpec {
|
||||
}
|
||||
''')
|
||||
and:
|
||||
stubMappingIsValidWiremockStub(wiremockStub)
|
||||
stubMappingIsValidWireMockStub(wireMockStub)
|
||||
}
|
||||
|
||||
def 'should convert groovy dsl stub with simple Body as String to wiremock stub for the client side'() {
|
||||
def 'should convert groovy dsl stub with simple Body as String to wireMock stub for the client side'() {
|
||||
given:
|
||||
GroovyDsl groovyDsl = GroovyDsl.make {
|
||||
request {
|
||||
@@ -221,9 +221,9 @@ class WiremockGroovyDslSpec extends WiremockSpec {
|
||||
}
|
||||
}
|
||||
when:
|
||||
String wiremockStub = new WiremockStubStrategy(groovyDsl).toWiremockClientStub()
|
||||
String wireMockStub = new WireMockStubStrategy(groovyDsl).toWireMockClientStub()
|
||||
then:
|
||||
new JsonSlurper().parseText(wiremockStub) == new JsonSlurper().parseText('''
|
||||
new JsonSlurper().parseText(wireMockStub) == new JsonSlurper().parseText('''
|
||||
{
|
||||
"request": {
|
||||
"method": "GET",
|
||||
@@ -244,7 +244,7 @@ class WiremockGroovyDslSpec extends WiremockSpec {
|
||||
}
|
||||
''')
|
||||
and:
|
||||
stubMappingIsValidWiremockStub(wiremockStub)
|
||||
stubMappingIsValidWireMockStub(wireMockStub)
|
||||
}
|
||||
|
||||
def 'should use equalToJson when body match is defined as map'() {
|
||||
@@ -271,9 +271,9 @@ class WiremockGroovyDslSpec extends WiremockSpec {
|
||||
}
|
||||
}
|
||||
when:
|
||||
String wiremockStub = new WiremockStubStrategy(groovyDsl).toWiremockClientStub()
|
||||
String wireMockStub = new WireMockStubStrategy(groovyDsl).toWireMockClientStub()
|
||||
then:
|
||||
new JsonSlurper().parseText(wiremockStub) == new JsonSlurper().parseText('''
|
||||
new JsonSlurper().parseText(wireMockStub) == new JsonSlurper().parseText('''
|
||||
{
|
||||
"request": {
|
||||
"method": "GET",
|
||||
@@ -290,7 +290,7 @@ class WiremockGroovyDslSpec extends WiremockSpec {
|
||||
}
|
||||
''')
|
||||
and:
|
||||
stubMappingIsValidWiremockStub(wiremockStub)
|
||||
stubMappingIsValidWireMockStub(wireMockStub)
|
||||
}
|
||||
|
||||
def 'should use equalToJson when content type ends with json'() {
|
||||
@@ -313,7 +313,7 @@ class WiremockGroovyDslSpec extends WiremockSpec {
|
||||
}
|
||||
}
|
||||
when:
|
||||
String json = toWiremockClientJsonStub(groovyDsl)
|
||||
String json = toWireMockClientJsonStub(groovyDsl)
|
||||
then:
|
||||
parseJson(json) == parseJson('''
|
||||
{
|
||||
@@ -337,7 +337,7 @@ class WiremockGroovyDslSpec extends WiremockSpec {
|
||||
}
|
||||
''')
|
||||
and:
|
||||
stubMappingIsValidWiremockStub(json)
|
||||
stubMappingIsValidWireMockStub(json)
|
||||
}
|
||||
|
||||
def 'should use equalToXml when content type ends with xml'() {
|
||||
@@ -356,7 +356,7 @@ class WiremockGroovyDslSpec extends WiremockSpec {
|
||||
}
|
||||
}
|
||||
when:
|
||||
String json = toWiremockClientJsonStub(groovyDsl)
|
||||
String json = toWireMockClientJsonStub(groovyDsl)
|
||||
then:
|
||||
parseJson(json) == parseJson('''
|
||||
{
|
||||
@@ -380,7 +380,7 @@ class WiremockGroovyDslSpec extends WiremockSpec {
|
||||
}
|
||||
''')
|
||||
and:
|
||||
stubMappingIsValidWiremockStub(json)
|
||||
stubMappingIsValidWireMockStub(json)
|
||||
}
|
||||
|
||||
def 'should use equalToXml when content type is parsable xml'() {
|
||||
@@ -396,7 +396,7 @@ class WiremockGroovyDslSpec extends WiremockSpec {
|
||||
}
|
||||
}
|
||||
when:
|
||||
String json = toWiremockClientJsonStub(groovyDsl)
|
||||
String json = toWireMockClientJsonStub(groovyDsl)
|
||||
then:
|
||||
parseJson(json) == parseJson('''
|
||||
{
|
||||
@@ -415,7 +415,7 @@ class WiremockGroovyDslSpec extends WiremockSpec {
|
||||
}
|
||||
''')
|
||||
and:
|
||||
stubMappingIsValidWiremockStub(json)
|
||||
stubMappingIsValidWireMockStub(json)
|
||||
}
|
||||
|
||||
def 'should support xml as a response body'() {
|
||||
@@ -431,7 +431,7 @@ class WiremockGroovyDslSpec extends WiremockSpec {
|
||||
}
|
||||
}
|
||||
when:
|
||||
String json = toWiremockClientJsonStub(groovyDsl)
|
||||
String json = toWireMockClientJsonStub(groovyDsl)
|
||||
then:
|
||||
parseJson(json) == parseJson('''
|
||||
{
|
||||
@@ -446,7 +446,7 @@ class WiremockGroovyDslSpec extends WiremockSpec {
|
||||
}
|
||||
''')
|
||||
and:
|
||||
stubMappingIsValidWiremockStub(json)
|
||||
stubMappingIsValidWireMockStub(json)
|
||||
}
|
||||
|
||||
def 'should use equalToJson'() {
|
||||
@@ -462,7 +462,7 @@ class WiremockGroovyDslSpec extends WiremockSpec {
|
||||
}
|
||||
}
|
||||
when:
|
||||
String json = toWiremockClientJsonStub(groovyDsl)
|
||||
String json = toWireMockClientJsonStub(groovyDsl)
|
||||
then:
|
||||
parseJson(json) == parseJson('''
|
||||
{
|
||||
@@ -481,7 +481,7 @@ class WiremockGroovyDslSpec extends WiremockSpec {
|
||||
}
|
||||
''')
|
||||
and:
|
||||
stubMappingIsValidWiremockStub(json)
|
||||
stubMappingIsValidWireMockStub(json)
|
||||
}
|
||||
|
||||
def 'should use equalToXml'() {
|
||||
@@ -497,7 +497,7 @@ class WiremockGroovyDslSpec extends WiremockSpec {
|
||||
}
|
||||
}
|
||||
when:
|
||||
String json = toWiremockClientJsonStub(groovyDsl)
|
||||
String json = toWireMockClientJsonStub(groovyDsl)
|
||||
then:
|
||||
parseJson(json) == parseJson('''
|
||||
{
|
||||
@@ -516,10 +516,10 @@ class WiremockGroovyDslSpec extends WiremockSpec {
|
||||
}
|
||||
''')
|
||||
and:
|
||||
stubMappingIsValidWiremockStub(json)
|
||||
stubMappingIsValidWireMockStub(json)
|
||||
}
|
||||
|
||||
def 'should convert groovy dsl stub with regexp Body as String to wiremock stub for the client side'() {
|
||||
def 'should convert groovy dsl stub with regexp Body as String to wireMock stub for the client side'() {
|
||||
given:
|
||||
GroovyDsl groovyDsl = GroovyDsl.make {
|
||||
request {
|
||||
@@ -545,9 +545,9 @@ class WiremockGroovyDslSpec extends WiremockSpec {
|
||||
}
|
||||
}
|
||||
when:
|
||||
String wiremockStub = new WiremockStubStrategy(groovyDsl).toWiremockClientStub()
|
||||
String wireMockStub = new WireMockStubStrategy(groovyDsl).toWireMockClientStub()
|
||||
then:
|
||||
new JsonSlurper().parseText(wiremockStub) == new JsonSlurper().parseText('''
|
||||
new JsonSlurper().parseText(wireMockStub) == new JsonSlurper().parseText('''
|
||||
{
|
||||
"request": {
|
||||
"method": "GET",
|
||||
@@ -566,7 +566,7 @@ class WiremockGroovyDslSpec extends WiremockSpec {
|
||||
}
|
||||
''')
|
||||
and:
|
||||
stubMappingIsValidWiremockStub(wiremockStub)
|
||||
stubMappingIsValidWireMockStub(wireMockStub)
|
||||
}
|
||||
|
||||
def 'should convert groovy dsl stub with a regexp and an integer in request body'() {
|
||||
@@ -600,9 +600,9 @@ class WiremockGroovyDslSpec extends WiremockSpec {
|
||||
|
||||
}
|
||||
when:
|
||||
String wiremockStub = new WiremockStubStrategy(groovyDsl).toWiremockClientStub()
|
||||
String wireMockStub = new WireMockStubStrategy(groovyDsl).toWireMockClientStub()
|
||||
then:
|
||||
new JsonSlurper().parseText(wiremockStub) == new JsonSlurper().parseText('''
|
||||
new JsonSlurper().parseText(wireMockStub) == new JsonSlurper().parseText('''
|
||||
{
|
||||
"request": {
|
||||
"method": "PUT",
|
||||
@@ -626,7 +626,7 @@ class WiremockGroovyDslSpec extends WiremockSpec {
|
||||
}
|
||||
''')
|
||||
and:
|
||||
stubMappingIsValidWiremockStub(wiremockStub)
|
||||
stubMappingIsValidWireMockStub(wireMockStub)
|
||||
}
|
||||
|
||||
|
||||
@@ -638,7 +638,7 @@ class WiremockGroovyDslSpec extends WiremockSpec {
|
||||
}
|
||||
}
|
||||
expect:
|
||||
new WiremockRequestStubStrategy(groovyDsl).buildClientRequestContent() == new JsonSlurper().parseText('''
|
||||
new WireMockRequestStubStrategy(groovyDsl).buildClientRequestContent() == new JsonSlurper().parseText('''
|
||||
{
|
||||
"method":"GET"
|
||||
}
|
||||
@@ -654,7 +654,7 @@ class WiremockGroovyDslSpec extends WiremockSpec {
|
||||
}
|
||||
}
|
||||
expect:
|
||||
new WiremockRequestStubStrategy(groovyDsl).buildClientRequestContent() == new JsonSlurper().parseText('''
|
||||
new WireMockRequestStubStrategy(groovyDsl).buildClientRequestContent() == new JsonSlurper().parseText('''
|
||||
{
|
||||
"method":"GET",
|
||||
"url":"/sth"
|
||||
@@ -673,7 +673,7 @@ class WiremockGroovyDslSpec extends WiremockSpec {
|
||||
}
|
||||
}
|
||||
expect:
|
||||
new WiremockRequestStubStrategy(groovyDsl).buildClientRequestContent() == new JsonSlurper().parseText('''
|
||||
new WireMockRequestStubStrategy(groovyDsl).buildClientRequestContent() == new JsonSlurper().parseText('''
|
||||
{
|
||||
"urlPattern":"^/[0-9]{2}$"
|
||||
}
|
||||
@@ -703,7 +703,7 @@ class WiremockGroovyDslSpec extends WiremockSpec {
|
||||
}
|
||||
}
|
||||
when:
|
||||
def json = toWiremockClientJsonStub(groovyDsl)
|
||||
def json = toWireMockClientJsonStub(groovyDsl)
|
||||
then:
|
||||
parseJson(json) == parseJson('''
|
||||
{
|
||||
@@ -743,7 +743,7 @@ class WiremockGroovyDslSpec extends WiremockSpec {
|
||||
}
|
||||
''')
|
||||
and:
|
||||
stubMappingIsValidWiremockStub(json)
|
||||
stubMappingIsValidWireMockStub(json)
|
||||
}
|
||||
|
||||
def "should generate request with urlPath for client side"() {
|
||||
@@ -758,7 +758,7 @@ class WiremockGroovyDslSpec extends WiremockSpec {
|
||||
}
|
||||
}
|
||||
when:
|
||||
def json = toWiremockClientJsonStub(groovyDsl)
|
||||
def json = toWireMockClientJsonStub(groovyDsl)
|
||||
then:
|
||||
parseJson(json) == parseJson('''
|
||||
{
|
||||
@@ -772,7 +772,7 @@ class WiremockGroovyDslSpec extends WiremockSpec {
|
||||
}
|
||||
''')
|
||||
and:
|
||||
stubMappingIsValidWiremockStub(json)
|
||||
stubMappingIsValidWireMockStub(json)
|
||||
}
|
||||
|
||||
def "should generate simple request with urlPath for client side"() {
|
||||
@@ -787,7 +787,7 @@ class WiremockGroovyDslSpec extends WiremockSpec {
|
||||
}
|
||||
}
|
||||
when:
|
||||
def json = toWiremockClientJsonStub(groovyDsl)
|
||||
def json = toWireMockClientJsonStub(groovyDsl)
|
||||
then:
|
||||
parseJson(json) == parseJson('''
|
||||
{
|
||||
@@ -801,7 +801,7 @@ class WiremockGroovyDslSpec extends WiremockSpec {
|
||||
}
|
||||
''')
|
||||
and:
|
||||
stubMappingIsValidWiremockStub(json)
|
||||
stubMappingIsValidWireMockStub(json)
|
||||
}
|
||||
|
||||
def "should not allow regexp in url for server value"() {
|
||||
@@ -933,7 +933,7 @@ class WiremockGroovyDslSpec extends WiremockSpec {
|
||||
}
|
||||
}
|
||||
when:
|
||||
def json = toWiremockClientJsonStub(groovyDsl)
|
||||
def json = toWireMockClientJsonStub(groovyDsl)
|
||||
then:
|
||||
parseJson(json) == parseJson('''
|
||||
{
|
||||
@@ -955,7 +955,7 @@ class WiremockGroovyDslSpec extends WiremockSpec {
|
||||
}
|
||||
''')
|
||||
and:
|
||||
stubMappingIsValidWiremockStub(json)
|
||||
stubMappingIsValidWireMockStub(json)
|
||||
}
|
||||
|
||||
def "should generate stub with some headers section for client side"() {
|
||||
@@ -976,7 +976,7 @@ class WiremockGroovyDslSpec extends WiremockSpec {
|
||||
}
|
||||
}
|
||||
expect:
|
||||
new WiremockRequestStubStrategy(groovyDsl).buildClientRequestContent() == new JsonSlurper().parseText('''
|
||||
new WireMockRequestStubStrategy(groovyDsl).buildClientRequestContent() == new JsonSlurper().parseText('''
|
||||
{
|
||||
"headers": {
|
||||
"Content-Type": {
|
||||
@@ -993,7 +993,7 @@ class WiremockGroovyDslSpec extends WiremockSpec {
|
||||
''')
|
||||
}
|
||||
|
||||
def 'should convert groovy dsl stub with rich tree Body as String to wiremock stub for the client side'() {
|
||||
def 'should convert groovy dsl stub with rich tree Body as String to wireMock stub for the client side'() {
|
||||
given:
|
||||
GroovyDsl groovyDsl = GroovyDsl.make {
|
||||
request {
|
||||
@@ -1032,9 +1032,9 @@ class WiremockGroovyDslSpec extends WiremockSpec {
|
||||
}
|
||||
}
|
||||
when:
|
||||
String wiremockStub = new WiremockStubStrategy(groovyDsl).toWiremockClientStub()
|
||||
String wireMockStub = new WireMockStubStrategy(groovyDsl).toWireMockClientStub()
|
||||
then:
|
||||
new JsonSlurper().parseText(wiremockStub) == new JsonSlurper().parseText('''
|
||||
new JsonSlurper().parseText(wireMockStub) == new JsonSlurper().parseText('''
|
||||
{
|
||||
"request": {
|
||||
"method": "GET",
|
||||
@@ -1083,7 +1083,7 @@ class WiremockGroovyDslSpec extends WiremockSpec {
|
||||
}
|
||||
}
|
||||
when:
|
||||
def json = toWiremockClientJsonStub(groovyDsl)
|
||||
def json = toWireMockClientJsonStub(groovyDsl)
|
||||
then:
|
||||
parseJson(json) == parseJson('''
|
||||
{
|
||||
@@ -1115,7 +1115,7 @@ class WiremockGroovyDslSpec extends WiremockSpec {
|
||||
new JsonSlurper().parseText(json)
|
||||
}
|
||||
|
||||
String toWiremockClientJsonStub(groovyDsl) {
|
||||
new WiremockStubStrategy(groovyDsl).toWiremockClientStub()
|
||||
String toWireMockClientJsonStub(groovyDsl) {
|
||||
new WireMockStubStrategy(groovyDsl).toWireMockClientStub()
|
||||
}
|
||||
}
|
||||
@@ -5,9 +5,9 @@ import spock.lang.Specification
|
||||
|
||||
import java.util.regex.Pattern
|
||||
|
||||
abstract class WiremockSpec extends Specification {
|
||||
abstract class WireMockSpec extends Specification {
|
||||
|
||||
void stubMappingIsValidWiremockStub(String mappingDefinition) {
|
||||
void stubMappingIsValidWireMockStub(String mappingDefinition) {
|
||||
StubMapping stubMapping = StubMapping.buildFrom(mappingDefinition)
|
||||
stubMapping.request.bodyPatterns.findAll { it.matches }.every {
|
||||
Pattern.compile(it.matches)
|
||||
@@ -11,7 +11,7 @@ import org.gradle.api.Task
|
||||
class AccurestGradlePlugin implements Plugin<Project> {
|
||||
|
||||
private static final String GENERATE_SERVER_TESTS_TASK_NAME = 'generateAccurest'
|
||||
private static final String DSL_TO_WIREMOCK_CLIENT_TASK_NAME = 'generateWiremockClientStubs'
|
||||
private static final String DSL_TO_WIREMOCK_CLIENT_TASK_NAME = 'generateWireMockClientStubs'
|
||||
|
||||
private static final Class IDEA_PLUGIN_CLASS = org.gradle.plugins.ide.idea.IdeaPlugin
|
||||
private static final String GROUP_NAME = "Verification"
|
||||
@@ -27,7 +27,8 @@ class AccurestGradlePlugin implements Plugin<Project> {
|
||||
|
||||
setConfigurationDefaults(extension)
|
||||
createGenerateTestsTask(extension)
|
||||
createAndConfigureGenerateWiremockClientStubsFromDslTask(extension)
|
||||
createAndConfigureGenerateWireMockClientStubsFromDslTask(extension)
|
||||
deprecatedCreateAndConfigureGenerateWiremockClientStubsFromDslTask()
|
||||
|
||||
project.afterEvaluate {
|
||||
def hasIdea = project.plugins.findPlugin(IDEA_PLUGIN_CLASS)
|
||||
@@ -60,13 +61,21 @@ class AccurestGradlePlugin implements Plugin<Project> {
|
||||
}
|
||||
}
|
||||
|
||||
private void createAndConfigureGenerateWiremockClientStubsFromDslTask(AccurestConfigProperties extension) {
|
||||
Task task = project.tasks.create(DSL_TO_WIREMOCK_CLIENT_TASK_NAME, GenerateWiremockClientStubsFromDslTask)
|
||||
task.description = "Generate Wiremock client stubs from GroovyDSL"
|
||||
private void createAndConfigureGenerateWireMockClientStubsFromDslTask(AccurestConfigProperties extension) {
|
||||
Task task = project.tasks.create(DSL_TO_WIREMOCK_CLIENT_TASK_NAME, GenerateWireMockClientStubsFromDslTask)
|
||||
task.description = "Generate WireMock client stubs from GroovyDSL"
|
||||
task.group = GROUP_NAME
|
||||
task.conventionMapping.with {
|
||||
contractsDslDir = { extension.contractsDslDir }
|
||||
stubsOutputDir = { extension.stubsOutputDir }
|
||||
}
|
||||
}
|
||||
|
||||
private void deprecatedCreateAndConfigureGenerateWiremockClientStubsFromDslTask() {
|
||||
Task task = project.tasks.create('generateWiremockClientStubs')
|
||||
task.dependsOn('generateWireMockClientStubs')
|
||||
task.description = "DEPRECATED - Generates WireMock client stubs. - DEPRECATED - use 'generateWireMockClientStubs' task"
|
||||
task.group = GROUP_NAME
|
||||
task.doFirst {logger.warn("DEPRECATION WARNING. Task 'generateWiremockClientStubs' is deprecated. Use 'generateWireMockClientStubs' task instead.")}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package io.codearte.accurest.plugin
|
||||
|
||||
import io.codearte.accurest.wiremock.DslToWiremockClientConverter
|
||||
import io.codearte.accurest.wiremock.DslToWireMockClientConverter
|
||||
import io.codearte.accurest.wiremock.RecursiveFilesConverter
|
||||
import org.gradle.api.internal.ConventionTask
|
||||
import org.gradle.api.tasks.InputDirectory
|
||||
@@ -8,7 +8,7 @@ import org.gradle.api.tasks.OutputDirectory
|
||||
import org.gradle.api.tasks.TaskAction
|
||||
|
||||
//TODO: Implement as an incremental task: https://gradle.org/docs/current/userguide/custom_tasks.html#incremental_tasks ?
|
||||
class GenerateWiremockClientStubsFromDslTask extends ConventionTask {
|
||||
class GenerateWireMockClientStubsFromDslTask extends ConventionTask {
|
||||
|
||||
@InputDirectory
|
||||
File contractsDslDir
|
||||
@@ -17,10 +17,10 @@ class GenerateWiremockClientStubsFromDslTask extends ConventionTask {
|
||||
|
||||
@TaskAction
|
||||
void generate() {
|
||||
logger.info("Accurest Plugin: Invoking GroovyDSL to Wiremock client stubs conversion")
|
||||
logger.info("Accurest Plugin: Invoking GroovyDSL to WireMock client stubs conversion")
|
||||
logger.debug("From '${getContractsDslDir()}' to '${getStubsOutputDir()}'")
|
||||
|
||||
RecursiveFilesConverter converter = new RecursiveFilesConverter(new DslToWiremockClientConverter(), getContractsDslDir(),
|
||||
RecursiveFilesConverter converter = new RecursiveFilesConverter(new DslToWireMockClientConverter(), getContractsDslDir(),
|
||||
getStubsOutputDir())
|
||||
converter.processFiles()
|
||||
}
|
||||
@@ -23,7 +23,7 @@ class BasicFunctionalSpec extends IntegrationSpec {
|
||||
when:
|
||||
def result = runTasksSuccessfully('check')
|
||||
then:
|
||||
result.wasExecuted(":generateWiremockClientStubs")
|
||||
result.wasExecuted(":generateWireMockClientStubs")
|
||||
result.wasExecuted(":generateAccurest")
|
||||
|
||||
and: "tests generated"
|
||||
@@ -38,7 +38,7 @@ class BasicFunctionalSpec extends IntegrationSpec {
|
||||
|
||||
def "should generate valid client json stubs for simple input"() {
|
||||
when:
|
||||
runTasksSuccessfully('generateWiremockClientStubs')
|
||||
runTasksSuccessfully('generateWireMockClientStubs')
|
||||
then:
|
||||
def generatedClientJsonStub = file(GENERATED_CLIENT_JSON_STUB).text
|
||||
new JsonSlurper().parseText(generatedClientJsonStub) == new JsonSlurper().parseText("""
|
||||
@@ -67,16 +67,16 @@ class BasicFunctionalSpec extends IntegrationSpec {
|
||||
assert !fileExists(GENERATED_CLIENT_JSON_STUB)
|
||||
assert !fileExists(TEST_EXECUTION_XML_REPORT)
|
||||
when:
|
||||
runTasksSuccessfully('generateWiremockClientStubs', 'generateAccurest')
|
||||
runTasksSuccessfully('generateWireMockClientStubs', 'generateAccurest')
|
||||
then:
|
||||
fileExists(GENERATED_CLIENT_JSON_STUB)
|
||||
fileExists(GENERATED_TEST)
|
||||
|
||||
when: "running generation without change inputs"
|
||||
def secondExecutionResult = runTasksSuccessfully('generateWiremockClientStubs', 'generateAccurest')
|
||||
def secondExecutionResult = runTasksSuccessfully('generateWireMockClientStubs', 'generateAccurest')
|
||||
|
||||
then: "tasks should be up-to-date"
|
||||
secondExecutionResult.wasUpToDate(":generateWiremockClientStubs")
|
||||
secondExecutionResult.wasUpToDate(":generateWireMockClientStubs")
|
||||
secondExecutionResult.wasUpToDate(":generateAccurest")
|
||||
|
||||
when: "inputs changed"
|
||||
@@ -84,10 +84,10 @@ class BasicFunctionalSpec extends IntegrationSpec {
|
||||
groovyDslFile.text = groovyDslFile.text.replace("200", "599")
|
||||
|
||||
and: "tasks run"
|
||||
def thirdExecutionResult = runTasksSuccessfully('generateWiremockClientStubs', 'generateAccurest')
|
||||
def thirdExecutionResult = runTasksSuccessfully('generateWireMockClientStubs', 'generateAccurest')
|
||||
|
||||
then: "tasks should be reexecuted"
|
||||
thirdExecutionResult.wasExecuted(":generateWiremockClientStubs")
|
||||
thirdExecutionResult.wasExecuted(":generateWireMockClientStubs")
|
||||
thirdExecutionResult.wasExecuted(":generateAccurest")
|
||||
|
||||
and: "changes visible in generate files"
|
||||
|
||||
@@ -12,8 +12,8 @@ apply plugin: 'accurest'
|
||||
|
||||
ext {
|
||||
contractsDir = file("${project.rootDir}/repository/mappings/com/ofg/twitter-places-analyzer")
|
||||
wiremockStubsOutputDirRoot = file("${project.buildDir}/production/${project.name}-stubs/")
|
||||
wiremockStubsOutputDir = new File(wiremockStubsOutputDirRoot, 'repository/mappings/')
|
||||
wireMockStubsOutputDirRoot = file("${project.buildDir}/production/${project.name}-stubs/")
|
||||
wireMockStubsOutputDir = new File(wireMockStubsOutputDirRoot, 'repository/mappings/')
|
||||
}
|
||||
|
||||
configurations {
|
||||
@@ -59,16 +59,16 @@ accurest {
|
||||
basePackageForTests = 'accurest'
|
||||
contractsDslDir = contractsDir
|
||||
// generatedTestSourcesDir = file("${project.rootDir}/src/test/groovy/")
|
||||
stubsOutputDir = wiremockStubsOutputDir
|
||||
stubsOutputDir = wireMockStubsOutputDir
|
||||
}
|
||||
|
||||
//TODO: Put it into the plugin
|
||||
task createWiremockStubsOutputDir << {
|
||||
wiremockStubsOutputDir.mkdirs()
|
||||
task createWireMockStubsOutputDir << {
|
||||
wireMockStubsOutputDir.mkdirs()
|
||||
}
|
||||
|
||||
generateWiremockClientStubs.dependsOn { createWiremockStubsOutputDir }
|
||||
generateAccurest.dependsOn generateWiremockClientStubs
|
||||
generateWireMockClientStubs.dependsOn { createWireMockStubsOutputDir }
|
||||
generateAccurest.dependsOn generateWireMockClientStubs
|
||||
|
||||
wrapper {
|
||||
gradleVersion '2.2.1'
|
||||
|
||||
@@ -40,8 +40,8 @@ configure([project(':fraudDetectionService'), project(':loanApplicationService')
|
||||
apply plugin: 'accurest'
|
||||
|
||||
ext {
|
||||
wiremockStubsOutputDirRoot = file("${project.buildDir}/production/${project.name}-stubs/")
|
||||
wiremockStubsOutputDir = new File(wiremockStubsOutputDirRoot, 'mappings/')
|
||||
wireMockStubsOutputDirRoot = file("${project.buildDir}/production/${project.name}-stubs/")
|
||||
wireMockStubsOutputDir = new File(wireMockStubsOutputDirRoot, 'mappings/')
|
||||
}
|
||||
|
||||
accurest {
|
||||
@@ -50,7 +50,7 @@ configure([project(':fraudDetectionService'), project(':loanApplicationService')
|
||||
baseClassForTests = 'com.blogspot.toomuchcoding.MvcSpec'
|
||||
contractsDslDir = file("${project.projectDir.absolutePath}/mappings/")
|
||||
generatedTestSourcesDir = file("${project.buildDir}/generated-sources/")
|
||||
stubsOutputDir = wiremockStubsOutputDir
|
||||
stubsOutputDir = wireMockStubsOutputDir
|
||||
}
|
||||
|
||||
jar {
|
||||
@@ -79,7 +79,7 @@ configure([project(':fraudDetectionService'), project(':loanApplicationService')
|
||||
}
|
||||
|
||||
configure(project(':fraudDetectionService')) {
|
||||
test.dependsOn('generateWiremockClientStubs')
|
||||
test.dependsOn('generateWireMockClientStubs')
|
||||
}
|
||||
|
||||
configure(project(':loanApplicationService')) {
|
||||
@@ -92,3 +92,4 @@ configure(project(':loanApplicationService')) {
|
||||
|
||||
generateAccurest.dependsOn('copyCollaboratorStubs')
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
buildscript {
|
||||
repositories {
|
||||
mavenCentral()
|
||||
mavenLocal()
|
||||
}
|
||||
dependencies {
|
||||
classpath "pl.allegro.tech.build:axion-release-plugin:1.2.2"
|
||||
|
||||
Reference in New Issue
Block a user