Note that there are some explanatory texts on larger screens.

plurals
  1. POUnit testing ModalWindow's content refresh fails while the actual functionality works as expected - what am I doing wrong?
    primarykey
    data
    text
    <p>So, I've spent a couple of hours first trying to "fix" this myself and then Googling like a madman but didn't find anything that would've helped so now I'm here.</p> <p>Basically I have a custom <code>Panel</code> within Wicket's own <code>ModalWindow</code> and since I like unit testing, I want to test it. The specific behavior here is refreshing the <code>ModalWindow</code>'s content: In my actual code from where I extracted this the Ajax event handling actually reloads new stuff to the content panel, I just removed those to make this shorter.</p> <p>So, here's the <code>Panel</code>'s code</p> <pre><code>package wicket.components; import org.apache.wicket.ajax.AjaxRequestTarget; import org.apache.wicket.ajax.markup.html.form.AjaxButton; import org.apache.wicket.extensions.ajax.markup.html.modal.ModalWindow; import org.apache.wicket.markup.html.form.Form; import org.apache.wicket.markup.html.panel.Panel; import org.apache.wicket.model.*; public class MyModalWindowPanel extends Panel { private Form form; private ModalWindow modal; public MyModalWindowPanel(String id, ModalWindow modal) { super(id); this.setOutputMarkupId(true); this.modal = modal; initializeForm(); addBasicDataFieldsToForm(); add(campaignForm); } private void initializeForm() { form = new Form("form"); form.setOutputMarkupId(true); } private void addBasicDataFieldsToForm() { campaignForm.add(new AjaxButton("infoSubmit", new Model&lt;String&gt;("Ajaxy Click")) { protected void onSubmit(AjaxRequestTarget target, Form&lt;?&gt; form) { modal.setContent(new MyModalWindowPanel(modal.getContentId(), modal)); modal.show(target); } }); } } </code></pre> <p>and the corresponding markup</p> <pre><code>&lt;wicket:panel&gt; &lt;form wicket:id="form"&gt; &lt;input type="submit" value="Ajaxy Click" wicket:id="infoSubmit" /&gt; &lt;/form&gt; &lt;/wicket:panel&gt; </code></pre> <p><strong>Do note that when run in servlet container such as Tomcat, this works correctly - there's no functional bugs here!</strong></p> <p>So what's the problem then? I'm not seemingly able to get the <em>unit test</em> for this to work! My test class for the panel looks like this</p> <pre><code>package wicket.components; import org.apache.wicket.extensions.ajax.markup.html.modal.ModalWindow; import org.apache.wicket.markup.html.panel.Panel; import org.apache.wicket.util.tester.*; import junit.framework.TestCase; public class MyModalWindowPanelTestCase extends TestCase { private WicketTester tester; private ModalWindow modal; @Override protected void setUp() throws Exception { tester = new WicketTester(); modal = new ModalWindow("modal"); tester.startPanel(new TestPanelSource() { public Panel getTestPanel(String id) { return new MyModalWindowPanel(id, modal); } }); } public void testReloadingPanelWorks() throws Exception { // the next line fails! tester.executeAjaxEvent("panel:campaignForm:campaignInfoSubmit", "onclick"); tester.assertNoErrorMessage(); } } </code></pre> <p>and here's the resulting stacktrace of running that</p> <pre><code>java.lang.IllegalStateException: No Page found for component [MarkupContainer [Component id = modal]] at org.apache.wicket.Component.getPage(Component.java:1763) at org.apache.wicket.RequestCycle.urlFor(RequestCycle.java:872) at org.apache.wicket.Component.urlFor(Component.java:3295) at org.apache.wicket.behavior.AbstractAjaxBehavior.getCallbackUrl(AbstractAjaxBehavior.java:124) at org.apache.wicket.ajax.AbstractDefaultAjaxBehavior.getCallbackScript(AbstractDefaultAjaxBehavior.java:118) at org.apache.wicket.ajax.AbstractDefaultAjaxBehavior.getCallbackScript(AbstractDefaultAjaxBehavior.java:106) at org.apache.wicket.extensions.ajax.markup.html.modal.ModalWindow$WindowClosedBehavior.getCallbackScript(ModalWindow.java:927) at org.apache.wicket.extensions.ajax.markup.html.modal.ModalWindow.getWindowOpenJavascript(ModalWindow.java:1087) at org.apache.wicket.extensions.ajax.markup.html.modal.ModalWindow.show(ModalWindow.java:352) at wicket.components.MyModalWindowPanel$1.onSubmit(MyModalWindowPanel.java:45) at org.apache.wicket.ajax.markup.html.form.AjaxButton$1.onSubmit(AjaxButton.java:102) at org.apache.wicket.ajax.form.AjaxFormSubmitBehavior.onEvent(AjaxFormSubmitBehavior.java:143) at org.apache.wicket.ajax.AjaxEventBehavior.respond(AjaxEventBehavior.java:177) at org.apache.wicket.ajax.AbstractDefaultAjaxBehavior.onRequest(AbstractDefaultAjaxBehavior.java:299) at org.apache.wicket.util.tester.BaseWicketTester.executeAjaxEvent(BaseWicketTester.java:1236) at org.apache.wicket.util.tester.BaseWicketTester.executeAjaxEvent(BaseWicketTester.java:1109) at wicket.components.MyModalWindowPanelTestCase.testReloadingPanelWorks(MyModalWindowPanelPanelTestCase.java:31) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at junit.framework.TestCase.runTest(TestCase.java:168) at junit.framework.TestCase.runBare(TestCase.java:134) at junit.framework.TestResult$1.protect(TestResult.java:110) at junit.framework.TestResult.runProtected(TestResult.java:128) at junit.framework.TestResult.run(TestResult.java:113) at junit.framework.TestCase.run(TestCase.java:124) at junit.framework.TestSuite.runTest(TestSuite.java:232) at junit.framework.TestSuite.run(TestSuite.java:227) at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:81) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:46) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197) </code></pre> <p>So, <strong>how can/should I fix my unit test so that it would pass?</strong></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload