Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NPE with WicketTester #110

Open
eximius313 opened this issue May 25, 2017 · 2 comments
Open

NPE with WicketTester #110

eximius313 opened this issue May 25, 2017 · 2 comments

Comments

@eximius313
Copy link

eximius313 commented May 25, 2017

I was trying to run simple test case:

public class WicketApplicationTest {
	private WicketTester tester;

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

	@Test
	public void homepageRendersSuccessfully() {
		//given
		Class<TestPage> testPage = TestPage.class;

		//when
		tester.startPage(testPage);

		//then
		tester.assertRenderedPage(testPage);
	}
}

When I try to run it as JUnit I get:

java.lang.NullPointerException
	at com.giffing.wicket.spring.boot.starter.app.WicketBootStandardWebApplication.getConfigurationType(WicketBootStandardWebApplication.java:84)
	at org.apache.wicket.protocol.http.WebApplication.internalInit(WebApplication.java:736)
	at org.apache.wicket.Application.initApplication(Application.java:777)
	at org.apache.wicket.util.tester.BaseWicketTester.<init>(BaseWicketTester.java:334)
	at org.apache.wicket.util.tester.BaseWicketTester.<init>(BaseWicketTester.java:264)
	at org.apache.wicket.util.tester.BaseWicketTester.<init>(BaseWicketTester.java:237)
	at org.apache.wicket.util.tester.WicketTester.<init>(WicketTester.java:203)
	at com.example.WicketApplicationTest.setUp(WicketApplicationTest.java:12)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
	at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:678)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)

can you please fix it?

@MarcGiffing
Copy link
Owner

The exception is thrown in

@Override
public RuntimeConfigurationType getConfigurationType() {
	return generalSettingsProperties.getConfigurationType();
}

The problem is that the WicketBootStandardWebApplication is based on the auto configuration of spring. If you don't configure your tests the Spring way you will get exceptions or not the identical configuration like your running production code (the autoconfiguration is missing).

You can ovveriride the method and provide a runtime configuration type or you can have a look at the following tests:

https://github.com/MarcGiffing/wicket-spring-boot/tree/master/wicket-spring-boot-starter-example/src/test/java/com/giffing/wicket/spring/boot/example/web

https://github.com/MarcGiffing/wicket-spring-boot-examples/blob/master/simple/src/test/java/com/giffing/examples/wicket/spring/boot/simple/HomePageTest.java

These tests are using the @SpringBootTest annotation. But I think for tests with mocks you shouldn't use the @SpringBootTest annotation....

@eximius313
Copy link
Author

@MarcGiffing, thanks for explanation.
I think it could be good to put this information in the README.adoc so other people can benefit from it

@MarcGiffing MarcGiffing added this to the 2.1.6 milestone Feb 10, 2019
@MarcGiffing MarcGiffing removed this from the 2.1.6 milestone Apr 26, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants