On 10/31/06, Derek Fues <[EMAIL PROTECTED]> wrote:

Hello,



I am trying to use the Shale testing framework in order to test how

ActionEvents can be trapped and manager.



I am using the AbstractJsfTestCase as my extension for my test case.



What I am trying to do is mimic the generation of the action event,

and then process asserts around that.





After calling super.setUp()  I have done the following:



// create the view

UIForm parent = new HtmlForm();



parent.setId("form1");

parent.setParent(facesContext.getViewRoot());



// Add the components to the HTML Form

button = new UICommand();

button.setId("button1");

button.setParent(parent);





UIData table = new UIData();

table.setId("myTable");

table.setParent(parent);



In my testMethod() I am performing the following:



ActionEvent eventFC = new ActionEvent(button);



assertNotNull("Action Event was returned null - expected an object",
eventFC);



UIComponent comp= eventFC. getComponent();



comp= button.findComponent("myTable");



assertNotNull("UIComponent was returned null directly from button -
expected an object", comp);



The call to find the component by name (myTable) returns a null object
- is there a way using this framework to simulate something like what I
am attempting?


Derek,

Actually, you are not really using the test framework at this point :-).
You are dealing with the real UIComponent class from the JSF API.  And the
findComponent() method has very specific Javadocs about what it's argument
is supposed to look like (at least the JSF RI version of this class has good
docs).

There are likely to be two different things going on here.

* Calling component.setParent(parent) is *not* sufficient to
 establish the linkages between two components.  Instead,
 you should do something like this:

   parent.getChildren().add(component)

 which will establish the bidirectional links, and should
 help make it possible for findComponent() to navigate up
 and down the entire component tree correctly.

* Components inside a naming container (the UIForm component
 in this case) will end up with compount client identifers.  If
 searching just by the simple name does not work, try that.

Craig

Thanks for any advice!





Derek





Reply via email to