You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@jmeter.apache.org by jmeter_user_2006 <it...@yahoo.com> on 2006/12/20 21:19:08 UTC

Adding Response Assertion to a Java Sampler

Hi, 

I am trying to load test a Java application and would like to verify some
results by applying a response assertion on the returned value. 

The code looks something liek this:
....
 SampleResult results = new SampleResult();
	    try {
	    	results.sampleStart();
	      		      	
	      	String response = getResponseFromJavaApp();
	      	results.setSamplerData("\\[testCount 1\\]"); // what does this
method do? 
	      	
	      	ResponseAssertion assertion = new ResponseAssertion();
	      	assertion.setAssumeSuccess(false);
	      	assertion.setName("Assertion Results");
	      	assertion.setTestField(response);

	      	AssertionResult result = assertion.getResult(results);
	      	logger.debug("Failure message = " + result.getFailureMessage());
	      	
	      	AssertionResult[] ars =results.getAssertionResults();
	      	results.setSampleLabel(response);
....

I would like to know if my response contains the required text....how do I
verify this? What is it that I am doing wrong in the code above/ 

Any tips would be appreciated .
Thanks
M

-- 
View this message in context: http://www.nabble.com/Adding-Response-Assertion-to-a-Java-Sampler-tf2861999.html#a7997105
Sent from the JMeter - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-user-help@jakarta.apache.org


Re: Adding Response Assertion to a Java Sampler

Posted by sebb <se...@gmail.com>.
On 21/12/06, jmeter_user_2006 <it...@yahoo.com> wrote:
>
> Thanks, that makes a lot of sense now :)
>
> "It sets the sampler data - i.e. the data that the sampler passed to
> the external system."
>
> What do you mean by the external system? Where exactly can I use this
> sampler data?

The external system is the system under test - e.g. for HTTP sampler
it is the http server.

The data is used by the Listeners. You can put whatever you like in
the field, but unless it corresponds (in some way) with the data the
sampler "sends" to the "external system" it won't be much use.

> Also is there anyway to create a "batch process" wherein
> 1) I call the method A with some input parameter (do-able)
> 2) get the response from method B  (do-able)
> 3) get the Patterns to Test from Response Assertion for a particular input
> parameter -- -- not sure how??? (of course, there should be 1-1 mapping
> between the input parameter and the pattern & this should be hard-coded
> somewhere)

If you code the sampler correctly, response Assertions will do this for you

> 4) and if the test fails, dump the output to a file (I think this step easy)

Listeners can already save failed samples.

> This way I can load-test and also verify if the expected & observed results
> match.

Please have a look at the example code, and try running some test
plans with Assertions and Listeners.

---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-user-help@jakarta.apache.org


Re: Adding Response Assertion to a Java Sampler

Posted by jmeter_user_2006 <it...@yahoo.com>.
Thanks, that makes a lot of sense now :) 

"It sets the sampler data - i.e. the data that the sampler passed to
the external system."

What do you mean by the external system? Where exactly can I use this
sampler data? 

Also is there anyway to create a "batch process" wherein 
1) I call the method A with some input parameter (do-able)
2) get the response from method B  (do-able)
3) get the Patterns to Test from Response Assertion for a particular input
parameter -- -- not sure how??? (of course, there should be 1-1 mapping
between the input parameter and the pattern & this should be hard-coded
somewhere)  
4) and if the test fails, dump the output to a file (I think this step easy) 

This way I can load-test and also verify if the expected & observed results
match. 
Cheers
M

sebb-2 wrote:
> 
> On 20/12/06, jmeter_user_2006 <it...@yahoo.com> wrote:
>>
>> Hi,
>>
>> I am trying to load test a Java application and would like to verify some
>> results by applying a response assertion on the returned value.
>>
>> The code looks something liek this:
>> ....
>>  SampleResult results = new SampleResult();
> OK
> 
>>             try {
>>                 results.sampleStart();
> 
> OK - you also need a sampleEnd();
> 
>>
>>                 String response = getResponseFromJavaApp();
>>                 results.setSamplerData("\\[testCount 1\\]"); // what does
>> this
>> method do?
> 
> It sets the sampler data - i.e. the data that the sampler passed to
> the external system.
> It should be set before running the sample.
> 
>>                 ResponseAssertion assertion = new ResponseAssertion();
>>                 assertion.setAssumeSuccess(false);
>>                 assertion.setName("Assertion Results");
>>                 assertion.setTestField(response);
>>
>>                 AssertionResult result = assertion.getResult(results);
>>                 logger.debug("Failure message = " +
>> result.getFailureMessage());
>>
>>                 AssertionResult[] ars =results.getAssertionResults();
> 
> Assertions are added as separate test elements, not as code in the
> sampler.
> 
>>                 results.setSampleLabel(response);
>> ....
>>
>> I would like to know if my response contains the required text....how do
>> I
> 
> Add an assertion in the test plan.
> 
> Or just use standard Java code.
> 
>> verify this? What is it that I am doing wrong in the code above/
>> Any tips would be appreciated .
> 
> 
> Have a look at some of the example samplers under src/examples.
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Adding-Response-Assertion-to-a-Java-Sampler-tf2861999.html#a8001060
Sent from the JMeter - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-user-help@jakarta.apache.org


Re: Adding Response Assertion to a Java Sampler

Posted by sebb <se...@gmail.com>.
On 20/12/06, jmeter_user_2006 <it...@yahoo.com> wrote:
>
> Hi,
>
> I am trying to load test a Java application and would like to verify some
> results by applying a response assertion on the returned value.
>
> The code looks something liek this:
> ....
>  SampleResult results = new SampleResult();
OK

>             try {
>                 results.sampleStart();

OK - you also need a sampleEnd();

>
>                 String response = getResponseFromJavaApp();
>                 results.setSamplerData("\\[testCount 1\\]"); // what does this
> method do?

It sets the sampler data - i.e. the data that the sampler passed to
the external system.
It should be set before running the sample.

>                 ResponseAssertion assertion = new ResponseAssertion();
>                 assertion.setAssumeSuccess(false);
>                 assertion.setName("Assertion Results");
>                 assertion.setTestField(response);
>
>                 AssertionResult result = assertion.getResult(results);
>                 logger.debug("Failure message = " + result.getFailureMessage());
>
>                 AssertionResult[] ars =results.getAssertionResults();

Assertions are added as separate test elements, not as code in the sampler.

>                 results.setSampleLabel(response);
> ....
>
> I would like to know if my response contains the required text....how do I

Add an assertion in the test plan.

Or just use standard Java code.

> verify this? What is it that I am doing wrong in the code above/
> Any tips would be appreciated .


Have a look at some of the example samplers under src/examples.

---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-user-help@jakarta.apache.org