2008-06-05

JBoss SeamTest 断言问题

关键字: jboss seam test

package org.jboss.seam.example.registration.test;

import javax.faces.context.FacesContext;

import org.jboss.seam.mock.SeamTest;
import org.testng.annotations.Test;

public class RegisterTest extends SeamTest
{
  
   @Test
   public void testLogin() throws Exception
   {
           
      new FacesRequest("/register.jspx") {

         @Override
         protected void processValidations() throws Exception
         {
            validateValue("#{user.username}", "1ovthafew");
            validateValue("#{user.name}", "Gavin King");
            validateValue("#{user.password}", "secret");
            assert !isValidationFailure();
         }
        
         @Override
         protected void updateModelValues() throws Exception
         {
            setValue("#{user.username}", "1ovthafew");
            setValue("#{user.name}", "Gavin King");
            setValue("#{user.password}", "secret");
         }

         @Override
         protected void invokeApplication()
         {
            assert invokeMethod("#{register.register}").equals("/registered.jspx");
            setOutcome("/registered.jspx");
         }
        
         @Override
         protected void afterRequest()
         {
            assert isInvokeApplicationComplete();
            assert  !isRenderResponseBegun();

         assert  IsRenderResponseComplete();
         }
        
      }.run();

 


      
      new NonFacesRequest("/registered.jspx")
      {

         @Override
         protected void renderResponse()
         {
            assert getValue("#{user.username}").equals("1ovthafew");
            assert getValue("#{user.password}").equals("secret");
            assert getValue("#{user.name}").equals("Gavin King");
         }
        
      }.run();
     
      new FacesRequest("/register.jspx") {

         @Override
         protected void processValidations() throws Exception
         {
            validateValue("#{user.username}", "1ovthafew");
            validateValue("#{user.name}", "Gavin A King");
            validateValue("#{user.password}", "password");
         }
        
         @Override
         protected void updateModelValues() throws Exception
         {
            setValue("#{user.username}", "1ovthafew");
            setValue("#{user.name}", "Gavin A King");
            setValue("#{user.password}", "password");
         }

         @Override
         protected void invokeApplication()
         {
            assert invokeMethod("#{register.register}")==null;
         }
        
         @Override
         protected void renderResponse() throws Exception
         {
            assert FacesContext.getCurrentInstance().getMessages().hasNext();
         }
        
         @Override
         protected void afterRequest()
         {
            assert isInvokeApplicationComplete();
            assert isRenderResponseComplete();
         }
        
      }.run();
     
   }
  
}

 

以上是seam框架包自带的registration项目的测试用例, 上面带红线的一行代码,isRenderResponseBegun(); 我浏览SeamTest的时候发现

  private void renderResponsePhase() throws Exception
      {
         phases.beforePhase(new PhaseEvent(facesContext, PhaseId.RENDER_RESPONSE, MockLifecycle.INSTANCE));

         try
         {
            updateConversationId();

            renderResponseBegun = true;

            renderResponse();

            renderResponseComplete = true;

            facesContext.getApplication().getStateManager().saveView(facesContext);

            updateConversationId();
         }
         finally
         {
            phases.afterPhase(new PhaseEvent(facesContext, PhaseId.RENDER_RESPONSE, MockLifecycle.INSTANCE));
         }
      }

在这个阶段的时候 renderResponseBegun = true;  为什么断言中是false? 即(是 assert  !isRenderResponseBegun();  而不是assert isRenderResponseBegun()? ) 请问高手解释一下?

这行代码  assert  isRenderResponseComplete(); 是我添加上的,但是测试的时候断言失败, 也就是  renderResponseComplete值是false,明明在上面的阶段设置为true了 ?  这又是怎么回事呀?


         
        

评论
发表评论

您还没有登录,请登录后发表评论

isky
搜索本博客
我的相册
A1241590-4201-3a57-ab8c-bfa7c633b181-thumb
SL372068
共 7 张
存档
最新评论