我想写一个小测试:
我有一个外部服务器调用我的 url:
domain.com/pages/test/postback.html?user_id=5
当调用 url 时,应该调用 Controller 方法 test()(在 page.xml 中定义)
我的问题是:我如何测试 id 是否填充了正确的值?
我已经写了一个测试,NonFacesRequest
但最后,该值始终为空
我的控制器:
@Name(PostbackController.COMPONENT_NAME)
@AutoCreate
public class PostbackController {
public static final String COMPONENT_NAME = "postbackController";
@RequestParameter("user_id")
private String userId;
public String getUserId() {
return userId;
}
public void setUserId(String userId) {
this.userId = userId;
}
public void test(){
// do something
}
}
我的测试
public class PostbackTest extends SeamTest {
@Test
public void test() throws Exception{
new NonFacesRequest("/pages/test/postback.html?user_id=5"){
@Override
protected void renderResponse() throws Exception {
PostbackController postbackController = (PostbackController) getInstance(PostbackController.class);
Assert.assertEquals(postbackController.getUserId(),"5");
}
}.run();
}
postback.page.xml:
<?xml version="1.0" encoding="UTF-8"?>
<page xmlns="http://jboss.com/products/seam/pages"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://jboss.com/products/seam/pages http://jboss.com/products/seam/pages-2.2.xsd"
view-id="/pages/test/postback.xhtml" login-required="false">
<action execute="#{postbackController.test}" />
<param name="user_id" />
</page>
xhtml 是一个空白页。
希望有人知道如何解决这个问题......