Ejemplo n.º 1
0
 protected String readAsString(String resource) throws Exception {
   InputStream is = null;
   try {
     is = ClassLoaderUtil.getResourceAsStream(resource, PlainTextResultTest.class);
     int sizeRead = 0;
     byte[] buffer = new byte[1024];
     StringBuilder stringBuilder = new StringBuilder();
     while ((sizeRead = is.read(buffer)) != -1) {
       stringBuilder.append(new String(buffer, 0, sizeRead));
     }
     return stringBuilder.toString();
   } finally {
     if (is != null) is.close();
   }
 }
Ejemplo n.º 2
0
  public void testPlainTextWithoutSlash() throws Exception {
    PlainTextResult result = new PlainTextResult();
    result.setLocation("someJspFile.jsp");

    response.setExpectedContentType("text/plain");
    response.setExpectedHeader("Content-Disposition", "inline");
    InputStream jspResourceInputStream =
        ClassLoaderUtil.getResourceAsStream(
            "org/apache/struts2/dispatcher/someJspFile.jsp", PlainTextResultTest.class);

    try {
      servletContext.setResourceAsStream(jspResourceInputStream);
      result.execute(invocation);

      String r = AbstractUITagTest.normalize(stringWriter.getBuffer().toString(), true);
      String e =
          AbstractUITagTest.normalize(
              readAsString("org/apache/struts2/dispatcher/someJspFile.jsp"), true);
      assertEquals(r, e);
    } finally {
      jspResourceInputStream.close();
    }
  }