Problem with JSFServerSession.getComponentValue() and Seam
orr94 May 13, 2011 9:22 AMI am currently running Seam 2.2.1 on JBoss AS 4.2.3, and I'm trying to start using JSFUnit 1.3.0 for testing. While I'm very impressed with it so far, I've been unable to successfully test the UI components. Any time I use JSFServerSession.getComponentValue(), it returns null.
I have a simple Ping component:
@Name("ping") @Scope(ScopeType.CONVERSATION) public class Ping implements Serializable { String pingMessage; @Out(required = false) String pingResponse; public String getPingMessage() { return pingMessage; } public void setPingMessage(String pingMessage) { this.pingMessage = pingMessage; } public void sendPing() { pingResponse = pingMessage; } }
And a simple view:
<h:form id="pingForm"> <rich:panel> <s:decorate id="pingMessageField" template="/layout/edit.xhtml"> <ui:define name="label">Message</ui:define> <h:inputText id="pingMessage" value="#{ping.pingMessage}" /> </s:decorate> <h:commandButton id="sendPing" value="Send Ping" action="#{ping.sendPing()}" /> <s:decorate id="pingResponseDisplay" template="/layout/display.xhtml"> <ui:define name="label">Ping Response</ui:define> <h:outputText id="pingResponseOut" value="#{pingResponse}" /> </s:decorate> <div style="clear: left" /> </rich:panel> </h:form>
And a simple test class (snipped out some portions for brevity)
public class PingTest extends ServletTestCase { public void setUp() throws IOException { // Initial JSF request JSFSession jsfSession = new JSFSession("/jsfUnit/ping.seam"); this.client = jsfSession.getJSFClientSession(); this.server = jsfSession.getJSFServerSession(); } public void testSendPing() throws IOException, SAXException { String pingMessage = "Hello Ping component!"; client.setValue("pingForm:pingMessageField:pingMessage", pingMessage); client.click("pingForm:sendPing"); // First test that Seam component was set correctly and value was outjected assertEquals( "#{seamconversation.ping.pingMessage} did not match expected value;", pingMessage, server.getManagedBeanValue("#{seamconversation.ping.pingMessage}")); assertEquals( "#{seamconversation.pingResponse} did not match expected value;", pingMessage, server.getManagedBeanValue("#{seamconversation.pingResponse}")); // Then test UI components Object pingMessageInput = server .getComponentValue("pingForm:pingMessageField:pingMessage"); assertEquals( "pingForm:pingMessageField:pingMessage did not match expected value;", pingMessage, pingMessageInput); Object pingResponse = server .getComponentValue("pingForm:pingResponseDisplay:pingResponseOut"); assertEquals( "pingForm:pingResponseDisplay:pingResponseOut did not match expected value;", pingMessage, pingResponse); } } }
When I run the application, it displays correctly in my browser.
When I run the test, the two assertions on server.getManagedBeanValue() pass (so we can assume that it updated the model correctly). However, the server.getComponentValue() assertions fail:
pingForm:pingMessageField:pingMessage did not match expected value; expected:<Hello Ping component!> but was:<null>
And if I comment out the first server.getComponentValue(), the second one fails too:
pingForm:pingResponseDisplay:pingResponseOut did not match expected value; expected:<Hello Ping component!> but was:<null>
Searching around, I found some discussions on bugs with getComponentValue() and UIData components, but that shouldn't apply to <h:inputText> or <h:outputText>.
I did notice that the Seam JSFUnit examples (jboss-jsfunit-examples-seam) don't actually call getComponentValue() anywhere, but I was unable to find any indication in the documentation or on a Google search that getComponentValue() doesn't work for Seam.
I'd really appreciate any help with this, because I am really excited to use JSFUnit for our projects!