Taurus Blazemter - How to use a function in a body - blazemeter

I would like to send a request with a random value or using the current date in the json payload of the request's body in Blazemeter
Example:
method: POST
url: ${url}/transaction
headers:
Content-Type: application/json
body: {
"order": {
"id": uuidGenerator() + "test" ,
"timestamp": datetime( now() , 'yyyy/MM/DDTHH:mm:ssZ')
}
}
Doc references Test Data Generator Functions:
https://guide.blazemeter.com/hc/en-us/articles/360011769877-Test-Data-Generator-Functions-Test-Data-Generator-Functions
Expected
"order": {
"id": "7d052488-6fbf-11eb-9439-0242ac130002-test" ,
"timestamp": "2021-01-15T18:00:00Z"
}
But
id value is not interpreted "uuidGenerator() + "test"
syntax seems to be incorrect for timestamp and card in Blazemter taurus

method: POST
url: ${url}/transaction
headers:
Content-Type: application/json
body: {
"order": {
"id": "${__UUID()}" ,
"timestamp": "${__time(yyyy-MM-dd'T'HH:mm:ss'Z',)}"
}
}
more functions: https://jmeter.apache.org/usermanual/functions.html#__time

Related

Customer booking API - Create bookingCustomer

When creating a new bookingCustomer object the displayName property value is replaced by emailAddress value:
POST https://graph.microsoft.com/beta/bookingBusinesses/Contosolunchdelivery#M365B489948.onmicrosoft.com/customers
Content-type: application/json
{
"displayName": "Joni Sherman",
"emailAddress": "jonis#relecloud.com"
}
Response:
HTTP/1.1 201 Created
Content-type: application/json
{
"#odata.context": "https://graph.microsoft.com/beta/$metadata#bookingBusinesses('Contosolunchdelivery%40M365B489948.onmicrosoft.com')/customers/$entity",
"id": "36038f36-634e-44e4-9415-d7d59c2347aa",
"displayName": "jonis#relecloud.com",
"emailAddress": "jonis#relecloud.com"
}
The example from docs (https://learn.microsoft.com/en-us/graph/api/bookingbusiness-post-customers?view=graph-rest-beta&tabs=http):
Same story over HTTP and SDK.
Any toughts?

How to make the response example in Swagger UI match the actual response for application/application/vnd.api+json?

I have an API response which adheres to json-api spec of application/vnd.api+json. The response looks like this:
{
"jsonapi": {
"version": "1.0"
},
"data": {
"type": "drawDate",
"id": "1",
"attributes": {
"schoolStartDate": "2019-01-02T00:00:00.000Z"
}
}
}
However, in Swagger UI under "Responses", where the model is specified, the response example is displayed as follows, which is different from the actual response:
[
{
"schoolStartDate": "2019-01-02T00:00:00.000Z"
}
]
I tried adding content type of application/vnd.api+json for the GET content property, but this did not help:
responses:
* 200:
* description: Gets school list
* content:
* application/vnd.api+json:
* schema:
* type: array
* items:
* $ref: '#...'
How to make the response example value in Swagger UI match the actual API response?

proper syntax for generating JSON body in API call

With the following long controller action code
#available = Available.find(694)
#tareservation_id = 8943
#request_date_time = Time.now.utc.iso8601
#request_id = Time.now.to_i
#in_date = (Date.today + 24.days).strftime("%Y-%m-%d").to_s
#book = %Q|{
"booking": {
"currencyCode": "USD",
"languageCode": "es",
"paxNationality": "ES",
"clientRef": {
"value": \"#{#tareservation_id}\",
"mustBeUnique": true
},
"items": [
{
"itemNumber": 1,
"immediateConfirmationRequired": true,
"productCode": \"#{#available.product_code}\",
"leadPaxName":
{ "firstName": "Guy",
"lastName": "Test"
},
"product":
{
"period":
{
"start": "2018-08-27",
"quantity": 2
}
}
} ]
},
"requestAuditInfo":
{ "agentCode": "001",
"requestPassword": "pass",
"requestDateTime": \"#{#requestDateTime}\",
"requestID": #{#request_id} },
"versionNumber": "2.0"
}|
This then must be shipped off to the API as JSON in the body call
#result = HTTParty.post(
'https://test.com/search',
:body => JSON.parse(#book).to_json,
headers: {
'Content-Type' => 'application/json',
'Accept' => 'application/json',
'Connection' => 'Keep-Alive'
}
)
If the following block is removed:
,
"product":
{
"period":
{
"start": "2018-08-27",
"quantity": 2
}
}
in console JSON.parse(#start), parses properly. With the block JSON::ParserError: 784: unexpected token. Yet I fail to see what is incorrect here?
Is Rails handling of string for future JSON conversion really strict on syntax, particularly since there is interpretation of instance variables - both as strings and integers - and har returns involved? What would it be then? Or is there a safer solution to get out of what quickly becomes quicksand?
It turns out that pasting too many lines into the console (iTerm2, in this case) does something to the memory. 25 lines of code pasted in a single time is the maximum observered where behaviour is as expected.

Pact verification: Failure/Error: expect(header_value).to match_header(name, expected_header_value)

Using pact to verify if the response header matches for the consumer and provider.
Running the pact verification on the provider side gives me the following error:
Failure/Error: expect(header_value).to match_header(name, expected_header_value)
Expected header "abc" to equal "xyz", but was nil
However, when I inspect if my response header, it gives me the expected value ("xyz").
Here is the sample pact file I'm trying to verify:
"interactions": [
{
"description": "a request to do something",
"request": {
"method": "get",
"path": "/example"
},
"response": {
"status": 200,
"headers": {
"abc": "xyz"
}
}
}]
I’m new to pact. Any help would be appreciated.
While this is an old post, I hope this will help anyone who views this.
I'm not familiar with ruby, however if your using a basic HTTP Rest request you need to add the accept headers on the 'withRequest' as well as the expected headers on the 'withRespondWith'. You can use Postman to view both request and response headers; JavaScript Example:
describe('When a request is made to get all <resources>', () => {
beforeAll(() =>
provider.setup().then(() => {
provider.addInteraction({
uponReceiving: 'a request to receive to receive all...',
withRequest: {
method: 'GET',
path: '/<resource>',
// Default headers from Axios documentation
headers: { Accept: "application/json, text/plain, */*" }
},
...
willRespondWith: {
// expected headers
headers: { "Content-Type": "application/json; charset=utf-8" },
...

GET /entity.svc failed in batch

I defined a service in dataSources
"dataSources": {
"mainService": {
"uri": "/backend/service/v1/entity.svc/",
"type": "OData",
}
}
"models": {
"": {
"dataSource": "mainService",
"preload": true,
"settings" : {
"sizeLimit" : 500,
"useBatch" : false,
"refreshAfterChange": false,
"defaultBindingMode": "TwoWay",
"defaultCountMode" : "None",
"defaultUpdateMethod" : "Put"
}
}
}
But for some reason I don't know, ui5 project will call GET /backend/service/v1/entity.svc/ when initial load, which returns several <collection>.
But when I set UseBatch to true, the batched GET request will fail, with payload like this:
--batch_67d5-9dc2-70e0
Content-Type: application/http
Content-Transfer-Encoding: binary
GET HTTP/1.1
sap-contextid-accept: header
Accept: application/json
Accept-Language: en-US
DataServiceVersion: 2.0
MaxDataServiceVersion: 2.0
sap-cancel-on-close: true
--batch_67d5-9dc2-70e0-
As it seems like a GET nothing request, the batch request will certainly fail. Is there any UI5/oData expert can tell me what's the point of GET /entity.svc, how to fix this batch or how to skip this request ?
I found that it is cause by data binding in sap.m.Table
_bindView : function (sObjectPath) {
var sAssignedPath = sObjectPath + "/assignedThings",
this._oModel.read(sAssignedPath , {
success : this._handleGetAssignedSuccess.bind(this, sAssignedPath),
error : this._handleGetAssignedError.bind(this)
});
oTable.setModel(this._oModel);
}
_handleGetAssignedSuccess : function (sAssignedPath, oMsg) {
var oTable = this.getView().byId("tableView").byId("assignTable"),
oJSONModel = new JSONModel(oMsg.results);
oAssignTable.setModel(oJSONModel);
},
//AssignTable.view.xml
<Table
id="assignTable"
inset="true"
items="{
path: '/'
}"
>
items="{path: '/'}" is mean to use in JSON Model data binding, but it also triggered an oData GET '/' Request.

Resources