KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > openinventions > webappfilter > processor > test > JUnitAssert


1 package com.openinventions.webappfilter.processor.test;
2
3 import com.openinventions.metaframework.*;
4 import com.openinventions.webappfilter.*;
5 import com.openinventions.webappfilter.util.*;
6 import org.apache.commons.logging.*;
7 import java.util.regex.*;
8 import junit.framework.*;
9
10 public class JUnitAssert implements Processor {
11     private static final Log log = LogFactory.getLog(JUnitAssert.class);
12     
13     public void process(State state, Element context) throws Exception JavaDoc {
14 // Assert junitAssert = (Assert) state.get("junit.framework.TestCase");
15
Assert junitAssert = WebAppFilterTest.getTest();
16         StateXPath stateXPath = (StateXPath) state.get("com.openinventions.webappfilter.util.StateXPath");
17         String JavaDoc xpath = context.getValue("xpath");
18         String JavaDoc value = stateXPath.getValue(state, xpath);
19         String JavaDoc regex = context.getValue("regex");
20         Pattern pattern = Pattern.compile(regex);
21         Matcher matcher = pattern.matcher(value);
22         
23         if (log.isDebugEnabled()) {
24             log.debug("regex = " + regex);
25             log.debug("value = " + value);
26             log.debug("ASSERT = " + matcher.matches());
27         }
28
29         junitAssert.assertTrue("value " + value + "\n\n****************does not match**************\n\n " + regex, matcher.matches());
30         
31     }
32 }
33 /* ====================================================================
34  * The webappfilter License, Version 1.1
35  *
36  * Copyright (c) 2002 Ivar Chan. All rights
37  * reserved.
38  *
39  * Redistribution and use in source and binary forms, with or without
40  * modification, are permitted provided that the following conditions
41  * are met:
42  *
43  * 1. Redistributions of source code must retain the above copyright
44  * notice, this list of conditions and the following disclaimer.
45  *
46  * 2. Redistributions in binary form must reproduce the above copyright
47  * notice, this list of conditions and the following disclaimer in
48  * the documentation and/or other materials provided with the
49  * distribution.
50  *
51  * 3. The end-user documentation included with the redistribution,
52  * if any, must include the following acknowledgment:
53  * "This product includes software developed by
54  * Ivar Chan (http://www.openinventions.com/webappfilter/)."
55  * Alternately, this acknowledgment may appear in the software itself,
56  * if and wherever such third-party acknowledgments normally appear.
57  *
58  * 4. The name "webappfilter" must not be used to endorse or promote products
59  * derived from this software without prior written permission. For
60  * written permission, please contact ivarchan@acm.org.
61  *
62  * 5. Products derived from this software may not be called "webappfilter",
63  * nor may "webappfilter" appear in their name, without
64  * prior written permission of Ivar Chan.
65  *
66  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
67  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
68  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
69  * DISCLAIMED. IN NO EVENT SHALL THE IVAR CHAN BE LIABLE FOR ANY
70  * DIRECT, INDIRECT, INCIDENTAL,
71  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
72  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
73  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
74  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
75  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
76  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
77  * SUCH DAMAGE.
78  * ====================================================================
79  *
80  * This software consists of voluntary contributions made by many
81  * individuals. For more information on webappfilter, please see
82  * <http://www.openinventions/webappfilter/>.
83  */

84
85
86
87
Popular Tags