-
Notifications
You must be signed in to change notification settings - Fork 12
Stub Configuration, Examples
Examples below are fictive examples, don't expect that they works as they are. Some of them requires further external classes, further external (template) files.
Examples below are just for getting a little insight on how to configure the stub part.
First start with the minimum stub configuration content:
{
"wilmaStubConfiguration": {
}
}
Meanwhile it is loadable, it does not do anything. If this configuration is used, technically Wilma does not generate any stub response, with its default setting acts as a simple proxy and saves the intercepted messages. Its content need to be populated according to the purpose of the use.
Now let's see another basic working example:
{
"wilmaStubConfiguration": {
"dialogDescriptors": [
{
"name": "error-pattern-descriptor1",
"usage": "always",
"conditionDescriptor": {
"condition": { "class": "AlwaysFalseChecker" }
},
"responseDescriptor": {
"code": 502,
"delay": 0,
"templateName": "errorResponse1",
"mimeType": "text/plain"
}
}
],
"templates": [
{
"name": "errorResponse1",
"resource": "Bad Gateway",
"type": "text"
}
]
}
}
Meanwhile this simple example can be loaded into Wilma, as you see, the condition will never match, so no stub response will be generated ever. Please note that if you change the condition class from AlwaysFalseChecker
to AlwaysTrueChecker
, for every request you will get the defined Bad Gateway response message.
{
"wilmaStubConfiguration": {
"dialogDescriptors": [
{
"name": "check-balance-error-500",
"comment": "CheckBalance - Error 500",
"usage": "always",
"conditionDescriptor": {
"condition": { "class": "JsonPathChecker",
"parameters": [
{
"name": "jsonPath",
"value": "$.attributes.card_number"
},
{
"name": "expected",
"value": "0000000000000500"
}
]
}
},
"responseDescriptor": {
"code": 500,
"delay": 0,
"templateName": "general-error",
"mimeType": "application/json",
"responseFormatterSet": [
{
"responseFormatter": {
"class": "JsonTemplateFormatter"
}
}
]
}
}
],
"templates": [
{
"name": "general-error",
"resource": "error_general.json",
"type": "jsonFile"
}
]
}
}
Note: the error_general.json
file should be available as well.
{
"wilmaStubConfiguration": {
"dialogDescriptors": [
{
"name": "my-dialog-descriptor",
"usage": "always",
"conditionDescriptor": {
"and": [
{
"condition": {
"class": "CustomXQueryBodyChecker",
"parameters": [
{
"name": "xquery",
"value": "(count(//*[local-name()='RequestName' and namespace-uri()='urn:a:complex:message:defn:v3'][1])=1)"
}
]
}
},
{
"condition": {
"class": "CustomXQueryBodyChecker",
"parameters": [
{
"name": "xquery",
"value": "(//*[local-name()='AnID']=23987)"
}
]
}
}
]
},
"responseDescriptor": {
"code": 200,
"delay": 0,
"templateName": "template_of_response",
"mimeType": "text/xml",
"responseFormatterSet": [
{
"responseFormatterSetInvoker": {
"name": "invoke_response_formatter"
}
}
]
}
}
],
"templates": [
{
"name": "template_of_response",
"resource": "response.xml",
"type": "xmlFile"
}
],
"responseFormatterSets": [
{
"name": "invoke_response_formatter",
"responseFormatterSet": [
{
"responseFormatter": {
"class": "XslBasedResponseFormatter",
"parameters": [
{
"name": "xslFile",
"value": "response-formatter.xsl"
}
]
}
}
]
}
]
}
}
In the above example, (which is a bit overcomplicated), when both 2 conditions are met in the request, Wilma will load response.xml as template, and will be sent back as response, after formatted by XslBasedResponseFormatter
class, using the response-formatter.xsl