Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wicket cannot resolve properties in Tests

In the same application I have Project A and Propject B. Project B has an implementation of a component, that is also used in Project A. When running the tests for Project A I get the following stacktrace:

org.apache.wicket.WicketRuntimeException: Exception in rendering component: [UploadPanel [Component id = content]]
    at org.apache.wicket.Component.internalRenderComponent(Component.java:2589)
    at org.apache.wicket.MarkupContainer.onRender(MarkupContainer.java:1663)
    at org.apache.wicket.Component.internalRender(Component.java:2380)
    at org.apache.wicket.Component.render(Component.java:2308)
    at org.apache.wicket.MarkupContainer.renderNext(MarkupContainer.java:1521)
    at org.apache.wicket.MarkupContainer.renderAll(MarkupContainer.java:1724)
    at org.apache.wicket.Page.onRender(Page.java:879)
    at org.apache.wicket.markup.html.WebPage.onRender(WebPage.java:141)
    at org.apache.wicket.Component.internalRender(Component.java:2380)
    at org.apache.wicket.Component.render(Component.java:2308)
    at org.apache.wicket.Page.renderPage(Page.java:1018)
    at org.apache.wicket.request.handler.render.WebPageRenderer.renderPage(WebPageRenderer.java:124)
    at org.apache.wicket.request.handler.render.WebPageRenderer.respond(WebPageRenderer.java:236)
    at org.apache.wicket.util.tester.BaseWicketTester$LastPageRecordingPageRendererProvider$1.respond(BaseWicketTester.java:2766)
    at org.apache.wicket.core.request.handler.RenderPageRequestHandler.respond(RenderPageRequestHandler.java:175)
    at org.apache.wicket.request.cycle.RequestCycle$HandlerExecutor.respond(RequestCycle.java:895)
    at org.apache.wicket.request.RequestHandlerStack.execute(RequestHandlerStack.java:64)
    at org.apache.wicket.request.cycle.RequestCycle.execute(RequestCycle.java:265)
    at org.apache.wicket.request.cycle.RequestCycle.processRequest(RequestCycle.java:222)
    at org.apache.wicket.request.cycle.RequestCycle.processRequestAndDetach(RequestCycle.java:293)
    at org.apache.wicket.util.tester.BaseWicketTester.processRequest(BaseWicketTester.java:714)
    at org.apache.wicket.util.tester.BaseWicketTester.processRequest(BaseWicketTester.java:653)
    at org.apache.wicket.util.tester.BaseWicketTester.startPage(BaseWicketTester.java:883)
    at org.apache.wicket.util.tester.BaseWicketTester.startPage(BaseWicketTester.java:900)
    at org.apache.wicket.util.tester.BaseWicketTester.startComponentInPage(BaseWicketTester.java:1462)
    at org.apache.wicket.util.tester.BaseWicketTester.startComponentInPage(BaseWicketTester.java:1382)
    at (FrameworkMethod.java:47)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
    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:675)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
Caused by: java.lang.RuntimeException: An error occurred while getting the model object for Component: [EmailLink [Component id = dataexchange.email.link, page = org.apache.wicket.util.tester.BaseWicketTester$StartComponentInPage, path = 1:content:dataexchange.email.link.EmailLink, isVisible = true, isVersioned = true, markup = [markup = file:/C:/dev/projects/Project A/web/content/upload/UploadPanel.html
<a href="#" wicket:id="dataexchange.email.link"><wicket:message key="massmeldupload.desc.3"/></a>, index = 0, current =  '<a href="#" wicket:id="dataexchange.email.link">' (line 0, column 0)]]]
    at org.apache.wicket.Component.getDefaultModelObject(Component.java:1631)
    at org.apache.wicket.Component.getDefaultModelObjectAsString(Component.java:1654)
    at Project B.web.comp.EmailLink.onComponentTag(EmailLink.java:36)
    at org.apache.wicket.Component.internalRenderComponent(Component.java:2521)
    at org.apache.wicket.MarkupContainer.onRender(MarkupContainer.java:1663)
    at org.apache.wicket.Component.internalRender(Component.java:2380)
    at org.apache.wicket.Component.render(Component.java:2308)
    at org.apache.wicket.MarkupContainer.renderNext(MarkupContainer.java:1521)
    at org.apache.wicket.MarkupContainer.renderAll(MarkupContainer.java:1724)
    at org.apache.wicket.MarkupContainer.renderComponentTagBody(MarkupContainer.java:1699)
    at org.apache.wicket.MarkupContainer.renderAssociatedMarkup(MarkupContainer.java:799)
    at org.apache.wicket.markup.html.panel.AssociatedMarkupSourcingStrategy.renderAssociatedMarkup(AssociatedMarkupSourcingStrategy.java:77)
    at org.apache.wicket.markup.html.panel.PanelMarkupSourcingStrategy.onComponentTagBody(PanelMarkupSourcingStrategy.java:112)
    at org.apache.wicket.Component.internalRenderComponent(Component.java:2565)
    ... 49 more
Caused by: java.util.MissingResourceException: Unable to find property: 'teaser.contact.dataexchange.email' for component: content:dataexchange.email.link [class=Project B.EmailLink]. Locale: null, style: null
    at org.apache.wicket.Localizer.getString(Localizer.java:268)
    at org.apache.wicket.model.ResourceModel$AssignmentWrapper.load(ResourceModel.java:129)
    at org.apache.wicket.model.ResourceModel$AssignmentWrapper.load(ResourceModel.java:99)
    at org.apache.wicket.model.LoadableDetachableModel.getObject(LoadableDetachableModel.java:134)
    at org.apache.wicket.Component.getDefaultModelObject(Component.java:1626)
    ... 62 more

The property teaser.contact.dataexchange.email is defined in Project B, but never in Project A.
For production all these properties get written into one DB and then read from there, it's just the failing test. How can I resolve this issue?

like image 468
Peter Avatar asked Mar 11 '23 00:03

Peter


1 Answers

You need to help Wicket to find it.

In YourTest.java you need to do:

tester.getApplication().getResourceSettings().getStringResourceLoaders().add(loader)

If the properties are in SomeClassInB.properties then loader should be new ClassStringResourceLoader(SomeClassInB.class). Otherwise you can use any of the other implementations of IStringResourceLoader interface or create your own one that knows how to load the properties.

like image 192
martin-g Avatar answered Mar 20 '23 22:03

martin-g