use of org.nutz.mvc.ActionContext in project nutz by nutzam.
the class MappingNodeTest method test_quesmark_asterisk.
@Test
public void test_quesmark_asterisk() {
MappingNode<String> root = new MappingNode<String>();
root.add("/*", "root");
root.add("/a/?/?", "A");
root.add("/a/*", "B");
root.add("/a/x", "C");
root.add("/x/?/*", "D");
root.add("/m/?/**", "E");
ActionContext ac = new ActionContext();
assertEquals("A", root.get(ac, "/a/b/c"));
assertEquals("/a/b/c", ac.getPath());
assertEquals("b,c", Lang.concat(",", ac.getPathArgs()).toString());
assertEquals("B", root.get(ac, "/a/c/d/e"));
assertEquals("/a/c/d/e", ac.getPath());
assertEquals("c,d,e", Lang.concat(",", ac.getPathArgs()).toString());
assertEquals("C", root.get(ac, "/a/x/"));
assertEquals("/a/x/", ac.getPath());
assertEquals("", Lang.concat(",", ac.getPathArgs()).toString());
assertEquals("D", root.get(ac, "/x/a/o/p"));
assertEquals("/x/a/o/p", ac.getPath());
assertEquals("a,o,p", Lang.concat(",", ac.getPathArgs()).toString());
assertEquals("D", root.get(ac, "/x/a"));
assertEquals("/x/a", ac.getPath());
assertEquals("a", Lang.concat(",", ac.getPathArgs()).toString());
assertEquals("E", root.get(ac, "/m/a/o/p"));
assertEquals("/m/a/o/p", ac.getPath());
assertEquals("a,o/p", Lang.concat(",", ac.getPathArgs()).toString());
assertEquals("E", root.get(ac, "/m/a"));
assertEquals("/m/a", ac.getPath());
assertEquals("a", Lang.concat(",", ac.getPathArgs()).toString());
}
use of org.nutz.mvc.ActionContext in project nutz by nutzam.
the class MappingNodeTest method test_single_and_multi_path_arg.
@Test
public void test_single_and_multi_path_arg() {
MappingNode<String> root = new MappingNode<String>();
root.add("/a/?/c/*", "A");
ActionContext ac = new ActionContext();
assertEquals("A", root.get(ac, "/a/b/c"));
assertEquals(1, ac.getPathArgs().size());
assertEquals("b", ac.getPathArgs().get(0));
assertEquals("A", root.get(ac, "/a/b/c/d"));
assertEquals(2, ac.getPathArgs().size());
assertEquals("b", ac.getPathArgs().get(0));
assertEquals("d", ac.getPathArgs().get(1));
assertEquals("A", root.get(ac, "/a/b/c/d/e"));
assertEquals(3, ac.getPathArgs().size());
assertEquals("b", ac.getPathArgs().get(0));
assertEquals("d", ac.getPathArgs().get(1));
assertEquals("e", ac.getPathArgs().get(2));
}
use of org.nutz.mvc.ActionContext in project nutz by nutzam.
the class MappingNodeTest method test_single_path_arg.
@Test
public void test_single_path_arg() {
MappingNode<String> root = new MappingNode<String>();
root.add("/a/?/c", "A");
ActionContext ac = new ActionContext();
assertEquals("A", root.get(ac, "/a/b/c"));
assertEquals(1, ac.getPathArgs().size());
assertEquals("b", ac.getPathArgs().get(0));
}
use of org.nutz.mvc.ActionContext in project nutz by nutzam.
the class EViewProcessor method test_error_processor.
@Test
public void test_error_processor() throws Throwable {
ViewProcessor p = new EViewProcessor();
ActionContext ac = new ActionContext();
ac.setRequest(request).setResponse(response).setServletContext(servletContext);
Throwable t = new Throwable();
ac.setError(t);
p.process(ac);
Object obj = request.getAttribute(ViewProcessor.DEFAULT_ATTRIBUTE);
assertNotNull(obj);
assertTrue(obj instanceof Throwable);
assertEquals(t, obj);
}
Aggregations