How to define ApiBlueprint array values example with MSON? - jsonschema

Can I use MSON to specify an example values instead of + Body?
Is it possible to override predefined structure values?
I've tried like this:
+ Request (application/json)
+ Headers
Authorization: JWT <token>
+ Attributes (ClientsideCommand)
+ alias: `show-xc`
+ args (array[AppCommandArg], fixed-type)
+ (AppCommandArg)
+ arg_key: address
+ order: 1
+ required: true
+ skip_arg_name: true
+ (AppCommandArg)
+ arg_key: `-A1`
+ order: 2
+ required: true
+ skip_arg_name: false
But such definition corrupts json-schema, because AppCommandArg descibed as separate objects.
And also in the JSON generated from the MSON has 3 items where first item is deafult AppCommandArg.

Looks like it's not possible to make this things twogether. If you add elements as showed abowe Apiary renders it as it sees it, if an element noted twice the json schema also will describe it twice.

Related

Is it possible to dynamically change an url with values in the array without storing the values in separate feature file

I need to array values say 10 values from the previous url response to get replace in the next url
*def k = [1,2,3]
Given url 'https://www.' + k + 'zzzz'
Tried this:
*def k = [1,2,3]
Given url 'https://www.' + k[*] + 'zzzz'
Expecting:
Given url 'https://www.+ 1 + zzzz'
need its response to store
Given url 'https://www.+ 2 + zzzz'
need its response to store
Given url 'https://www.+ 3 + zzzz'
need its response to store
Yes, in Karate 1.3.1 onwards: https://github.com/karatelabs/karate#setup
Try the below and see it work.
Feature:
#setup
Scenario:
# do some http stuff here and prepare the data to use in the loop
* def data = [{ myNum: 1 }, { myNum: 2 }, { myNum: 3 }]
Scenario Outline:
* url `https://httpbin.org/anything/${myNum}`
* method get
Examples:
| karate.setup().data |

How to manage response assertion if the values are same but sequence changes in Jmeter

I am getting response, let's suppose {"profiles":{"HLS_1200":[{"profile_id":38,"quality_id":11}],"ADAPTIVE" {"L","XL","XXL"}, now every time when we hit the API the response is same but the sequence is getting changed and therefore assetion is getting failed.
Next time I will get the response like {"profiles":{"HLS_1200":[{"profile_id":38,"quality_id":11}],"ADAPTIVE" {"XL","L","XXL"},
I want to pass this response assertion even if the sequence is changed.
Go for JSONAssert library which performs "deep scans" and doesn't care about the order of the attributes
Obtain the following libraries and drop them to JMeter Classpath:
android-json-0.0.20131108.vaadin1.jar
jsonassert-1.5.0.jar
Restart JMeter to pick up the libraries
Add JSR223 Assertion as a child of the request which returns your JSON
Put the following code into "Script" area:
def expected = '{\n' +
' "profiles": {\n' +
' "HLS_1200": [\n' +
' {\n' +
' "profile_id": 38,\n' +
' "quality_id": 11\n' +
' }\n' +
' ],\n' +
' "ADAPTIVE": [\n' +
' "L",\n' +
' "XL",\n' +
' "XXL"\n' +
' ]\n' +
' }\n' +
'}'
org.skyscreamer.jsonassert.JSONAssert.assertEquals(expected, prev.getResponseDataAsString(), false)
More information:
Introduction to JSONassert
Scripting JMeter Assertions in Groovy - A Tutorial

Extract and comparing data from json array not working in karate

I am trying to search a certain value in a JSON array using the value stored in a variable and then comparing somehow this is not working for me. Can you please help. BillerId1 is always returning a blank value
Given url buyerApi
Given url paymentHub
Then path '/BPAY/v' + version + '/billers'
And header Authorization = 'Bearer ' + token
When method get
Then status 200
* def id = response[0].savedBillerId
Then url paymentHub
Then path '/BPAY/v' + version + '/billers/' +id
And header Authorization = 'Bearer ' + token
And request {billerCode:<billerCode>, billerCRN:'<billerCRN>'}
When method put
Then status 200
Then url paymentHub
Then path '/BPAY/v' + version + '/billers'
And header Authorization = 'Bearer ' + token
When method get
Then status 200
* print id
* def billId1 = get[0] response[?(#.savedBillerId==**'#id'**)].savedBillerId
* print billId1
And match billId1 == id
Examples:
| billerCode | billerCRN |
| 65284 | 65112345675 |
Array looks like this
[
{
"savedBillerId": "ebfa2b9f-f49c-4b0c-c6ee-08d7e671944a",
"billerId": "26c67edb-b3dc-44ea-aa74-08d7d6890798",
"billerName": "test case 21c",
"billerCode": 65284,
"crn": "65112345675"
},
{
"savedBillerId": "500dfde7-e31c-408d-c6ef-08d7e671944a",
"billerId": "26c67edb-b3dc-44ea-aa74-08d7d6890798",
"billerName": "test case 21c",
"billerCode": 65284,
"crn": "65112345672"
}
]
#ptrthomas
Please read the docs: https://github.com/intuit/karate#jsonpath-filters
* def id = '500dfde7-e31c-408d-c6ef-08d7e671944a'
* def billId1 = karate.jsonPath(response, "$[?(#.savedBillerId=='" + id + "')].savedBillerId")[0]
* match billId1 == id
Also I feel this is a worthless check. You find by id and again check that id ?

Karate - switch between headers

Presume I have 2 users and I use basic authentication. I'd like to generate the 2 basic auth tokens once and reuse it per scenario in one feature. On top of that I have scnearios where no authorization is needed. How could I achieve this with the least biolerplate? Currently I have
auth-header.js
function(creds) {
var temp = creds.username + ':' + creds.password;
var Base64 = Java.type('java.util.Base64');
var encoded = Base64.getEncoder().encodeToString(temp.bytes);
return 'Basic ' + encoded;
}
karate-config.js
...
config.apitester1AuthHeader =
karate.call('classpath:auth-headers.js', {username:'apitester1', password:'xxx'});
config.apitester2AuthHeader =
karate.call('classpath:auth-headers.js', {username:'apitester2', password:'xxx'});
...
project-get.feature
Feature: project end-point
Background:
* url baseUrl
Scenario: get projects user has right to
* configure headers = {Authorization : '#(apitester1AuthHeader)'}
Given path 'project'
...
What you have looks reasonable.
Note that if you do:
* configure headers = null
It will have the effect of temporary no authorization. I would recommend stick with what you have and it is quite modular already.

Export custom formatted expressions from Mathematica

How can I get Mathematica to export/save/write a text file with proper Fortan77 formatting, that is, 72 columns and a continuation marker on the sixth column?
I am using Mathematica to generate large and complex analytic expressions, which I then need to insert into pre-existing Fortran77 code. I have everything working correctly in the front end of Mathematica with FortranForm[] and
SetOptions[$Output, PageWidth -> 72]
However, I can't figure out how to get Mathematica to output correctly to a text file. I want something like this:
MM11 = mH1**2 + (g2**2*v1**2)/2. -
- (g2**2*(v1**2/2. -
- ((v2*Cos(phi2) - (0,1)*v2*Sin(phi2))*
- (v2*Cos(phi2) + (0,1)*v2*Sin(phi2)))/2.))/2.
...
but get either this:
MM11 = FortranForm[mH1^2 + (g2^2*v1^2)/2 - ...
or this:
MM11 = mH1**2 + (g2**2*v1**2)/2. - (g2**2*
(v1**2/2. - ((v2*Cos(phi2) - (0,1)*v2*Sin(phi2))*
...
This is a job for the surprisingly little-known Splice function. First, you make a template file, with the extension ".mf", like so:
file = "test.mf";
out = OpenWrite[file];
WriteString[out, "MH1 = <* form *>"];
Close[out];
Now when you use Splice, Mathematica will automatically replace everything between the <* and *> delimiters with its evaluated form. So if you set
form = 4 + b9^2 + c1^5 + c4^5 + h10^4 + j2 + k10^4 + p10^4 + q5^5 +
q8 + s3^3 + s7^2 + t6^3 + u3^2 + u9^3 + x8^4 + z2^3;
and call
Splice["test.mf", PageWidth -> 72];
which will automatically infer you want FortranForm output from the file extension, and which allows you to set PageWidth as an option, you will get a pretty decent result in the automatically generated file "test.f" (note the new extension):
MH1 = 4 + b9**2 + c1**5 + c4**5 + h10**4 + j2 + k10**4 + p10**4 +
- q5**5 + q8 + s3**3 + s7**2 + t6**3 + u3**2 + u9**3 + x8**4 +
- z2**3
Look at the docs for Splice for more options (changing the name of the output file and the like).