JSONAssert.assertequals to compare two jsons fails if the resultant payload has additional array value - jsonassert

My api has a response payload that is inside an array and the size of the array can change between test runs. Array is big hence not posting the expected / actual values here.
I have assert code that can compare two payload and ignore values that i'm expecting to be different. but if the response array is bigger than expected (which is likely in my case) it fails. is there a way to ignore the size of the array validation in JSONAssert.assertequals()method? JSONCompareMode.LENIENT is not cutting it.
i can ignore any key/value pairs in the payload with this and the assertion still passes. but if i have a response array that's bigger than the expected, then it fails.
java.lang.AssertionError: []: Expected 55 values but got 57
My assertion code:
JSONAssert.assertEquals(expResponseBody.toString(), actualResponseBody.toString(), new CustomComparator(JSONCompareMode.LENIENT, new Customization("ignoreKey", (o1, o2) -> {return true;})));

Related

Is it valid that two FIX messages are sent together in one go?

My QuickFIX client is complaining that the body length is not expected.
After checking, it is found that it receives a message which actually contains 2 messages (2 different MsgTypes <35>). Also, 2 BeginStrings <8>
Is it a valid message?
The error is reported by QuickFIX, instead of my own code.
Hence, it looks like an invalid message to me although I cannot find any official doc, saying that it is not allowed.
I would expect that QuickFIX could parse the messages as long as the body length of the first message is correct.
You could check if the body length is correct by using the following:
counting the number of characters in the message following the BodyLength (9) field up to, and including, the delimiter immediately preceding the CheckSum (10) field. ALWAYS SECOND FIELD IN MESSAGE. (Always unencrypted) For example, for message 8=FIX 4.4^9=5^35=0^10=10^, the BodyLength is 5 for 35=0^
Source: https://btobits.com/fixopaedia/fixdic44/index.html?tag_9_BodyLength.html
Its completely depends on your fix engine whether to support multiple messages in one go or not.
Using BodyLength[9] and CheckSum[10] fields.
BodyLength is calculated starting from field starting after BodyLenght and
before CheckSum field.
CheckSum is calculated from ‘8= upto SOH before the checksum field.
Binary value of each character is calculated and compared to the LSB of the calculated value to the checksum value.
If the checksum has been calculated to be 274 then the modulo 256 value is 18 (256 + 18 = 274). This value would be transmitted a 10=018 where
"10="is the tag for the checksum field.

Karate - Conditional logic with string and array

This question derives from this question asked earlier. I am making a Soap request, and I am receiving the response as either an Array, or String.
[print] [ "M4205N", "M4206U" ]
[print] M5967H
When I get the response as an array, I figured out how to loop through it, and pass the values to another request. However, sometimes the response will come back as a single Code, and it will be returned as a String. In that case, I cannot perform the same logic as I did with the array. I've read about Karate conditional logic, but I cannot figure out how to make it do what I want.
I want to do something like this:
If the response is returned as a String, then call this method with the one value.
If the response is returned as an array, then call this method and pass each value from the array.
This is one of the ways I had in mind, but it does not work because of the Type difference:
* def memberCodes = memberCodes.size() > 1 ? karate.mapWithKey(memberCodes, 'memberCode') : {}
* def result = call read('OtherRequest.feature') memberCodes
This works if the response is returned as an array, but obviously if it's returned as a String it will break.
What is the right way to perform this conditional logic? Also, please refer to my previous question for more context if needed. Thanks!
Interesting. This check should work for testing if (not) a string:
* def memberCodes = typeof memberCodes != 'string' ? karate.mapWithKey(memberCodes, 'memberCode') : {}
Also refer this somewhat related question: https://stackoverflow.com/a/58543843/143475

Validation failed if the Compare happened between Integer

I have to test one Temp Sensitive IoT device API, Where Need to pass the Maximum and Minimum Temp in the Request Paylod, And the Response need to validate if the correct data is processed successfully. I have used the method .validate .validate("$.minVal", "(${minVal})") minVal = 20 to do a validation. But however the script is ended up with the exception as follow
FAILURE: Caused by: ValidationException: Validation failed: Values not
equal for element '$.maxVal', expected '(20.0)' but was '20
Request--> {"minVal": "20.0", "maxVal": "20.0"}
Response--> {"maxVal":20,"minVal":20,}
Note: if my Request Input is 20.12 its working fine.
Appreciate you guys help.
First of all remove the brackets () around ${minVal} variable. Secondly your minVal variable value is obviously a decimal number 20.0. The received value in Json is a non-decimal number 20. This is why the validation did fail - I think the error message is pretty clear.

why the output always "System.Object"

in EF I want tto get the first value of query so I use
ExecuteStoreQuery<object>(Query, null).FirstOrDefault();
because I don't know what's the actual returned data type
if the value comming is numeric is crash , so I used the following
ExecuteStoreQuery<object>(Query, null).Select(x => x.ToString()).FirstOrDefault()
but the resulted string always System.Object
any idea how to get the actual value
Best regards

MATLAB: Referencing an element in a structure

I am trying to reference an element buried within a structure that I did not create (hence I don't know the exact way in which it was built).
Having loaded the structure, if I type:
dataFile.RECORDINGS.eye
I receive the following output:
ans =
2
ans =
2
Both of those variables will always be the same, but they could be at any time 1, 2 or 3. What I'd like to do is check with a switch statement which looks like this:
switch dataFile.RECORDINGS.eye
case {1, 2}
% action A
case 3
% action B
end
Of course, the above throws up an error because 'case' cannot check whether dataFile.RECORDINGS.eye contains a given value since there are two elements stored under that address. So, my question is: how do I reference just one of the elements? I thought it would be as simple as replacing the first line with:
switch dataFile.RECORDINGS.eye(1)
...But, this gives the error:
??? Field reference for multiple structure elements that is followed by more reference blocks is an error.
Similarly, I can't access the element like this:
switch dataFile.RECORDINGS.eye.1
...As I get the following error:
??? Dot name reference on non-scalar structure.
If the values are really always the same, you can try the following to get a scalar that can be used in the switch command:
unique([dataFile.RECORDINGS.eye])
By the way, did you try to index RECORDINGS, i.e.,
dataFile.RECORDINGS(1).eye
dataFile.RECORDINGS(2).eye
Perhaps instead of eye having multiple elements, you have multiple elements of RECORDINGS that each have a single value of eye? You might want dataFile.RECORDINGS(1).eye or dataFile.RECORDINGS(2).eye.