[jboss-user] [JBoss Seam] - A suggested SeamTest improvement

matt.drees do-not-reply at jboss.com
Thu Jul 12 02:33:15 EDT 2007


I spent some time debugging one of my tests, trying to figure out why the conversation wasn't being propagated.  I had something (very roughly) like this:


  | 
  | 		String cid = new FacesRequest("/page1.xhtml") {
  | 			@Override
  | 			protected void invokeApplication() throws Exception {
  | 				Manager.instance().beginConversation();
  | 				FacesManager.instance().redirect("/page2.xhtml");
  | 			}
  | 			
  | 		}.run();
  | 		
  | 		cid = new FacesRequest("/page2.xhtml", cid) {
  | 			@Override
  | 			protected void invokeApplication() {
  | 				assert Manager.instance().isLongRunningConversation();
  | 			}
  | 		}.run();
  | 

But the assertion fails, which I learned has to do with the fact that there was nothing rendered in the first request.  So, I can fix it by doing this:


  | 
  | 		String cid = new FacesRequest("/page1.xhtml") {
  | 			@Override
  | 			protected void invokeApplication() throws Exception {
  | 				Manager.instance().beginConversation();
  | 			    FacesManager.instance().redirect("/page2.xhtml");
  | 			}
  | 			
  | 		}.run();
  | 		
  | 		cid = new NonFacesRequest("/page2.xhtml", cid) {
  | 		}.run();
  | 		
  | 		cid = new FacesRequest("/page2.xhtml", cid) {
  | 			@Override
  | 			protected void invokeApplication() {
  | 				assert Manager.instance().isLongRunningConversation();
  | 			}
  | 		}.run();
  | 

But it annoys me to have that empty request in there.  So, it'd be nice to have something like this:


  | 		String cid = new FacesRequestAndRedirect("/page1.xhtml", null, "/page2.xhtml") {
  | 			@Override
  | 			protected void invokeApplication() throws Exception {
  | 				Manager.instance().beginConversation();
  | 			    FacesManager.instance().redirect(getRedirectedTo());
  | 			}
  | 			
  | 			@Override
  | 			public void renderAfterRedirect() throws Exception {
  | 				assert Manager.instance().isLongRunningConversation();
  | 			}
  | 		}.run();
  | 		
  | 		cid = new FacesRequest("/page2.xhtml", cid) {
  | 			@Override
  | 			protected void invokeApplication() throws Exception {
  | 				assert Manager.instance().isLongRunningConversation();
  | 			}
  | 		}.run();
  | 

And it turns out that I could make it happen with this convolution:

  | 
  | 	public class FacesRequestAndRedirect extends FacesRequest {
  | 		
  | 		private String redirectedTo;
  | 
  | 		public FacesRequestAndRedirect() {
  | 			super();
  | 		}
  | 		
  | 		public FacesRequestAndRedirect(String viewId, String conversationId) {
  | 			super(viewId, conversationId);
  | 		}
  | 
  | 		public FacesRequestAndRedirect(String viewId) {
  | 			super(viewId);
  | 		}
  | 
  | 		public FacesRequestAndRedirect(String viewId, String conversationId, String redirectedTo) {
  | 			super(viewId, conversationId);
  | 			setRedirectedTo(redirectedTo);
  | 		}
  | 		
  | 		@Override
  | 		public final void renderResponse() throws Exception {
  | 
  | 		}
  | 		
  | 		public void renderAfterRedirect() throws Exception {
  | 			
  | 		}
  | 		
  | 		public String getRedirectedTo() {
  | 			return redirectedTo;
  | 		}
  | 		
  | 		public void setRedirectedTo(String redirectedTo) {
  | 			this.redirectedTo = redirectedTo;
  | 		}
  | 		
  | 		@Override
  | 		public String run() throws Exception {
  | 			String cid = super.run();
  | 			
  | 			cid = new NonFacesRequest(getRedirectedTo(), cid) {
  | 			
  | 				@Override
  | 				protected void renderResponse() throws Exception {
  | 					renderAfterRedirect();
  | 				}
  | 			}.run();
  | 			return cid;
  | 		}
  | 	}
  | 

So, I haven't used it or thought about it much, but it might be worth putting something like this into Seam.  Any thoughts?



View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4063325#4063325

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4063325



More information about the jboss-user mailing list