How to fetch 2 DB column value and compare it with Single JSON element in JMeter - jmeter

Below is the Table:
Customer ID     Customer number
1                        ABC123
null                    DEF123
JSON variable name is, CustomerDetail:
In my scenario I want to check if Customer ID is not null then in JSON, Customer ID should display against CustomerDetails. That means CustomerDetails: "1"
If Customer ID is null then in JSON Customer number should display against CustomerDetails. That means CustomerDetails: "DEF123"
How Can I perform this validation in JMeter using JSR223 assertion.
Question: For CutomerDetails (In JSON)- if CustomerID is not null then display its value otherwise display value for customer number. In below provided code how can I fetch value of both the column from Db and then compare them?

Your question is unclear, if you configure your JDBC Request sampler as follows:
it will generate the following JMeter Variables
CustomerID_1=1
CustomerID_2=null
CustomerID_#=2
CustomerNumber_1=ABC123
CustomerNumber_2=DEF123
CustomerNumber_#=2
In the JSR223 Assertion you can use vars shorthand for JMeterVariables class instance in order to access variable values like:
1.upto(vars.get('CustomerID_#') as int, { index ->
if (vars.get('CustomerID_' + index) == 'null') {
//do something
} else {
//do something else
}
})

Related

Filebeat Script Processor Event.Get All Fields In Log

I am looking to get all of the fields in a record in filebeat using the Script processor and perform an action on them. Using the event.Get() from the script processor, it says, "Get a value from the event (either a scalar or an object). If the key does not exist null is returned. If no key is provided then an object containing all fields is returned."
https://www.elastic.co/guide/en/beats/filebeat/current/processor-script.html
Therefore, my question is, what would I do to ensure that no key is provided to get an object that contains all of the fields are returned?
The event.Get() field will provide the top level fields. To look through these top level fields, use a for loop like:
- script:
lang: javascript
id: get_fields
source: >
function process(event) {
var a = event.Get();
for (var key in a) {
if(event.Get(key) == ""){
event.Delete(key);
}
}
}
I am unsure how to do this for nested fields in this way nor have I tried to extend it to nested fields, but this is how it works for now.

Validate the JDBC request with a user defined variable

I am new to JMeter,
In my test I am creating a JDBC Connection to oracle DB and running a query which fetching me the count of records, which I want to validate must be equal to the SAMPLE-NUMBER (which is a defined variable in the user defined variable).
SELECT COUNT(*) FROM event_log WHERE audit_context_key LIKE '288017ec-0dcf-4fd5-9565-e8ad15e65cd2' AND event_desc = 'Success'
Response Body:
COUNT(*)
2
UserDefined Variable
You can do this, defined the variable name in JDBC request,
for example, TOTALCOUNT and add a JSR223 Assertion with the following code,
1.upto(vars.get('TOTALCOUNT_#') as int, {
if (vars.get('TOTALCOUNT_' + it) == '${__groovy(vars.get('SAMPLE-NUMBER'),)}') {
AssertionResult.setFailure(false);
}
})
Response Assertion can do the trick for you:
In the JDBC Request define "Variable Names", i.e. ACTUAL_COUNT
Once done you can compare the ACTUAL_COUNT variable value with the SAMPLE-NUMBER variable like:

How to pass multiple values in a for each controller

This is how the test plan looks :
Thread group
Bean shell sampler
For each Controller
Graphql request
In the previous thread I extracted 2 attributes which are id and price. Now this id and price are unique for each case.
I extracted these 2 attributes from the json response and stored in a text file separated by colon. Sample below (id : price)
123-456-789 : 45.5
889-332-121 : 60
I need to run the above thread for each such combination i.e. id and price need to be passed at run time to the variable section of graphql request.Using for each controller I am able to pass each of the Ids but how do I pass the corresponding price ?
If you have JMeter Variables like:
id_1=123-456-789
id_2=889-332-121
price_1=45.5
price_2=60
The id you can get from the ForEach Controller configured like:
And refer it as ${id} under the ForEach Controller
With regards to the "price" you will need to use __V() and __intSum() functions combination like:
${__V(price_${__intSum(${__jm__ForEach Controller__idx},1,)},)}
Demo:
More information: Here’s What to Do to Combine Multiple JMeter Variables

GraphQL mutation with subquery for parameter - update/convert DB on write?

Is it possible to add a look up to a mutation in GraphQL? Let's say something like an input type where one property is the result of another query.
createPerson(name: "Steve", gender: genders ( name: { eq: "mail" } ) { id } )
where genders ( name: { eq: "mail" } ) { id } would return exactly one result value
GraphQL allows you to:
"get what you want";
manipulate data on write;
customize response on read;
You can of course write a createPerson mutation resolver to:
ask another table for additional data (if missing arg);
write into DB;
But it doesn't affect (isn't suitable for) existing records.
You can also use read resolvers to update missing fields in records using field resolver - a kind of 'eventual consistency'.
Write person resolver to read a person record and additional person.gender field resolver to get value for missing gender value. The second one can be used to update the 'main' person [DB table] record:
read a missing value from other table;
write a value into person record on the 'main' table;
return value.
Next time person resolver will read gender value at once (from 'main' person table), [additional] field resolver won't be called at all.
This technique can be used to convert DB data without writing SQL/DB specific code (different syntax/types problems, safer on more complex logic) - it's enough to read each/all person's gender fields. Field resolver (and the other/old table) can be removed after that.

Composer query to match a participant reference

So I have a query like this:
query selectOrder{
description: "Select an Order that matches a Client reference and an Order Number"
statement:
SELECT com.x.Order
WHERE (client == _$client AND orderNumber == _$orderNumber)
}
The order is something like this:
asset Order identified by uuid {
o String uuid
--> Client client
o String orderNumber
--> Item[] items
}
How do I pass the reference to the client to the query?
I tried the reference and was told to toJSON it.
I tried that and it won't parse the thing - there's a clear issue with the parsing of the query.
I can't find the answer in the docs, so I'm wondering if anyone has done this or if I have to save the client id instead of the reference to client and lose the integrity.
EDIT: For completeness for the first answer below.
I'm trying to add an Item to the array of Items.
My Item object is defined like this:
asset Item identified by uuid {
o String uuid
o DateTime timestamp
o String orderNumber
--> Client client
o String[] message
}
When the transaction is invoked the single object passed in is the Item.
I'm setting Item.client as the _$client value in the query.
Should I be pre-pending it with "resource:"?
I'm asking because I thought that was in the reference string already - at least it is in the view in the playground.
EDIT2:
So I manually construct the following variable:
var RSRC = 'resource:com.x.Client#XYZ123'
Set that as the client in this query
return query('selectOrder', {agency : RSRC, orderNumber : orderNumber});
But I'm still getting this:
Error: unknown operator "0" - should be one of $eq, $lte, $lt, $gt,
$gte, $exists, $ne, $in, $nin, $size, $mod, $regex, $elemMatch, $type
or $all
What next?
Embedding the "resource..." string in quotes didn't work either.
Your query looks ok, but you need to pass a string with the format:
resource:type.Name#instance for the relationship.
E.g. resource:org.acme.Car#123ABC

Resources