verify a method is called only once with a given parameter with Junit 5 - junit5

I want to ensure that my test calls the userService.find(userName) only with the expected aTestName and only once. Currently, I am achieving this by the following code. Is there a way to combine the two BDDMockito.then... in one?
String aTestName = "aTestName";
BDDMockito.then(userService).should(times(1)).findByName(any());
BDDMockito.then(userService).should(times(1)).findByName(aTestName);

What you should use is only(). So like:
BDDMockito.then(userService).should(only()).findByName(aTestName);

Related

DBT Test configuration for particular scenario

Hello Could anyone help me how to simulate this scenario. Example I want to validate these 3 fields on my table "symbol_type", "symbol_subtype", "taker_symbol" and return unique combination/result.
I tried to use this command, however Its not working properly on my test. Not sure if this is the correct syntax to simulate my scenario. Your response is highly appreciated.
Expected Result: These 3 fields should return my unique combination using DBT commands.
I'd recommend to either:
use the generate_surrogate_key (docs) macro in the model, or
use the dbt_utils.unique_combination_of_columns (docs) generic test.
For the first case, you would need to define the following in the model:
select
{{- dbt_utils.generate_surrogate_key(['symbol_type', 'symbol_subtype', 'taker_symbol']) }} as hashed_key_,
(...)
from your_model
This would create a hashed value of the three columns. You could then use a unique test in your YAML file.
For the second case, you would only need to add the generic test in your YAML file as follows:
# your model's YAML file
- name: your_model_name
description: ""
tests:
- dbt_utils.unique_combination_of_columns:
combination_of_columns:
- symbol_type
- symbol_subtype
- taker_symbol
Both these approaches will let you check whether the combination of the three columns is unique over the whole model's output.

Karate Netty - CallSingle but not so single

What I had till today:
I have get_jwt.feature and I call it as a part of karate-config.js. Since I have used one account test#test.com I needed only one jwt and I can reuse it across scenarios. callSingle worked as a charm in this case.
Today:
Suddenly I have need for jwt's from two accounts which I dont want to generate for each scenario, callSingle falls short of this task as it does exactly what its supposed to be doing. Now I have hacky idea, I can simply make two files, get_jwt.feature and get_jwt_user2.feature, and single call them each.
So my question: Is there a better way of doing this?
You can use "2 levels" of calls. So point the callSingle() to a JS function that calls get_jwt.feature 2 times, maybe with different arguments and then return a JSON. Pseudo-code below. First is get_jwts.js:
function fn(users) {
var jwt1 = karate.call('get_jwt.feature', users.user1);
var jwt2 = karate.call('get_jwt.feature', users.user2);
return { jwt1: jwt1, jwt2: jwt2 };
};
Then in karate-config.js
config.jwts = karate.callSingle('classpath:get_jwts.js', users);
And now you should be able to do this:
* print jwts.jwt1
* print jwts.jwt2
You can also do a feature-->feature call chain. Do let me know if this works !
EDIT: see Babu's answer in the comments, looks like you can pass an array to callSingle() ! so that may be quite convenient :)

Query parameter handling in karate framework

Is there any easy way to handle huge query param like below. Also I would like to know how can I do run time parameterisation for some values?
http://154.213.196.243:7941/v1/banking/Jumio/callback?callBackType=NetVerifyId&jumioIdScanReference=123abcde-1244-8571-3454-abcd12345567&merchantIdScanReference=66a9ff2e-d8ec-e811-a956-000d3ab3f117&verificationStatus=APPROVED_VERIFIED&idScanStatus=SUCCESS&id+ScanSource=API&idCheckDataPositions=OK&idCheckDocumentValidation=OK&idCheckHologram=OK&idCheckMRZcode=OK&idCheckMicroprint=OK&idCheckSecurityFeatures=OK&idCheckSignature=OK&transactionDate=2018-11-20T20%3A53%3A25.797Z&callbackDate=2018-11-20T20%3A53%3A25.797Z&idType=DRIVING_LICENSE&idCountry=GBR&idScanImage+=https%3A%2F%2Fnetverify.com%2Frecognition%2Fv1%2Fidscan%2F123abcde-1244-8571-3454-abcd12345567%2Ffront&idFirstName=ILARIA&idLastName=FURS&idDob=1976-12-23&idExpiry=2025-12-31&personalNumber=123456789&clientIp=xxx.xxx.xxx.xxx&idAddress=%7B%22country%22%3A%22USA%22%2C%20%22stateCode%22%3A%22US-OH%22%7D&idNumber=P12345&idStatus=TESTER961260SS9DL54&identityVerification=%7B%22similarity%22%3A%22MATCH%22%2C%22validity%22%3Atrue%7D HTTP/1.1
Yes. Read the docs: https://github.com/intuit/karate#param
For example:
* param callBackType = 'NetVerifyId'
and so on. And look at params where you can set all keys up as one single JSON and also do parameterization if needed, there are multiple possibilities: https://github.com/intuit/karate#params
See this example as well: dynamic-params.feature

How to Set Postman Test Equal to This or That

I am writing an API test in Postman, and I would like it to succeed if a Number is returned or the string "NA".
Based on my current understanding one condition can be tested at a time, like:
pm.test('Qty returned is number', () => {
pm.expect(typeof parseInt(pm.response.json().qty)).to.be.not.equal('NaN');
});
Writing as two separate tests, one will pass and one will fail.
How can I code this exception into a single test?
Worked for my case, wanted the test to pass if one of two values is returned:
.to.be.oneOf(["value1","value2"]);
answer from jaikl

How to parameterize tests for each iteration in Postman collection?

My GET request goes like this:
<some ip>/search?IW_INDEX={IW_INDEX}&IW_FIELD_WEB_STYLE={IW_FIELD_TEXT}
The data file is as follows:
IW_INDEX,IW_FIELD_TEXT
index1,text1
index2,text2
My test for iteration 1 is as follows:
tests["parameter1"] = responseBody.has("value=\"19\"");
Now this value 19 will change depending upon the iteration and might be 20 in iteration 2.
Is there a way to provide expected test results iteration-wise in Postman?
I think you could do it by adding a column to your CSV file with "expected_result" and in the test, call that value by {{data.expected_result}}, so your test should probably look like:
tests["parameter1"] = responseBody.has("value=\"{{data.expected_result}}\");