Methods Summary |
---|
protected void | setUp()
request = new MockHttpServletRequest();
response = new MockHttpServletResponse();
servletContext = new MockServletContext();
result = new XSLTResult();
stack = ValueStackFactory.getFactory().createValueStack();
ActionContext.getContext().setValueStack(stack);
MyAction action = new MyAction();
mai = new com.opensymphony.xwork2.mock.MockActionInvocation();
mai.setAction(action);
mai.setStack(stack);
mai.setInvocationContext(ActionContext.getContext());
stack.push(action);
ActionContext.getContext().put(ServletActionContext.HTTP_REQUEST, request);
ActionContext.getContext().put(ServletActionContext.HTTP_RESPONSE, response);
ActionContext.getContext().put(ServletActionContext.SERVLET_CONTEXT, servletContext);
|
protected void | tearDown()
request = null;
response = null;
servletContext = null;
result = null;
stack = null;
mai = null;
|
public void | testNoFileFound()
try {
result.setParse(false);
result.setLocation("nofile.xsl");
result.execute(mai);
fail("Should have thrown a TransformerException");
} catch (TransformerException e) {
// success
}
|
public void | testNoLocation()
try {
result.setParse(false);
result.setLocation(null);
result.execute(mai);
fail("Should have thrown an IllegalArgumentException");
} catch (IllegalArgumentException e) {
// success
}
|
public void | testSimpleTransform()
result.setParse(false);
result.setLocation("XSLTResultTest.xsl");
result.execute(mai);
String out = response.getContentAsString();
assertTrue(out.startsWith("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"));
assertTrue(out.indexOf("<result xmlns=\"http://www.w3.org/TR/xhtml1/strict\"") > -1);
|
public void | testSimpleTransformParse()
result.setParse(true);
result.setLocation("${top.myLocation}");
result.execute(mai);
String out = response.getContentAsString();
assertTrue(out.startsWith("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"));
assertTrue(out.indexOf("<result xmlns=\"http://www.w3.org/TR/xhtml1/strict\"") > -1);
|
public void | testTransform2()
result.setParse(false);
result.setLocation("XSLTResultTest2.xsl");
result.execute(mai);
String out = response.getContentAsString();
assertTrue(out.startsWith("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"));
assertTrue(out.indexOf("<html xmlns=\"http://www.w3.org/TR/xhtml1/strict\"") > -1);
assertTrue(out.indexOf("Hello Santa Claus how are you?") > -1);
|
public void | testTransform3()
result.setParse(false);
result.setLocation("XSLTResultTest3.xsl");
result.execute(mai);
String out = response.getContentAsString();
assertTrue(out.startsWith("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"));
assertTrue(out.indexOf("<html xmlns=\"http://www.w3.org/TR/xhtml1/strict\"") > -1);
assertTrue(out.indexOf("Hello Santa Claus how are you?") > -1);
assertTrue(out.indexOf("WebWork in Action by Patrick and Jason") > -1);
assertTrue(out.indexOf("XWork not in Action by Superman") > -1);
|
public void | testTransform4WithDocumentInclude()
result = new XSLTResult(){
protected URIResolver getURIResolver() {
return new URIResolver() {
public Source resolve(String href, String base) throws TransformerException {
return new StreamSource(ClassLoaderUtils.getResourceAsStream(href, this.getClass()));
}
};
}
};
result.setParse(false);
result.setLocation("XSLTResultTest4.xsl");
result.execute(mai);
String out = response.getContentAsString();
assertTrue(out.startsWith("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"));
assertTrue(out.indexOf("<validators>") > -1);
|