You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by lucast <lu...@hotmail.com> on 2014/06/04 15:03:32 UTC

Re: Unit testing with Spring injected Application

Hi Nick,
I know you have posted this solution a long time ago but I happen to be
having the very same exception: IllegalStateException: Application name can
only be set once.

I'm using wicket 6, spring 4 (and hibernate). And I am trying to do an
integration, end-to-end test.

This is what my test looks like:





I tried implementing your suggested solution but I'm afraid I'm stuck in a
number of places:

Where do you get the  *applicationContext value from? If I add  to the above
class, it will throw a null pointer exception when running setUp. I tried a
number of workarounds but none of them seem to work.

I just would like to know how you initialized autowireCapableBeanFactory
from applicationContext, if the test environment is set up by Spring.

If I move setUpLoginEnvironment to inside userSuccessfullyLogsIn(), then I
don't have the problem. I just wanted to divide the test up for readability
purpose. 

Thanks in advance,
Lucas


--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Unit-testing-with-Spring-injected-Application-tp4653110p4666117.html
Sent from the Users forum mailing list archive at Nabble.com.

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


Re: Unit testing with Spring injected Application

Posted by "dennis.germany" <de...@gmail.com>.
Hi,

I used this solution to get this to work:

/**
 * Simple test using the WicketTester
 */
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "classpath:applicationContext.xml" })
public class UserAddPageTest {
	private WicketTester tester;

	@Autowired
	private ApplicationContext ctx;

	@Before
	public void setUp() {
		WicketApplication application = new WicketApplication();
		application.setApplicationContext(ctx);
		tester = new WicketTester(application);
		tester.startPage(UserAddPage.class);
	}

	@Test
	public void homepageRendersSuccessfully() {
		// assert rendered page class
		tester.assertRenderedPage(UserAddPage.class);
	}

	@Test
	public void foo() {
		FormTester formTester = tester.newFormTester("userForm");
		formTester.setValue("firstname", "Udo");
		formTester.setValue("lastname", "Berliner");
		formTester.submit();
		tester.assertRenderedPage(UserShowPage.class);
	}
}


--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Unit-testing-with-Spring-injected-Application-tp4653110p4668216.html
Sent from the Users forum mailing list archive at Nabble.com.

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