jmeter-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Felix Schumacher <felix.schumac...@internetallee.de>
Subject Re: svn commit: r1793271 - /jmeter/trunk/test/src/org/apache/jmeter/engine/util/TestValueReplacer.java
Date Wed, 03 May 2017 13:03:04 GMT
Am 30.04.2017 22:34, schrieb pmouawad@apache.org:
> Author: pmouawad
> Date: Sun Apr 30 20:34:17 2017
> New Revision: 1793271
> 
> URL: http://svn.apache.org/viewvc?rev=1793271&view=rev
> Log:
> Add test case to show partial replacement does not work
> 
> Modified:
>     
> jmeter/trunk/test/src/org/apache/jmeter/engine/util/TestValueReplacer.java
> 
> Modified:
> jmeter/trunk/test/src/org/apache/jmeter/engine/util/TestValueReplacer.java
> URL:
> http://svn.apache.org/viewvc/jmeter/trunk/test/src/org/apache/jmeter/engine/util/TestValueReplacer.java?rev=1793271&r1=1793270&r2=1793271&view=diff
> ==============================================================================
> ---
> jmeter/trunk/test/src/org/apache/jmeter/engine/util/TestValueReplacer.java
> (original)
> +++
> jmeter/trunk/test/src/org/apache/jmeter/engine/util/TestValueReplacer.java
> Sun Apr 30 20:34:17 2017
> @@ -107,6 +107,24 @@ public class TestValueReplacer extends J
>              String replacedDomain = 
> element.getPropertyAsString("domain");
>              assertEquals("${${shortMatch}", replacedDomain);
>          }
> +
> +        @Test
> +        public void test2Matches() throws Exception {
> +            TestPlan plan = new TestPlan();
> +            plan.addParameter("firstMatch", "toto");
> +            plan.addParameter("secondMatch", "005");
> +            ValueReplacer replacer = new ValueReplacer(plan);
> +            TestElement element = new TestPlan();
> +            element.setProperty(new StringProperty("mail", 
> "toto%40005"));

If you want to replace 005 "in" a word (40005), then you have to 
surround the regex with parentheses. The '%' is a word boundary, '0' is 
not.

So instead of "005" you have to write "(005)". The behaviour is 
described in 
http://jmeter.apache.org/usermanual/component_reference.html#HTTP(S)_Test_Script_Recorder
and further down on that page under "User Defined Variable replacement".

But maybe you wanted to document that behaviour here?

A few notes on the test itself. I like tests, that test one thing in one 
method - this tests two things.
It might help, if the test name hints at the problem by using a name, 
that is a bit more descriptive.

Regards,
  Felix

> +            replacer.reverseReplace(element, true);
> +            String replacedDomain = 
> element.getPropertyAsString("mail");
> +            assertEquals("${firstMatch}%40005", replacedDomain);
> +
> +            element.setProperty(new StringProperty("mail", 
> "toto@005"));
> +            replacer.reverseReplace(element, true);
> +            replacedDomain = element.getPropertyAsString("mail");
> +            assertEquals("${firstMatch}@${secondMatch}", 
> replacedDomain);
> +        }
> 
>          @Test
>          public void testReplace() throws Exception {

Mime
View raw message