Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy does the controller not get injected when testing .zul page with Zats?
    primarykey
    data
    text
    <p>I am trying to implement a first Zats test and got stuck because of missing Spring dependency injection.</p> <p>The test with the code snippets from below goes green, but <em>doAfterCompose</em> is never called. It seems that the controller injection into the zul page does not work. Changing the <em>apply="${teamsPopupCtrl}"</em> to a full qualified name, the controller gets used, but <em>teamService</em> is null and I got a NullPointerException when <em>teamService.findAll()</em> is called from <em>doAfterCompose</em>. So again it seems that nothing gets injected.</p> <p>The ApplicationContext itself is loading without any error and using <em>@Autowired private TeamService teamService;</em> for verification in my test class works as expected. When firstTest is executed, teamService is not null.</p> <p>I also tried to use</p> <pre><code>&lt;?variable-resolver class="org.zkoss.zkplus.spring.DelegatingVariableResolver"?&gt; </code></pre> <p>in zul page but that only leads to</p> <pre><code>IOException: Server returned HTTP response code: 500 for URL: http://127.0.0.1:56851/teamsPopup.zul </code></pre> <p>which I could not specify any further.</p> <p><strong>Zul page:</strong></p> <pre><code>&lt;?page id="teamsPopup" title="layout" contentType="text/html;charset=UTF-8"?&gt; &lt;zk&gt; &lt;window apply="${teamsPopupCtrl}" width="400px" title="Fachteams" border="normal" closable="true"&gt; &lt;listbox id="teamsList" multiple="true" checkmark="true" width="380px" mold="paging" pageSize="10"&gt; &lt;listhead&gt;&lt;listheader label="Fachteams" /&gt;&lt;/listhead&gt; &lt;/listbox&gt; &lt;hbox height="10px" /&gt; &lt;toolbar mold="panel" align="center"&gt; &lt;button id="btnOk" forward="onOK" label="OK" mold="trendy" height="25px" width="120px" image="./images/ok.png" /&gt; &lt;button forward="onClose" label="Abbruch" mold="trendy" height="25px" width="120px" image="./images/cancel.png" /&gt; &lt;/toolbar&gt; &lt;/window&gt; &lt;/zk&gt; </code></pre> <p><strong>Test class:</strong></p> <pre><code>@RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = {"classpath:applicationContext/test-applicationContext.xml"}) public class TeamsPopupTest { @BeforeClass public static void beforeClass() throws Exception { Zats.init("./src/main/webapp/WEB-INF/pages/schemaOverview"); } @AfterClass public static void afterClass() throws Exception { Zats.end(); } @After public void after() throws Exception { Zats.cleanup(); } @Test public void firstTest() throws Exception { final DesktopAgent desktop = Zats.newClient().connect("/teamsPopup.zul"); } } </code></pre> <p><strong>Controller class:</strong></p> <pre><code>@Component @Scope(value = "prototype") public class TeamsPopupCtrl extends AbstractPopupCtrl { private static final long serialVersionUID = -1945118180857183121L; // ZK Autowire Listbox teamsList; @Autowired @Qualifier("teamsPopupModel") private PopupModel popupModel; @Autowired private TeamService teamService; // ZK Autowire private Listbox teamsBox; @Override public void doAfterCompose(final Window comp) throws Exception { super.doAfterCompose(comp); this.teamsList.setItemRenderer(new TeamListBoxRenderer()); this.teamsList.setModel(getFilteredTeamList()); } public SchemaModel getSchemaModel() { return (SchemaModel) getPerspectiveController().getCurrentPerspective().getModel(); } @SuppressWarnings({"unchecked", "rawtypes"}) public void onOK(final Event event) { final ListModelList&lt;?&gt; model = (ListModelList&lt;?&gt;) this.teamsList.getModel(); final List&lt;Team&gt; selectedTeams = new ArrayList(model.getSelection()); this.teamService.addTeamsToNodeInSchema(getSchemaModel().getCurrentNode(), selectedTeams); this.teamsBox.setModel(new ListModelList&lt;NodeTeamAssociation&gt;(getSchemaModel().getCurrentNode().getNodeTeamList())); doClosePopup(); if (!model.getSelection().isEmpty()) { modify(); } } @Override public void doOpenPopup(final org.zkoss.zul.Window window) { super.doOpenPopup(window); Executions.createComponents("/WEB-INF/pages/schemaOverview/teamsPopup.zul", getModel().getPopupWindow(), null); } private ListModelList&lt;Team&gt; getFilteredTeamList() { final Collection&lt;Team&gt; allTeams = new ArrayList&lt;Team&gt;(this.teamService.findAll()); for (final NodeTeamAssociation selectedTeam : getSchemaModel().getCurrentNode().getNodeTeamList()) { allTeams.remove(selectedTeam.getTeam()); } return new ListModelList&lt;Team&gt;(allTeams); } protected class TeamListBoxRenderer implements ListitemRenderer&lt;Team&gt;, Serializable { private static final long serialVersionUID = 8268285374821502239L; @Override public void render(final Listitem item, final Team teamdata, final int index) throws Exception { final Listcell lc = new org.zkoss.zul.Listcell(); lc.setLabel(teamdata.getName()); lc.setValue(teamdata); lc.setParent(item); TeamsPopupCtrl.this.teamsList.setMultiple(true); TeamsPopupCtrl.this.teamsList.setCheckmark(true); } } @Override protected PopupModel getModel() { return this.popupModel; } } </code></pre> <p>Does anyone have any idea how to get the test work with dependency injection or what I am missing in my test setup?</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