You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jmeter-dev@jakarta.apache.org by se...@apache.org on 2006/01/17 20:44:13 UTC
svn commit: r369896 - in /jakarta/jmeter/branches/rel-2-1:
src/core/org/apache/jmeter/testbeans/gui/
src/core/org/apache/jmeter/testelement/property/
src/core/org/apache/jmeter/threads/
src/functions/org/apache/jmeter/functions/ test/src/org/apache/jme...
Author: sebb
Date: Tue Jan 17 11:43:50 2006
New Revision: 369896
URL: http://svn.apache.org/viewcvs?rev=369896&view=rev
Log:
Move test code to test tree
Added:
jakarta/jmeter/branches/rel-2-1/test/src/org/apache/jmeter/functions/TestRegexFunction.java
jakarta/jmeter/branches/rel-2-1/test/src/org/apache/jmeter/testbeans/gui/TestComboStringEditor.java
jakarta/jmeter/branches/rel-2-1/test/src/org/apache/jmeter/testbeans/gui/TestFieldStringEditor.java
jakarta/jmeter/branches/rel-2-1/test/src/org/apache/jmeter/threads/
jakarta/jmeter/branches/rel-2-1/test/src/org/apache/jmeter/threads/TestTestCompiler.java
Modified:
jakarta/jmeter/branches/rel-2-1/src/core/org/apache/jmeter/testbeans/gui/ComboStringEditor.java
jakarta/jmeter/branches/rel-2-1/src/core/org/apache/jmeter/testbeans/gui/FieldStringEditor.java
jakarta/jmeter/branches/rel-2-1/src/core/org/apache/jmeter/testelement/property/CollectionProperty.java
jakarta/jmeter/branches/rel-2-1/src/core/org/apache/jmeter/threads/TestCompiler.java
jakarta/jmeter/branches/rel-2-1/src/functions/org/apache/jmeter/functions/RegexFunction.java
jakarta/jmeter/branches/rel-2-1/src/functions/org/apache/jmeter/functions/XPathFileContainer.java
jakarta/jmeter/branches/rel-2-1/test/src/org/apache/jmeter/functions/PackageTest.java
jakarta/jmeter/branches/rel-2-1/test/src/org/apache/jmeter/testelement/property/PackageTest.java
Modified: jakarta/jmeter/branches/rel-2-1/src/core/org/apache/jmeter/testbeans/gui/ComboStringEditor.java
URL: http://svn.apache.org/viewcvs/jakarta/jmeter/branches/rel-2-1/src/core/org/apache/jmeter/testbeans/gui/ComboStringEditor.java?rev=369896&r1=369895&r2=369896&view=diff
==============================================================================
--- jakarta/jmeter/branches/rel-2-1/src/core/org/apache/jmeter/testbeans/gui/ComboStringEditor.java (original)
+++ jakarta/jmeter/branches/rel-2-1/src/core/org/apache/jmeter/testbeans/gui/ComboStringEditor.java Tue Jan 17 11:43:50 2006
@@ -1,4 +1,3 @@
-// $Header$
/*
* Copyright 2003-2004 The Apache Software Foundation.
*
@@ -82,7 +81,8 @@
* non-editable during processing of secondary events.
*/
- private static final Object UNDEFINED = new UniqueObject(JMeterUtils.getResString("property_undefined"));
+ // Needs to be visible to test cases
+ static final Object UNDEFINED = new UniqueObject(JMeterUtils.getResString("property_undefined"));
private static final Object EDIT = new UniqueObject(JMeterUtils.getResString("property_edit"));
@@ -302,44 +302,6 @@
public String toString() {
return s;
- }
- }
-
- public static class Test extends junit.framework.TestCase {
- public Test(String name) {
- super(name);
- }
-
- private void testSetGet(ComboStringEditor e, Object value) throws Exception {
- e.setValue(value);
- assertEquals(value, e.getValue());
- }
-
- private void testSetGetAsText(ComboStringEditor e, String text) throws Exception {
- e.setAsText(text);
- assertEquals(text, e.getAsText());
- }
-
- public void testSetGet() throws Exception {
- ComboStringEditor e = new ComboStringEditor();
-
- testSetGet(e, "any string");
- testSetGet(e, "");
- testSetGet(e, null);
- testSetGet(e, "${var}");
- }
-
- public void testSetGetAsText() throws Exception {
- ComboStringEditor e = new ComboStringEditor();
-
- testSetGetAsText(e, "any string");
- testSetGetAsText(e, "");
- testSetGetAsText(e, null);
- testSetGetAsText(e, "${var}");
-
- // Check "Undefined" does not become a "reserved word":
- e.setAsText(UNDEFINED.toString());
- assertNotNull(e.getAsText());
}
}
}
Modified: jakarta/jmeter/branches/rel-2-1/src/core/org/apache/jmeter/testbeans/gui/FieldStringEditor.java
URL: http://svn.apache.org/viewcvs/jakarta/jmeter/branches/rel-2-1/src/core/org/apache/jmeter/testbeans/gui/FieldStringEditor.java?rev=369896&r1=369895&r2=369896&view=diff
==============================================================================
--- jakarta/jmeter/branches/rel-2-1/src/core/org/apache/jmeter/testbeans/gui/FieldStringEditor.java (original)
+++ jakarta/jmeter/branches/rel-2-1/src/core/org/apache/jmeter/testbeans/gui/FieldStringEditor.java Tue Jan 17 11:43:50 2006
@@ -1,4 +1,3 @@
-// $Header$
/*
* Copyright 2003-2004 The Apache Software Foundation.
*
@@ -128,37 +127,5 @@
*/
public void focusLost(FocusEvent e) {
firePropertyChange();
- }
-
- public static class Test extends junit.framework.TestCase {
- public Test(String name) {
- super(name);
- }
-
- private void testSetGet(ComboStringEditor e, Object value) throws Exception {
- e.setValue(value);
- assertEquals(value, e.getValue());
- }
-
- private void testSetGetAsText(ComboStringEditor e, String text) throws Exception {
- e.setAsText(text);
- assertEquals(text, e.getAsText());
- }
-
- public void testSetGet() throws Exception {
- ComboStringEditor e = new ComboStringEditor();
-
- testSetGet(e, "any string");
- testSetGet(e, "");
- testSetGet(e, "${var}");
- }
-
- public void testSetGetAsText() throws Exception {
- ComboStringEditor e = new ComboStringEditor();
-
- testSetGetAsText(e, "any string");
- testSetGetAsText(e, "");
- testSetGetAsText(e, "${var}");
- }
}
}
Modified: jakarta/jmeter/branches/rel-2-1/src/core/org/apache/jmeter/testelement/property/CollectionProperty.java
URL: http://svn.apache.org/viewcvs/jakarta/jmeter/branches/rel-2-1/src/core/org/apache/jmeter/testelement/property/CollectionProperty.java?rev=369896&r1=369895&r2=369896&view=diff
==============================================================================
--- jakarta/jmeter/branches/rel-2-1/src/core/org/apache/jmeter/testelement/property/CollectionProperty.java (original)
+++ jakarta/jmeter/branches/rel-2-1/src/core/org/apache/jmeter/testelement/property/CollectionProperty.java Tue Jan 17 11:43:50 2006
@@ -1,4 +1,3 @@
-// $Header$
/*
* Copyright 2003-2004 The Apache Software Foundation.
*
@@ -22,7 +21,6 @@
import java.util.Collection;
import java.util.List;
-import org.apache.jmeter.junit.JMeterTestCase;
import org.apache.jmeter.testelement.TestElement;
/**
@@ -194,20 +192,6 @@
value = savedValue;
}
recoverRunningVersionOfSubElements(owner);
- }
-
- public static class Test extends JMeterTestCase {
- public Test(String name) {
- super(name);
- }
-
- public void testAddingProperties() throws Exception {
- CollectionProperty coll = new CollectionProperty();
- coll.addItem("joe");
- coll.addProperty(new FunctionProperty());
- assertEquals("joe", coll.get(0).getStringValue());
- assertEquals("org.apache.jmeter.testelement.property.FunctionProperty", coll.get(1).getClass().getName());
- }
}
/*
Modified: jakarta/jmeter/branches/rel-2-1/src/core/org/apache/jmeter/threads/TestCompiler.java
URL: http://svn.apache.org/viewcvs/jakarta/jmeter/branches/rel-2-1/src/core/org/apache/jmeter/threads/TestCompiler.java?rev=369896&r1=369895&r2=369896&view=diff
==============================================================================
--- jakarta/jmeter/branches/rel-2-1/src/core/org/apache/jmeter/threads/TestCompiler.java (original)
+++ jakarta/jmeter/branches/rel-2-1/src/core/org/apache/jmeter/threads/TestCompiler.java Tue Jan 17 11:43:50 2006
@@ -1,4 +1,3 @@
-// $Header$
/*
* Copyright 2001-2004 The Apache Software Foundation.
*
@@ -31,14 +30,11 @@
import org.apache.jmeter.assertions.Assertion;
import org.apache.jmeter.config.ConfigTestElement;
import org.apache.jmeter.control.Controller;
-import org.apache.jmeter.control.GenericController;
import org.apache.jmeter.engine.event.LoopIterationListener;
import org.apache.jmeter.processor.PostProcessor;
import org.apache.jmeter.processor.PreProcessor;
-import org.apache.jmeter.samplers.AbstractSampler;
import org.apache.jmeter.samplers.SampleEvent;
import org.apache.jmeter.samplers.SampleListener;
-import org.apache.jmeter.samplers.SampleResult;
import org.apache.jmeter.samplers.Sampler;
import org.apache.jmeter.testbeans.TestBeanHelper;
import org.apache.jmeter.testelement.AbstractTestElement;
@@ -46,7 +42,6 @@
import org.apache.jmeter.timers.Timer;
import org.apache.jorphan.collections.HashTree;
import org.apache.jorphan.collections.HashTreeTraverser;
-import org.apache.jorphan.collections.ListedHashTree;
import org.apache.jorphan.logging.LoggingManager;
import org.apache.log.Logger;
@@ -228,43 +223,6 @@
if (maybeController instanceof Controller) {
log.debug("adding controller: " + maybeController + " to sampler config");
controllers.add(maybeController);
- }
- }
-
- /**
- * @version $Revision$
- */
- public static class Test extends junit.framework.TestCase {
- public Test(String name) {
- super(name);
- }
-
- public void testConfigGathering() throws Exception {
- ListedHashTree testing = new ListedHashTree();
- GenericController controller = new GenericController();
- ConfigTestElement config1 = new ConfigTestElement();
- config1.setName("config1");
- config1.setProperty("test.property", "A test value");
- TestSampler sampler = new TestSampler();
- sampler.setName("sampler");
- testing.add(controller, config1);
- testing.add(controller, sampler);
- TestCompiler.initialize();
-
- TestCompiler compiler = new TestCompiler(testing, new JMeterVariables());
- testing.traverse(compiler);
- sampler = (TestSampler) compiler.configureSampler(sampler).getSampler();
- assertEquals("A test value", sampler.getPropertyAsString("test.property"));
- }
-
- class TestSampler extends AbstractSampler {
- public SampleResult sample(org.apache.jmeter.samplers.Entry e) {
- return null;
- }
-
- public Object clone() {
- return new TestSampler();
- }
}
}
Modified: jakarta/jmeter/branches/rel-2-1/src/functions/org/apache/jmeter/functions/RegexFunction.java
URL: http://svn.apache.org/viewcvs/jakarta/jmeter/branches/rel-2-1/src/functions/org/apache/jmeter/functions/RegexFunction.java?rev=369896&r1=369895&r2=369896&view=diff
==============================================================================
--- jakarta/jmeter/branches/rel-2-1/src/functions/org/apache/jmeter/functions/RegexFunction.java (original)
+++ jakarta/jmeter/branches/rel-2-1/src/functions/org/apache/jmeter/functions/RegexFunction.java Tue Jan 17 11:43:50 2006
@@ -27,11 +27,8 @@
import java.util.Random;
import org.apache.jmeter.engine.util.CompoundVariable;
-import org.apache.jmeter.junit.JMeterTestCase;
import org.apache.jmeter.samplers.SampleResult;
import org.apache.jmeter.samplers.Sampler;
-import org.apache.jmeter.threads.JMeterContext;
-import org.apache.jmeter.threads.JMeterContextService;
import org.apache.jmeter.threads.JMeterVariables;
import org.apache.jmeter.util.JMeterUtils;
import org.apache.jorphan.logging.LoggingManager;
@@ -261,122 +258,4 @@
return new Perl5Matcher().contains(rawData, pattern);
}
- /**/
- public static class Test extends JMeterTestCase {
- RegexFunction variable;
-
- SampleResult result;
-
- Collection params;
-
- private JMeterVariables vars;
-
- private JMeterContext jmctx = null;
-
- public Test(String name) {
- super(name);
- }
-
- public void setUp() {
- variable = new RegexFunction();
- result = new SampleResult();
- jmctx = JMeterContextService.getContext();
- 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());
- vars = new JMeterVariables();
- jmctx.setVariables(vars);
- jmctx.setPreviousResult(result);
- }
-
- public void testVariableExtraction() throws Exception {
- params = new LinkedList();
- params.add(new CompoundVariable("<value field=\"(pinposition\\d+)\">(\\d+)</value>"));
- params.add(new CompoundVariable("$2$"));
- params.add(new CompoundVariable("2"));
- variable.setParameters(params);
- String match = variable.execute(result, null);
- assertEquals("5", match);
- }
-
- public void testVariableExtraction2() throws Exception {
- params = new LinkedList();
- params.add(new CompoundVariable("<value field=\"(pinposition\\d+)\">(\\d+)</value>"));
- params.add(new CompoundVariable("$1$"));
- params.add(new CompoundVariable("3"));
- variable.setParameters(params);
- String match = variable.execute(result, null);
- assertEquals("pinposition3", match);
- }
-
- public void testVariableExtraction5() throws Exception {
- params = new LinkedList();
- params.add(new CompoundVariable("<value field=\"(pinposition\\d+)\">(\\d+)</value>"));
- params.add(new CompoundVariable("$1$"));
- params.add(new CompoundVariable("ALL"));
- params.add(new CompoundVariable("_"));
- variable.setParameters(params);
- String match = variable.execute(result, null);
- assertEquals("pinposition1_pinposition2_pinposition3", match);
- }
-
- public void testVariableExtraction6() throws Exception {
- params = new LinkedList();
- params.add(new CompoundVariable("<value field=\"(pinposition\\d+)\">(\\d+)</value>"));
- params.add(new CompoundVariable("$2$"));
- params.add(new CompoundVariable("4"));
- params.add(new CompoundVariable(""));
- params.add(new CompoundVariable("default"));
- variable.setParameters(params);
- String match = variable.execute(result, null);
- assertEquals("default", match);
- }
-
- public void testComma() throws Exception {
- params = new LinkedList();
- params.add(new CompoundVariable("<value,? field=\"(pinposition\\d+)\">(\\d+)</value>"));
- params.add(new CompoundVariable("$1$"));
- params.add(new CompoundVariable("3"));
- variable.setParameters(params);
- String match = variable.execute(result, null);
- assertEquals("pinposition3", match);
- }
-
- public void testVariableExtraction3() throws Exception {
- params = new LinkedList();
- params.add(new CompoundVariable("<value field=\"(pinposition\\d+)\">(\\d+)</value>"));
- params.add(new CompoundVariable("_$1$"));
- params.add(new CompoundVariable("2"));
- variable.setParameters(params);
- String match = variable.execute(result, null);
- assertEquals("_pinposition2", match);
- }
-
- public void testVariableExtraction4() throws Exception {
- params = new LinkedList();
- params.add(new CompoundVariable("<value field=\"(pinposition\\d+)\">(\\d+)</value>"));
- params.add(new CompoundVariable("$2$, "));
- params.add(new CompoundVariable(".333"));
- variable.setParameters(params);
- String match = variable.execute(result, null);
- assertEquals("1, ", match);
- }
-
- public void testDefaultValue() throws Exception {
- params = new LinkedList();
- params.add(new CompoundVariable("<value,, field=\"(pinposition\\d+)\">(\\d+)</value>"));
- params.add(new CompoundVariable("$2$, "));
- params.add(new CompoundVariable(".333"));
- params.add(new CompoundVariable(""));
- params.add(new CompoundVariable("No Value Found"));
- variable.setParameters(params);
- String match = variable.execute(result, null);
- assertEquals("No Value Found", match);
- }
- }
}
Modified: jakarta/jmeter/branches/rel-2-1/src/functions/org/apache/jmeter/functions/XPathFileContainer.java
URL: http://svn.apache.org/viewcvs/jakarta/jmeter/branches/rel-2-1/src/functions/org/apache/jmeter/functions/XPathFileContainer.java?rev=369896&r1=369895&r2=369896&view=diff
==============================================================================
--- jakarta/jmeter/branches/rel-2-1/src/functions/org/apache/jmeter/functions/XPathFileContainer.java (original)
+++ jakarta/jmeter/branches/rel-2-1/src/functions/org/apache/jmeter/functions/XPathFileContainer.java Tue Jan 17 11:43:50 2006
@@ -27,7 +27,6 @@
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.TransformerException;
-import org.apache.jmeter.junit.JMeterTestCase;
import org.apache.jorphan.logging.LoggingManager;
import org.apache.log.Logger;
import org.apache.xpath.XPathAPI;
@@ -50,7 +49,10 @@
/** Keeping track of which row is next to be read. */
private int nextRow;
-
+ int getNextRow(){// give access to Test code
+ return nextRow;
+ }
+
private XPathFileContainer()// Not intended to be called directly
{
}
@@ -124,75 +126,6 @@
public int size() {
return (nodeList == null) ? -1 : nodeList.getLength();
- }
-
- public static class Test extends JMeterTestCase {
-
- static {
- // LoggingManager.setPriority("DEBUG","jmeter");
- // LoggingManager.setTarget(new java.io.PrintWriter(System.out));
- }
-
- public Test(String a) {
- super(a);
- }
-
- public void testNull() throws Exception {
- try {
- new XPathFileContainer("nosuch.xml", "/");
- fail("Should not find the file");
- } catch (FileNotFoundException e) {
- }
- }
-
- public void testrowNum() throws Exception {
- XPathFileContainer f = new XPathFileContainer("../build.xml", "/project/target/@name");
- assertNotNull(f);
- // assertEquals("Expected 4 lines",4,f.size());
-
- int myRow = f.nextRow();
- assertEquals(0, myRow);
- assertEquals(1, f.nextRow);
-
- myRow = f.nextRow();
- assertEquals(1, myRow);
- assertEquals(2, f.nextRow);
-
- myRow = f.nextRow();
- assertEquals(2, myRow);
- assertEquals(3, f.nextRow);
-
- // myRow = f.nextRow();
- // assertEquals(3,myRow);
- // assertEquals(0,f.nextRow);
-
- // myRow = f.nextRow();
- // assertEquals(0,myRow);
- // assertEquals(1,f.nextRow);
-
- }
-
- public void testColumns() throws Exception {
- XPathFileContainer f = new XPathFileContainer("../build.xml", "/project/target/@name");
- assertNotNull(f);
- assertTrue("Not empty", f.size() > 0);
- int last = 0;
- for (int i = 0; i < f.size(); i++) {
- last = f.nextRow();
- log.debug("found [" + i + "]" + f.getXPathString(last));
- }
- assertEquals(last + 1, f.size());
-
- }
-
- public void testDefault() throws Exception {
- XPathFileContainer f = new XPathFileContainer("../build.xml", "/project/@default");
- assertNotNull(f);
- assertTrue("Not empty", f.size() > 0);
- assertEquals("all", f.getXPathString(0));
-
- }
-
}
/**
Modified: jakarta/jmeter/branches/rel-2-1/test/src/org/apache/jmeter/functions/PackageTest.java
URL: http://svn.apache.org/viewcvs/jakarta/jmeter/branches/rel-2-1/test/src/org/apache/jmeter/functions/PackageTest.java?rev=369896&r1=369895&r2=369896&view=diff
==============================================================================
--- jakarta/jmeter/branches/rel-2-1/test/src/org/apache/jmeter/functions/PackageTest.java (original)
+++ jakarta/jmeter/branches/rel-2-1/test/src/org/apache/jmeter/functions/PackageTest.java Tue Jan 17 11:43:50 2006
@@ -25,6 +25,7 @@
*/
package org.apache.jmeter.functions;
+import java.io.FileNotFoundException;
import java.util.Collection;
import java.util.LinkedList;
@@ -153,6 +154,13 @@
split.addTest(new PackageTest("SplitTest1"));
allsuites.addTest(split);
+ TestSuite xpath = new TestSuite("XPath");
+ xpath.addTest(new PackageTest("XPathtestColumns"));
+ xpath.addTest(new PackageTest("XPathtestDefault"));
+ xpath.addTest(new PackageTest("XPathtestNull"));
+ xpath.addTest(new PackageTest("XPathtestrowNum"));
+ allsuites.addTest(xpath);
+
return allsuites;
}
@@ -612,4 +620,63 @@
}
}
+
+ // XPathFileContainer tests
+
+ public void XPathtestNull() throws Exception {
+ try {
+ new XPathFileContainer("nosuch.xml", "/");
+ fail("Should not find the file");
+ } catch (FileNotFoundException e) {
+ }
+ }
+
+ public void XPathtestrowNum() throws Exception {
+ XPathFileContainer f = new XPathFileContainer("../build.xml", "/project/target/@name");
+ assertNotNull(f);
+ // assertEquals("Expected 4 lines",4,f.size());
+
+ int myRow = f.nextRow();
+ assertEquals(0, myRow);
+ assertEquals(1, f.getNextRow());
+
+ myRow = f.nextRow();
+ assertEquals(1, myRow);
+ assertEquals(2, f.getNextRow());
+
+ myRow = f.nextRow();
+ assertEquals(2, myRow);
+ assertEquals(3, f.getNextRow());
+
+ // myRow = f.nextRow();
+ // assertEquals(3,myRow);
+ // assertEquals(0,f.getNextRow());
+
+ // myRow = f.nextRow();
+ // assertEquals(0,myRow);
+ // assertEquals(1,f.getNextRow());
+
+ }
+
+ public void XPathtestColumns() throws Exception {
+ XPathFileContainer f = new XPathFileContainer("../build.xml", "/project/target/@name");
+ assertNotNull(f);
+ assertTrue("Not empty", f.size() > 0);
+ int last = 0;
+ for (int i = 0; i < f.size(); i++) {
+ last = f.nextRow();
+ log.debug("found [" + i + "]" + f.getXPathString(last));
+ }
+ assertEquals(last + 1, f.size());
+
+ }
+
+ public void XPathtestDefault() throws Exception {
+ XPathFileContainer f = new XPathFileContainer("../build.xml", "/project/@default");
+ assertNotNull(f);
+ assertTrue("Not empty", f.size() > 0);
+ assertEquals("all", f.getXPathString(0));
+
+ }
+
}
Added: jakarta/jmeter/branches/rel-2-1/test/src/org/apache/jmeter/functions/TestRegexFunction.java
URL: http://svn.apache.org/viewcvs/jakarta/jmeter/branches/rel-2-1/test/src/org/apache/jmeter/functions/TestRegexFunction.java?rev=369896&view=auto
==============================================================================
--- jakarta/jmeter/branches/rel-2-1/test/src/org/apache/jmeter/functions/TestRegexFunction.java (added)
+++ jakarta/jmeter/branches/rel-2-1/test/src/org/apache/jmeter/functions/TestRegexFunction.java Tue Jan 17 11:43:50 2006
@@ -0,0 +1,146 @@
+/*
+ * Copyright 2001-2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.jmeter.functions;
+
+import java.util.Collection;
+import java.util.LinkedList;
+
+import org.apache.jmeter.engine.util.CompoundVariable;
+import org.apache.jmeter.junit.JMeterTestCase;
+import org.apache.jmeter.samplers.SampleResult;
+import org.apache.jmeter.threads.JMeterContext;
+import org.apache.jmeter.threads.JMeterContextService;
+import org.apache.jmeter.threads.JMeterVariables;
+
+public class TestRegexFunction extends JMeterTestCase {
+ RegexFunction variable;
+
+ SampleResult result;
+
+ Collection params;
+
+ private JMeterVariables vars;
+
+ private JMeterContext jmctx = null;
+
+ public TestRegexFunction(String name) {
+ super(name);
+ }
+
+ public void setUp() {
+ variable = new RegexFunction();
+ result = new SampleResult();
+ jmctx = JMeterContextService.getContext();
+ 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());
+ vars = new JMeterVariables();
+ jmctx.setVariables(vars);
+ jmctx.setPreviousResult(result);
+ }
+
+ public void testVariableExtraction() throws Exception {
+ params = new LinkedList();
+ params.add(new CompoundVariable("<value field=\"(pinposition\\d+)\">(\\d+)</value>"));
+ params.add(new CompoundVariable("$2$"));
+ params.add(new CompoundVariable("2"));
+ variable.setParameters(params);
+ String match = variable.execute(result, null);
+ assertEquals("5", match);
+ }
+
+ public void testVariableExtraction2() throws Exception {
+ params = new LinkedList();
+ params.add(new CompoundVariable("<value field=\"(pinposition\\d+)\">(\\d+)</value>"));
+ params.add(new CompoundVariable("$1$"));
+ params.add(new CompoundVariable("3"));
+ variable.setParameters(params);
+ String match = variable.execute(result, null);
+ assertEquals("pinposition3", match);
+ }
+
+ public void testVariableExtraction5() throws Exception {
+ params = new LinkedList();
+ params.add(new CompoundVariable("<value field=\"(pinposition\\d+)\">(\\d+)</value>"));
+ params.add(new CompoundVariable("$1$"));
+ params.add(new CompoundVariable("ALL"));
+ params.add(new CompoundVariable("_"));
+ variable.setParameters(params);
+ String match = variable.execute(result, null);
+ assertEquals("pinposition1_pinposition2_pinposition3", match);
+ }
+
+ public void testVariableExtraction6() throws Exception {
+ params = new LinkedList();
+ params.add(new CompoundVariable("<value field=\"(pinposition\\d+)\">(\\d+)</value>"));
+ params.add(new CompoundVariable("$2$"));
+ params.add(new CompoundVariable("4"));
+ params.add(new CompoundVariable(""));
+ params.add(new CompoundVariable("default"));
+ variable.setParameters(params);
+ String match = variable.execute(result, null);
+ assertEquals("default", match);
+ }
+
+ public void testComma() throws Exception {
+ params = new LinkedList();
+ params.add(new CompoundVariable("<value,? field=\"(pinposition\\d+)\">(\\d+)</value>"));
+ params.add(new CompoundVariable("$1$"));
+ params.add(new CompoundVariable("3"));
+ variable.setParameters(params);
+ String match = variable.execute(result, null);
+ assertEquals("pinposition3", match);
+ }
+
+ public void testVariableExtraction3() throws Exception {
+ params = new LinkedList();
+ params.add(new CompoundVariable("<value field=\"(pinposition\\d+)\">(\\d+)</value>"));
+ params.add(new CompoundVariable("_$1$"));
+ params.add(new CompoundVariable("2"));
+ variable.setParameters(params);
+ String match = variable.execute(result, null);
+ assertEquals("_pinposition2", match);
+ }
+
+ public void testVariableExtraction4() throws Exception {
+ params = new LinkedList();
+ params.add(new CompoundVariable("<value field=\"(pinposition\\d+)\">(\\d+)</value>"));
+ params.add(new CompoundVariable("$2$, "));
+ params.add(new CompoundVariable(".333"));
+ variable.setParameters(params);
+ String match = variable.execute(result, null);
+ assertEquals("1, ", match);
+ }
+
+ public void testDefaultValue() throws Exception {
+ params = new LinkedList();
+ params.add(new CompoundVariable("<value,, field=\"(pinposition\\d+)\">(\\d+)</value>"));
+ params.add(new CompoundVariable("$2$, "));
+ params.add(new CompoundVariable(".333"));
+ params.add(new CompoundVariable(""));
+ params.add(new CompoundVariable("No Value Found"));
+ variable.setParameters(params);
+ String match = variable.execute(result, null);
+ assertEquals("No Value Found", match);
+ }
+}
Added: jakarta/jmeter/branches/rel-2-1/test/src/org/apache/jmeter/testbeans/gui/TestComboStringEditor.java
URL: http://svn.apache.org/viewcvs/jakarta/jmeter/branches/rel-2-1/test/src/org/apache/jmeter/testbeans/gui/TestComboStringEditor.java?rev=369896&view=auto
==============================================================================
--- jakarta/jmeter/branches/rel-2-1/test/src/org/apache/jmeter/testbeans/gui/TestComboStringEditor.java (added)
+++ jakarta/jmeter/branches/rel-2-1/test/src/org/apache/jmeter/testbeans/gui/TestComboStringEditor.java Tue Jan 17 11:43:50 2006
@@ -0,0 +1,54 @@
+/*
+ * Copyright 2003-2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jmeter.testbeans.gui;
+
+public class TestComboStringEditor extends junit.framework.TestCase {
+ public TestComboStringEditor(String name) {
+ super(name);
+ }
+
+ private void testSetGet(ComboStringEditor e, Object value) throws Exception {
+ e.setValue(value);
+ assertEquals(value, e.getValue());
+ }
+
+ private void testSetGetAsText(ComboStringEditor e, String text) throws Exception {
+ e.setAsText(text);
+ assertEquals(text, e.getAsText());
+ }
+
+ public void testSetGet() throws Exception {
+ ComboStringEditor e = new ComboStringEditor();
+
+ testSetGet(e, "any string");
+ testSetGet(e, "");
+ testSetGet(e, null);
+ testSetGet(e, "${var}");
+ }
+
+ public void testSetGetAsText() throws Exception {
+ ComboStringEditor e = new ComboStringEditor();
+
+ testSetGetAsText(e, "any string");
+ testSetGetAsText(e, "");
+ testSetGetAsText(e, null);
+ testSetGetAsText(e, "${var}");
+
+ // Check "Undefined" does not become a "reserved word":
+ e.setAsText(ComboStringEditor.UNDEFINED.toString());
+ assertNotNull(e.getAsText());
+ }
+}
\ No newline at end of file
Added: jakarta/jmeter/branches/rel-2-1/test/src/org/apache/jmeter/testbeans/gui/TestFieldStringEditor.java
URL: http://svn.apache.org/viewcvs/jakarta/jmeter/branches/rel-2-1/test/src/org/apache/jmeter/testbeans/gui/TestFieldStringEditor.java?rev=369896&view=auto
==============================================================================
--- jakarta/jmeter/branches/rel-2-1/test/src/org/apache/jmeter/testbeans/gui/TestFieldStringEditor.java (added)
+++ jakarta/jmeter/branches/rel-2-1/test/src/org/apache/jmeter/testbeans/gui/TestFieldStringEditor.java Tue Jan 17 11:43:50 2006
@@ -0,0 +1,49 @@
+/*
+ * Copyright 2003-2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jmeter.testbeans.gui;
+
+
+public class TestFieldStringEditor extends junit.framework.TestCase {
+ public TestFieldStringEditor(String name) {
+ super(name);
+ }
+
+ private void testSetGet(ComboStringEditor e, Object value) throws Exception {
+ e.setValue(value);
+ assertEquals(value, e.getValue());
+ }
+
+ private void testSetGetAsText(ComboStringEditor e, String text) throws Exception {
+ e.setAsText(text);
+ assertEquals(text, e.getAsText());
+ }
+
+ public void testSetGet() throws Exception {
+ ComboStringEditor e = new ComboStringEditor();
+
+ testSetGet(e, "any string");
+ testSetGet(e, "");
+ testSetGet(e, "${var}");
+ }
+
+ public void testSetGetAsText() throws Exception {
+ ComboStringEditor e = new ComboStringEditor();
+
+ testSetGetAsText(e, "any string");
+ testSetGetAsText(e, "");
+ testSetGetAsText(e, "${var}");
+ }
+}
\ No newline at end of file
Modified: jakarta/jmeter/branches/rel-2-1/test/src/org/apache/jmeter/testelement/property/PackageTest.java
URL: http://svn.apache.org/viewcvs/jakarta/jmeter/branches/rel-2-1/test/src/org/apache/jmeter/testelement/property/PackageTest.java?rev=369896&r1=369895&r2=369896&view=diff
==============================================================================
--- jakarta/jmeter/branches/rel-2-1/test/src/org/apache/jmeter/testelement/property/PackageTest.java (original)
+++ jakarta/jmeter/branches/rel-2-1/test/src/org/apache/jmeter/testelement/property/PackageTest.java Tue Jan 17 11:43:50 2006
@@ -309,4 +309,11 @@
}
}
+ public void testAddingProperties() throws Exception {
+ CollectionProperty coll = new CollectionProperty();
+ coll.addItem("joe");
+ coll.addProperty(new FunctionProperty());
+ assertEquals("joe", coll.get(0).getStringValue());
+ assertEquals("org.apache.jmeter.testelement.property.FunctionProperty", coll.get(1).getClass().getName());
+ }
}
Added: jakarta/jmeter/branches/rel-2-1/test/src/org/apache/jmeter/threads/TestTestCompiler.java
URL: http://svn.apache.org/viewcvs/jakarta/jmeter/branches/rel-2-1/test/src/org/apache/jmeter/threads/TestTestCompiler.java?rev=369896&view=auto
==============================================================================
--- jakarta/jmeter/branches/rel-2-1/test/src/org/apache/jmeter/threads/TestTestCompiler.java (added)
+++ jakarta/jmeter/branches/rel-2-1/test/src/org/apache/jmeter/threads/TestTestCompiler.java Tue Jan 17 11:43:50 2006
@@ -0,0 +1,58 @@
+/*
+ * Copyright 2001-2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.jmeter.threads;
+
+import org.apache.jmeter.config.ConfigTestElement;
+import org.apache.jmeter.control.GenericController;
+import org.apache.jmeter.samplers.AbstractSampler;
+import org.apache.jmeter.samplers.SampleResult;
+import org.apache.jorphan.collections.ListedHashTree;
+
+public class TestTestCompiler extends junit.framework.TestCase {
+ public TestTestCompiler(String name) {
+ super(name);
+ }
+
+ public void testConfigGathering() throws Exception {
+ ListedHashTree testing = new ListedHashTree();
+ GenericController controller = new GenericController();
+ ConfigTestElement config1 = new ConfigTestElement();
+ config1.setName("config1");
+ config1.setProperty("test.property", "A test value");
+ TestSampler sampler = new TestSampler();
+ sampler.setName("sampler");
+ testing.add(controller, config1);
+ testing.add(controller, sampler);
+ TestCompiler.initialize();
+
+ TestCompiler compiler = new TestCompiler(testing, new JMeterVariables());
+ testing.traverse(compiler);
+ sampler = (TestSampler) compiler.configureSampler(sampler).getSampler();
+ assertEquals("A test value", sampler.getPropertyAsString("test.property"));
+ }
+
+ class TestSampler extends AbstractSampler {
+ public SampleResult sample(org.apache.jmeter.samplers.Entry e) {
+ return null;
+ }
+
+ public Object clone() {
+ return new TestSampler();
+ }
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-dev-help@jakarta.apache.org