Save This Page
Home » jakarta-jmeter-2.3.4_src » org.apache.jmeter.engine.util » [javadoc | source]
    1   // $Header: /home/cvs/jakarta-jmeter/src/core/org/apache/jmeter/engine/util/PackageTest.java,v 1.7 2005/07/12 20:50:51 mstover1 Exp $
    2   /*
    3    * Copyright 2003-2004 The Apache Software Foundation.
    4    *
    5    * Licensed under the Apache License, Version 2.0 (the "License");
    6    * you may not use this file except in compliance with the License.
    7    * You may obtain a copy of the License at
    8    *
    9    *   http://www.apache.org/licenses/LICENSE-2.0
   10    *
   11    * Unless required by applicable law or agreed to in writing, software
   12    * distributed under the License is distributed on an "AS IS" BASIS,
   13    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   14    * See the License for the specific language governing permissions and
   15    * limitations under the License.
   16    * 
   17    */
   18   
   19   /*
   20    * Created on Jul 25, 2003
   21    */
   22   package org.apache.jmeter.engine.util;
   23   
   24   import java.util.HashMap;
   25   import java.util.Map;
   26   
   27   import junit.framework.TestCase;
   28   
   29   import org.apache.jmeter.samplers.SampleResult;
   30   import org.apache.jmeter.testelement.property.JMeterProperty;
   31   import org.apache.jmeter.testelement.property.StringProperty;
   32   import org.apache.jmeter.threads.JMeterContext;
   33   import org.apache.jmeter.threads.JMeterContextService;
   34   import org.apache.jmeter.threads.JMeterVariables;
   35   
   36   public class PackageTest extends TestCase {
   37   	Map variables;
   38   
   39   	SampleResult result;
   40   
   41   	ReplaceStringWithFunctions transformer;
   42   
   43   	/**
   44   	 * @param arg0
   45   	 */
   46   	public PackageTest(String arg0) {
   47   		super(arg0);
   48   		// TODO Auto-generated constructor stub
   49   	}
   50   
   51   	private JMeterContext jmctx = null;
   52   
   53   	public void setUp() {
   54   		jmctx = JMeterContextService.getContext();
   55   		variables = new HashMap();
   56   		variables.put("my_regex", ".*");
   57   		variables.put("server", "jakarta.apache.org");
   58   		result = new SampleResult();
   59   		result.setResponseData("<html>hello world</html> costs: $3.47,$5.67".getBytes());
   60   		transformer = new ReplaceStringWithFunctions(new CompoundVariable(), variables);
   61   		jmctx.setVariables(new JMeterVariables());
   62   		jmctx.setSamplingStarted(true);
   63   		jmctx.setPreviousResult(result);
   64   		jmctx.getVariables().put("server", "jakarta.apache.org");
   65   		jmctx.getVariables().put("my_regex", ".*");
   66   	}
   67   
   68   	public void testFunctionParse1() throws Exception {
   69   		StringProperty prop = new StringProperty("date", "${__javaScript((new Date().getDate() / 100).toString()."
   70   				+ "substr(${__javaScript(1+1,d\\,ay)}\\,2),heute)}");
   71   		JMeterProperty newProp = transformer.transformValue(prop);
   72   		newProp.setRunningVersion(true);
   73   		assertEquals("org.apache.jmeter.testelement.property.FunctionProperty", newProp.getClass().getName());
   74   		newProp.recoverRunningVersion(null);
   75   		assertTrue(Integer.parseInt(newProp.getStringValue()) > -1);
   76   		assertEquals("2", jmctx.getVariables().getObject("d,ay"));
   77   	}
   78   
   79   	public void testParseExample1() throws Exception {
   80   		StringProperty prop = new StringProperty("html", "${__regexFunction(<html>(.*)</html>,$1$)}");
   81   		JMeterProperty newProp = transformer.transformValue(prop);
   82   		newProp.setRunningVersion(true);
   83   		assertEquals("org.apache.jmeter.testelement.property.FunctionProperty", newProp.getClass().getName());
   84   		assertEquals("hello world", newProp.getStringValue());
   85   	}
   86   
   87   	public void testParseExample2() throws Exception {
   88   		StringProperty prop = new StringProperty("html", "It should say:\\${${__regexFunction(<html>(.*)</html>,$1$)}}");
   89   		JMeterProperty newProp = transformer.transformValue(prop);
   90   		newProp.setRunningVersion(true);
   91   		assertEquals("org.apache.jmeter.testelement.property.FunctionProperty", newProp.getClass().getName());
   92   		assertEquals("It should say:${hello world}", newProp.getStringValue());
   93   	}
   94   
   95   	public void testParseExample3() throws Exception {
   96   		StringProperty prop = new StringProperty("html", "${__regexFunction(<html>(.*)</html>,$1$)}"
   97   				+ "${__regexFunction(<html>(.*o)(.*o)(.*)</html>," + "$1$$3$)}");
   98   		JMeterProperty newProp = transformer.transformValue(prop);
   99   		newProp.setRunningVersion(true);
  100   		assertEquals("org.apache.jmeter.testelement.property.FunctionProperty", newProp.getClass().getName());
  101   		assertEquals("hello worldhellorld", newProp.getStringValue());
  102   	}
  103   
  104   	public void testParseExample4() throws Exception {
  105   		StringProperty prop = new StringProperty("html", "${non-existing function}");
  106   		JMeterProperty newProp = transformer.transformValue(prop);
  107   		newProp.setRunningVersion(true);
  108   		assertEquals("org.apache.jmeter.testelement.property.FunctionProperty", newProp.getClass().getName());
  109   		assertEquals("${non-existing function}", newProp.getStringValue());
  110   	}
  111   
  112   	public void testParseExample6() throws Exception {
  113   		StringProperty prop = new StringProperty("html", "${server}");
  114   		JMeterProperty newProp = transformer.transformValue(prop);
  115   		newProp.setRunningVersion(true);
  116   		assertEquals("org.apache.jmeter.testelement.property.FunctionProperty", newProp.getClass().getName());
  117   		assertEquals("jakarta.apache.org", newProp.getStringValue());
  118   	}
  119   
  120   	public void testParseExample5() throws Exception {
  121   		StringProperty prop = new StringProperty("html", "");
  122   		JMeterProperty newProp = transformer.transformValue(prop);
  123   		newProp.setRunningVersion(true);
  124   		assertEquals("org.apache.jmeter.testelement.property.StringProperty", newProp.getClass().getName());
  125   		assertEquals("", newProp.getStringValue());
  126   	}
  127   
  128   	public void testParseExample7() throws Exception {
  129   		StringProperty prop = new StringProperty("html", "${__regexFunction(\\<([a-z]*)\\>,$1$)}");
  130   		JMeterProperty newProp = transformer.transformValue(prop);
  131   		newProp.setRunningVersion(true);
  132   		assertEquals("org.apache.jmeter.testelement.property.FunctionProperty", newProp.getClass().getName());
  133   		assertEquals("html", newProp.getStringValue());
  134   	}
  135   
  136   	public void testParseExample8() throws Exception {
  137   		StringProperty prop = new StringProperty("html", "${__regexFunction((\\\\$\\d+\\.\\d+),$1$)}");
  138   		JMeterProperty newProp = transformer.transformValue(prop);
  139   		newProp.setRunningVersion(true);
  140   		assertEquals("org.apache.jmeter.testelement.property.FunctionProperty", newProp.getClass().getName());
  141   		assertEquals("$3.47", newProp.getStringValue());
  142   	}
  143   
  144   	public void testParseExample9() throws Exception {
  145   		StringProperty prop = new StringProperty("html", "${__regexFunction(([$]\\d+\\.\\d+),$1$)}");
  146   		JMeterProperty newProp = transformer.transformValue(prop);
  147   		newProp.setRunningVersion(true);
  148   		assertEquals("org.apache.jmeter.testelement.property.FunctionProperty", newProp.getClass().getName());
  149   		assertEquals("$3.47", newProp.getStringValue());
  150   	}
  151   
  152   	public void testParseExample10() throws Exception {
  153   		StringProperty prop = new StringProperty("html", "${__regexFunction(\\ "
  154   				+ "(\\\\\\$\\d+\\.\\d+\\,\\\\$\\d+\\.\\d+),$1$)}");
  155   		JMeterProperty newProp = transformer.transformValue(prop);
  156   		newProp.setRunningVersion(true);
  157   		assertEquals("org.apache.jmeter.testelement.property.FunctionProperty", newProp.getClass().getName());
  158   		assertEquals("$3.47,$5.67", newProp.getStringValue());
  159   	}
  160   
  161   	public void testNestedExample1() throws Exception {
  162   		StringProperty prop = new StringProperty("html", "${__regexFunction(<html>(${my_regex})</html>,"
  163   				+ "$1$)}${__regexFunction(<html>(.*o)(.*o)(.*)" + "</html>,$1$$3$)}");
  164   		JMeterProperty newProp = transformer.transformValue(prop);
  165   		newProp.setRunningVersion(true);
  166   		assertEquals("org.apache.jmeter.testelement.property.FunctionProperty", newProp.getClass().getName());
  167   		assertEquals("hello worldhellorld", newProp.getStringValue());
  168   	}
  169   
  170   	public void testNestedExample2() throws Exception {
  171   		StringProperty prop = new StringProperty("html", "${__regexFunction(<html>(${my_regex})</html>,$1$)}");
  172   		JMeterProperty newProp = transformer.transformValue(prop);
  173   		newProp.setRunningVersion(true);
  174   		assertEquals("org.apache.jmeter.testelement.property.FunctionProperty", newProp.getClass().getName());
  175   		assertEquals("hello world", newProp.getStringValue());
  176   	}
  177   
  178   }

Save This Page
Home » jakarta-jmeter-2.3.4_src » org.apache.jmeter.engine.util » [javadoc | source]