Author: sebb Date: Sun May 10 18:19:28 2009 New Revision: 773382 URL: http://svn.apache.org/viewvc?rev=773382&view=rev Log: Tab police
Modified: jakarta/jmeter/trunk/test/src/org/apache/jmeter/engine/TestTreeCloner.java jakarta/jmeter/trunk/test/src/org/apache/jmeter/engine/util/PackageTest.java jakarta/jmeter/trunk/test/src/org/apache/jmeter/engine/util/TestValueReplacer.java jakarta/jmeter/trunk/test/src/org/apache/jmeter/extractor/TestRegexExtractor.java jakarta/jmeter/trunk/test/src/org/apache/jmeter/extractor/TestXPathExtractor.java jakarta/jmeter/trunk/test/src/org/apache/jmeter/functions/PackageTest.java jakarta/jmeter/trunk/test/src/org/apache/jmeter/functions/TestFileRowColContainer.java jakarta/jmeter/trunk/test/src/org/apache/jmeter/functions/TestRegexFunction.java jakarta/jmeter/trunk/test/src/org/apache/jmeter/functions/TestTimeFunction.java jakarta/jmeter/trunk/test/src/org/apache/jmeter/gui/action/PackageTest.java jakarta/jmeter/trunk/test/src/org/apache/jmeter/gui/action/TestLoad.java jakarta/jmeter/trunk/test/src/org/apache/jmeter/gui/action/TestSave.java jakarta/jmeter/trunk/test/src/org/apache/jmeter/gui/util/TestMenuFactory.java jakarta/jmeter/trunk/test/src/org/apache/jmeter/junit/JMeterTest.java jakarta/jmeter/trunk/test/src/org/apache/jmeter/junit/JMeterTestCase.java jakarta/jmeter/trunk/test/src/org/apache/jmeter/junit/stubs/TestSampler.java jakarta/jmeter/trunk/test/src/org/apache/jmeter/monitor/model/TestObjectFactory.java jakarta/jmeter/trunk/test/src/org/apache/jmeter/monitor/model/benchmark/ParseBenchmark.java jakarta/jmeter/trunk/test/src/org/apache/jmeter/protocol/http/config/MultipartUrlConfigTest.java jakarta/jmeter/trunk/test/src/org/apache/jmeter/protocol/http/config/UrlConfigTest.java jakarta/jmeter/trunk/test/src/org/apache/jmeter/protocol/http/control/TestAuthManager.java jakarta/jmeter/trunk/test/src/org/apache/jmeter/protocol/http/control/TestCookieManager.java jakarta/jmeter/trunk/test/src/org/apache/jmeter/protocol/http/control/TestHTTPMirrorThread.java jakarta/jmeter/trunk/test/src/org/apache/jmeter/protocol/http/control/gui/TestHttpTestSampleGui.java jakarta/jmeter/trunk/test/src/org/apache/jmeter/protocol/http/modifier/TestAnchorModifier.java jakarta/jmeter/trunk/test/src/org/apache/jmeter/protocol/http/modifier/TestURLRewritingModifier.java jakarta/jmeter/trunk/test/src/org/apache/jmeter/protocol/http/parser/TestHtmlParsingUtils.java jakarta/jmeter/trunk/test/src/org/apache/jmeter/protocol/http/proxy/TestProxyControl.java jakarta/jmeter/trunk/test/src/org/apache/jmeter/protocol/http/sampler/HTTPNullSampler.java jakarta/jmeter/trunk/test/src/org/apache/jmeter/protocol/http/sampler/NullURLConnection.java jakarta/jmeter/trunk/test/src/org/apache/jmeter/protocol/http/sampler/PackageTest.java jakarta/jmeter/trunk/test/src/org/apache/jmeter/protocol/http/sampler/PostWriterTest.java jakarta/jmeter/trunk/test/src/org/apache/jmeter/protocol/http/sampler/PutWriterTest.java jakarta/jmeter/trunk/test/src/org/apache/jmeter/protocol/http/sampler/TestHTTPSamplersAgainstHttpMirrorServer.java jakarta/jmeter/trunk/test/src/org/apache/jmeter/protocol/http/util/TestHTTPArgument.java jakarta/jmeter/trunk/test/src/org/apache/jmeter/protocol/http/util/TestHTTPFileArg.java jakarta/jmeter/trunk/test/src/org/apache/jmeter/protocol/http/util/TestHTTPFileArgs.java jakarta/jmeter/trunk/test/src/org/apache/jmeter/protocol/http/util/TestHTTPUtils.java jakarta/jmeter/trunk/test/src/org/apache/jmeter/protocol/http/util/accesslog/TestLogFilter.java jakarta/jmeter/trunk/test/src/org/apache/jmeter/protocol/http/util/accesslog/TestTCLogParser.java jakarta/jmeter/trunk/test/src/org/apache/jmeter/protocol/ldap/config/gui/PackageTest.java jakarta/jmeter/trunk/test/src/org/apache/jmeter/resources/PackageTest.java jakarta/jmeter/trunk/test/src/org/apache/jmeter/samplers/TestSampleResult.java jakarta/jmeter/trunk/test/src/org/apache/jmeter/save/TestCSVSaveService.java jakarta/jmeter/trunk/test/src/org/apache/jmeter/save/TestSaveService.java jakarta/jmeter/trunk/test/src/org/apache/jmeter/testbeans/gui/PackageTest.java jakarta/jmeter/trunk/test/src/org/apache/jmeter/testbeans/gui/TestBooleanPropertyEditor.java jakarta/jmeter/trunk/test/src/org/apache/jmeter/testbeans/gui/TestComboStringEditor.java jakarta/jmeter/trunk/test/src/org/apache/jmeter/testbeans/gui/TestFieldStringEditor.java jakarta/jmeter/trunk/test/src/org/apache/jmeter/testelement/BarChartTest.java jakarta/jmeter/trunk/test/src/org/apache/jmeter/testelement/LineGraphTest.java jakarta/jmeter/trunk/test/src/org/apache/jmeter/testelement/PackageTest.java jakarta/jmeter/trunk/test/src/org/apache/jmeter/testelement/property/PackageTest.java jakarta/jmeter/trunk/test/src/org/apache/jmeter/threads/TestTestCompiler.java jakarta/jmeter/trunk/test/src/org/apache/jmeter/timers/PackageTest.java jakarta/jmeter/trunk/test/src/org/apache/jmeter/util/PackageTest.java jakarta/jmeter/trunk/test/src/org/apache/jmeter/util/TestJMeterUtils.java jakarta/jmeter/trunk/test/src/org/apache/jorphan/TestFunctorUsers.java jakarta/jmeter/trunk/test/src/org/apache/jorphan/TestXMLBuffer.java jakarta/jmeter/trunk/test/src/org/apache/jorphan/collections/PackageTest.java jakarta/jmeter/trunk/test/src/org/apache/jorphan/math/TestStatCalculator.java jakarta/jmeter/trunk/test/src/org/apache/jorphan/reflect/TestFunctor.java jakarta/jmeter/trunk/test/src/org/apache/jorphan/test/AllTests.java Modified: jakarta/jmeter/trunk/test/src/org/apache/jmeter/engine/TestTreeCloner.java URL: http://svn.apache.org/viewvc/jakarta/jmeter/trunk/test/src/org/apache/jmeter/engine/TestTreeCloner.java?rev=773382&r1=773381&r2=773382&view=diff ============================================================================== --- jakarta/jmeter/trunk/test/src/org/apache/jmeter/engine/TestTreeCloner.java (original) +++ jakarta/jmeter/trunk/test/src/org/apache/jmeter/engine/TestTreeCloner.java Sun May 10 18:19:28 2009 @@ -29,53 +29,53 @@ import org.apache.jorphan.collections.ListedHashTree; public class TestTreeCloner extends junit.framework.TestCase { - public TestTreeCloner(String name) { - super(name); - } + public TestTreeCloner(String name) { + super(name); + } - public void testCloning() throws Exception { - ListedHashTree original = new ListedHashTree(); - GenericController controller = new GenericController(); - controller.setName("controller"); - Arguments args = new Arguments(); - args.setName("args"); - TestPlan plan = new TestPlan(); - plan.addParameter("server", "jakarta"); - original.add(controller, args); - original.add(plan); - ResultCollector listener = new ResultCollector(); - listener.setName("Collector"); - original.add(controller, listener); - TreeCloner cloner = new TreeCloner(); - original.traverse(cloner); - ListedHashTree newTree = cloner.getClonedTree(); - assertTrue(original != newTree); - assertEquals(original.size(), newTree.size()); - assertEquals(original.getTree(original.getArray()[0]).size(), newTree.getTree(newTree.getArray()[0]).size()); - assertTrue(original.getArray()[0] != newTree.getArray()[0]); - assertEquals(((GenericController) original.getArray()[0]).getName(), ((GenericController) newTree - .getArray()[0]).getName()); - assertSame(original.getTree(original.getArray()[0]).getArray()[1], newTree.getTree(newTree.getArray()[0]) - .getArray()[1]); - TestPlan clonedTestPlan = (TestPlan) newTree.getArray()[1]; - clonedTestPlan.setRunningVersion(true); - clonedTestPlan.recoverRunningVersion(); - assertTrue(!plan.getUserDefinedVariablesAsProperty().isRunningVersion()); - assertTrue(clonedTestPlan.getUserDefinedVariablesAsProperty().isRunningVersion()); - Arguments vars = (Arguments) plan.getUserDefinedVariablesAsProperty().getObjectValue(); - PropertyIterator iter = ((CollectionProperty) vars.getProperty(Arguments.ARGUMENTS)).iterator(); - while (iter.hasNext()) { - JMeterProperty argProp = iter.next(); - assertTrue(!argProp.isRunningVersion()); - assertTrue(argProp.getObjectValue() instanceof Argument); - Argument arg = (Argument) argProp.getObjectValue(); - arg.setValue("yahoo"); - assertEquals("yahoo", arg.getValue()); - } - vars = (Arguments) clonedTestPlan.getUserDefinedVariablesAsProperty().getObjectValue(); - iter = vars.propertyIterator(); - while (iter.hasNext()) { - assertTrue(iter.next().isRunningVersion()); - } - } + public void testCloning() throws Exception { + ListedHashTree original = new ListedHashTree(); + GenericController controller = new GenericController(); + controller.setName("controller"); + Arguments args = new Arguments(); + args.setName("args"); + TestPlan plan = new TestPlan(); + plan.addParameter("server", "jakarta"); + original.add(controller, args); + original.add(plan); + ResultCollector listener = new ResultCollector(); + listener.setName("Collector"); + original.add(controller, listener); + TreeCloner cloner = new TreeCloner(); + original.traverse(cloner); + ListedHashTree newTree = cloner.getClonedTree(); + assertTrue(original != newTree); + assertEquals(original.size(), newTree.size()); + assertEquals(original.getTree(original.getArray()[0]).size(), newTree.getTree(newTree.getArray()[0]).size()); + assertTrue(original.getArray()[0] != newTree.getArray()[0]); + assertEquals(((GenericController) original.getArray()[0]).getName(), ((GenericController) newTree + .getArray()[0]).getName()); + assertSame(original.getTree(original.getArray()[0]).getArray()[1], newTree.getTree(newTree.getArray()[0]) + .getArray()[1]); + TestPlan clonedTestPlan = (TestPlan) newTree.getArray()[1]; + clonedTestPlan.setRunningVersion(true); + clonedTestPlan.recoverRunningVersion(); + assertTrue(!plan.getUserDefinedVariablesAsProperty().isRunningVersion()); + assertTrue(clonedTestPlan.getUserDefinedVariablesAsProperty().isRunningVersion()); + Arguments vars = (Arguments) plan.getUserDefinedVariablesAsProperty().getObjectValue(); + PropertyIterator iter = ((CollectionProperty) vars.getProperty(Arguments.ARGUMENTS)).iterator(); + while (iter.hasNext()) { + JMeterProperty argProp = iter.next(); + assertTrue(!argProp.isRunningVersion()); + assertTrue(argProp.getObjectValue() instanceof Argument); + Argument arg = (Argument) argProp.getObjectValue(); + arg.setValue("yahoo"); + assertEquals("yahoo", arg.getValue()); + } + vars = (Arguments) clonedTestPlan.getUserDefinedVariablesAsProperty().getObjectValue(); + iter = vars.propertyIterator(); + while (iter.hasNext()) { + assertTrue(iter.next().isRunningVersion()); + } + } } \ No newline at end of file Modified: jakarta/jmeter/trunk/test/src/org/apache/jmeter/engine/util/PackageTest.java URL: http://svn.apache.org/viewvc/jakarta/jmeter/trunk/test/src/org/apache/jmeter/engine/util/PackageTest.java?rev=773382&r1=773381&r2=773382&view=diff ============================================================================== --- jakarta/jmeter/trunk/test/src/org/apache/jmeter/engine/util/PackageTest.java (original) +++ jakarta/jmeter/trunk/test/src/org/apache/jmeter/engine/util/PackageTest.java Sun May 10 18:19:28 2009 @@ -37,127 +37,127 @@ * as it is needed to resolve the functions. */ public class PackageTest extends JMeterTestCase { - private Map variables; + private Map variables; - private SampleResult result; + private SampleResult result; - private ReplaceStringWithFunctions transformer; + private ReplaceStringWithFunctions transformer; - public PackageTest(String arg0) { - super(arg0); - } - - private JMeterContext jmctx = null; - - public void setUp() { - jmctx = JMeterContextService.getContext(); - variables = new HashMap(); - variables.put("my_regex", ".*"); - variables.put("server", "jakarta.apache.org"); - result = new SampleResult(); - result.setResponseData("<html>hello world</html> costs: $3.47,$5.67".getBytes()); - transformer = new ReplaceStringWithFunctions(new CompoundVariable(), variables); - jmctx.setVariables(new JMeterVariables()); - jmctx.setSamplingStarted(true); - jmctx.setPreviousResult(result); - jmctx.getVariables().put("server", "jakarta.apache.org"); - jmctx.getVariables().put("my_regex", ".*"); - } - - public void testFunctionParse1() throws Exception { - StringProperty prop = new StringProperty("date", "${__javaScript((new Date().getDate() / 100).toString()." - + "substr(${__javaScript(1+1,d\\,ay)}\\,2),heute)}"); - JMeterProperty newProp = transformer.transformValue(prop); - newProp.setRunningVersion(true); - assertEquals("org.apache.jmeter.testelement.property.FunctionProperty", newProp.getClass().getName()); - newProp.recoverRunningVersion(null); - assertTrue(Integer.parseInt(newProp.getStringValue()) > -1); - assertEquals("2", jmctx.getVariables().getObject("d,ay")); - } - - public void testParseExample1() throws Exception { - StringProperty prop = new StringProperty("html", "${__regexFunction(<html>(.*)</html>,$1$)}"); - JMeterProperty newProp = transformer.transformValue(prop); - newProp.setRunningVersion(true); - assertEquals("org.apache.jmeter.testelement.property.FunctionProperty", newProp.getClass().getName()); - assertEquals("hello world", newProp.getStringValue()); - } - - public void testParseExample2() throws Exception { - StringProperty prop = new StringProperty("html", "It should say:\\${${__regexFunction(<html>(.*)</html>,$1$)}}"); - JMeterProperty newProp = transformer.transformValue(prop); - newProp.setRunningVersion(true); - assertEquals("org.apache.jmeter.testelement.property.FunctionProperty", newProp.getClass().getName()); - assertEquals("It should say:${hello world}", newProp.getStringValue()); - } - - public void testParseExample3() throws Exception { - StringProperty prop = new StringProperty("html", "${__regexFunction(<html>(.*)</html>,$1$)}" - + "${__regexFunction(<html>(.*o)(.*o)(.*)</html>," + "$1$$3$)}"); - JMeterProperty newProp = transformer.transformValue(prop); - newProp.setRunningVersion(true); - assertEquals("org.apache.jmeter.testelement.property.FunctionProperty", newProp.getClass().getName()); - assertEquals("hello worldhellorld", newProp.getStringValue()); - } - - public void testParseExample4() throws Exception { - StringProperty prop = new StringProperty("html", "${non-existing function}"); - JMeterProperty newProp = transformer.transformValue(prop); - newProp.setRunningVersion(true); - assertEquals("org.apache.jmeter.testelement.property.FunctionProperty", newProp.getClass().getName()); - assertEquals("${non-existing function}", newProp.getStringValue()); - } - - public void testParseExample6() throws Exception { - StringProperty prop = new StringProperty("html", "${server}"); - JMeterProperty newProp = transformer.transformValue(prop); - newProp.setRunningVersion(true); - assertEquals("org.apache.jmeter.testelement.property.FunctionProperty", newProp.getClass().getName()); - assertEquals("jakarta.apache.org", newProp.getStringValue()); - } - - public void testParseExample5() throws Exception { - StringProperty prop = new StringProperty("html", ""); - JMeterProperty newProp = transformer.transformValue(prop); - newProp.setRunningVersion(true); - assertEquals("org.apache.jmeter.testelement.property.StringProperty", newProp.getClass().getName()); - assertEquals("", newProp.getStringValue()); - } - - public void testParseExample7() throws Exception { - StringProperty prop = new StringProperty("html", "${__regexFunction(\\<([a-z]*)\\>,$1$)}"); - JMeterProperty newProp = transformer.transformValue(prop); - newProp.setRunningVersion(true); - assertEquals("org.apache.jmeter.testelement.property.FunctionProperty", newProp.getClass().getName()); - assertEquals("html", newProp.getStringValue()); - } - - public void testParseExample8() throws Exception { - StringProperty prop = new StringProperty("html", "${__regexFunction((\\\\$\\d+\\.\\d+),$1$)}"); - JMeterProperty newProp = transformer.transformValue(prop); - newProp.setRunningVersion(true); - assertEquals("org.apache.jmeter.testelement.property.FunctionProperty", newProp.getClass().getName()); - assertEquals("$3.47", newProp.getStringValue()); - } - - public void testParseExample9() throws Exception { - StringProperty prop = new StringProperty("html", "${__regexFunction(([$]\\d+\\.\\d+),$1$)}"); - JMeterProperty newProp = transformer.transformValue(prop); - newProp.setRunningVersion(true); - assertEquals("org.apache.jmeter.testelement.property.FunctionProperty", newProp.getClass().getName()); - assertEquals("$3.47", newProp.getStringValue()); - } - - public void testParseExample10() throws Exception { - StringProperty prop = new StringProperty("html", "${__regexFunction(\\ " - + "(\\\\\\$\\d+\\.\\d+\\,\\\\$\\d+\\.\\d+),$1$)}"); - JMeterProperty newProp = transformer.transformValue(prop); - newProp.setRunningVersion(true); - assertEquals("org.apache.jmeter.testelement.property.FunctionProperty", newProp.getClass().getName()); - assertEquals("$3.47,$5.67", newProp.getStringValue()); - } + public PackageTest(String arg0) { + super(arg0); + } + + private JMeterContext jmctx = null; + + public void setUp() { + jmctx = JMeterContextService.getContext(); + variables = new HashMap(); + variables.put("my_regex", ".*"); + variables.put("server", "jakarta.apache.org"); + result = new SampleResult(); + result.setResponseData("<html>hello world</html> costs: $3.47,$5.67".getBytes()); + transformer = new ReplaceStringWithFunctions(new CompoundVariable(), variables); + jmctx.setVariables(new JMeterVariables()); + jmctx.setSamplingStarted(true); + jmctx.setPreviousResult(result); + jmctx.getVariables().put("server", "jakarta.apache.org"); + jmctx.getVariables().put("my_regex", ".*"); + } + + public void testFunctionParse1() throws Exception { + StringProperty prop = new StringProperty("date", "${__javaScript((new Date().getDate() / 100).toString()." + + "substr(${__javaScript(1+1,d\\,ay)}\\,2),heute)}"); + JMeterProperty newProp = transformer.transformValue(prop); + newProp.setRunningVersion(true); + assertEquals("org.apache.jmeter.testelement.property.FunctionProperty", newProp.getClass().getName()); + newProp.recoverRunningVersion(null); + assertTrue(Integer.parseInt(newProp.getStringValue()) > -1); + assertEquals("2", jmctx.getVariables().getObject("d,ay")); + } + + public void testParseExample1() throws Exception { + StringProperty prop = new StringProperty("html", "${__regexFunction(<html>(.*)</html>,$1$)}"); + JMeterProperty newProp = transformer.transformValue(prop); + newProp.setRunningVersion(true); + assertEquals("org.apache.jmeter.testelement.property.FunctionProperty", newProp.getClass().getName()); + assertEquals("hello world", newProp.getStringValue()); + } + + public void testParseExample2() throws Exception { + StringProperty prop = new StringProperty("html", "It should say:\\${${__regexFunction(<html>(.*)</html>,$1$)}}"); + JMeterProperty newProp = transformer.transformValue(prop); + newProp.setRunningVersion(true); + assertEquals("org.apache.jmeter.testelement.property.FunctionProperty", newProp.getClass().getName()); + assertEquals("It should say:${hello world}", newProp.getStringValue()); + } + + public void testParseExample3() throws Exception { + StringProperty prop = new StringProperty("html", "${__regexFunction(<html>(.*)</html>,$1$)}" + + "${__regexFunction(<html>(.*o)(.*o)(.*)</html>," + "$1$$3$)}"); + JMeterProperty newProp = transformer.transformValue(prop); + newProp.setRunningVersion(true); + assertEquals("org.apache.jmeter.testelement.property.FunctionProperty", newProp.getClass().getName()); + assertEquals("hello worldhellorld", newProp.getStringValue()); + } + + public void testParseExample4() throws Exception { + StringProperty prop = new StringProperty("html", "${non-existing function}"); + JMeterProperty newProp = transformer.transformValue(prop); + newProp.setRunningVersion(true); + assertEquals("org.apache.jmeter.testelement.property.FunctionProperty", newProp.getClass().getName()); + assertEquals("${non-existing function}", newProp.getStringValue()); + } + + public void testParseExample6() throws Exception { + StringProperty prop = new StringProperty("html", "${server}"); + JMeterProperty newProp = transformer.transformValue(prop); + newProp.setRunningVersion(true); + assertEquals("org.apache.jmeter.testelement.property.FunctionProperty", newProp.getClass().getName()); + assertEquals("jakarta.apache.org", newProp.getStringValue()); + } - // Escaped dollar commma and backslash with no variable reference + public void testParseExample5() throws Exception { + StringProperty prop = new StringProperty("html", ""); + JMeterProperty newProp = transformer.transformValue(prop); + newProp.setRunningVersion(true); + assertEquals("org.apache.jmeter.testelement.property.StringProperty", newProp.getClass().getName()); + assertEquals("", newProp.getStringValue()); + } + + public void testParseExample7() throws Exception { + StringProperty prop = new StringProperty("html", "${__regexFunction(\\<([a-z]*)\\>,$1$)}"); + JMeterProperty newProp = transformer.transformValue(prop); + newProp.setRunningVersion(true); + assertEquals("org.apache.jmeter.testelement.property.FunctionProperty", newProp.getClass().getName()); + assertEquals("html", newProp.getStringValue()); + } + + public void testParseExample8() throws Exception { + StringProperty prop = new StringProperty("html", "${__regexFunction((\\\\$\\d+\\.\\d+),$1$)}"); + JMeterProperty newProp = transformer.transformValue(prop); + newProp.setRunningVersion(true); + assertEquals("org.apache.jmeter.testelement.property.FunctionProperty", newProp.getClass().getName()); + assertEquals("$3.47", newProp.getStringValue()); + } + + public void testParseExample9() throws Exception { + StringProperty prop = new StringProperty("html", "${__regexFunction(([$]\\d+\\.\\d+),$1$)}"); + JMeterProperty newProp = transformer.transformValue(prop); + newProp.setRunningVersion(true); + assertEquals("org.apache.jmeter.testelement.property.FunctionProperty", newProp.getClass().getName()); + assertEquals("$3.47", newProp.getStringValue()); + } + + public void testParseExample10() throws Exception { + StringProperty prop = new StringProperty("html", "${__regexFunction(\\ " + + "(\\\\\\$\\d+\\.\\d+\\,\\\\$\\d+\\.\\d+),$1$)}"); + JMeterProperty newProp = transformer.transformValue(prop); + newProp.setRunningVersion(true); + assertEquals("org.apache.jmeter.testelement.property.FunctionProperty", newProp.getClass().getName()); + assertEquals("$3.47,$5.67", newProp.getStringValue()); + } + + // Escaped dollar commma and backslash with no variable reference public void testParseExample11() throws Exception { StringProperty prop = new StringProperty("html", "\\$a \\, \\\\ \\x \\ jakarta.apache.org"); JMeterProperty newProp = transformer.transformValue(prop); @@ -197,21 +197,21 @@ assertEquals("$a , \\ \\x \\ ${__missing(a)} $b , \\ cd", newProp.getStringValue()); } - public void testNestedExample1() throws Exception { - StringProperty prop = new StringProperty("html", "${__regexFunction(<html>(${my_regex})</html>," - + "$1$)}${__regexFunction(<html>(.*o)(.*o)(.*)" + "</html>,$1$$3$)}"); - JMeterProperty newProp = transformer.transformValue(prop); - newProp.setRunningVersion(true); - assertEquals("org.apache.jmeter.testelement.property.FunctionProperty", newProp.getClass().getName()); - assertEquals("hello worldhellorld", newProp.getStringValue()); - } - - public void testNestedExample2() throws Exception { - StringProperty prop = new StringProperty("html", "${__regexFunction(<html>(${my_regex})</html>,$1$)}"); - JMeterProperty newProp = transformer.transformValue(prop); - newProp.setRunningVersion(true); - assertEquals("org.apache.jmeter.testelement.property.FunctionProperty", newProp.getClass().getName()); - assertEquals("hello world", newProp.getStringValue()); - } + public void testNestedExample1() throws Exception { + StringProperty prop = new StringProperty("html", "${__regexFunction(<html>(${my_regex})</html>," + + "$1$)}${__regexFunction(<html>(.*o)(.*o)(.*)" + "</html>,$1$$3$)}"); + JMeterProperty newProp = transformer.transformValue(prop); + newProp.setRunningVersion(true); + assertEquals("org.apache.jmeter.testelement.property.FunctionProperty", newProp.getClass().getName()); + assertEquals("hello worldhellorld", newProp.getStringValue()); + } + + public void testNestedExample2() throws Exception { + StringProperty prop = new StringProperty("html", "${__regexFunction(<html>(${my_regex})</html>,$1$)}"); + JMeterProperty newProp = transformer.transformValue(prop); + newProp.setRunningVersion(true); + assertEquals("org.apache.jmeter.testelement.property.FunctionProperty", newProp.getClass().getName()); + assertEquals("hello world", newProp.getStringValue()); + } } Modified: jakarta/jmeter/trunk/test/src/org/apache/jmeter/engine/util/TestValueReplacer.java URL: http://svn.apache.org/viewvc/jakarta/jmeter/trunk/test/src/org/apache/jmeter/engine/util/TestValueReplacer.java?rev=773382&r1=773381&r2=773382&view=diff ============================================================================== --- jakarta/jmeter/trunk/test/src/org/apache/jmeter/engine/util/TestValueReplacer.java (original) +++ jakarta/jmeter/trunk/test/src/org/apache/jmeter/engine/util/TestValueReplacer.java Sun May 10 18:19:28 2009 @@ -32,60 +32,60 @@ import org.apache.jmeter.threads.JMeterVariables; public class TestValueReplacer extends JMeterTestCase { - TestPlan variables; + TestPlan variables; - public TestValueReplacer(String name) { - super(name); - } - - public void setUp() { - variables = new TestPlan(); - variables.addParameter("server", "jakarta.apache.org"); - variables.addParameter("username", "jack"); - // The following used to be jacks_password, but the Arguments class uses - // HashMap for which the order is not defined. - variables.addParameter("password", "his_password"); - variables.addParameter("regex", ".*"); - JMeterVariables vars = new JMeterVariables(); - vars.put("server", "jakarta.apache.org"); - JMeterContextService.getContext().setVariables(vars); - JMeterContextService.getContext().setSamplingStarted(true); - } - - public void testReverseReplacement() throws Exception { - ValueReplacer replacer = new ValueReplacer(variables); - assertTrue(variables.getUserDefinedVariables().containsKey("server")); - assertTrue(replacer.containsKey("server")); - TestElement element = new TestPlan(); - element.setProperty(new StringProperty("domain", "jakarta.apache.org")); - List args = new ArrayList(); - args.add("username is jack"); - args.add("his_password"); - element.setProperty(new CollectionProperty("args", args)); - replacer.reverseReplace(element); - assertEquals("${server}", element.getPropertyAsString("domain")); - args = (List) element.getProperty("args").getObjectValue(); - assertEquals("username is ${username}", ((JMeterProperty) args.get(0)).getStringValue()); - assertEquals("${password}", ((JMeterProperty) args.get(1)).getStringValue()); - } - - public void testReplace() throws Exception { - ValueReplacer replacer = new ValueReplacer(); - replacer.setUserDefinedVariables(variables.getUserDefinedVariables()); - TestElement element = new ConfigTestElement(); - element.setProperty(new StringProperty("domain", "${server}")); - replacer.replaceValues(element); - //log.debug("domain property = " + element.getProperty("domain")); - element.setRunningVersion(true); - assertEquals("jakarta.apache.org", element.getPropertyAsString("domain")); - } - - /* - * (non-Javadoc) - * - * @see junit.framework.TestCase#tearDown() - */ - protected void tearDown() throws Exception { - JMeterContextService.getContext().setSamplingStarted(false); - } + public TestValueReplacer(String name) { + super(name); + } + + public void setUp() { + variables = new TestPlan(); + variables.addParameter("server", "jakarta.apache.org"); + variables.addParameter("username", "jack"); + // The following used to be jacks_password, but the Arguments class uses + // HashMap for which the order is not defined. + variables.addParameter("password", "his_password"); + variables.addParameter("regex", ".*"); + JMeterVariables vars = new JMeterVariables(); + vars.put("server", "jakarta.apache.org"); + JMeterContextService.getContext().setVariables(vars); + JMeterContextService.getContext().setSamplingStarted(true); + } + + public void testReverseReplacement() throws Exception { + ValueReplacer replacer = new ValueReplacer(variables); + assertTrue(variables.getUserDefinedVariables().containsKey("server")); + assertTrue(replacer.containsKey("server")); + TestElement element = new TestPlan(); + element.setProperty(new StringProperty("domain", "jakarta.apache.org")); + List args = new ArrayList(); + args.add("username is jack"); + args.add("his_password"); + element.setProperty(new CollectionProperty("args", args)); + replacer.reverseReplace(element); + assertEquals("${server}", element.getPropertyAsString("domain")); + args = (List) element.getProperty("args").getObjectValue(); + assertEquals("username is ${username}", ((JMeterProperty) args.get(0)).getStringValue()); + assertEquals("${password}", ((JMeterProperty) args.get(1)).getStringValue()); + } + + public void testReplace() throws Exception { + ValueReplacer replacer = new ValueReplacer(); + replacer.setUserDefinedVariables(variables.getUserDefinedVariables()); + TestElement element = new ConfigTestElement(); + element.setProperty(new StringProperty("domain", "${server}")); + replacer.replaceValues(element); + //log.debug("domain property = " + element.getProperty("domain")); + element.setRunningVersion(true); + assertEquals("jakarta.apache.org", element.getPropertyAsString("domain")); + } + + /* + * (non-Javadoc) + * + * @see junit.framework.TestCase#tearDown() + */ + protected void tearDown() throws Exception { + JMeterContextService.getContext().setSamplingStarted(false); + } } Modified: jakarta/jmeter/trunk/test/src/org/apache/jmeter/extractor/TestRegexExtractor.java URL: http://svn.apache.org/viewvc/jakarta/jmeter/trunk/test/src/org/apache/jmeter/extractor/TestRegexExtractor.java?rev=773382&r1=773381&r2=773382&view=diff ============================================================================== --- jakarta/jmeter/trunk/test/src/org/apache/jmeter/extractor/TestRegexExtractor.java (original) +++ jakarta/jmeter/trunk/test/src/org/apache/jmeter/extractor/TestRegexExtractor.java Sun May 10 18:19:28 2009 @@ -29,133 +29,133 @@ import org.apache.jmeter.threads.JMeterVariables; public class TestRegexExtractor extends TestCase { - RegexExtractor extractor; + RegexExtractor extractor; - SampleResult result; + SampleResult result; - JMeterVariables vars; + JMeterVariables vars; - public TestRegexExtractor(String name) { - super(name); - } - - private JMeterContext jmctx = null; - - public void setUp() { - jmctx = JMeterContextService.getContext(); - extractor = new RegexExtractor(); - extractor.setThreadContext(jmctx);// This would be done by the run - // command - extractor.setRefName("regVal"); - result = new SampleResult(); - String data = "<company-xmlext-query-ret>" + "<row>" + "<value field=\"RetCode\">LIS_OK</value>" - + "<value field=\"RetCodeExtension\"></value>" + "<value field=\"alias\"></value>" - + "<value field=\"positioncount\"></value>" + "<value field=\"invalidpincount\">0</value>" - + "<value field=\"pinposition1\">1</value>" + "<value field=\"pinpositionvalue1\"></value>" - + "<value field=\"pinposition2\">5</value>" + "<value field=\"pinpositionvalue2\"></value>" - + "<value field=\"pinposition3\">6</value>" + "<value field=\"pinpositionvalue3\"></value>" - + "</row>" + "</company-xmlext-query-ret>"; - result.setResponseData(data.getBytes()); - result.setResponseHeaders("Header1: Value1\nHeader2: Value2"); - result.setResponseCode("abcd"); - result.setResponseMessage("The quick brown fox"); - vars = new JMeterVariables(); - jmctx.setVariables(vars); - jmctx.setPreviousResult(result); - } - - public void testVariableExtraction() throws Exception { - extractor.setRegex("<value field=\"(pinposition\\d+)\">(\\d+)</value>"); - extractor.setTemplate("$2$"); - extractor.setMatchNumber(2); - extractor.process(); - assertEquals("5", vars.get("regVal")); - assertEquals("pinposition2", vars.get("regVal_g1")); - assertEquals("5", vars.get("regVal_g2")); - assertEquals("<value field=\"pinposition2\">5</value>", vars.get("regVal_g0")); + public TestRegexExtractor(String name) { + super(name); + } + + private JMeterContext jmctx = null; + + public void setUp() { + jmctx = JMeterContextService.getContext(); + extractor = new RegexExtractor(); + extractor.setThreadContext(jmctx);// This would be done by the run + // command + extractor.setRefName("regVal"); + result = new SampleResult(); + String data = "<company-xmlext-query-ret>" + "<row>" + "<value field=\"RetCode\">LIS_OK</value>" + + "<value field=\"RetCodeExtension\"></value>" + "<value field=\"alias\"></value>" + + "<value field=\"positioncount\"></value>" + "<value field=\"invalidpincount\">0</value>" + + "<value field=\"pinposition1\">1</value>" + "<value field=\"pinpositionvalue1\"></value>" + + "<value field=\"pinposition2\">5</value>" + "<value field=\"pinpositionvalue2\"></value>" + + "<value field=\"pinposition3\">6</value>" + "<value field=\"pinpositionvalue3\"></value>" + + "</row>" + "</company-xmlext-query-ret>"; + result.setResponseData(data.getBytes()); + result.setResponseHeaders("Header1: Value1\nHeader2: Value2"); + result.setResponseCode("abcd"); + result.setResponseMessage("The quick brown fox"); + vars = new JMeterVariables(); + jmctx.setVariables(vars); + jmctx.setPreviousResult(result); + } + + public void testVariableExtraction() throws Exception { + extractor.setRegex("<value field=\"(pinposition\\d+)\">(\\d+)</value>"); + extractor.setTemplate("$2$"); + extractor.setMatchNumber(2); + extractor.process(); + assertEquals("5", vars.get("regVal")); + assertEquals("pinposition2", vars.get("regVal_g1")); + assertEquals("5", vars.get("regVal_g2")); + assertEquals("<value field=\"pinposition2\">5</value>", vars.get("regVal_g0")); assertNull(vars.get("regVal_g3")); assertEquals("2",vars.get("regVal_g")); - } + } + + static void templateSetup(RegexExtractor rex, String tmp) { + rex.setRegex("<company-(\\w+?)-(\\w+?)-(\\w+?)>"); + rex.setMatchNumber(1); + rex.setTemplate(tmp); + rex.process(); + } - static void templateSetup(RegexExtractor rex, String tmp) { - rex.setRegex("<company-(\\w+?)-(\\w+?)-(\\w+?)>"); - rex.setMatchNumber(1); - rex.setTemplate(tmp); - rex.process(); - } - - public void testTemplate1() throws Exception { - templateSetup(extractor, ""); - assertEquals("<company-xmlext-query-ret>", vars.get("regVal_g0")); - assertEquals("xmlext", vars.get("regVal_g1")); - assertEquals("query", vars.get("regVal_g2")); - assertEquals("ret", vars.get("regVal_g3")); - assertEquals("", vars.get("regVal")); + public void testTemplate1() throws Exception { + templateSetup(extractor, ""); + assertEquals("<company-xmlext-query-ret>", vars.get("regVal_g0")); + assertEquals("xmlext", vars.get("regVal_g1")); + assertEquals("query", vars.get("regVal_g2")); + assertEquals("ret", vars.get("regVal_g3")); + assertEquals("", vars.get("regVal")); assertEquals("3",vars.get("regVal_g")); - } + } + + public void testTemplate2() throws Exception { + templateSetup(extractor, "ABC"); + assertEquals("ABC", vars.get("regVal")); + } + + public void testTemplate3() throws Exception { + templateSetup(extractor, "$2$"); + assertEquals("query", vars.get("regVal")); + } + + public void testTemplate4() throws Exception { + templateSetup(extractor, "PRE$2$"); + assertEquals("PREquery", vars.get("regVal")); + } + + public void testTemplate5() throws Exception { + templateSetup(extractor, "$2$POST"); + assertEquals("queryPOST", vars.get("regVal")); + } + + public void testTemplate6() throws Exception { + templateSetup(extractor, "$2$$1$"); + assertEquals("queryxmlext", vars.get("regVal")); + } + + public void testTemplate7() throws Exception { + templateSetup(extractor, "$2$MID$1$"); + assertEquals("queryMIDxmlext", vars.get("regVal")); + } + + public void testVariableExtraction2() throws Exception { + extractor.setRegex("<value field=\"(pinposition\\d+)\">(\\d+)</value>"); + extractor.setTemplate("$1$"); + extractor.setMatchNumber(3); + extractor.process(); + assertEquals("pinposition3", vars.get("regVal")); + } + + public void testVariableExtraction6() throws Exception { + extractor.setRegex("<value field=\"(pinposition\\d+)\">(\\d+)</value>"); + extractor.setTemplate("$2$"); + extractor.setMatchNumber(4); + extractor.setDefaultValue("default"); + extractor.process(); + assertEquals("default", vars.get("regVal")); + } - public void testTemplate2() throws Exception { - templateSetup(extractor, "ABC"); - assertEquals("ABC", vars.get("regVal")); - } - - public void testTemplate3() throws Exception { - templateSetup(extractor, "$2$"); - assertEquals("query", vars.get("regVal")); - } - - public void testTemplate4() throws Exception { - templateSetup(extractor, "PRE$2$"); - assertEquals("PREquery", vars.get("regVal")); - } - - public void testTemplate5() throws Exception { - templateSetup(extractor, "$2$POST"); - assertEquals("queryPOST", vars.get("regVal")); - } - - public void testTemplate6() throws Exception { - templateSetup(extractor, "$2$$1$"); - assertEquals("queryxmlext", vars.get("regVal")); - } - - public void testTemplate7() throws Exception { - templateSetup(extractor, "$2$MID$1$"); - assertEquals("queryMIDxmlext", vars.get("regVal")); - } - - public void testVariableExtraction2() throws Exception { - extractor.setRegex("<value field=\"(pinposition\\d+)\">(\\d+)</value>"); - extractor.setTemplate("$1$"); - extractor.setMatchNumber(3); - extractor.process(); - assertEquals("pinposition3", vars.get("regVal")); - } - - public void testVariableExtraction6() throws Exception { - extractor.setRegex("<value field=\"(pinposition\\d+)\">(\\d+)</value>"); - extractor.setTemplate("$2$"); - extractor.setMatchNumber(4); - extractor.setDefaultValue("default"); - extractor.process(); - assertEquals("default", vars.get("regVal")); - } - - public void testVariableExtraction3() throws Exception { - extractor.setRegex("<value field=\"(pinposition\\d+)\">(\\d+)</value>"); - extractor.setTemplate("_$1$"); - extractor.setMatchNumber(2); - extractor.process(); - assertEquals("_pinposition2", vars.get("regVal")); - } - - public void testVariableExtraction5() throws Exception { - extractor.setRegex("<value field=\"(pinposition\\d+)\">(\\d+)</value>"); - extractor.setTemplate("$1$"); - extractor.setMatchNumber(1);// Set up the non-wild variables - extractor.process(); + public void testVariableExtraction3() throws Exception { + extractor.setRegex("<value field=\"(pinposition\\d+)\">(\\d+)</value>"); + extractor.setTemplate("_$1$"); + extractor.setMatchNumber(2); + extractor.process(); + assertEquals("_pinposition2", vars.get("regVal")); + } + + public void testVariableExtraction5() throws Exception { + extractor.setRegex("<value field=\"(pinposition\\d+)\">(\\d+)</value>"); + extractor.setTemplate("$1$"); + extractor.setMatchNumber(1);// Set up the non-wild variables + extractor.process(); assertNotNull(vars.get("regVal")); - assertEquals("2",vars.get("regVal_g")); + assertEquals("2",vars.get("regVal_g")); assertNotNull(vars.get("regVal_g0")); assertNotNull(vars.get("regVal_g1")); assertNotNull(vars.get("regVal_g2")); @@ -167,33 +167,33 @@ assertNull(vars.get("regVal_g1")); assertNull(vars.get("regVal_g2")); assertEquals("3", vars.get("regVal_matchNr")); - assertEquals("pinposition1", vars.get("regVal_1")); - assertEquals("pinposition2", vars.get("regVal_2")); - assertEquals("pinposition3", vars.get("regVal_3")); + assertEquals("pinposition1", vars.get("regVal_1")); + assertEquals("pinposition2", vars.get("regVal_2")); + assertEquals("pinposition3", vars.get("regVal_3")); assertEquals("2", vars.get("regVal_1_g")); - assertEquals("pinposition1", vars.get("regVal_1_g1")); - assertEquals("1", vars.get("regVal_1_g2")); + assertEquals("pinposition1", vars.get("regVal_1_g1")); + assertEquals("1", vars.get("regVal_1_g2")); assertEquals("6", vars.get("regVal_3_g2")); - assertEquals("<value field=\"pinposition1\">1</value>", vars.get("regVal_1_g0")); - assertNull(vars.get("regVal_4")); + assertEquals("<value field=\"pinposition1\">1</value>", vars.get("regVal_1_g0")); + assertNull(vars.get("regVal_4")); - // Check old values don't hang around: - extractor.setRegex("(\\w+)count"); // fewer matches - extractor.process(); - assertEquals("2", vars.get("regVal_matchNr")); - assertEquals("position", vars.get("regVal_1")); + // Check old values don't hang around: + extractor.setRegex("(\\w+)count"); // fewer matches + extractor.process(); + assertEquals("2", vars.get("regVal_matchNr")); + assertEquals("position", vars.get("regVal_1")); assertEquals("1", vars.get("regVal_1_g")); assertEquals("position", vars.get("regVal_1_g1")); assertNull("Unused variables should be null", vars.get("regVal_1_g2")); - assertEquals("invalidpin", vars.get("regVal_2")); + assertEquals("invalidpin", vars.get("regVal_2")); assertEquals("1", vars.get("regVal_2_g")); assertEquals("invalidpin", vars.get("regVal_2_g1")); assertNull("Unused variables should be null", vars.get("regVal_2_g2")); assertEquals("1", vars.get("regVal_1_g")); - assertNull("Unused variables should be null", vars.get("regVal_3")); + assertNull("Unused variables should be null", vars.get("regVal_3")); assertNull("Unused variables should be null", vars.get("regVal_3_g")); - assertNull("Unused variables should be null", vars.get("regVal_3_g0")); - assertNull("Unused variables should be null", vars.get("regVal_3_g1")); + assertNull("Unused variables should be null", vars.get("regVal_3_g0")); + assertNull("Unused variables should be null", vars.get("regVal_3_g1")); assertNull("Unused variables should be null", vars.get("regVal_3_g2")); // Check when match fails @@ -204,68 +204,68 @@ assertNull("Unused variables should be null", vars.get("regVal_1_g0")); assertNull("Unused variables should be null", vars.get("regVal_1_g1")); assertNull("Unused variables should be null", vars.get("regVal_1_g2")); - } + } + + public void testVariableExtraction7() throws Exception { + extractor.setRegex("Header1: (\\S+)"); + extractor.setTemplate("$1$"); + extractor.setMatchNumber(1); + assertTrue("useBody should be true", extractor.useBody()); + assertFalse("useHdrs should be false", extractor.useHeaders()); + assertFalse("useURL should be false", extractor.useUrl()); + extractor.setUseField(RegexExtractor.USE_BODY); + assertTrue("useBody should be true", extractor.useBody()); + assertFalse("useHdrs should be false", extractor.useHeaders()); + assertFalse("useURL should be false", extractor.useUrl()); + extractor.setUseField(RegexExtractor.USE_HDRS); + assertTrue("useHdrs should be true", extractor.useHeaders()); + assertFalse("useBody should be false", extractor.useBody()); + assertFalse("useURL should be false", extractor.useUrl()); + extractor.process(); + assertEquals("Value1", vars.get("regVal")); + extractor.setUseField(RegexExtractor.USE_URL); + assertFalse("useHdrs should be false", extractor.useHeaders()); + assertFalse("useBody should be false", extractor.useBody()); + assertTrue("useURL should be true", extractor.useUrl()); + } + + public void testVariableExtraction8() throws Exception { + extractor.setRegex("http://jakarta\\.apache\\.org/(\\w+)"); + extractor.setTemplate("$1$"); + extractor.setMatchNumber(1); + extractor.setUseField(RegexExtractor.USE_URL); + assertFalse("useHdrs should be false", extractor.useHeaders()); + assertFalse("useBody should be false", extractor.useBody()); + assertTrue("useURL should be true", extractor.useUrl()); + extractor.process(); + assertNull(vars.get("regVal")); + result.setURL(new URL("http://jakarta.apache.org/index.html?abcd")); + extractor.process(); + assertEquals("index",vars.get("regVal")); + } - public void testVariableExtraction7() throws Exception { - extractor.setRegex("Header1: (\\S+)"); - extractor.setTemplate("$1$"); - extractor.setMatchNumber(1); - assertTrue("useBody should be true", extractor.useBody()); - assertFalse("useHdrs should be false", extractor.useHeaders()); - assertFalse("useURL should be false", extractor.useUrl()); - extractor.setUseField(RegexExtractor.USE_BODY); - assertTrue("useBody should be true", extractor.useBody()); - assertFalse("useHdrs should be false", extractor.useHeaders()); - assertFalse("useURL should be false", extractor.useUrl()); - extractor.setUseField(RegexExtractor.USE_HDRS); - assertTrue("useHdrs should be true", extractor.useHeaders()); - assertFalse("useBody should be false", extractor.useBody()); - assertFalse("useURL should be false", extractor.useUrl()); - extractor.process(); - assertEquals("Value1", vars.get("regVal")); - extractor.setUseField(RegexExtractor.USE_URL); - assertFalse("useHdrs should be false", extractor.useHeaders()); - assertFalse("useBody should be false", extractor.useBody()); - assertTrue("useURL should be true", extractor.useUrl()); - } - - public void testVariableExtraction8() throws Exception { - extractor.setRegex("http://jakarta\\.apache\\.org/(\\w+)"); - extractor.setTemplate("$1$"); - extractor.setMatchNumber(1); - extractor.setUseField(RegexExtractor.USE_URL); - assertFalse("useHdrs should be false", extractor.useHeaders()); - assertFalse("useBody should be false", extractor.useBody()); - assertTrue("useURL should be true", extractor.useUrl()); - extractor.process(); - assertNull(vars.get("regVal")); - result.setURL(new URL("http://jakarta.apache.org/index.html?abcd")); - extractor.process(); - assertEquals("index",vars.get("regVal")); - } - - public void testVariableExtraction9() throws Exception { - extractor.setRegex("(\\w+)"); - extractor.setTemplate("$1$"); - extractor.setMatchNumber(1); - extractor.setUseField(RegexExtractor.USE_CODE); - assertFalse("useHdrs should be false", extractor.useHeaders()); - assertFalse("useBody should be false", extractor.useBody()); - assertFalse("useURL should be false", extractor.useUrl()); - assertFalse("useMessage should be false", extractor.useMessage()); - assertTrue("useCode should be true", extractor.useCode()); - extractor.process(); - assertEquals("abcd",vars.get("regVal")); - extractor.setUseField(RegexExtractor.USE_MESSAGE); - assertFalse("useHdrs should be false", extractor.useHeaders()); - assertFalse("useBody should be false", extractor.useBody()); - assertFalse("useURL should be false", extractor.useUrl()); - assertTrue("useMessage should be true", extractor.useMessage()); - assertFalse("useCode should be falsee", extractor.useCode()); - extractor.setMatchNumber(3); - extractor.process(); - assertEquals("brown",vars.get("regVal")); - } + public void testVariableExtraction9() throws Exception { + extractor.setRegex("(\\w+)"); + extractor.setTemplate("$1$"); + extractor.setMatchNumber(1); + extractor.setUseField(RegexExtractor.USE_CODE); + assertFalse("useHdrs should be false", extractor.useHeaders()); + assertFalse("useBody should be false", extractor.useBody()); + assertFalse("useURL should be false", extractor.useUrl()); + assertFalse("useMessage should be false", extractor.useMessage()); + assertTrue("useCode should be true", extractor.useCode()); + extractor.process(); + assertEquals("abcd",vars.get("regVal")); + extractor.setUseField(RegexExtractor.USE_MESSAGE); + assertFalse("useHdrs should be false", extractor.useHeaders()); + assertFalse("useBody should be false", extractor.useBody()); + assertFalse("useURL should be false", extractor.useUrl()); + assertTrue("useMessage should be true", extractor.useMessage()); + assertFalse("useCode should be falsee", extractor.useCode()); + extractor.setMatchNumber(3); + extractor.process(); + assertEquals("brown",vars.get("regVal")); + } public void testNoDefault() throws Exception { extractor.setRegex("<value field=\"(pinposition\\d+)\">(\\d+)</value>"); Modified: jakarta/jmeter/trunk/test/src/org/apache/jmeter/extractor/TestXPathExtractor.java URL: http://svn.apache.org/viewvc/jakarta/jmeter/trunk/test/src/org/apache/jmeter/extractor/TestXPathExtractor.java?rev=773382&r1=773381&r2=773382&view=diff ============================================================================== --- jakarta/jmeter/trunk/test/src/org/apache/jmeter/extractor/TestXPathExtractor.java (original) +++ jakarta/jmeter/trunk/test/src/org/apache/jmeter/extractor/TestXPathExtractor.java Sun May 10 18:19:28 2009 @@ -27,67 +27,67 @@ import org.apache.jmeter.threads.JMeterVariables; public class TestXPathExtractor extends TestCase { - XPathExtractor extractor; + XPathExtractor extractor; - SampleResult result; + SampleResult result; - JMeterVariables vars; + JMeterVariables vars; - public TestXPathExtractor(String name) { - super(name); - } + public TestXPathExtractor(String name) { + super(name); + } - private JMeterContext jmctx = null; + private JMeterContext jmctx = null; private final static String VAL_NAME = "value"; private final static String VAL_NAME_NR = "value_matchNr"; - public void setUp() { - jmctx = JMeterContextService.getContext(); - extractor = new XPathExtractor(); - extractor.setThreadContext(jmctx);// This would be done by the run command - extractor.setRefName(VAL_NAME); + public void setUp() { + jmctx = JMeterContextService.getContext(); + extractor = new XPathExtractor(); + extractor.setThreadContext(jmctx);// This would be done by the run command + extractor.setRefName(VAL_NAME); extractor.setDefaultValue("Default"); - result = new SampleResult(); - String data = "<book><preface title='Intro'>zero</preface><page>one</page><page>two</page><empty></empty><a><b></b></a></book>"; - result.setResponseData(data.getBytes()); - vars = new JMeterVariables(); - jmctx.setVariables(vars); - jmctx.setPreviousResult(result); - } - - public void testAttributeExtraction() throws Exception { - extractor.setXPathQuery("/book/preface/@title"); - extractor.process(); - assertEquals("Intro", vars.get(VAL_NAME)); + result = new SampleResult(); + String data = "<book><preface title='Intro'>zero</preface><page>one</page><page>two</page><empty></empty><a><b></b></a></book>"; + result.setResponseData(data.getBytes()); + vars = new JMeterVariables(); + jmctx.setVariables(vars); + jmctx.setPreviousResult(result); + } + + public void testAttributeExtraction() throws Exception { + extractor.setXPathQuery("/book/preface/@title"); + extractor.process(); + assertEquals("Intro", vars.get(VAL_NAME)); assertEquals("1", vars.get(VAL_NAME_NR)); assertEquals("Intro", vars.get(VAL_NAME+"_1")); assertNull(vars.get(VAL_NAME+"_2")); extractor.setXPathQuery("/book/prefa...@title]"); - extractor.process(); - assertEquals("zero", vars.get(VAL_NAME)); + extractor.process(); + assertEquals("zero", vars.get(VAL_NAME)); assertEquals("1", vars.get(VAL_NAME_NR)); assertEquals("zero", vars.get(VAL_NAME+"_1")); assertNull(vars.get(VAL_NAME+"_2")); extractor.setXPathQuery("/book/prefa...@title='Intro']"); - extractor.process(); - assertEquals("zero", vars.get(VAL_NAME)); + extractor.process(); + assertEquals("zero", vars.get(VAL_NAME)); assertEquals("1", vars.get(VAL_NAME_NR)); assertEquals("zero", vars.get(VAL_NAME+"_1")); assertNull(vars.get(VAL_NAME+"_2")); extractor.setXPathQuery("/book/prefa...@title='xyz']"); - extractor.process(); - assertEquals("Default", vars.get(VAL_NAME)); + extractor.process(); + assertEquals("Default", vars.get(VAL_NAME)); assertEquals("0", vars.get(VAL_NAME_NR)); assertNull(vars.get(VAL_NAME+"_1")); - } - + } + public void testVariableExtraction() throws Exception { - extractor.setXPathQuery("/book/preface"); - extractor.process(); - assertEquals("zero", vars.get(VAL_NAME)); + extractor.setXPathQuery("/book/preface"); + extractor.process(); + assertEquals("zero", vars.get(VAL_NAME)); assertEquals("1", vars.get(VAL_NAME_NR)); assertEquals("zero", vars.get(VAL_NAME+"_1")); assertNull(vars.get(VAL_NAME+"_2")); @@ -134,7 +134,7 @@ extractor.process(); assertEquals("Default", vars.get(VAL_NAME)); assertEquals("0", vars.get(VAL_NAME_NR)); - } + } public void testInvalidDocument() throws Exception { result.setResponseData("<z>".getBytes()); --------------------------------------------------------------------- To unsubscribe, e-mail: jmeter-dev-unsubscr...@jakarta.apache.org For additional commands, e-mail: jmeter-dev-h...@jakarta.apache.org