Removed server side stubs generation

This commit is contained in:
Jakub Kubrynski
2015-02-21 21:02:39 +01:00
parent be552a28b8
commit dd4635fe95
7 changed files with 2 additions and 299 deletions

View File

@@ -1,13 +0,0 @@
package io.codearte.accurest.wiremock
import groovy.transform.CompileStatic
import io.coderate.accurest.dsl.WiremockStubStrategy
@CompileStatic
class DslToWiremockServerConverter extends DslToWiremockConverter {
@Override
String convertContent(String dslBody) {
return new WiremockStubStrategy(createGroovyDSLfromStringContent(dslBody)).toWiremockServerStub()
}
}

View File

@@ -1,29 +0,0 @@
package io.codearte.accurest.wiremock
import groovy.json.JsonSlurper
import spock.lang.Specification
class DslToWiremockServerConverterSpec extends Specification {
def "should convert DSL file to Wiremock JSON"() {
given:
def converter = new DslToWiremockServerConverter()
and:
String dslBody = """
io.coderate.accurest.dsl.GroovyDsl.make {
request {
method('PUT')
urlPattern \$(client('/[0-9]{2}'), server('/12'))
}
response {
status 200
}
}
"""
when:
String json = converter.convertContent(dslBody)
then:
new JsonSlurper().parseText(json) == new JsonSlurper().parseText("""
{"request":{"method":"PUT","urlPattern":"/12"},"response":{"status":200}}""")
}
}

View File

@@ -21,11 +21,6 @@ class WiremockRequestStubStrategy extends BaseWiremockStubStrategy {
return buildRequestContent(new ClientRequest(request))
}
@PackageScope
Map buildServerRequestContent() {
return buildRequestContent(new ServerRequest(request))
}
private Map<String, Object> buildRequestContent(ClientRequest request) {
return [method : request?.method?.clientValue,
url : request?.url?.clientValue,
@@ -36,13 +31,4 @@ class WiremockRequestStubStrategy extends BaseWiremockStubStrategy {
].findAll { it.value }
}
private Map<String, Object> buildRequestContent(ServerRequest request) {
return [method : request?.method?.serverValue,
url : request?.url?.serverValue,
urlPattern: request?.urlPattern?.serverValue,
urlPath : request?.urlPath?.serverValue,
headers : buildServerHeadersSection(request.headers),
body : request?.body?.serverValue
].findAll { it.value }
}
}

View File

@@ -21,21 +21,9 @@ class WiremockResponseStubStrategy extends BaseWiremockStubStrategy {
return buildResponseContent(new ClientResponse(response))
}
@PackageScope
Map buildServerResponseContent() {
return buildResponseContent(new ServerResponse(response))
}
private Map<String, Object> buildResponseContent(ClientResponse response) {
return [status : response?.status?.clientValue,
body : response?.body?.clientValue,
headers: buildClientHeadersSection(response.headers)].findAll { it.value }
}
private Map<String, Object> buildResponseContent(ServerResponse response) {
return [status : response?.status?.serverValue,
body : response?.body?.serverValue,
headers: buildServerHeadersSection(response.headers)].findAll { it.value }
}
}

View File

@@ -18,9 +18,4 @@ class WiremockStubStrategy {
return JsonOutput.prettyPrint(JsonOutput.toJson([request : wiremockRequestStubStrategy.buildClientRequestContent(),
response: wiremockResponseStubStrategy.buildClientResponseContent()]))
}
String toWiremockServerStub() {
return JsonOutput.prettyPrint(JsonOutput.toJson([request : wiremockRequestStubStrategy.buildServerRequestContent(),
response: wiremockResponseStubStrategy.buildServerResponseContent()]))
}
}

View File

@@ -7,7 +7,7 @@ import spock.lang.Specification
class WiremockGroovyDslResponseSpec extends Specification {
def 'should generate response without body for #side side'() {
def 'should generate response without body for client side'() {
given:
GroovyDsl dsl = GroovyDsl.make {
response {
@@ -15,9 +15,8 @@ class WiremockGroovyDslResponseSpec extends Specification {
}
}
expect:
new WiremockResponseStubStrategy(dsl)."build${side}ResponseContent"() == new JsonSlurper().parseText(expectedStub)
new WiremockResponseStubStrategy(dsl).buildClientResponseContent() == new JsonSlurper().parseText(expectedStub)
where:
side << ['Client', 'Server']
expectedStub << ['''
{
"status": 200
@@ -54,47 +53,4 @@ class WiremockGroovyDslResponseSpec extends Specification {
''')
}
def 'should generate headers for response for server side'() {
given:
GroovyDsl dsl = GroovyDsl.make {
response {
status 200
headers {
header('Content-Type').matches $(client('text/xml'), server('text/*'))
}
}
}
expect:
new WiremockResponseStubStrategy(dsl).buildServerResponseContent() == new JsonSlurper().parseText('''
{
"status": 200,
"headers": {
"Content-Type": {
"matches": "text/*"
}
}
}
''')
}
def 'should generate an exact header for response for both sides '() {
given:
GroovyDsl dsl = GroovyDsl.make {
response {
status 200
headers {
header 'Content-Type': 'text/xml'
}
}
}
expect:
new WiremockResponseStubStrategy(dsl).buildServerResponseContent() == new JsonSlurper().parseText('''
{
"status": 200,
"headers": {
"Content-Type": "text/xml"
}
}
''')
}
}

View File

@@ -159,105 +159,6 @@ class WiremockGroovyDslSpec extends Specification {
''')
}
def 'should convert groovy dsl stub with Body as String to wiremock stub for the server side'() {
given:
GroovyDsl groovyDsl = GroovyDsl.make {
request {
method('GET')
urlPattern $(client('/[0-9]{2}'), server('/12'))
}
response {
status 200
body("""\
{
"id": "${value(client('123'), server('321'))}",
"surname": "${value(client('Kowalsky'), server('Lewandowski'))}",
"name": "Jan",
"created" : "${$(client('2014-02-02 12:23:43'), server('2999-09-09 01:23:45'))}"
}
"""
)
headers {
header 'Content-Type': 'text/plain'
}
}
}
when:
String wiremockStub = new WiremockStubStrategy(groovyDsl).toWiremockServerStub()
then:
new JsonSlurper().parseText(wiremockStub) == new JsonSlurper().parseText('''
{
"request": {
"method": "GET",
"urlPattern": "/12"
},
"response": {
"status": 200,
"body": {
"id": "321",
"surname": "Lewandowski",
"name": "Jan",
"created" : "2999-09-09 01:23:45"
},
"headers": {
"Content-Type": "text/plain"
}
}
}
''')
}
def 'should convert groovy dsl stub to wiremock stub for the server side'() {
given:
GroovyDsl groovyDsl = GroovyDsl.make {
request {
method('GET')
urlPattern $(client('/[0-9]{2}'), server('/12'))
}
response {
status(200)
body(
id: value(
client('123'),
server('321')
),
surname: $(
client('Kowalsky'),
server('Lewandowski')
),
name: 'Jan',
created: $(client('2014-02-02 12:23:43'), server('1999-01-01 01:23:45'))
)
headers {
header('Content-Type': 'text/plain')
}
}
}
when:
String wiremockStub = new WiremockStubStrategy(groovyDsl).toWiremockServerStub()
then:
new JsonSlurper().parseText(wiremockStub) == new JsonSlurper().parseText('''
{
"request": {
"method": "GET",
"urlPattern": "/12"
},
"response": {
"status": 200,
"body": {
"id": "321",
"surname": "Lewandowski",
"name": "Jan",
"created" : "1999-01-01 01:23:45"
},
"headers": {
"Content-Type": "text/plain"
}
}
}
''')
}
def "should generate stub with GET"() {
given:
GroovyDsl groovyDsl = GroovyDsl.make {
@@ -308,24 +209,6 @@ class WiremockGroovyDslSpec extends Specification {
''')
}
def "should generate stub with urlPattern for server side"() {
given:
GroovyDsl groovyDsl = GroovyDsl.make {
request {
urlPattern $(
client('/[0-9]{2}'),
server('/12')
)
}
}
expect:
new WiremockRequestStubStrategy(groovyDsl).buildServerRequestContent() == new JsonSlurper().parseText('''
{
"urlPattern":"/12"
}
''')
}
def "should generate stub with urlPath for client side"() {
given:
GroovyDsl groovyDsl = GroovyDsl.make {
@@ -341,21 +224,6 @@ class WiremockGroovyDslSpec extends Specification {
''')
}
def "should generate stub with urlPath for server side"() {
given:
GroovyDsl groovyDsl = GroovyDsl.make {
request {
urlPath('/12')
}
}
expect:
new WiremockRequestStubStrategy(groovyDsl).buildClientRequestContent() == new JsonSlurper().parseText('''
{
"urlPath":"/12"
}
''')
}
def "should generate stub with some headers section for client side"() {
given:
GroovyDsl groovyDsl = GroovyDsl.make {
@@ -397,52 +265,4 @@ class WiremockGroovyDslSpec extends Specification {
}
''')
}
def "should generate stub with some headers section for server side"() {
given:
GroovyDsl groovyDsl = GroovyDsl.make {
request {
headers {
header('Content-Type').equalTo('text/xml')
header('Accept').matches $(
client('text/.*'),
server('text/plain')
)
header('etag').doesNotMatch $(
client('abcd.*'),
server('abcdef')
)
header('X-Custom-Header').contains $(
client('2134'),
server('121345')
)
}
}
}
expect:
new WiremockRequestStubStrategy(groovyDsl).buildServerRequestContent() == new JsonSlurper().parseText('''
{
"headers": {
"Content-Type": {
"equalTo": "text/xml"
},
"Accept": {
"matches": "text/plain"
},
"etag": {
"doesNotMatch": "abcdef"
},
"X-Custom-Header": {
"contains": "121345"
}
}
}
''')
}
@Ignore("Not implemented yet")
def "should generate stub with request body matching for server side"() {}
@Ignore("Not implemented yet")
def "should generate stub with request query parameter matching for server side"() {}
}