Unable to match predicate of path and value for grpc request - mountebank

I am using the grpc plugin to create stubs for grpc requests. It works very well when matching the path only. However, I am facing issues to match both the path and the value. In particular, I am using the jsonpath to select the fields to match. Here is a sample o the request:
{
"path": "/service.DataProvider/ReadData",
"value": {
"identifiers": [
{
"unique_id": "unset",
"data_id": "point1",
"system_id": "mock"
}
],
"start_time": {
"seconds": "1650431509",
"nanos": 0
},
"end_time": {
"seconds": "1650431569",
"nanos": 0
}
}
}
and the predicates:
"predicates": [
{
"deepEquals": {
"path": "/service.DataProvider/ReadData"
}
},
{
"jsonpath": {
"selector": "$.identifiers[0].data_id"
},
"deepEquals": {
"value": "point1"
}
},
{
"jsonpath": {
"selector": "$.identifiers[0].system_id"
},
"deepEquals": {
"value": "mock"
}
}
]
Any idea of what is wrong on the predicates above? Any comments will be highly appreciated. Thanks!

Related

ja and complex json object

I'm converting a Sdmx xml api output to an Json Object. I try with boot 'xml-js' and 'xml2js' and
the result is a complex object like this:
{
"_declaration": {
"_attributes": {
"version": "1.0",
"encoding": "utf-8"
}
},
"_comment": "NSI Web Service v6.16.0",
"message:Structure": {
"_attributes": {
"xmlns:message": "http://www.sdmx.org/resources/sdmxml/schemas/v2_1/message",
"xmlns:structure": "http://www.sdmx.org/resources/sdmxml/schemas/v2_1/structure",
"xmlns:common": "http://www.sdmx.org/resources/sdmxml/schemas/v2_1/common"
},
"message:Header": {
"message:ID": {
"_text": "IDREF161"
},
"message:Test": {
"_text": "false"
},
"message:Prepared": {
"_text": "2021-04-11T13:21:40.0658418+02:00"
},
"message:Sender": {
"_attributes": {
"id": "Unknown"
}
},
"message:Receiver": {
"_attributes": {
"id": "Unknown"
}
}
},
"message:Structures": {
"structure:Codelists": {
"structure:Codelist": {
"_attributes": {
"id": "CL_CAUSEMORTE_SL",
"urn": "urn:sdmx:org.sdmx.infomodel.codelist.Codelist=IT1:CL_CAUSEMORTE_SL(1.1)",
"agencyID": "IT1",
"version": "1.1",
"isFinal": "true"
},
"common:Name": [
{
"_attributes": {
"xml:lang": "it"
},
"_text": "Cause di morte - European short list"
},
{
"_attributes": {
"xml:lang": "en"
},
"_text": "European short list of causes of death"
}
],
I can't navigate the structure and retrive elements value in anyway, examples:
console.log(result['message:Structure']);
undefined
console.log(result[2]);
undefined
any help is appreciated,
regards, Maurizio

Mountebank predicates doesn't check headers

I have below code and looks like it is not checking headers as a predicate.
{
"responses": [
{
"inject": "<%- stringify(filename, 'Scripts/MyDept/CutOffTime.ejs') %>"
}
],
"predicates": [
{
"matches": {
"method": "GET",
"path": "/cutoff-times",
"query": {
"country": "\\w+"
},
"headers": {
"X-CLIENT-ID": "^[ A-Za-z0-9]*$"
}
}
}
]
}
Strangely, when I pass # as the value to header X-CLIENT-ID it validate and shows the message as no predicate match. Because it is not part of the regex.
Identified the issue,
Basically if you need have multiple predicates need to merge them as below,(using and / or)
{
"responses": [
{
"inject": "<%- stringify(filename, 'Scripts/MyDept/CutOffTime.ejs') %>"
}
],
"predicates": [
{
"and": [
{
"exists": {
"headers": {
"X-CLIENT-ID": true,
}
}
},
{
"matches": {
"method": "GET",
"path": "/cutoff-times",
"headers": {
"X-CLIENT-ID": "^[ A-Za-z0-9]*$"
},
"query": {
"country": "\\w+"
}
}
}
]
}
]
}
Mountebank site
Further matches predicate doesn't check the existence (e.g. header existence)

Use Mountebank copy behavior in multiple stubs

Is it possible to share a variable between Mountebank stubs?
Here's a high level example:
Stub A:
{
"predicates": [
{
"matches": {
"body": "amount=420"
}
}
],
"responses": [
{
"is": {
"statusCode": 200
},
"body": {
"transaction_id": "123456",
"amount": 420
},
"_behaviors": {
"copy": [{
"from": {"query": "transaction_id"},
"into": "${TRANSACTION1}",
"using": {
"method": "regex",
"selector": "(?<=transaction_id%5D=).{6}"
}
}]
}
Stub B:
{
"predicates": [
{
"matches": {
"body": "approved=420"
}
}
],
"responses": [
{
"is": {
"statusCode": 200
},
"body": {
"transaction_id": "${TRANSACTION1}",
"amount": 420
}
}
The copy _behavior approaches I have tried for Stub B do not seem to recognize the variable specified in Stub A. From the documentation, it seems as though I cannot use copy between these stubs.
As per the developer, this behavior isn't supported at this time. See: https://github.com/bbyars/mountebank/issues/476

Where can I find the complete reference document for CouchDb Design Docs syntax?

Please don't tell me to "googleit"!
I have been poring over the Apache pages and the IBM pages for days trying to find the full allowed syntax for a Design Doc.
From the above readings:
the 'map' property is always a Javascript function
the 'options' property may be one/both of local_seq or include_design.
When I use Fauxton to edit a Mango Query, however, I see that the reality is much broader.
I defined a query ...
{
"selector": {
"data.type": {
"$eq": "invoice"
},
"data.idib": {
"$gt": 0,
"$lt": 99999
}
},
"sort": [
{
"data.type": "desc"
},
{
"data.idib": "desc"
}
]
}
... with an accompanying index ...
{
"index": {
"fields": [
"foo"
]
},
"name": "foo-json-index",
"type": "json"
}
... and then looked at the design doc produced ...
{
"_id": "_design/5b1cf1be5a6b7013019ba4afac2b712fc06ea82f",
"_rev": "1-1e6c5b7bc622d9b3c9b5f14cb0fcb672",
"language": "query",
"views": {
"invoice_code": {
"map": {
"fields": {
"data.type": "desc",
"data.idib": "desc"
},
"partial_filter_selector": {}
},
"reduce": "_count",
"options": {
"def": {
"fields": [
{
"data.type": "desc"
},
{
"data.idib": "desc"
}
]
}
}
}
}
}
Both of the published syntax rules are broken!
map is not a function
options defines the fields of the index
Where can I find a full description of all the allowed properties of a Design Document?

Preserving the position while searching

I need to make elasticsearch query to work with multiple words. I am using edgeNgram tokenizer to support autocompletion feature and I am using query_string for searching.
Document
{
"title":"Gold digital cinema",
"region":"Mumbai"
}
{
"title":"cine park",
"region":"Mumbai"
}
{
"title":"Premier Gold",
"region":"mumbai"
}
Query
{
"query": {
"bool": {
"should": [
{
"query_string": {
"fields": [
"title",
"region"
],
"query":"gold cine"
}
},
{
"fuzzy": {
"title": {
"value":"gold cine",
"min_similarity": 0.5,
"max_expansions": 50,
"prefix_length": 0
}
}
}
]
}
}
}
When I search for gold cine, I need "title":"Gold digital cinema" to be in the top results. But I am getting "title":"cine park" and "title":"Premier Gold" in top.
Is there any way to preserve position while searching?
Thanks in advance.
UPDATE
{
"query":{
"bool":{
"should":[{
"query_string":{
"fields":["title.default_title^10",
"title.ngrams_front^2",
"title.ngrams_back"],
"query":"gold cine",
"boost":2
}
},
{
"function_score":{
"query":{
"query_string":{
"fields":["region"],
"query":"MUMBAI"
}
},
"functions":[{
"script_score":{
"script":"_score + 0.6"}
}
],
"score_mode":"max",
"boost_mode":"avg"
}
}
]
}
}
}
You can use boost to pull up the data on top..
{
"query": {
"bool": {
"should": [
{
"query_string": {
"fields": [
"title",
"region"
],
"query":"gold cine",
"boost": 3
}
},
{
"fuzzy": {
"title": {
"value":"gold cine",
"min_similarity": 0.5,
"max_expansions": 50,
"prefix_length": 0
}
}
}
]
}
}
}
If you use version 1.0.0.and above you should use function score query.
HOpe it helps..!

Resources