Methods Summary |
---|
protected java.lang.String | readAsString(java.lang.String resource)
InputStream is = null;
try {
is = ClassLoaderUtil.getResourceAsStream(resource, PlainTextResultTest.class);
int sizeRead = 0;
byte[] buffer = new byte[1024];
StringBuffer stringBuffer = new StringBuffer();
while((sizeRead = is.read(buffer)) != -1) {
stringBuffer.append(new String(buffer, 0, sizeRead));
}
return stringBuffer.toString();
}
finally {
if (is != null)
is.close();
}
|
protected void | setUp()
super.setUp();
stringWriter = new StringWriter();
writer = new PrintWriter(stringWriter);
response = new StrutsMockHttpServletResponse();
response.setWriter(writer);
servletContext = new StrutsMockServletContext();
stack = ValueStackFactory.getFactory().createValueStack();
context = new ActionContext(stack.getContext());
context.put(StrutsStatics.HTTP_RESPONSE, response);
context.put(StrutsStatics.SERVLET_CONTEXT, servletContext);
invocation = new MockActionInvocation();
invocation.setStack(stack);
invocation.setInvocationContext(context);
|
protected void | tearDown()
stack = null;
invocation = null;
context = null;
response = null;
writer = null;
stringWriter = null;
servletContext = null;
super.tearDown();
|
public void | testPlainText()
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();
}
|
public void | testPlainTextWithEncoding()
PlainTextResult result = new PlainTextResult();
result.setLocation("/someJspFile.jsp");
result.setCharSet("UTF-8");
response.setExpectedContentType("text/plain; charset=UTF-8");
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();
}
|