Author: julien_viet
Date: 2010-11-29 09:52:18 -0500 (Mon, 29 Nov 2010)
New Revision: 5352
Modified:
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/regexp/RENode.java
portal/branches/navcontroller/component/web/controller/src/test/java/org/exoplatform/web/controller/router/TestRouteEscaper.java
Log:
add relevant unit test for route escape
Modified:
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/regexp/RENode.java
===================================================================
---
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/regexp/RENode.java 2010-11-29
13:30:56 UTC (rev 5351)
+++
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/regexp/RENode.java 2010-11-29
14:52:18 UTC (rev 5352)
@@ -31,8 +31,12 @@
public abstract String toString();
- public final RENode replaceBy(RENode that)
+ public final RENode replaceBy(RENode that) throws IllegalStateException
{
+ if (owner == null)
+ {
+ throw new IllegalStateException("Not attached");
+ }
return owner.replace(that);
}
@@ -779,9 +783,16 @@
super(type);
//
- if (node != null && node.owner != null)
+ if (node != null)
{
- throw new IllegalArgumentException();
+ if (node.owner != null)
+ {
+ throw new IllegalArgumentException();
+ }
+ else
+ {
+ node.owner = this;
+ }
}
this.node = node;
}
Modified:
portal/branches/navcontroller/component/web/controller/src/test/java/org/exoplatform/web/controller/router/TestRouteEscaper.java
===================================================================
---
portal/branches/navcontroller/component/web/controller/src/test/java/org/exoplatform/web/controller/router/TestRouteEscaper.java 2010-11-29
13:30:56 UTC (rev 5351)
+++
portal/branches/navcontroller/component/web/controller/src/test/java/org/exoplatform/web/controller/router/TestRouteEscaper.java 2010-11-29
14:52:18 UTC (rev 5352)
@@ -23,6 +23,9 @@
import org.exoplatform.web.controller.regexp.RENode;
import org.exoplatform.web.controller.regexp.RegExpParser;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
/**
* @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
* @version $Revision$
@@ -30,7 +33,7 @@
public class TestRouteEscaper extends BaseGateInTest
{
- private void assertFoo(String pattern) throws Exception
+ private void match(String pattern, String test, String expectedValue) throws
Exception
{
RegExpParser parser = new RegExpParser(pattern);
RouteEscaper escaper = new RouteEscaper('/', '_');
@@ -39,13 +42,20 @@
RegExpAnalyser analyser = new RegExpAnalyser();
analyser.process(re);
System.out.println(pattern + " --> " + analyser.getPattern());
+ Pattern p = Pattern.compile(analyser.getPattern());
+ Matcher matcher = p.matcher(test);
+ assertTrue(matcher.find());
+ assertEquals(expectedValue, matcher.group());
}
- public void testFoo() throws Exception
+ public void testMatch() throws Exception
{
- assertFoo("/+");
- assertFoo(".*");
- assertFoo("[a/]");
- assertFoo("[,-1]");
+ match(".*", "_", "_");
+ match(".*", "_/", "_");
+ match(".*", "_/_", "_");
+ match("/", "_/", "_");
+ match("/*", "_/_", "_");
+ match("[/a]*", "_a_/_", "_a_");
+ match("[,-1&&[^/]]*", "_/_", "");
}
}
Show replies by date