logo       

RE: NullPointerException when invoking JUnit using Groovy Ant under Tomcat: msg#00156

lang.groovy.user

Subject: RE: NullPointerException when invoking JUnit using Groovy Ant under Tomcat

Trevor,

Thanks a lot for your feedback on this issue and to keep us informed about it.
I was clueless about your problem, and I'm sorry I could not help you.
That's great that your colleague solved it!

--
Guillaume Laforge
http://glaforge.free.fr/weblog


-----Message d'origine-----
De : Trevor Butler [mailto:Trevor.Butler-LVvIjLR0h5w@xxxxxxxxxxxxxxxx]
Envoyé : mercredi 27 octobre 2004 16:47
À : user-i9PBDF1N6cxnkHa44VUL00B+6BGkLq7r@xxxxxxxxxxxxxxxx
Cc : John W. Lewis; Jared Richardson
Objet : RE: [groovy-user] NullPointerException when invoking JUnit using
Groovy Ant under Tomcat


Just wanted to let the Groovy User community know that my colleague, John
Lewis, solved this problem.

The issue was not Groovy, but rather the way I was setting system properties to
pass into Junit. Here was the method I was using to set system properties - I
got the idea from Googling around online:

static public void setSysProperties(String key1, String val1,
String key2, String val2,
String key3, String val3 )
{
// Read current properties from the System environment
Properties p = System.getProperties();
p.setProperty(key1, val1);
p.setProperty(key2, val2);
p.setProperty(key3, val3);

// set the system properties
System.setProperties(p);
}

John changed the line:

Properties p = new Properties(System.getProperties())

To:

Properties p = System.getProperties()

The Properies constructor that was used takes a properties object as a
parameter. That parameter sets the defaults but does not actually add those as
properties. Later, Ant code (not Groovy) enumerates over the system properties
and adds more properties similar to what I was trying to do. Because all of
the "old" system properties are just defaults, they do not show up in the
enumeration. So, they are not passed on.

I guess this could be viewed as an Ant deficiency that was made visible by what
I was doing using the Properties constructor.

Here is the Ant code:

sys = System.getProperties();
Properties p = new Properties();
for (Enumeration e = sys.keys(); e.hasMoreElements();) {
Object o = e.nextElement();
p.put(o, sys.get(o));
}

They should enumerate with sys.propertyNames() instead. They would get the
defaults if they did that.

Regards,
Trevor Butler


-----Original Message-----
From: Trevor Butler [mailto:Trevor.Butler-LVvIjLR0h5w@xxxxxxxxxxxxxxxx]
Sent: Friday, October 22, 2004 4:39 PM
To: user-i9PBDF1N6cxnkHa44VUL00B+6BGkLq7r@xxxxxxxxxxxxxxxx
Subject: [groovy-user] NullPointerException when invoking JUnit using Groovy
Ant under Tomcat


The subject line is a mouthful! Here is what I am doing:

I needed a means to invoke JUnit within a web container within the same jvm, so
that I can pass system properties to the Junit test. Someone in my department
suggested using Groovy's Ant integration to invoke JUnit, which I have done.
When groovy invokes Junit, I get a nasty Exception. Here is a snippet of the
Tomcat console:

[junit] Running com.mycompany.MyTest
[junit] Tests run: 1, Failures: 0, Errors: 1, Time elapsed: 0 secnull
java.lang.NullPointerException
at java.io.Writer.write(Writer.java:126)
at
org.apache.tools.ant.util.DOMElementWriter.write(DOMElementWriter.java:113)
at
org.apache.tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter.endTestSuite(XMLJUnitResultFormatter.java:135)
at
org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.fireEndTestSuite(JUnitTestRunner.java:440)
at
org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.run(JUnitTestRunner.java:313)
at
org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.executeInVM(JUnitTask.java:954)
at
org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.execute(JUnitTask.java:626)
at
org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.execute(JUnitTask.java:600)
at org.apache.tools.ant.Task.perform(Task.java:364)
at groovy.util.AntBuilder.nodeCompleted(AntBuilder.java:115)
at groovy.util.BuilderSupport.doInvokeMethod(BuilderSupport.java:160)
at groovy.util.BuilderSupport.invokeMethod(BuilderSupport.java:85)
at org.codehaus.groovy.runtime.Invoker.invokeMethod(Invoker.java:130)
at
org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(InvokerHelper.java:106)
at com.sas.junit.JUnitInvoker.runJUnit(C:\JUnitInvoker.groovy:29)
at
gjdk.com.sas.junit.JUnitInvoker_GroovyReflector.invoke(JUnitInvoker_GroovyReflector.java)
at groovy.lang.MetaMethod.invoke(MetaMethod.java:110)
at groovy.lang.MetaClass.doMethodInvoke(MetaClass.java:1398)
at groovy.lang.MetaClass.invokeMethod(MetaClass.java:319)
at
gjdk.groovy.lang.MetaClass_GroovyReflector.invoke(MetaClass_GroovyReflector.java)
at groovy.lang.MetaMethod.invoke(MetaMethod.java:110)
at groovy.lang.MetaClass.doMethodInvoke(MetaClass.java:1398)
at groovy.lang.MetaClass.invokeMethod(MetaClass.java:319)
at org.codehaus.groovy.runtime.Invoker.invokeMethod(Invoker.java:143)
at
org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(InvokerHelper.java:106)
at com.mycompany.junit.JUnitInvoker.invokeMethod(C:\JUnitInvoker.groovy)
at com.mycompany.junit.caller.InvokerCaller.callJUnitInvoker(Unknown
Source)
at
com.mycompany.testserver.handler.EmpirixHandler.handleRequest(EmpirixHandler.java:150)
at
com.mycompany.testserver.RemoteControlTestService.handleRequest(RemoteControlTestService.java:201)
at
com.mycompany.testserver.RemoteControlTestService.doPost(RemoteControlTestService.java:62)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:237)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)
at
org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at
org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:198)
at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:152)
at
org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137)
at
org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
at
org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at
org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:929)
at
org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)
at
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799)
at
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705)
at
org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577)
at
org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
at java.lang.Thread.run(Thread.java:534)


>From the following post, it appears that the problem is caused by the Junit
>testcase name being null:
http://www.diasparsoftware.com/weblog/archives/00000004.html

Well, I think the name is being passed in by groovy (or Ant), when it creates
the Junit testcase (using the TestCase constructor).

Does anyone know if this is a Groovy bug, or if perhaps it can be fixed by
configuration changes, etc? I have been trying to figure it out for over two
days.

Thanks,
Trevor





<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise