Search in sources :

Example 1 with ParamInjector

use of org.nutz.mvc.adaptor.ParamInjector in project nutz by nutzam.

the class ArrayInjectorTest method test_array_no_split.

/**
     * for issue #816
     */
@Test
public void test_array_no_split() {
    // 准备数据
    MockHttpServletRequest req = Mock.servlet.request();
    req.setParameterValues("abc", Lang.array("A,B"));
    // 执行
    ParamInjector pi = inj("abc", String[].class, false);
    Object obj = pi.get(null, req, null, null);
    // 检测
    assertEquals(String[].class, obj.getClass());
    String[] ss = (String[]) obj;
    assertEquals(1, ss.length);
    assertEquals("A,B", ss[0]);
}
Also used : ParamInjector(org.nutz.mvc.adaptor.ParamInjector) MockHttpServletRequest(org.nutz.mock.servlet.MockHttpServletRequest) Test(org.junit.Test)

Example 2 with ParamInjector

use of org.nutz.mvc.adaptor.ParamInjector in project nutz by nutzam.

the class ArrayInjectorTest method test_array_auto_split.

/**
     * for issue #816
     */
@Test
public void test_array_auto_split() {
    // 准备数据
    MockHttpServletRequest req = Mock.servlet.request();
    req.setParameterValues("abc", Lang.array("A,B"));
    // 执行
    ParamInjector pi = inj("abc", String[].class, true);
    Object obj = pi.get(null, req, null, null);
    // 检测
    assertEquals(String[].class, obj.getClass());
    String[] ss = (String[]) obj;
    assertEquals(2, ss.length);
    assertEquals("A", ss[0]);
    assertEquals("B", ss[1]);
}
Also used : ParamInjector(org.nutz.mvc.adaptor.ParamInjector) MockHttpServletRequest(org.nutz.mock.servlet.MockHttpServletRequest) Test(org.junit.Test)

Example 3 with ParamInjector

use of org.nutz.mvc.adaptor.ParamInjector in project nutz by nutzam.

the class ArrayInjectorTest method test_array_no_split2.

/**
     * for issue #816
     */
@Test
public void test_array_no_split2() {
    // 准备数据
    MockHttpServletRequest req = Mock.servlet.request();
    req.setParameterValues("abc", Lang.array("A,B", "X,Y"));
    // 执行
    ParamInjector pi = inj("abc", String[].class, false);
    Object obj = pi.get(null, req, null, null);
    // 检测
    assertEquals(String[].class, obj.getClass());
    String[] ss = (String[]) obj;
    assertEquals(2, ss.length);
    assertEquals("A,B", ss[0]);
    assertEquals("X,Y", ss[1]);
}
Also used : ParamInjector(org.nutz.mvc.adaptor.ParamInjector) MockHttpServletRequest(org.nutz.mock.servlet.MockHttpServletRequest) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)3 MockHttpServletRequest (org.nutz.mock.servlet.MockHttpServletRequest)3 ParamInjector (org.nutz.mvc.adaptor.ParamInjector)3