Package org.nutz.mock.servlet

Examples of org.nutz.mock.servlet.MockHttpServletRequest


    }

    @Test
    public void test_array_to_string() {
        // 准备数据
        MockHttpServletRequest req = Mock.servlet.request();
        req.setParameterValues("pojo.str", Lang.array("A", "B", "C"));

        // 执行
        MvcTestPojo pojo = (MvcTestPojo) inj().get(null, req, null, null);

        // 检测
View Full Code Here


    }

    @Test
    public void test_string_to_string() {
        // 准备数据
        MockHttpServletRequest req = Mock.servlet.request();
        req.setParameterValues("pojo.str", Lang.array("A"));

        // 执行
        MvcTestPojo pojo = (MvcTestPojo) inj().get(null, req, null, null);

        // 检测
View Full Code Here

    }
   
    @Test
    public void test_date(){
        // 准备数据
        MockHttpServletRequest req = Mock.servlet.request();
        req.setParameter("pojo.date", "2010-01-01");
        // 执行
        MvcTestPojo pojo = (MvcTestPojo) inj().get(null, req, null, null);
       
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        System.out.println(sdf.format(pojo.date));
        assertEquals("2010-01-01", sdf.format(pojo.date));
       
        req.setParameter("pojo.date", "");
        // 执行
        MvcTestPojo pojoNull = (MvcTestPojo) inj().get(null, req, null, null);
       
        assertEquals(null, pojoNull.date);
    }
View Full Code Here

    }
   
    @Test
    public void testList(){
        //准备数据
        MockHttpServletRequest req = Mock.servlet.request();
        req.setParameter("pojo.books[1]", "a");
        req.setParameter("pojo.books[ads]", "b");
        req.setParameter("pojo.books[3]", "c");
      
        //执行
        MvcTestPojo pojo = (MvcTestPojo) inj().get(null, req, null, null);
       
        assertTrue(pojo.books.contains("a"));
View Full Code Here

   
    @SuppressWarnings("unchecked")
    @Test
    public void testListParam() throws NoSuchFieldException{
        //准备数据
        MockHttpServletRequest req = Mock.servlet.request();
        req.setParameter("lists[1].str", "a");
        ObjectNavlPairInjector onpi = inj("lists", NutType.list(MvcTestPojo.class));
        //执行
        List<MvcTestPojo> pojo =  (List<MvcTestPojo>) onpi.get(null, req, null, null);
        assertTrue(pojo.get(0).str.contains("a"));
    }
View Full Code Here

    }
   
    @Test
    public void testMap(){
        //准备数据
        MockHttpServletRequest req = Mock.servlet.request();
        req.setParameter("pojo.maps(abc).str", "a");
        req.setParameter("pojo.maps(1).str", "b");
        req.setParameter("pojo.maps(jk).str", "c");
        req.setParameter("pojo.maps(jk).maps.nutz.str", "k");
        //执行
        MvcTestPojo pojo = (MvcTestPojo) inj().get(null, req, null, null);
       
        assertEquals(pojo.maps.get("abc").str, "a");
        assertEquals(pojo.maps.get("1").str, "b");
View Full Code Here

        final Uploading up = UploadUnit.TYPE.born();
        final UploadingContext uc = UploadingContext.create("~/nutz/unit/uploadtmp");

        File[] files = dir.listFiles();
        final MockHttpServletRequest req = request().setInputStream(insmulti("UTF-8", files));
        req.setSession(session(context()));
        req.init();

        Object monLock = new Object();
        int monInterval = 2000;
        UploadMonitor mon = new UploadMonitor(monLock, req.getSession(), out, monInterval);
        Thread monThread = new Thread(mon, "UploadingMonitor");
        monThread.start();

        out.println("Begin...");
        Stopwatch sw = null;
View Full Code Here

   
    @SuppressWarnings("unchecked")
    @Test
    public void testMapParam() throws NoSuchFieldException{
        //准备数据
        MockHttpServletRequest req = Mock.servlet.request();
        req.setParameter("maps(abc).str", "a");
        req.setParameter("maps(1).str", "b");
        req.setParameter("maps(jk).str", "c");
        req.setParameter("maps.jk.maps.nutz.str", "k");
        //执行
        ObjectNavlPairInjector onpi = inj("maps", NutType.map(String.class, MvcTestPojo.class));
        Map<String, MvcTestPojo> pojo = (Map<String, MvcTestPojo>) onpi.get(null, req, null, null);
       
        assertEquals(pojo.get("abc").str, "a");
View Full Code Here

    }
   
    @Test
    public void testSet(){
        //准备数据
        MockHttpServletRequest req = Mock.servlet.request();
        req.setParameter("pojo.sets[jk].str", "c");
        req.setParameter("pojo.sets[jk].maps(nutz).str", "k");
        //执行
        MvcTestPojo pojo = (MvcTestPojo) inj().get(null, req, null, null);
       
        for(MvcTestPojo m : pojo.sets){
            assertEquals(m.str, "c");
View Full Code Here

    }
   
    @Test
    public void testArray() throws NoSuchFieldException{
        //准备数据
        MockHttpServletRequest req = Mock.servlet.request();
        req.setParameter("arrays[1].str", "a");
        ObjectNavlPairInjector onpi = inj("arrays", NutType.array(MvcTestPojo.class));
        //执行
        MvcTestPojo[] pojo =  (MvcTestPojo[]) onpi.get(null, req, null, null);
        assertTrue(pojo[0].str.contains("a"));
    }
View Full Code Here

TOP

Related Classes of org.nutz.mock.servlet.MockHttpServletRequest

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.