-
Notifications
You must be signed in to change notification settings - Fork 12
Stub Configuration, Condition Checkers
The general checkers can be used for every request type, because they investigate the request headers and the request body as string.
If a general checker is called without parameter then it will return with false!
The OrPatternChecker.class
searches for patterns in the request. If one of the pattern is an empty string, it returns false. Otherwise if one of the given patterns is found either in the headers or in the body or in the request URL, it returns true.
"condition": {
"class": "OrPatternChecker",
"parameters": [
{
"name": "pattern1",
"value": "WILMA-ERESPONSE500"
},
{
"name": "pattern2",
"value": "ERROR-RESPONSE-NECESSARY_WWW_XXX"
}
]
}
The AndPatternChecker.class
searches for patterns in the request. If one of the pattern is an empty string, it returns false. Otherwise if all of the given patterns are found either in the headers or in the body or in the request URL, it returns true.
"condition": {
"class": "AndPatternChecker",
"parameters": [
{
"name": "pattern1",
"value": "WILMA-ERESPONSE500"
},
{
"name": "pattern2",
"value": "ERROR-RESPONSE-NECESSARY_WWW_XXX"
}
]
}
The AndRegExpChecker.class
processes the request's headers and the request's body. The parameter "value" attribute should be the desired regular expression and a header's value or one of the body's sub-strings must match with the expression to return with true. It is configurable with more parameters as the following picture presents and to return with true all of the given regular expressions must be matched. The "name" attribute is not taken into consideration.
"condition": {
"class": "AndRegExpChecker",
"parameters": [
{
"name": "ex1",
"value": "A[a-zA-Z]{8}ary"
},
{
"name": "ex2",
"value": "Av[a-zA-Z]{7}ary"
}
]
}
The OrRegExpChecker.class
processes the request's headers and the request's body. The parameter "value" attribute should be the desired regular expression and a header's value or one of the body's sub-strings must match with the expression to return with true. It is configurable with more parameters as the following picture presents and to return with true one of the given regular expressions must be matched. The "name" attribute is not taken into consideration.
"condition": {
"class": "OrRegExpChecker",
"parameters": [
{
"name": "ex1",
"value": "A[a-zA-Z]{8}ary"
},
{
"name": "ex2",
"value": "Av[a-zA-Z]{7}ary"
}
]
}
These condition checker classes can be used if the request method is the expected one or not. The following methods can be checked:
GET -> "condition": { "class": "com.epam.wilma.stubconfig.condition.checker.general.header.GetMethodChecker" }
POST -> "condition": { "class": "com.epam.wilma.stubconfig.condition.checker.general.header.PostMethodChecker" }
PUT -> "condition": { "class": "com.epam.wilma.stubconfig.condition.checker.general.header.PutMethodChecker" }
DELETE -> "condition": { "class": "com.epam.wilma.stubconfig.condition.checker.general.header.DeleteMethodChecker" }
HEAD -> "condition": { "class": "com.epam.wilma.stubconfig.condition.checker.general.header.HeadMethodChecker" }
OPTIONS -> "condition": { "class": "com.epam.wilma.stubconfig.condition.checker.general.header.OptionsMethodChecker" }
In case you need combinations, like both GET and POST is ok, then use the or
"logicalCondition":
"or": [
{"condition": { "class": "com.epam.wilma.stubconfig.condition.checker.general.header.GetMethodChecker" }},
{"condition": { "class": "com.epam.wilma.stubconfig.condition.checker.general.header.PostMethodChecker" }}
]
approach.
This condition checker class provides the possibility to check if a request header exactly matches the given value. The HeaderParameterChecker.class
can be configured with more than one parameter as the following json snipplet presents. In the parameter the name attribute should be the header key/name and the value attribute should be the desired header value.
"condition": {
"class": "HeaderParameterChecker",
"parameters": [
{
"name": "Content-Type",
"value": "application/fastinfoset"
},
{
"name": "Wilma-Logger-ID",
"value": "20131009092413.0000"
}
]
}
The AndHeaderPatternChecker.class
checks all headers in the request and all of the parameters must be contained by the headers otherwise it returns with false. The parameter value attribute should be the desired value which can be contained by a header's value, so the name attribute is not taken into consideration. It is configurable with more parameters as the following picture presents.
"condition": {
"class": "AndHeaderPatternChecker",
"parameters": [
{
"name": "wilmaSequence",
"value": "example=dialog-descriptor-1"
},
{
"name": "wilmaSequence",
"value": "example=dialog-descriptor-2"
}
]
}
The OrHeaderPatternChecker.class
checks all headers in the request and if any of them contains any of the given parameter, returns true. The parameter value attribute should be the desired value which can be contained by a header's value, so the name attribute is not taken into consideration. It is configurable with more parameters as the following picture presents.
"condition": {
"class": "OrHeaderPatternChecker",
"parameters": [
{
"name": "wilmaSequence",
"value": "example=dialog-descriptor-1"
},
{
"name": "wilmaSequence",
"value": "example=dialog-descriptor-2"
}
]
}
The AndHeaderRegExpChecker.class
checks all headers in the request. The parameter "value" attribute should be the desired regular expression and a header's value must match with the expression to return with true. It is configurable with more parameters as the following picture presents and to return with true all of the given regular expressions must be matched. The "name" attribute is not taken into consideration.
"condition": {
"class": "AndHeaderRegExpChecker",
"parameters": [
{
"name": "ex1",
"value": "A[a-zA-Z]{8}ary"
},
{
"name": "ex2",
"value": "Av[a-zA-Z]{7}ary"
}
]
}
The OrHeaderRegExpChecker.class
checks all headers in the request. The parameter "value" attribute should be the desired regular expression and a header's value must match with the expression to return with true. It is configurable with more parameters as the following picture presents and to return with true one of the given regular expressions must be matched. The "name" attribute is not taken into consideration.
"condition": {
"class": "OrHeaderRegExpChecker",
"parameters": [
{
"name": "ex1",
"value": "A[a-zA-Z]{8}ary"
},
{
"name": "ex2",
"value": "Av[a-zA-Z]{7}ary"
}
]
}
The AndBodyPatternChecker.class
checks the message body as plain text and returns true if the message body contains all the values, which given in the parameters 'value' attribute. The 'name' attribute is not taken into consideration.
"condition": {
"class": "AndBodyPatternChecker",
"parameters": [
{
"name": "errorPattern",
"value": "WILMA-ERESPONSE500"
},
{
"name": "specialExpression",
"value": "ALMAFA_ALMAFA"
}
]
}
The OrBodyPatternChecker.class
checks the message body as plain text and returns true if the message body contains any of the values, which given in the parameters 'value' attribute. The 'name' attribute is not taken into consideration.
"condition": {
"class": "OrBodyPatternChecker",
"parameters": [
{
"name": "errorPattern",
"value": "WILMA-ERESPONSE500"
},
{
"name": "specialExpression",
"value": "ALMAFA_ALMAFA"
}
]
}
The AndBodyRegExpChecker.class
processes the request's body. The parameter "value" attribute should be the desired regular expression and one of the body's sub-strings must match with the expression to return with true. It is configurable with more parameters as the following picture presents and to return with true all of the given regular expressions must be matched. The "name" attribute is not taken into consideration.
"condition": {
"class": "AndBodyRegExpChecker",
"parameters": [ {"name": "ex1", "value": "A[a-zA-Z]{8}ary"},
{"name": "ex2", "value": "Av[a-zA-Z]{7}ary"} ]
}
The OrBodyRegExpChecker.class
processes the request's body. The parameter "value" attribute should be the desired regular expression and one of the body's sub-strings must match with the expression to return with true. It is configurable with more parameters as the following picture presents and to return with true one of the given regular expressions must be matched. The "name" attribute is not taken into consideration.
"condition": {
"class": "OrBodyRegExpChecker",
"parameters": [ {"name": "ex1", "value": "A[a-zA-Z]{8}ary"},
{"name": "ex2", "value": "Av[a-zA-Z]{7}ary"} ]
}
The AndUrlPatternChecker.class
checks the request's URL and all of the configured condition parameter's value must be contained by the URL otherwise it returns with false. The parameter's value attribute should be the desired value which can be contained by the URL, so the name attribute is not taken into consideration. It is configurable with more parameters as the following picture presents.
"condition": {
"class": "AndUrlPatternChecker",
"parameters": [ {"name": "param1", "value": "getParam1=example1"},
{"name": "param2", "value": "getParam2=example2"} ]
}
The OrUrlPatternChecker.class
checks the request's URL and one of the configured condition parameter's value must be contained by the URL otherwise it returns with false. The parameter's value attribute should be the desired value, which can be contained by the URL, so the name attribute is not taken into consideration. It is configurable with more parameters as the following picture presents.
"condition": {
"class": "OrUrlPatternChecker",
"parameters": [ {"name": "param1", "value": "getParam1=example1"},
{"name": "param2", "value": "getParam2=example2"} ]
}
There are 4 different built-in condition checkers for the easiest usage, when xml files arrive as the request body.
All of them must be configured with exactly one parameter!
The XmlMessageTypeChecker.class
searches for a node that's name is specified in the parameter 'value' attribute. If the tag is declared with a prefix, the prefix must be provided as well, like below:
"condition": {
"class": "XmlMessageTypeChecker",
"parameters": [ {"name": "some-element", "value": "xxx:getData"} ]
}
The XmlNodeValueChecker.class
searches for a node which has the specified name and value. If the tag is declared with a prefix, the prefix must be provided as well, like below:
"condition": {
"class": "XmlNodeValueChecker",
"parameters": [ {"name": "xxx:SomeID", "value": "179"} ]
}
The XmlAttributeChecker.class
searches for a node which has the specified name, attribute and attribute's value. The attribute's name must be specified using XQuery syntax, like on the following picture. If the tag is declared with a prefix, it must be provided as well!
"condition": {
"class": "XmlAttributeChecker",
"parameters": [ {"name": "xxx:SomeID/@valid", "value": "true"} ]
}
The CustomXQueryBodyChecker.class
executes the given query on the request's body and transform the query result to a logical value. If the query result can not be transformed to a logical value, it will return with true.
The given query is validated syntactically when the stub configuration is parsed, if the query is syntactically invalid the entire stub configuration will be rejected.
"condition": {
"class": "CustomXQueryBodyChecker",
"parameters": [ {"name": "xquery", "value": "(//*[name()='xx:AlmaId'])='179'"} ]
}
There are 3 different built-in condition checkers for the easiest usage, when JSON data arrives as the request body.
The JsonPathChecker.class
runs the given JSONPath query and check whether the expected value is equal to the result if it is the checker will catch the request. Both parameters are mandatory.
"condition": {
"class": "JsonPathChecker",
"parameters": [ {"name": "jsonPath", "value": "$.any_request[0].node_id"},
{"name": "expected", "value": "94375490"} ]
}
Note: In the next release of Wilma, this checker will be enhanced, and the second (expected) parameter will be optional. If it does not exist, just checks the existence of the element (runs the JSONPath query only), and if found, returns with true, regardless its actual value.
The JsonPathRegExChecker.class
runs the given JSONPath query and check whether the expected regexp matches to the result. Both parameters are mandatory.
"condition": {
"class": "JsonPathRegExChecker",
"parameters": [ {"name": "jsonPath", "value": "$.any_request[0].message"},
{"name": "expected", "value": ".*Error"} ]
}
See more about the used library here: https://code.google.com/p/json-path/.
The JsonSchemaChecker.class
checks if the request body fits to a specific JSON Schema. You may specify the Schema in the first parameter, meanwhile if you set the second parameter as false, then the Schema will be cached (static through Wilma app lifecycle), meanwhile if it is missing or true, then Wilma will load the schema every time the checker is called.
"condition": {
"class": "JsonSchemaChecker",
"parameters": [ {"name": "schema", "value": "requestSchema.json"},
{"name": "isSchemaVolatile", "value": "false"} ]
}
The schema file must be uploaded to templates folder of Wilma before loading the stub configuration.
In usual use case, when the condition is true, then everything is fine; when the condition is false then the request was wrong and an error (stub) response need to be generated. To reflect this approach, the behavior of the condition checker need to be negated. See example stub configuration part:
{
"wilmaStubConfiguration": {
"dialogDescriptors": [
{
"name": "Bad schema responder",
"comment": "This dialog descriptor will generate stub response if the request does not fit to the given schema",
"usage": "always",
"conditionDescriptor": {
"not": {
"condition": {
"class": "JsonSchemaChecker",
"parameters": [ {"name": "schema", "value": "jsonTestSchema.json"},
{"name": "isSchemaVolatile", "value": "false"} ]
}
}
}
},
"responseDescriptor": {
"code": 200, "delay": 0, "templateName": "templateBadFile", "mimeType": "application/json"
}
}
],
"templates": [
{
"name": "templateBadFile",
"resource": "responseWithBadSchema.json",
"type": "jsonFile"
}
]
}
}
Json schema version is supported up to version draft-06.
The SessionIdChecker
class checks if the request contains a header with the given name. The value part of the parameter isn't used.
"condition": {
"class": "SessionIdChecker",
"parameters": [ {"name": "SESSION-ID", "value": "something"} ]
}
The AlwaysTrueChecker
and the AlwaysFalseChecker
built in condition classes - as their name suggest - will return with true/false result, always. Can be used for testing purposes, and when a request condition part should always be evaluated as true (or false).
Example:
"condition": { "class": "AlwaysTrueChecker" }