Revision: 764
http://jwebunit.svn.sourceforge.net/jwebunit/?rev=764&view=rev
Author: jevonwright
Date: 2008-11-18 02:18:30 +0000 (Tue, 18 Nov 2008)
Log Message:
-----------
issue 1637716: adding assertMatch(regexp, text) and assertNotMatch(regexp,
text) methods
Modified Paths:
--------------
trunk/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/IElementTest.java
trunk/jwebunit-core/src/main/java/net/sourceforge/jwebunit/junit/WebTester.java
trunk/src/changes/changes.xml
Modified:
trunk/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/IElementTest.java
===================================================================
---
trunk/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/IElementTest.java
2008-11-18 01:43:31 UTC (rev 763)
+++
trunk/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/IElementTest.java
2008-11-18 02:18:30 UTC (rev 764)
@@ -143,6 +143,12 @@
assertEquals("initial", inputs.get(2).getAttribute("value"));
assertEquals("unchanged", inputs.get(3).getAttribute("value"));
+ // test regexps
+ assertMatch("init.+", inputs.get(2).getAttribute("value"));
+ assertNotMatch("^xinitial", inputs.get(2).getAttribute("value"));
+ assertMatch("test regexp with message", "init.+",
inputs.get(2).getAttribute("value"));
+ assertNotMatch("test regexp with message", "$xinitial",
inputs.get(2).getAttribute("value"));
+
// get parent through xpath
IElement parent = element.getElement("..");
assertNotNull(parent);
Modified:
trunk/jwebunit-core/src/main/java/net/sourceforge/jwebunit/junit/WebTester.java
===================================================================
---
trunk/jwebunit-core/src/main/java/net/sourceforge/jwebunit/junit/WebTester.java
2008-11-18 01:43:31 UTC (rev 763)
+++
trunk/jwebunit-core/src/main/java/net/sourceforge/jwebunit/junit/WebTester.java
2008-11-18 02:18:30 UTC (rev 764)
@@ -428,7 +428,7 @@
}
/**
- * Assert that supplied regexp is matched.
+ * Assert that supplied regexp is matched in the text of a page.
*
* @param regexp
*/
@@ -438,8 +438,53 @@
Assert.fail("Expected rexexp not matched in response: [" + regexp
+ "]");
}
+
+ /**
+ * Assert a given string matches a given regular expression.
+ *
+ * @param regexp
+ * @param text
+ */
+ public void assertMatch(String regexp, String text) {
+ assertMatch("Expected rexexp '" + regexp + "' not matched in text '" +
text + "'", regexp, text);
+ }
/**
+ * Assert a given string does not match a given regular expression.
+ *
+ * @param regexp
+ * @param text
+ */
+ public void assertNotMatch(String regexp, String text) {
+ assertNotMatch("Expected rexexp '" + regexp + "' matched in text '" +
text + "'", regexp, text);
+ }
+
+
+ /**
+ * Assert a given string matches a given regular expression.
+ *
+ * @param regexp
+ * @param text
+ */
+ public void assertMatch(String message, String regexp, String text) {
+ RE re = getRE(regexp);
+ if (!re.match(text))
+ Assert.fail(message);
+ }
+
+ /**
+ * Assert a given string does not match a given regular expression.
+ *
+ * @param regexp
+ * @param text
+ */
+ public void assertNotMatch(String message, String regexp, String text) {
+ RE re = getRE(regexp);
+ if (re.match(text))
+ Assert.fail(message);
+ }
+
+ /**
* Assert that a web resource's value is not present.
*
* @param key web resource name
Modified: trunk/src/changes/changes.xml
===================================================================
--- trunk/src/changes/changes.xml 2008-11-18 01:43:31 UTC (rev 763)
+++ trunk/src/changes/changes.xml 2008-11-18 02:18:30 UTC (rev 764)
@@ -30,6 +30,9 @@
<action type="fix" dev="jevonwright" issue="2306967"
due-to="r_monson">
Fixed proxy authentication bug in HtmlUnit
implementation.
</action>
+ <action type="fix" dev="jevonwright" issue="1637716">
+ Added assertMatch(regexp, text) and
assertNotMatch(regexp, text) methods.
+ </action>
</release>
<release version="2.0" date="October 27, 2008">
<action type="update" dev="henryju">
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
JWebUnit-development mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jwebunit-development