Methods Summary |
---|
protected void | setUp()
super.setUp();
stack = ValueStackFactory.getFactory().createValueStack();
request = new InternalMockHttpServletRequest();
response = new MockHttpServletResponse();
strutsUtil = new StrutsUtil(stack, request, response);
|
protected void | tearDown()
stack = null;
request = null;
response = null;
strutsUtil = null;
super.tearDown();
|
public void | testBeanMethod()
Object o = strutsUtil.bean("org.apache.struts2.TestAction");
assertNotNull(o);
assertTrue(o instanceof TestAction);
|
public void | testBuildUrlMethod()
request.setContextPath("/myContextPath");
assertEquals(strutsUtil.buildUrl("/someUrl?param1=value1"), "/myContextPath/someUrl?param1=value1");
|
public void | testFindStringMethod()
stack.push(new Object() {
public String getMyString() {
return "myString";
}
public boolean getMyBoolean(boolean bool) {
return bool;
}
});
assertEquals(strutsUtil.findString("myString"), "myString");
assertNull(strutsUtil.findString("myOtherString"));
assertEquals(strutsUtil.findString("getMyBoolean(true)"), "true");
|
public void | testFindValueMethod()
stack.push(new Object() {
public String getMyString() {
return "myString";
}
public boolean getMyBoolean(boolean bool) {
return bool;
}
});
Object obj1 = strutsUtil.findValue("myString", "java.lang.String");
Object obj2 = strutsUtil.findValue("getMyBoolean(true)", "java.lang.Boolean");
assertNotNull(obj1);
assertNotNull(obj2);
assertTrue(obj1 instanceof String);
assertTrue(obj2 instanceof Boolean);
assertEquals(obj1, "myString");
assertEquals(obj2, Boolean.TRUE);
|
public void | testGetContextMethod()
request.setContextPath("/myContext");
assertEquals(strutsUtil.getContext(), "/myContext");
|
public void | testGetTextMethod()
// this should be in xwork-messages.properties (included by default
// by LocalizedTextUtil
assertNotNull(strutsUtil.getText("xwork.error.action.execution"));
assertEquals(strutsUtil.getText("xwork.error.action.execution"), "Error during Action invocation");
|
public void | testHtmlEncode()
assertEquals(
strutsUtil.htmlEncode("<html><head><title>some title</title><body>some content</body></html>"),
"<html><head><title>some title</title><body>some content</body></html>");
|
public void | testIncludeMethod()
strutsUtil.include("/some/includedJspFile.jsp");
// with include, this must have been created and should not be null
assertNotNull(request.getDispatcher());
// this must be true, indicating we actaully ask container to do an include
assertTrue(request.getDispatcher().included);
|
public void | testIsTrueMethod()
stack.push(new Object() {
public String getMyString() {
return "myString";
}
public boolean getMyBoolean(boolean bool) {
return bool;
}
});
assertTrue(strutsUtil.isTrue("myString == 'myString'"));
assertFalse(strutsUtil.isTrue("myString == 'myOtherString'"));
assertTrue(strutsUtil.isTrue("getMyBoolean(true)"));
assertFalse(strutsUtil.isTrue("getMyBoolean(false)"));
|
public void | testMakeSelectListMethod()
String[] selectedList = new String[] { "Car", "Airplane", "Bus" };
List list = new ArrayList();
list.add("Lorry");
list.add("Car");
list.add("Helicopter");
stack.getContext().put("mySelectedList", selectedList);
stack.getContext().put("myList", list);
List listMade = strutsUtil.makeSelectList("#mySelectedList", "#myList", null, null);
assertEquals(listMade.size(), 3);
assertEquals(((ListEntry)listMade.get(0)).getKey(), "Lorry");
assertEquals(((ListEntry)listMade.get(0)).getValue(), "Lorry");
assertEquals(((ListEntry)listMade.get(0)).getIsSelected(), false);
assertEquals(((ListEntry)listMade.get(1)).getKey(), "Car");
assertEquals(((ListEntry)listMade.get(1)).getValue(), "Car");
assertEquals(((ListEntry)listMade.get(1)).getIsSelected(), true);
assertEquals(((ListEntry)listMade.get(2)).getKey(), "Helicopter");
assertEquals(((ListEntry)listMade.get(2)).getValue(), "Helicopter");
assertEquals(((ListEntry)listMade.get(2)).getIsSelected(), false);
|
public void | testToInt()
assertEquals(strutsUtil.toInt(11l), 11);
|
public void | testToLong()
assertEquals(strutsUtil.toLong(11), 11l);
|
public void | testToString()
assertEquals(strutsUtil.toString(1), "1");
assertEquals(strutsUtil.toString(11l), "11");
|
public void | testUrlEncodeMethod()
assertEquals(
strutsUtil.urlEncode("http://www.opensymphony.com/action2/index.jsp?param1=value1"),
"http%3A%2F%2Fwww.opensymphony.com%2Faction2%2Findex.jsp%3Fparam1%3Dvalue1");
|