@Test public void testSimpleWrite() throws IOException { String a = "<html>"; String b = "foo"; String c = "</html>"; EvoHttpServletResponse res = new EvoHttpServletResponse(); Assert.assertFalse(res.isCommitted()); PrintWriter out = res.getWriter(); out.print(a); out.print(b); out.print(c); Assert.assertEquals(EvoHttpServletResponse.WARN_NO_COMMITTED, res.getBody()); out.close(); Assert.assertTrue(res.isCommitted()); Assert.assertEquals(a+b+c, res.getBody()); } }
@Test public void testSimpleScenarioWithParams() throws IOException { EvoHttpServletRequest req = new EvoHttpServletRequest(); EvoHttpServletResponse res = new EvoHttpServletResponse(); req.addParam("foo", "bar"); PrintWriter out = res.getWriter(); out.print(req.getParameter("foo")); res.flushBuffer(); Assert.assertEquals("bar", res.getBody()); }
servlet.service(req, resp); String body = resp.getBody(); Assert.assertNotEquals(EvoHttpServletResponse.WARN_NO_COMMITTED, body); Assert.assertTrue(body.length() > 0);
@Test public void testAsyn() throws ServletException, IOException { HttpServlet servlet = new AnnotatedServlet_for_testAsyn(); EvoServletState.initServlet(servlet); boolean supported = EvoServletState.getRequest().isAsyncSupported(); Assert.assertTrue(supported); servlet.service(EvoServletState.getRequest(), EvoServletState.getResponse()); String body = EvoServletState.getResponse().getBody(); Assert.assertEquals("foo", body); }
@Test public void testParts() throws ServletException, IOException{ HttpServlet servlet = new HttpServlet() { @Override public void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { Collection<Part> parts = req.getParts(); String s = ""; for(Part p : parts){ Scanner in = new Scanner(p.getInputStream()); s += in.nextLine(); in.close(); } PrintWriter out = resp.getWriter(); out.print(s); out.close(); } }; String msg0 = "foo"; String msg1 = "bar"; EvoServletState.initServlet(servlet); EvoHttpServletRequest req = EvoServletState.getRequest(); req.asPOST(); req.asMultipartFormData(); req.addPart(new EvoPart("first", msg0)); req.addPart(new EvoPart("second", msg1)); servlet.service(req, EvoServletState.getResponse()); Assert.assertTrue(TestDataJavaEE.getInstance().getViewOfParts().size() == 0); Assert.assertTrue(EvoServletState.getResponse().getBody().equals(msg0+msg1)); }