You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Mokka provides a feature to define response body as a Groovy scripts.
It is particularly handled by GroovyMockHandler.
Exemplary response body can for example look as follows:
result='''<responseBody>'''
result+=ctx.uri
result+='''</responseBody>'''
return result
Send a request on path defined in the mock configuration and you should receive something like <responseBody><path></responseBody>
On the other hand WireMock response templating does not support Groovy templates but we may try to achieve the same using WireMock extension mechanism (http://wiremock.org/docs/extending-wiremock): just define custom ResponseDefinitionTransformer or ResponseTransformer with "groovy-transformer" name. ResponseDefinitionTransformer seems to be more proper but to be verified if it will work at this point
Then new extension should be registered in WireMockServerConfiguration via o.extensions.
When implementing Groovy transformer for WireMock please consider the following:
GroovyMockHandler uses MockContext in Binding definition (as "ctx" variable). In WireMock case we need to support it also. We do not have to (and in fact we do not want to) reuse MockContext class here but the semantic (fields naming and structure) is important so currently existing scripts could work. That means we should consider some kind of abstraction that will take com.github.tomakehurst.wiremock.http.Request as an input and prepare object similar to MockContext but only with fields: uri, httpMethod, requestBody and from.
variables like 'mockConfiguration' and 'httpHelper' - to be removed from GroovyMockHandler
WireMock uses RequestTemplateModel as binding variable in its "Response Templating". Would be good to if we could introduce the same model (in parallel to "ctx") in WireMock Groovy Transformer. This simply means:
Mokka provides a feature to define response body as a Groovy scripts.
It is particularly handled by
GroovyMockHandler
.Exemplary response body can for example look as follows:
Send a request on path defined in the mock configuration and you should receive something like
<responseBody><path></responseBody>
On the other hand WireMock response templating does not support Groovy templates but we may try to achieve the same using WireMock extension mechanism (http://wiremock.org/docs/extending-wiremock): just define custom
ResponseDefinitionTransformer
orResponseTransformer
with "groovy-transformer" name.ResponseDefinitionTransformer
seems to be more proper but to be verified if it will work at this pointThen new extension should be registered in
WireMockServerConfiguration
viao.extensions
.When implementing Groovy transformer for WireMock please consider the following:
GroovyMockHandler
uses MockContext inBinding
definition (as "ctx" variable). In WireMock case we need to support it also. We do not have to (and in fact we do not want to) reuseMockContext
class here but the semantic (fields naming and structure) is important so currently existing scripts could work. That means we should consider some kind of abstraction that will takecom.github.tomakehurst.wiremock.http.Request
as an input and prepare object similar toMockContext
but only with fields: uri, httpMethod, requestBody and from.GroovyMockHandler
RequestTemplateModel
as binding variable in its "Response Templating". Would be good to if we could introduce the same model (in parallel to "ctx") in WireMock Groovy Transformer. This simply means:RequestTemplateModel
should also be introduced in GroovyMockHandler - under the same binding variable ("request").Apart of JUnit tests the implementation can be also tested manually on the running server by:
The text was updated successfully, but these errors were encountered: