multiple if then conditions in Jmeter - if-statement

How is possible to peform multiple if then checks for the same variable in Jmeter ?I need to implement the following if then conditions in Jmeter:
if ${laiks} >=0 and ${laiks} <=85959 then ${OrderTime}=0
if ${laiks} >=90000 and ${laiks} <=105959 then ${OrderTime}=90000
if ${laiks} >=110000 and ${laiks} <=125959 then ${OrderTime}=110000
if ${laiks} >=130000 and ${laiks} <=152959 then ${OrderTime}=130000
if ${laiks} >=153000 and ${laiks} <=235959 then ${OrderTime}=153000
I created 5 IF controllers, each with its own condition, but Jmeter is always assigning last value 153000 to ${OrderTime} variable.

If you need to create OrderTime JMeter Variable based on laiks variable value the easiest way of doing this is going for a suitable JSR223 Test Element and the following Groovy code:
switch (vars.get('laiks') as int) {
case 0..85959:
vars.put('OrderTime', '0')
break
case 90000..105959:
vars.put('OrderTime', '90000')
break
//etc
default:
vars.put('OrderTime', '-1')
}
More information on Groovy scripting in JMeter: Apache Groovy: What Is Groovy Used For?

Related

Check value extracted with JSONPath and compare with regex using Gatling

Is there a way of doing something like this in Gatling:
scenario("Check UUID with regex")
.exec(http("Get UUID")
.get("http://myapp/api/v1/goal/a24e210c-0fc1-44a0-a5ca-9bd5d8d71916")
.check(jsonPath("$.id").is(regex("[0-9a-fA-F]{8}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{12}")))
Basically I want to apply a regex comparison on something returned in a check JSONPath construct.
Peace out!
P.S. I know I can do:
.check(regex("\"id\": \"[0-9a-fA-F]{8}\\-[0-9a-fA-F]{4}\\-[0-9a-fA-F]{4}\\-[0-9a-fA-F]{4}\\-[0-9a-fA-F]{12}\"").exists)
There's nothing quite like what you describe, but you can kind of fake it using a transform
.check(jsonPath("$.id")
.find
.transform(id => "[0-9a-fA-F]{8}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{12}".r
.findFirstMatchIn(id) match {
case Some(value) => true
case None => false
}
).is(true)
but if the straight regex check works... I'd go with that

How to use flowVars inside wildcard filter and expression filter Mule

Is it possible to use the flowVariable inside wildcard or expression filter directly.
I need to stop the flow based on the flow Variable value.
Example: My flow Variable name keyValue have the value like customer/feed/h26/h56 in this 'h26/h56' should set dynamically but customer/feed is constant always. I need to set my filter only after '/feed/' if it contain any characters.
<flow name="testFlow1" doc:name="testFlow1">
<file:inbound-endpoint responseTimeout="10000" doc:name="File" path="c:/in"/>
.......( Many component)
<set-variable variableName="keyValue" value="#[customer/feed/h26/h56]" doc:name="Variable"/>
.......( Many component)
<message-filter doc:name="Message">
<wildcard-filter pattern="customer/feed/+*" caseSensitive="true"/>
</message-filter>
</flow>
Used + in pattern to check whether it contain one or more characters.
Also I used expression filter, not sure how to use flow Variable inside the filter expression. Could you please help me on this.
I don't want to use property filter.
Use expression filter instead, and since your expression is simple just use the startsWith method of String.
for example
<expression-filter expression="flowVars.keyValue.startsWith('customer/feed/')" doc:name="Expression"/>
this will allow messages
First of all, you can't use wildcard-filter on flowVars directly because it applies a wildcard pattern to the message payload. Here is the implementation excerpt from the org.mule.routing.filters.WildcardFilter class
public boolean accept(MuleMessage message) {
try {
return accept(message.getPayloadAsString());
} catch (Exception e) {
logger.warn("An exception occurred while filtering", e);
return false;
}
}
So it is clear that the WildcardFilter converts the payload to a String and applies the filter.
Also, in the case of regex-filter, it applies a regex pattern to the message payload. Here is an implementation excerpt from the org.mule.routing.filters.RegExFilter
public boolean accept(MuleMessage message) {
try {
return accept(message.getPayloadAsString());
} catch (Exception e) {
throw new IllegalArgumentException(e);
}
}
Now coming to your question, you can very well use expression-filter as suggested by Tyrone Villaluna. But you may want to include the expression in start and end signs like ^customer/feed/.+$
And so
<expression-filter expression="flowVars.keyValue.matches('^customer/feed/.+$')" />

ASP.NET Web API 2 Model Validation with Regular Expression

In my web api 2 Controller i have a Create method that contains the following logic:
if (((assignment.type).ToLower() != "individual" && (assignment.type).ToLower() != "staff")) {
return Request.CreateErrorResponse(HttpStatusCode.BadRequest, "The Assignment Type
must be either 'individual' or 'staff'");
}
I am using model state validation. Is it possible to assign a regular expression to a property to eliminate the need to do the checking in the controller? If so, what would that reg ex look like to return valid only if the exact string (case insensitive) of "individual" or "staff" is passed by the user of the api?
Thanks to some guidance in the comments, I ended up with this, which works well:
[RegularExpression(#"^(?i)(individual|staff)$", ErrorMessage="...")]
public string type { get; set; }
If you want a Regex than use something like
new Regex(#"^(individual|staff)$", RegexOptions.IgnoreCase)
But, I would recommend to create an enum with corresponding values and make your model property of that enum.

Soap UI load testing

I want to call the webservice multiple times passing different parameter,
e.g. getDetail(Id) , by reading the ids from an excel sheet or a constant.
I understand you can do this by writing groovy script in SoapUI, does anyone have a working example to start with.
PS: I am using the free SoapUI version and not SoapUI Pro.
One way to achieve this would be to have Test Case with 3 steps.
The first one: a groovy script step that does something like this:
['111', '222', '333'].each {
com.eviware.soapui.SoapUI.globalProperties.setPropertyValue('id', it)
testRunner.runTestStepByName("testRequest")
}
testRunner.gotoStepByName('done')
Secondly the Test Request step. Inside the request you can refer to the id parameter by ${id}
and thirdly an empty Groovy script step 'done' for jumping out of there.
Instead of the static list you can get the test ids from a file.
We achieve this by using a groovy script step at the start of our test:
switch (context.ThreadIndex) {
case 0: context.Id = 'id for thread 1 here'; break;
case 1: context.Id = 'id for thread 2 here'; break;
...
default:
log.error 'Thread['+context.ThreadIndex+'] Run['+context.RunCount+']: no Id available for assignment'
}

JMeter Response Assertion: incorporating property into pattern test

I'd like to setup a JMeter test plan to suggest whether a web site (URL) is Drupal-based (based completely on the HTTP response from the site) and compare it with existing data that I have on the environment. (I realize that using an HTTP approach, as opposed to say examining the site's file system, is "iffy" but I'm curious how useful the approach is)
The JMeter command line might look like this:
JMeter -t "DrupalAssertions.jmx" -Jurl=http://my.dot.com -Jdrupal=true
where I provide the URL to test and an additional property "drupal" indicating my best guess on whether the site is Drupal-based.
In my test plan, I add an HTTP Request to return the HTML content of the page for the URL. I'm then able to successfully add a Response Assertion that tests a pattern (say (?i)(drupal) for a sadly lacking pattern) to see if it's contained in the response.
That much works fine, or as expected, but what I'd like to do is to compare the value of the "drupal" property against the result of that pattern test in that same Response Assertion. I know I'm missing something simple here, but I'm not seeing how to do that.
I want to try to use an expression like this:
(?i)(drupal) == ${__P(drupal)}
in a pattern, but that doesn't work. The name of the Compare Assertion looks promising, but I don't see how to incorporate the property into a comparison.
Update: The approach suggested by PMD UBIK-INGENIERIE does work. I used a Regular Expression Extractor like this:
<RegexExtractor guiclass="RegexExtractorGui" testclass="RegexExtractor" testname="Extract Drupal in Response" enabled="true">
<stringProp name="RegexExtractor.useHeaders">false</stringProp>
<stringProp name="RegexExtractor.refname">drupalInResponse</stringProp>
<stringProp name="RegexExtractor.regex">(.*drupal.*)</stringProp>
<stringProp name="RegexExtractor.template">$0$</stringProp>
<stringProp name="RegexExtractor.default">__false__</stringProp>
<stringProp name="RegexExtractor.match_number">1</stringProp>
</RegexExtractor>
followed by this BeanShell Assertion:
// Variable "drupalInResponse" is "__false__" by default
if ( !(vars.get("drupalInResponse").equals("__false__") ) ) {
vars.put("drupalInResponse","true");
}
else {
vars.put("drupalInResponse","false");
}
print("\n\nThe value of property 'drupal' is: " + props.get("drupal") + "\n");
print("\n\nThe value of variable 'drupalInResponse' is: " + vars.get("drupalInResponse") + "\n");
if (vars.get("drupalInResponse").equals( props.get("drupal") ) ) {
print("Site Drupalness is consistent with your beliefs");
}
else {
print("You're wrong about the site's Drupalness");
Failure = true;
FailureMessage = "Incorrect Drupal assumption";
}
In the Regular Expression Extractor, I'd set a default value that I felt wouldn't be matched by my pattern of interest, then did an ugly verbose Java comparison with the "drupal" property in the BeanShell Assertion.
Wish somehow that the assertion could be made in a single component rather than it having two parts, but you can't argue with "working" :)
You can use a regexp extractir with your first pattern
Then use a Beanshell assertion which will use your variable and compare it to drupal property.