Re: Wicket + Guice + unittests

2012-10-10 Thread Ronan O'Connell

Hi Daniel,

I'm using Guice in a couple of wicket projects though my understanding 
of it is a little limited! My set-up matches yours except that in my 
unit test setup I call injectMembers :


@Before
public void setUp()
{
final StubProjectorApplication stubApplication = new 
StubProjectorApplication();

_tester = new WicketTester(stubApplication);
stubApplication.getWarpInjector().injectMembers(this); // 
getWarpInjector returns the injector built in the init method

}

I'm not sure this is right..it feels to me that it shouldn't be be 
necessary, but it works for me :) .


Ronan

On 10/10/2012 18:30, Daniel Watrous wrote:

Hi,

I've integrated Guice into Wicket successfully, but I'm struggling
with the unittests. I'm not sure how to get the injector into my
HomePage class. Here's my setup.

I'm using GuiceFilter with a GuiceServletContextListener. That creates
the injector and a ServletModule which defines the WicketApplication.
I followed:
http://code.google.com/p/google-guice/wiki/ServletModule

Here's some of MyGuiceServletConfig extends GuiceServletContextListener

 @Override
 protected Injector getInjector() {
 return Guice.createInjector(createServletModule(), new
MongoHoneybadgerModule());
 }

 private ServletModule createServletModule() {
 return new ServletModule() {
...

In my WicketApplication extends WebApplication I have this init() method

 @Override
 public void init()
 {
 super.init();
 Injector bootStrapInjector = (Injector)
this.getServletContext().getAttribute(Injector.class.getName());
 getComponentInstantiationListeners().add(new
GuiceComponentInjector(this, bootStrapInjector));
 }

Now, in my HomePage.java class I have

public class HomePage extends WebPage {
 private static final long serialVersionUID = 1L;
 @Inject private Injector injector;

 public HomePage(final PageParameters parameters) {
super(parameters);
 SomeType myobj = injector.getInstance(SomeType.class);

add(new Label("version", myobj.getValue()));
 }
}

This all runs great inside a web container as a servlet.

The PROBLEM: I'm getting a NullPointerException on the line where I
reference the injector:
 SomeType myobj = injector.getInstance(SomeType.class);

My test class is what was generated by the wicket quickstart. I'm not
sure how to make an injector available in setUp.

 @Before
 public void setUp() {
 tester = new WicketTester(new WicketApplication());
 }

Any ideas?

Thanks,
Daniel

-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org




-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org



Re: Unit Test InMethod DataGrid

2010-06-04 Thread Ronan O'Connell

Thank you very much Nino and Kent,

I've read about Wicketpagetest before and I've been planning to try it 
out. Looks like now is my chance :-)


Ronan

On 04/06/2010 02:16, Kent Tong wrote:

Hi Ronan,

Looking at the output of WicketTester.debugComponentTrees() I can see 
that the grid row is the deepest level with a wicket id:

...
panel:storyGrid:form:bodyContainer:body:row:2:item 
com.inmethod.grid.common.AbstractGridRow


If you use http://wicketpagetest.sourceforge.net, then you can test
it easily like:

   Selenium s = ...;
   assert 
s.getText("wicket=//storyGrid//body//row[2]//item[3]").equals("foo";


In this example you're checking the the 3rd cell in the 2nd row (both
are 0-based).




-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org



Unit Test InMethod DataGrid

2010-06-03 Thread Ronan O'Connell

Hi,

Does anybody know how to check the values of individual cells of an 
InMethod DataGrid/Treedrid. in a unit test?


Looking at the output of WicketTester.debugComponentTrees() I can see 
that the grid row is the deepest level with a wicket id:


NFO  - BaseWicketTester   - path
panel:storyGrid:form:bodyContainer:body 
com.inmethod.grid.datagrid.DataGridBody
INFO  - BaseWicketTester   - path
panel:storyGrid:form:bodyContainer:body:row 
com.inmethod.grid.common.AbstractPageableView
INFO  - BaseWicketTester   - path
panel:storyGrid:form:bodyContainer:body:row:1 
org.apache.wicket.markup.repeater.Item
INFO  - BaseWicketTester   - path
panel:storyGrid:form:bodyContainer:body:row:1:item 
com.inmethod.grid.common.AbstractGridRow
INFO  - BaseWicketTester   - path
panel:storyGrid:form:bodyContainer:body:row:2 
org.apache.wicket.markup.repeater.Item
INFO  - BaseWicketTester   - path
panel:storyGrid:form:bodyContainer:body:row:2:item 
com.inmethod.grid.common.AbstractGridRow


I've looked at those component classes and can't see anything helpful in 
them.


Hoping I'm not missing the obvious,
Ronan






-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org