Jonathan,

1. The compiler and matcher definitions were private.

2. I think you forgot to include:

    Public final static String TEST_PATTERNS = "Assertion.test_patterns";

I'll post the patch to bugzilla shortly.

Cheers,

Scott
-- 
Scott Eade
Backstage Technologies Pty. Ltd.
http://www.backstagetech.com.au
.Mac Chat/AIM: seade at mac dot com


On 20/12/2002 4:14 AM, "Jonathan Carlson" <[EMAIL PROTECTED]> wrote:

> Here are all the changes again, but with thread protection added for
> Perl5Compiler and pre-compilation of all regex patterns.  I included the full
> methods since it seemed easier to do and because I added javadoc where there
> was none.  Any news on getting the nightly builds going again?
> 
> 1) The compiler and matcher field definitions replace the existing ones.  (I
> don't remember what the original access level was, but I think they were
> protected.
> 2) The default constructor is a replacement.
> 3) The #getTestPatterns() method is new.
> 4) The #evaluateResponse method is a replacement.
> 
> 
>   protected transient static ThreadLocal compiler =
>       new ThreadLocal()
>       {
>           protected Object initialValue()
>           {
>               return new Perl5Compiler();
>           }
>       };
> 
>   protected transient static ThreadLocal matcher =
>       new ThreadLocal()
>       {
>           protected Object initialValue()
>           {
>               return new Perl5Matcher();
>           }
>       };
> 
> 
>   /************************************************************
>    *  Constructs a ResponseAssertion instance.
>    ***********************************************************/
>   public ResponseAssertion()
>   {
>       setProperty(TEST_STRINGS,new ArrayList());
> 
>       // This ThreadLocal inner class assumes that all test strings will be
>       // set before it is accessed the first time.  It should be a safe
>       // assumption since it is only accessed from the #evaluateResponse
>       // method.  If a test string cannot be compiled, this will add the
>       // MalformedPatternException instead of the compiled pattern.
>       ThreadLocal testPatterns =
>           new ThreadLocal()
>           {
>               protected Object initialValue()
>               {
>                   List compiledPatternList = new ArrayList();
>                   Iterator iterator = getTestStrings().iterator();
>                   Perl5Compiler localCompiler = (Perl5Compiler)
> compiler.get();
>                   while (iterator.hasNext())
>                   {
>                       String stringPattern = (String)iterator.next();
>                       try
>                       {
>                  
> compiledPatternList.add(localCompiler.compile(stringPattern));
>                       }
>                       catch (MalformedPatternException e)
>                       {
>                           compiledPatternList.add(e);
>                       }
>                   }
>                   return compiledPatternList;
>               }
>           };
>       setProperty(TEST_PATTERNS, testPatterns);
>   }
> 
>   /**
>    * Returns a list of compiled regex patterns.  If a test string is not
>    * compilable into a pattern, then a MalformedPatternException will be in
>    * the list in place of the compiled pattern.
>    * @return a list of compiled regex patterns and MalformedPatternExceptions
>    */
>   private List getTestPatterns()
>   {
>       ThreadLocal testPatterns = (ThreadLocal) getProperty(TEST_PATTERNS);
>       List patternList = (List) testPatterns.get();
>       return patternList;
>   }
> 
>   /**
>    * Make sure the response satisfied the specified assertion requirements.
>    * @param response an instance of SampleResult
>    * @return an instance of AssertionResult
>    */
>   private AssertionResult evaluateResponse(SampleResult response)
>   {
>       boolean pass = true;
>       boolean not = (NOT & getTestType()) > 0;
>       AssertionResult result = new AssertionResult();
>       try
>       {
>           String responseString = new String(response.getResponseData());
>           // Get the matcher for this thread
>           Perl5Matcher localMatcher = (Perl5Matcher) this.matcher.get();
>           Iterator iter = getTestPatterns().iterator();
>           while (iter.hasNext())
>           {
>               Object element = iter.next();
>               // I know this is strange looking but ThreadLocal#initialValue()
>               // won't let you throw an exception
>               if (element instanceof MalformedPatternException)
>               {
>                   throw (MalformedPatternException) element;
>               }
>               Pattern pattern = (Pattern) element;
>               boolean found;
>               if ((CONTAINS & getTestType()) > 0)
>               {
>                   found = localMatcher.contains(responseString, pattern);
>               }
>               else
>               {
>                   found = localMatcher.matches(responseString, pattern);
>               }
>               pass = not ? !found : found;
> 
>               if (!pass)
>               {
>                   result.setFailure(true);
>                   result.setFailureMessage(
>                           "Test Failed, expected " + notMessage + failMessage
> + pattern);
>                   break;
>               }
>           }
>           if(pass)
>           {
>               result.setFailure(false);
>           }
>           result.setError(false);
>       }
>       catch(MalformedPatternException e)
>       {
>           result.setError(true);
>           result.setFailure(false);
>           result.setFailureMessage("Bad test configuration"+e);
>       }
>       return result;
>   }


Scott
-- 
Scott Eade
Backstage Technologies Pty. Ltd.
http://www.backstagetech.com.au
[EMAIL PROTECTED]
Mobile: 0403 278 908
.Mac Chat/AIM: seade at mac dot com


--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to