Używam Struts 2.3.14 do mojej aplikacji ... Potrzebuję jakiegoś testu jednostkowego w mojej aplikacji ... więc używam junit4 ... ale kiedy używam ActionProxy
w moim Test, pokaże NullPointerException
...Struts 2.3.14 junit test
mój kod test jest:
ActionProxy proxy=getActionProxy("/customize/saveRewards");
SaveRewardsPlus rewards=(SaveRewardsPlus)proxy.getAction();
request.setParameter("list[0].img_id", "1");
request.setParameter("list[0].tag", "Test Tag");
request.setParameter("list[0].desc", "Test Desc");
String result=proxy.execute();
assertEquals("success", result);
i mój Action klasy jest:
private List<RewardsBean> list;
public String execute() {
try {
Class.forName(DRIVER);
con = DriverManager.getConnection(CONSTR, USER, PWD);
for (RewardsBean rb : list) {
sql = "update rewards set tag=?,description=? where img_id=?";
PreparedStatement ps = con.prepareStatement(sql);
ps.setString(1, rb.getTag());
ps.setString(2, rb.getDesc());
ps.setInt(3, rb.getImg_id());
ps.executeUpdate();
}
} catch (SQLException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
return SUCCESS;
}
/**
* @return the list
*/
public List<RewardsBean> getList() {
return list;
}
Jak mogę wysłać wniosek do klasy akcji i jak używać ActionProxy
... Proszę mi pomóc poprawić ..... Dziękuje z góry ......
mój plik struts.xml poniżej podana jest .....
<struts>
<!-- Configuration for the default package. -->
<package name="default" extends="struts-default">
<action name="addRewards" class="com.customize.rewards.AddRewards">
<result name="success">index.jsp</result>
</action>
</package>
<include file="addrewards/struts-addrewards.xml"></include>
<include file="customize/struts-customize.xml"></include>
</struts>
i mój importowany plik XML znajduje się poniżej ....
<struts>
<package name="customize" namespace="/customize" extends="struts-default">
<!--<action name="viewRewards" class="com.customize.rewards.ViewRewards">
<result>/customizeRewards/viewRewards.jsp</result>
</action> -->
<!-- New Rewards-->
<action name="viewRewards" class="com.customize.rewards.ViewRewards">
<result>/customizeRewards/viewRewardsPlus.jsp</result>
</action>
<action name="saveRewards" class="com.customize.rewards.SaveRewardsPlus">
<result name="success" type="redirect">viewRewards</result>
</action>
<!--/New Rewards-->
<!-- <action name="saveRewards" class="com.customize.rewards.SaveRewards">
<result name="success" type="redirect">viewRewards</result>
</action>-->
<action name="deleteRewards" class="com.customize.rewards.DeleteRewards">
<result name="success" type="redirect">viewRewards</result>
</action>
<action name="addRewards" class="com.customize.rewards.AddRewards">
<result name="success" type="redirect">viewRewards</result>
</action>
</package>
</struts>
mój StackTrace ....
java.lang.NullPointerException at
org.apache.struts2.StrutsTestCase.getActionProxy(StrutsTestCase.java:130) at
com.customize.rewards.SaveRewardsPlusTest.testExecute(SaveRewardsPlusTest.java:49)
Testsuite: com.customize.rewards.SaveRewardsTest