How to use Pact Matcher for values other than 'Strings' - pact

In pact-jvm (groovy on consumer side and gradle on the provider side), I'm trying to use Pact matchers like below:
name regexp(~/\w+/,'sony')
Will Pact matcher regex work only for Strings ? For values other than strings, do I need to use Pact term ?
If the answer is 'yes' for the above two questions. Please explain me how to use Pact term in groovy style.
I have tried using Pact term like below:
date Pact.Term(generate :"02/11/2013", matcher:/\d{2}\/\d{2}\/\d{4}/)
But getting groovy - MethodMissingException.
My complete response body for reference:
withBody {
id regexp('[0-9a-f]{8}-([0-9a-f]{4}-){3}[0-9a-f]{12}','e8cda07e-849f-49c2-94d6-aaa5c4ab7fcd')
name regexp(~/\w+/,'sony')
date Pact.Term(generate :"02/11/2013", matcher:/\d{2}\/\d{2}\/\d{4}/)
}

Regex only applies to strings.
If you want to match a date, I'd suggest using the date matcher, e.g.
withBody {
id regexp('[0-9a-f]{8}-([0-9a-f]{4}-){3}[0-9a-f]{12}','e8cda07e-849f-49c2-94d6-aaa5c4ab7fcd')
name regexp(~/\w+/,'sony')
date date("dd/MM/yyyy", "02/11/2013")
}
See the available DSL methods https://github.com/DiUS/pact-jvm/tree/master/pact-jvm-consumer-groovy#dsl-methods-1

Related

Is it possible to use a fluent-bit record's timestamp?

I'm trying to create a fluent-bit config which uses a record's timestamp to a custom key using a filter. Something like:
[INPUT]
Name tail
Path /some/path
...
[FILTER]
Name record_modifier
Match *
Record fluenbit_orig_ts SOME_MAGIC_WAY_TO_GET_UNIXTIME
[OUTPUT]
Name stdout
Match *
The rationale for this that I'm using several parsers, each has its own time format (Time_Format, as it's used in the regular expression parser. Even if I used Time_Keep, it won't help because the time is specified differently by different services, with a different Time_Format). I'd like the records getting to an [OUTPUT} to have the same key to describe the timestamp. In this example that key would be fluenbit_orig_ts
Is this possible?
I got an answer from the fluent-bit slack channel.
Seems like this is possible using lua filters. Specifically, this example seems to be relevant: https://github.com/fluent/fluent-bit/blob/master/scripts/append_tag.lua
I've same issue.
According to #BugoK, I've solved.
This is lua script.
function append_tag(tag, timestamp, record)
new_record = record
new_record["log_time"] = os.date("%Y-%m-%d %H:%M:%S")
return 1, timestamp, new_record
end
And this is td-agent-bit config.
[FILTER]
Name lua
Match nginx.access
script override_time.lua
call append_tag
And then restart td-agent-bit. It works~!

Jmeter-How to sent the variable value to the response of particular Request

I am working in Jmeter.
I need to sent the value for the variable name 'Reference' in the response of the particular request.
I am able to get the response using Bean shell Post processor using the string "vars.put("response", new String(data));"
I need the get the variable 'Reference' which is referred by id as id="reference"
I need to pass value to the variable 'Reference'.
Can anyone help?
Since JMeter 3.1 it's recommended to use JSR223 Test Elements and Groovy language for any form of scripting so if you want to store the response into the Reference JMeter Variable you can do it as follows:
Add JSR223 PostProcessor as a child of the request which response you want to store
Put the following code into "Script" area:
vars.put("Reference", prev.getResponseDataAsString());
where:
vars is a shorthand for JMeterVariables class instance
prev stands for the parent SampleResult
see JavaDoc for the above shorthands for all available functions/properties description and Top 8 JMeter Java Classes You Should Be Using with Groovy for comprehensive explanation with examples for the above and other JMeter API shortcuts available for Groovy scripts

Jmeter how to get the dynamic parameter value in the path

JMeter path contents some dynamically generated value.
Eg
[HTTP Request]
[path-home/user?p=er3562]
This "p" value is dynamically generated.
I want to get this parameter value in the first HTTP request path.
This parameter value should pass through each HTTP request path.
I am new to JMeter. Please help me to solve this?
You need to extract it somehow and convert into a JMeter Variable for later reuse. JMeter provides several PostProcessors for extracting data from different responses types, in your case the most suitable one will be Regular Expression Extractor.
Add Regular Expression Extractor as a child of the request which returns that path-home/user?p=er3562 value
Configure it as follows:
Apply to: depending on where the "interesting" value lives, the most "safe" setting is Main sample and sub-samples
Field to check: depending on where the "interesting" value comes from, in the majority of cases it's Body but in your case it may be i.e. URL
Reference Name: anything meaningful, it is JMeter Variable name, if JMeter finds anything it will store the result in a variable named accordingly to this field. I.e. path-home
Regular Expression: Perl5-style regular expression, in your case it would be something like: path-home/user\?p=er(\d+)
Template: if you're looking to extract a single value it will be $1$
Refer extracted value as ${path-home} where required.
References and tips:
You can use Debug Sampler and View Results Tree listener combination to view JMeter Variable names and test regular expressions against actual response
Using RegEx (Regular Expression Extractor) With JMeter
Perl 5 Regex Cheat sheet
JMeter Regular Expressions
By using correlation concept ,
regular expression extractor concept & try this key
p=er(.*?)

Jayway Jsonpath syntax for string array filter?

I am attempting to use the EvaluateJsonPath processor in Nifi, and am having trouble with the jayway jsonpath syntax.
My object looks like the following:
{"text":"my stuff", "tags":["abc", "xyz", "beq"]}
I want to route messages based on the tags - I want everything containing "xyz" to be routed one way, and everything not containing it to be routed another way.
Using http://jsonpath.herokuapp.com/ I've been testing and trying to figure out the syntax to filter based on a json object containing an array of strings matching. I can match based on overt index (so $.[?(#.tags[1] =~ /xyz/i)] works just fine), but I can't guarantee the order or number of objects in the tags field.
Is there a way to do this in the jayway json module? I saw filter the Json according to string in an array in JSONPATH which I've tried, but it doesn't appear to work in the simulator above.
I do not know how to do this in one EvaluateJsonPath processor step. But it can certainly be done in a two-step process:
Use EvaluateJsonPath to filter "xyz" tags out of the tags array, using a JsonPath expression like $.tags[?(# =~ /xyz/i)] and setting the processors return-type to json so an array may be returned. This will result in ["xyz"] for a match and [] for non-matching files
Use RouteOnAttribute to route based on the resulting array, with an expression like ${matchingTags:toLower():contains('xyz')}.
It might also be worth considering evaluating the JSON as text against a regular expression to match the tag.

Compare responses in SoapUI in order to assert case insensitivity

we have a web service that is supposed to be case insenisitive. So, we want the same result on a search for 'foo' and 'FOO'. What is the best way to create an assertion that compares the response for the two different string parameters?
Thank you!
I would not compare the two results at all. Your tests could just test the response you receive. So if you are testing each response the same you would be verifying the responses match.
If using soapUI open source, I would create two tests that are exactly the same except for the data, probably use a test case property. My requests and response assertions would be the same, but the data is extracted.
If I'm using soapUI Pro, I could have one test case that uses a data sheet, which is alot easier to maintain going forward, but that costs money.
If you want to know what exactly to assert in your test, you will need to look at your requirements and decide which pieces are important to assert. If the answer is the whole request a simple xpath match against the entire soap envelope would work.
If you must, groovy is the answer, I think something like this should work:
def rawRequest = context.expand( '${Teststepname#RawRequest#declare namespace soapenv=\'http://schemas.xmlsoap.org/soap/envelope/\'; //soapenv:Body[1]}' )
def rawRequest2 = context.expand( '${Teststepname2#RawRequest#declare namespace soapenv=\'http://schemas.xmlsoap.org/soap/envelope/\'; //soapenv:Body[1]}' )
if (rawRequest == rawRequest2) {
assert true
}
else {
assert false
}

Resources