-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Hi all.
I'm trying to follow the documentation to write some unit test for my web application, however I always get a NullPointerException:
org.zkoss.zats.ZatsException at org.zkoss.zats.mimic.impl.EmulatorClient.connect(EmulatorClient.java:130) at x.y.z.testclass.fakeTest(UserManagementTest.java:50) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:601) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20) at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:30) at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222) at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28) at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:30) at org.junit.runners.ParentRunner.run(ParentRunner.java:300) 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: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)
Caused by: java.lang.NullPointerException at org.zkoss.zats.mimic.impl.DefaultDesktopAgent.getId(DefaultDesktopAgent.java:42) at org.zkoss.zats.mimic.impl.EmulatorClient.connect(EmulatorClient.java:109) ... 27 more
I digged into the code, and found the problem to be here:
desktopAgents.put(desktopAgent.getId(), desktopAgent);
in my case, desktopAgent is null.
The page I'm trying to connect to is a zul page that includes a login.zul page that submits username/password to jspringsecurity_check.
Do you have any workaround?
Thanks in advance, Massimiliano
The ZATS code I use is:
DefaultZatsEnvironment env = new DefaultZatsEnvironment("./src/main/webapp/WEB-INF");
env.init("./src/main/webapp");
env.newClient().connect("/public/index.zul"); // NullPointerException
Here is the index.zul page :
<?page title="${labels.a3serverweb.title}" contentType="text/html;charset=UTF-8"?>
<?taglib uri="http://www.zkoss.org/dsp/web/core" prefix="c"?>
<zk>
<borderlayout >
<north height="52px">
<borderlayout>
<west width="250px" sclass="a3-header-left"
border="none" />
<center border="none" sclass="a3-header-center" />
<east width="373px" sclass="a3-header-right"
border="none">
</east>
</borderlayout>
</north>
<west size="180px" style="background-color: darkgray;" collapsible="true" splittable="true">
<include src="loginHelp.zul"/>
</west>
<center autoscroll="true" >
<window style="background-color: white">
<include src="login.zul" />
</window>
</center>
</borderlayout>
</zk>
Below the included login.zul page:
<?page id="testZul" title="CUSTOM ZK + SPRING SECURITY LOGIN"?>
<vlayout width="100%">
<zscript>
String contextRoot = Executions.getCurrent().getContextPath();
</zscript>
<space orient="vertical" height="30px" />
<label sclass="z-header"
value="${labels.a3serverweb.admin.login.instructions}" />
<h:form id="f" name="f"
action="${contextRoot}/j_spring_security_check" method="POST"
xmlns:h="native">
<grid>
<columns>
<column hflex="min" />
<column hflex="min" />
<column />
</columns>
<rows>
<row>
<label
value="${labels.a3serverweb.admin.login.label.username}" />
<textbox id="u" name="j_username" />
<label />
</row>
<row>
<label
value="${labels.a3serverweb.admin.login.label.password}">
</label>
<textbox id="p" type="password"
name="j_password" />
<button type="submit" label="Login" iconSclass="z-icon-sign-in a3server-button-icon"/>
</row>
<row spans="3">
<html style="color:red"
if="${not empty param.login_error}">
<![CDATA[
${SPRING_SECURITY_LAST_EXCEPTION.message}
]]>
</html>
</row>
</rows>
</grid>
</h:form>
</vlayout>
Try
Zats.init("./src/main/webapp");
DesktopAgent desktop = Zats.newClient().connect("/public/index.zul");
No workaround for this bug?
Do the ZK team still follow this forum?
I think this is a high priority bug: if the test is not able to pass the login page, there's no way to use it at all...
Zk team follows this forum, got today answer from a team member of zk.
chillworld ( 2014-04-02 11:17:29 +0800 )editThank you. I was beginning to think they didn't follow this anymore since lately I wrote more than one bug and never got an answer.I've even opened issues with working ZK fiddles to replicate the problem, but no-one did even comment the jira issue (http://tracker.zkoss.org/browse/ZK-2154).
ziccardi ( 2014-04-02 11:39:04 +0800 )editIt take sometimes long, I just got 1 tracker resolved and a lot still open :). For your problem, with the zats, can't you put a user in the securitycontextholder so your authentication is already done?
chillworld ( 2014-04-02 12:23:40 +0800 )editAsked: 2014-04-01 13:26:17 +0800
Seen: 33 times
Last updated: Apr 02 '14
Do you use context/bindingsparams in the init/doaftercompose?
chillworld ( 2014-04-01 13:27:53 +0800 )editNo... both the index.zul page and the included login.zul page do not have viewmodel or composer.
ziccardi ( 2014-04-01 13:47:20 +0800 )edit