Wicket and Guice, webpage injection and testing

I'm trying to work with a wicket and a graph, more specifically inserting a facade (or controller, whatever) onto the web page with a pattern. The problem is that I can not do any injection other than injection on the box on the web page. If I try to use setter injection, the setter just doesn't get called. Embedding a constructor in a web page is not possible (or I did not find how to do this).

Thus, I seem to be left with the injection field as the only injection opportunity on the web page.

Can someone, first of all, confirm that this is correct? It seems that I found on the apache site that the setter injection does not work, as with gate 1.5 (I am 6 by the way), but did not find more information about this.

Secondly, if, indeed, it is only possible to overlay a field on a web page, how can I enter a field into a form purely unit test? (I think about the mock test, all I need to know is that the corresponding facade is correctly called with the correct arguments after clicking the button, the facade itself can be tested in another unit test).

Didn't ship the code because the question seems pretty simple. If necessary, I will add some fragments

Kasper

+4
source share
3 answers

I also struggled with this. The integration turned out to be very smooth:

http://software.danielwatrous.com/wicket-guice-including-unittests/

Following this method, an injector is introduced, which gives full flexibility.

+3
source

For all that I know, the IoC module for the gate only provides field injection for the components, so there is no easy way to insert something into the component from the setter. You can confirm this by reading the source code for Wicket-IoC / Wicket-Guice.

To clear the entered field, you can use the Java reflation API to create a null field. However, the page may have a certain state after the test. Therefore, I would recommend just re-creating the page after each test.

0
source

I use Wicket with Guice doing a mock test. You can see how I link everything here http://blog.yanivkessler.com/2010/05/wicket-and-guice-alternate-route.html (with my comment in Gaetan)

Tests are not a problem since the injection is performed by the Component constructor. In my case, I have small tests on Component that check calls to manufactured services depending on user interactions.

Here is a simplified version of initializing my tests.

  @BeforeClass public void buildMockedTester() { List<Module> modules = buildModules(); injector = Guice.createInjector(modules); MyApplicationFactory instance = injector.getInstance(MyApplicationFactory.class); WebApplication application = instance.buildWebApplication(); tester = new WicketTester(application); } 
0
source

Source: https://habr.com/ru/post/1438186/


All Articles