Search in sources :

Example 6 with ActionContext

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());
}
Also used : ActionContext(org.nutz.mvc.ActionContext) Test(org.junit.Test)

Example 7 with ActionContext

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));
}
Also used : ActionContext(org.nutz.mvc.ActionContext) Test(org.junit.Test)

Example 8 with ActionContext

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));
}
Also used : ActionContext(org.nutz.mvc.ActionContext) Test(org.junit.Test)

Example 9 with ActionContext

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);
}
Also used : ActionContext(org.nutz.mvc.ActionContext) ViewProcessor(org.nutz.mvc.impl.processor.ViewProcessor) AbstractMvcTest(org.nutz.mvc.AbstractMvcTest) Test(org.junit.Test)

Aggregations

ActionContext (org.nutz.mvc.ActionContext)9 Test (org.junit.Test)8 HashMap (java.util.HashMap)1 HttpSession (javax.servlet.http.HttpSession)1 Context (org.nutz.lang.util.Context)1 AbstractMvcTest (org.nutz.mvc.AbstractMvcTest)1 AtMap (org.nutz.mvc.config.AtMap)1 ViewProcessor (org.nutz.mvc.impl.processor.ViewProcessor)1