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 ms...@apache.org on 2003/07/27 22:59:58 UTC

cvs commit: jakarta-jmeter/src/core/org/apache/jmeter/testelement/property FunctionProperty.java

mstover1    2003/07/27 13:59:57

  Modified:    src/core/org/apache/jmeter/engine/util CompoundVariable.java
               src/core/org/apache/jmeter/testelement/property
                        FunctionProperty.java
  Added:       src/core/org/apache/jmeter/engine/util FunctionParser.java
                        PackageTest.java
  Log:
  Fixing function parsing and escaped commas
  
  Revision  Changes    Path
  1.17      +16 -437   jakarta-jmeter/src/core/org/apache/jmeter/engine/util/CompoundVariable.java
  
  Index: CompoundVariable.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jmeter/src/core/org/apache/jmeter/engine/util/CompoundVariable.java,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- CompoundVariable.java	27 Jun 2003 21:48:13 -0000	1.16
  +++ CompoundVariable.java	27 Jul 2003 20:59:57 -0000	1.17
  @@ -61,7 +61,6 @@
   import java.util.LinkedList;
   import java.util.List;
   import java.util.Map;
  -import java.util.StringTokenizer;
   
   import org.apache.jmeter.functions.Function;
   import org.apache.jmeter.functions.InvalidVariableException;
  @@ -74,11 +73,7 @@
   import org.apache.jorphan.logging.LoggingManager;
   import org.apache.jorphan.reflect.ClassFinder;
   import org.apache.log.Logger;
  -import org.apache.oro.text.regex.MalformedPatternException;
   import org.apache.oro.text.regex.Perl5Compiler;
  -import org.apache.oro.text.regex.Perl5Matcher;
  -import org.apache.oro.text.regex.Perl5Substitution;
  -import org.apache.oro.text.regex.Util;
   
   
   /**
  @@ -96,13 +91,15 @@
       
       //private JMeterVariables threadVars;
       //private Map varMap = new HashMap();
  +    
  +    static FunctionParser functionParser = new FunctionParser();
   
       static Map functions = new HashMap();
       private boolean hasFunction, isDynamic;
       private String staticSubstitution;
       //private Perl5Util util = new Perl5Util();
       private Perl5Compiler compiler = new Perl5Compiler();
  -    private static final String unescapePattern = "[\\\\]([${}\\,])";
  +    private static final String unescapePattern = "[\\\\]([${}\\\\,])";
       private String permanentResults = "";
       
       LinkedList compiledComponents = new LinkedList();
  @@ -251,7 +248,11 @@
           if (parameters == null || parameters.length() == 0)
               return;
   
  -        compiledComponents = buildComponents(parameters);
  +        compiledComponents = functionParser.compileString(parameters);
  +        if(compiledComponents.size() > 1 || !(compiledComponents.get(0) instanceof String))
  +        {
  +            hasFunction = true;
  +        }
       }
   
       /* (non-Javadoc)
  @@ -261,273 +262,25 @@
           throws InvalidVariableException
       {
       }
  -
  -    private LinkedList buildComponents(String parameters)
  -        throws InvalidVariableException
  -    {
  -        LinkedList components = new LinkedList();
  -        String current, pre, functionStr;
  -        int funcStartIndex, funcEndIndex;
  -
  -        current = parameters;
  -        funcStartIndex = current.indexOf("${");
  -
  -        while (funcStartIndex > -1)
  -        {
  -            pre = current.substring(0, funcStartIndex);
  -            if (!pre.equals(""))
  -            {
  -                components.addLast(unescape(pre));
  -            }
  -
  -            funcEndIndex = findMatching("${", "}", current);
  -            functionStr = current.substring(funcStartIndex + 2, funcEndIndex);
  -            Function newFunction = null;
  -            try
  -            {
  -                newFunction = buildFunction(functionStr);
  -            }
  -            catch (InvalidVariableException e)
  -            { // Don't abandon processing if function fails
  -            }
  -
  -            if (newFunction == null)
  -            {
  -                components.addLast(new SimpleVariable(functionStr));
  -            }
  -            else
  -            {
  -                components.addLast(newFunction);
  -            }
  -
  -            hasFunction = true;
  -            current = current.substring(funcEndIndex + 1);
  -            funcStartIndex = current.indexOf("${");
  -        }
  -
  -        if (!current.equals(""))
  -        {
  -            components.addLast(unescape(current));
  -        }
  -
  -        return components;
  -    }
  -
  -    private Function buildFunction(String functionStr)
  -        throws InvalidVariableException
  +    
  +    static Object getNamedFunction(String functionName) throws InvalidVariableException
       {
  -        Function returnFunction = null;
  -        //LinkedList parameterList;
  -        String functionName, params;
  -        int paramsStart = functionStr.indexOf("(");
  -
  -        if (paramsStart > -1)
  -            functionName = functionStr.substring(0, functionStr.indexOf("("));
  -        else
  -            functionName = functionStr;
  -
  -        if (functions.containsKey(functionName))
  +        if(functions.containsKey(functionName))
           {
  -            Object replacement = functions.get(functionName);
  -            params = extractParams(functionStr);
  -
               try
               {
  -                returnFunction = (Function) ((Class) replacement).newInstance();
  -                Collection paramList = parseParams(params);
  -                returnFunction.setParameters(paramList);
  +                return (Function) ((Class) functions.get(functionName)).newInstance();
               }
               catch (Exception e)
               {
                   log.error("", e);
  -                throw new InvalidVariableException();
  +                 throw new InvalidVariableException();
               }
           }
  -
  -        return returnFunction;
  -
  -    }
  -
  -    private String extractParams(String functionStr)
  -    {
  -        String params;
  -        int startIndex, endIndex, embeddedStartIndex;
  -
  -        params = "";
  -        startIndex = functionStr.indexOf("(");
  -        endIndex = findMatching("(", ")", functionStr);
  -        embeddedStartIndex = functionStr.indexOf("${");
  -
  -        if (startIndex != -1 && endIndex != -1)
  -        {
  -            if (embeddedStartIndex == -1
  -                || (embeddedStartIndex != -1 &&
  -                    startIndex < embeddedStartIndex))
  -            {
  -                params = functionStr.substring(startIndex + 1, endIndex);
  -            }
  -        }
  -
  -        return params;
  -    }
  -
  -    private LinkedList parseParams(String params)
  -        throws InvalidVariableException
  -    {
  -        LinkedList uncompiled = new LinkedList();
  -        LinkedList compiled = new LinkedList();
  -        StringTokenizer st = new StringTokenizer(params, ",", true);
  -        StringBuffer buffer = new StringBuffer();
  -        String token, previous;
  -
  -        previous = token = "";
  -
  -        while (st.hasMoreElements())
  -        {
  -            buffer.append(st.nextElement());
  -            token = buffer.toString();
  -            boolean foundOpen = false;
  -            int searchIndex = -1;
  -
  -            while (!foundOpen)
  -            {
  -                searchIndex = token.indexOf("(", searchIndex + 1);
  -                if (searchIndex == -1)
  -                    break;
  -                else if (
  -                    searchIndex == 0 || token.charAt(searchIndex - 1) != '\\')
  -                    foundOpen = true;
  -            }
  -
  -            if (foundOpen)
  -            {
  -                if (findMatching("(", ")", token) != -1)
  -                {
  -                    uncompiled.add(token);
  -                    previous = token;
  -                    buffer = new StringBuffer();
  -                }
  -            }
  -            else
  -            {
  -                if (token.equals(",")
  -                    && (previous.equals(",") || previous.length() == 0))
  -                {
  -                    uncompiled.add("");
  -                }
  -                else if (!token.equals(","))
  -                {
  -                    uncompiled.add(token);
  -                }
  -
  -                previous = token;
  -                buffer = new StringBuffer();
  -            }
  -
  -        }
  -
  -        if (token.equals(","))
  -        {
  -            uncompiled.add("");
  -        }
  -
  -        for (int i = 0; i < uncompiled.size(); i++)
  -        {
  -            CompoundVariable c = new CompoundVariable();
  -            c.setParameters((String) uncompiled.get(i));
  -            compiled.addLast(c);
  -        }
  -
  -        return compiled;
  -    }
  -
  -    private static int findMatching(
  -        String openStr,
  -        String closeStr,
  -        String searchString)
  -    {
  -        //int count;
  -        int openIndex, closeIndex, previousMatch;
  -        boolean found = false;
  -
  -        openIndex = closeIndex = previousMatch = -1;
  -
  -        while (!found)
  -        {
  -            openIndex = searchString.indexOf(openStr, previousMatch + 1);
  -            if (openIndex == -1)
  -                break;
  -            else if (
  -                openIndex == 0 || searchString.charAt(openIndex - 1) != '\\')
  -                found = true;
  -            else
  -            {
  -                previousMatch = openIndex;
  -                openIndex = -1;
  -            }
  -        }
  -
  -        if (openIndex < searchString.indexOf(closeStr))
  -        {
  -            if (openIndex != -1)
  -            {
  -                String subSearch;
  -
  -                subSearch =
  -                    searchString.substring(
  -                        openIndex + 1,
  -                        searchString.length());
  -                int subMatch = findMatching(openStr, closeStr, subSearch);
  -
  -                while (subMatch != -1)
  -                {
  -                    if (previousMatch == -1)
  -                        previousMatch = openIndex + subMatch + 1;
  -                    else
  -                        previousMatch += subMatch + 1;
  -
  -                    subSearch =
  -                        searchString.substring(
  -                            previousMatch + 1,
  -                            searchString.length());
  -                    subMatch = findMatching(openStr, closeStr, subSearch);
  -                }
  -
  -                found = false;
  -                while (!found)
  -                {
  -                    closeIndex =
  -                        searchString.indexOf(closeStr, previousMatch + 1);
  -                    if (closeIndex == -1)
  -                        break;
  -                    else if (searchString.charAt(closeIndex - 1) != '\\')
  -                        found = true;
  -                    else
  -                        previousMatch = closeIndex;
  -                }
  -            }
  -        }
  -
  -        return closeIndex;
  -    }
  -
  -    private String unescape(String input)
  -    {
  -        String result = input;
  -        try
  -        {
  -            result =
  -                Util.substitute(
  -                    new Perl5Matcher(),
  -                    compiler.compile(unescapePattern),
  -                    new Perl5Substitution("$1"),
  -                    input,
  -                    Util.SUBSTITUTE_ALL);
  -        }
  -        catch (MalformedPatternException e)
  +        else
           {
  +            return new SimpleVariable(functionName);
           }
  -        return result;
       }
   
       public boolean hasFunction()
  @@ -547,179 +300,5 @@
       {
           return JMeterContextService.getContext().getVariables();
       }
  -
  -
  -/*    public static class Test extends TestCase
  -    {
  -        CompoundVariable function;
  -        SampleResult result;
  -
  -        public Test(String name)
  -        {
  -            super(name);
  -        }
  -
  -        public void setUp()
  -        {
  -            Map userDefinedVariables = new HashMap();
  -            userDefinedVariables.put("my_regex", ".*");
  -            userDefinedVariables.put("server", "jakarta.apache.org");
  -            function = new CompoundVariable();
  -            function.setUserDefinedVariables(userDefinedVariables);
  -            result = new SampleResult();
  -            result.setResponseData("<html>hello world</html>".getBytes());
  -        }
  -
  -        public void testParseExample1() throws Exception
  -        {
  -            function.setParameters(
  -                "${__regexFunction(<html>\\(.*\\)</html>,$1$)}");
  -            function.setJMeterVariables(new JMeterVariables());
  -            assertEquals(1, function.compiledComponents.size());
  -            assertEquals(
  -                "org.apache.jmeter.functions.RegexFunction",
  -                function.compiledComponents.getFirst().getClass().getName());
  -            assertTrue(function.hasFunction());
  -//            assertTrue(!function.hasStatics());
  -            assertEquals(
  -                "hello world",
  -                ((Function) function.compiledComponents.getFirst()).execute(
  -                    result,
  -                    null));
  -            assertEquals("hello world", function.execute(result, null));
  -        }
  -
  -        public void testParseExample2() throws Exception
  -        {
  -            function.setParameters(
  -                "It should say:${${__regexFunction("
  -                    + ArgumentEncoder.encode("<html>(.*)</html>")
  -                    + ",$1$)}}");
  -            function.setJMeterVariables(new JMeterVariables());
  -            assertEquals(3, function.compiledComponents.size());
  -            assertEquals(
  -                "It should say:${",
  -                function.compiledComponents.getFirst().toString());
  -            assertTrue(function.hasFunction());
  -//            assertTrue(!function.hasStatics());
  -            assertEquals(
  -                "hello world",
  -                ((Function) function.compiledComponents.get(1)).execute(
  -                    result,
  -                    null));
  -            assertEquals("}", function.compiledComponents.get(2).toString());
  -            assertEquals(
  -                "It should say:${hello world}",
  -                function.execute(result, null));
  -            assertEquals(
  -                "It should say:${<html>(.*)</html>,$1$}",
  -                function.execute(null, null));
  -        }
  -
  -        public void testParseExample3() throws Exception
  -        {
  -            function.setParameters(
  -                "${__regexFunction(<html>\\(.*\\)</html>,$1$)}" +
  -                "${__regexFunction(<html>\\(.*o\\)\\(.*o\\)\\(.*\\)</html>," +
  -                "$1$$3$)}");
  -            function.setJMeterVariables(new JMeterVariables());
  -            assertEquals(2, function.compiledComponents.size());
  -            assertTrue(function.hasFunction());
  -//            assertTrue(!function.hasStatics());
  -            assertEquals(
  -                "hello world",
  -                ((Function) function.compiledComponents.get(0)).execute(
  -                    result,
  -                    null));
  -            assertEquals(
  -                "hellorld",
  -                ((Function) function.compiledComponents.get(1)).execute(
  -                    result,
  -                    null));
  -            assertEquals("hello worldhellorld", function.execute(result, null));
  -//            assertEquals(
  -//                "<html>(.*)</html>,$1$<html>(.*o)(.*o)(.*)</html>,$1$$3$",
  -//                function.execute(null, null));
  -        }
  -
  -        public void testParseExample4() throws Exception
  -        {
  -            function.setParameters("${non-existing function}");
  -            function.setJMeterVariables(new JMeterVariables());
  -            assertEquals(1, function.compiledComponents.size());
  -            assertTrue(function.hasFunction());
  -//            assertTrue(!function.hasStatics());
  -            assertEquals(
  -                "${non-existing function}",
  -                function.execute(result, null));
  -            assertEquals(
  -                "${non-existing function}",
  -                function.execute(null, null));
  -        }
  -
  -        public void testParseExample6() throws Exception
  -        {
  -            function.setParameters("${server}");
  -            function.setJMeterVariables(new JMeterVariables());
  -            assertEquals(1, function.compiledComponents.size());
  -//            assertTrue(!function.hasFunction());
  -//            assertTrue(function.hasStatics());
  -            assertEquals("jakarta.apache.org", function.execute(null, null));
  -        }
  -
  -        public void testParseExample5() throws Exception
  -        {
  -            function.setParameters("");
  -            function.setJMeterVariables(new JMeterVariables());
  -            assertEquals(0, function.compiledComponents.size());
  -            assertTrue(!function.hasFunction());
  -//            assertTrue(!function.hasStatics());
  -        }
  -
  -        public void testNestedExample1() throws Exception
  -        {
  -            function.setParameters(
  -                "${__regexFunction(<html>\\(\\$\\{my_regex\\}\\)</html>," +
  -                "$1$)}${__regexFunction(<html>\\(.*o\\)\\(.*o\\)\\(.*\\)" +
  -                "</html>,$1$$3$)}");
  -            function.setJMeterVariables(new JMeterVariables());
  -            assertEquals(2, function.compiledComponents.size());
  -            assertTrue(function.hasFunction());
  -//            assertTrue(function.hasStatics());
  -            assertEquals(
  -                "hello world",
  -                ((Function) function.compiledComponents.get(0)).execute(
  -                    result,
  -                    null));
  -            assertEquals(
  -                "hellorld",
  -                ((Function) function.compiledComponents.get(1)).execute(
  -                    result,
  -                    null));
  -            assertEquals("hello worldhellorld", function.execute(result, null));
  -            assertEquals(
  -                "<html>(.*)</html>,$1$<html>(.*o)(.*o)(.*)</html>,$1$$3$",
  -                function.execute(null, null));
  -        }
  -
  -        public void testNestedExample2() throws Exception
  -        {
  -            function.setParameters(
  -                "${__regexFunction(<html>(\\$\\{my_regex\\})</html>,$1$)}");
  -            function.setJMeterVariables(new JMeterVariables());
  -            assertEquals(1, function.compiledComponents.size());
  -            assertEquals(
  -                "org.apache.jmeter.functions.RegexFunction",
  -                function.compiledComponents.getFirst().getClass().getName());
  -            assertTrue(function.hasFunction());
  -//            assertTrue(function.hasStatics());
  -            assertEquals(
  -                "hello world",
  -                ((Function) function.compiledComponents.getFirst()).execute(
  -                    result,
  -                    null));
  -            assertEquals("hello world", function.execute(result, null));
  -        }
  -    }*/
   
   }
  
  
  
  1.1                  jakarta-jmeter/src/core/org/apache/jmeter/engine/util/FunctionParser.java
  
  Index: FunctionParser.java
  ===================================================================
  /*
   * Created on Jul 25, 2003
   *
   * To change the template for this generated file go to
   * Window>Preferences>Java>Code Generation>Code and Comments
   */
  package org.apache.jmeter.engine.util;
  
  import java.io.IOException;
  import java.io.StringReader;
  import java.util.LinkedList;
  
  import org.apache.jmeter.functions.Function;
  import org.apache.jmeter.functions.InvalidVariableException;
  import org.apache.jorphan.logging.LoggingManager;
  import org.apache.log.Logger;
  
  /**
   * @author ano ano
   *
   * To change the template for this generated type comment go to
   * Window>Preferences>Java>Code Generation>Code and Comments
   */
  class FunctionParser
  {
      Logger log = LoggingManager.getLoggerForClass();
      
      /**
       * Compile a general string into a list of elements for a CompoundVariable.
       * @param value
       * @return
       * @throws InvalidVariableException
       */
      LinkedList compileString(String value) throws InvalidVariableException
      {
          log.debug("parsing string: " + value);
          StringReader reader = new StringReader(value);
          LinkedList result = new LinkedList();
          StringBuffer buffer = new StringBuffer();
          char previous = ' ';
          char[] current = new char[1];
         try
          {
               while(reader.read(current) == 1)
                  {
                      if(current[0] == '\\')
                      {
                          previous = current[0];
                          if(reader.read(current) == 0)
                          {
                              break;
                          }
                          if(current[0] != '$' && current[0] != ',')
                          {
                              buffer.append(previous);
                          }
                          previous = ' ';
                          buffer.append(current[0]);
                          continue;
                      }
                      else if(current[0] == '{' && previous == '$')
                      {
                          buffer.deleteCharAt(buffer.length()-1);
                          if(buffer.length() > 0)
                          {
                              result.add(buffer.toString());
                              buffer.setLength(0);
                          }
                          result.add(makeFunction(reader));
                          previous = ' ';
                      }
                      else
                      {
                          buffer.append(current[0]);
                          previous = current[0];
                      }
                  }
                  if(buffer.length() > 0)
                  {
                      result.add(buffer.toString());
                  }
          }
          catch (IOException e)
          {
              log.error("Error parsing function: " + value,e);
              result.clear();
              result.add(value);
          }
          if(result.size() == 0)
          {
              result.add("");
          }
          return result;
      }
      
      /**
       * Compile a string into a function or SimpleVariable.
       * @param reader
       * @return
       * @throws InvalidVariableException
       */
      Object makeFunction(StringReader reader) throws InvalidVariableException
      {
          char[] current = new char[1];
          char previous = ' ';;
          StringBuffer buffer = new StringBuffer();
          Object function;
          try
          {
              while(reader.read(current) == 1)
              {
                  if(current[0] == '\\')
                  {
                      if(reader.read(current) == 0)
                      {
                          break;
                      }
                      previous = ' ';
                      buffer.append(current[0]);
                      continue;
                  }
                  else if(current[0] == '(' && previous != ' ')
                  {
                      log.debug("making function from: " + buffer.toString());
                      function = CompoundVariable.getNamedFunction(buffer.toString());
                      buffer.setLength(0);
                      if(function instanceof Function)
                      {
                          ((Function)function).setParameters(parseParams(reader));
                          if(reader.read(current) == 0 || current[0] != '}')
                          {
                              throw new InvalidVariableException();
                          }
                          return function;
                      }
                      else
                      {
                          continue;
                      }
                  }
                  else if(current[0] == '}')
                  {
                      function = CompoundVariable.getNamedFunction(buffer.toString());
                      buffer.setLength(0);
                      return function;
                  }
                  else
                  {
                      buffer.append(current[0]);
                      previous = current[0];
                  }                        
              }
          }
          catch (IOException e)
          {
              log.error("Error parsing function: " + buffer.toString(),e);
              return null;
          }
          log.warn("Probably an invalid function string: " + buffer.toString());
          return buffer.toString();
      }
      
      /**
       * Compile a String into a list of parameters, each made into a CompoundVariable
       * @param reader
       * @return
       * @throws InvalidVariableException
       */
      LinkedList parseParams(StringReader reader) throws InvalidVariableException
      {
          LinkedList result = new LinkedList();
          StringBuffer buffer = new StringBuffer();
          char[] current = new char[1];
          char previous = ' ';
          int functionRecursion = 0;
          int parenRecursion = 0;
          try
          {
              while(reader.read(current) == 1)
              {
                  if(current[0] == '\\')
                  {
                      buffer.append(current[0]);
                      if(reader.read(current) == 0)
                      {
                          break;
                      }
                      previous = ' ';
                      buffer.append(current[0]);
                      continue;
                  }
                  else if(current[0] == ',' && functionRecursion == 0)
                  {
                      log.debug("Making new compoundvariable with a param of " + buffer.toString());
                      CompoundVariable param = new CompoundVariable();
                      param.setParameters(buffer.toString());
                      buffer.setLength(0);
                      result.add(param);
                  }
                  else if(current[0] == ')' && functionRecursion == 0 && parenRecursion == 0)
                  {
                      log.debug("Making new compoundvariable with a param of " + buffer.toString());
                      CompoundVariable param = new CompoundVariable();
                      param.setParameters(buffer.toString());
                      buffer.setLength(0);
                      result.add(param);
                      log.debug("parsed params = " + result);
                      return result;
                  }
                  else if(current[0] == '{' && previous == '$')
                  {
                      buffer.append(current[0]);
                      previous = current[0];
                      functionRecursion++;
                  }
                  else if(current[0] == '}' && functionRecursion > 0)
                  {
                      buffer.append(current[0]);
                      previous = current[0];
                      functionRecursion--;
                  }
                  else if(current[0] == ')' && functionRecursion == 0 && parenRecursion > 0)
                  {
                      buffer.append(current[0]);
                      previous = current[0];
                      parenRecursion--;
                  }
                  else if(current[0] == '(' && functionRecursion == 0)
                  {
                      buffer.append(current[0]);
                      previous = current[0];
                      parenRecursion++;
                  }
                  else
                  {
                      buffer.append(current[0]);
                      previous = current[0];
                  }
              }
          }
          catch (IOException e)
          {
              log.error("Error parsing function: " + buffer.toString(),e);
          }
          log.warn("Probably an invalid function string: " + buffer.toString());
          CompoundVariable var = new CompoundVariable();
          var.setParameters(buffer.toString());
          result.add(var);
          return result;
      }
  
  }
  
  
  
  1.1                  jakarta-jmeter/src/core/org/apache/jmeter/engine/util/PackageTest.java
  
  Index: PackageTest.java
  ===================================================================
  /*
   * Created on Jul 25, 2003
   *
   * To change the template for this generated file go to
   * Window>Preferences>Java>Code Generation>Code and Comments
   */
  package org.apache.jmeter.engine.util;
  
  import java.util.HashMap;
  import java.util.Map;
  
  import junit.framework.TestCase;
  
  import org.apache.jmeter.samplers.SampleResult;
  import org.apache.jmeter.testelement.property.JMeterProperty;
  import org.apache.jmeter.testelement.property.StringProperty;
  import org.apache.jmeter.threads.JMeterContextService;
  
  /**
   * @author ano ano
   *
   * To change the template for this generated type comment go to
   * Window>Preferences>Java>Code Generation>Code and Comments
   */
  public class PackageTest extends TestCase
  {
      Map variables;
      SampleResult result;
      ReplaceStringWithFunctions transformer;
      /**
      * @param arg0
      */
      public PackageTest(String arg0)
      {
          super(arg0);
          // TODO Auto-generated constructor stub
      }
  
      public void setUp()
      {
          variables = new HashMap();
          variables.put("my_regex", ".*");
          variables.put("server", "jakarta.apache.org");
          result = new SampleResult();
          result.setResponseData("<html>hello world</html>".getBytes());
          transformer = new ReplaceStringWithFunctions(new CompoundVariable(), variables);
          JMeterContextService.getContext().setSamplingStarted(true);
          JMeterContextService.getContext().setPreviousResult(result);
          JMeterContextService.getContext().getVariables().put("server", "jakarta.apache.org");
          JMeterContextService.getContext().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", JMeterContextService.getContext().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 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());
      }
  
  }
  
  
  
  1.11      +3 -1      jakarta-jmeter/src/core/org/apache/jmeter/testelement/property/FunctionProperty.java
  
  Index: FunctionProperty.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jmeter/src/core/org/apache/jmeter/testelement/property/FunctionProperty.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- FunctionProperty.java	16 Jul 2003 13:12:11 -0000	1.10
  +++ FunctionProperty.java	27 Jul 2003 20:59:57 -0000	1.11
  @@ -110,6 +110,8 @@
        */
       public String getStringValue()
       {
  +        log.debug("Calling getStringValue from FunctionProperty");
  +        log.debug("boogedy boogedy");
           if (!isRunningVersion()
               || !JMeterContextService.getContext().isSamplingStarted())
           {
  
  
  

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