Ticket #166 (closed defect: duplicate)

Opened 7 months ago

Last modified 2 months ago

TestScenario missing langtype attribute throws NPE

Reported by: fcohen Assigned to: llara@avanticatec.net
Priority: major Milestone:
Version: 5.1 Keywords: testscenario npe langtype
Cc:

Description

On Sep 29, 2007, at 12:25 AM, Lars Huttar wrote:

Well, that particular error was apparently caused by the fact that I was missing a langtype attribute on my <run> element:

<run module="ethnunit" name="test1" testclass="HTTPExample" method="runtest" />

After supplying langtype="jython", that particular NPE goes away. Hopefully that could be fixed to tell the user they're missing a langtype attribute, if it is indeed required.

Now I get a different set of errors:

java.lang.NullPointerException?

at java.io.FileInputStream?.<init>(Unknown Source) at java.io.FileInputStream?.<init>(Unknown Source) at java.io.FileReader?.<init>(Unknown Source) at com.pushtotest.testmaker.XSTest.xml.TestScenario.ScriptRunner?.argumentsFormCallScript(ScriptRunner?.java:488) at com.pushtotest.testmaker.XSTest.xml.TestScenario.ScriptRunner?.argumentsFromCall(ScriptRunner?.java:421) at com.pushtotest.testmaker.XSTest.xml.TestScenario.ScriptRunner?.setupMethodForTest(ScriptRunner?.java:225) at com.pushtotest.testmaker.XSTest.xml.TestScenario.ScriptRunner?.setMethods(ScriptRunner?.java:213) at com.pushtotest.testmaker.XSTest.xml.TestScenario.ScriptRunner?.<init>(ScriptRunner?.java:192) at com.pushtotest.testmaker.XSTest.xml.TestScenario.TestusecaseRunner?.runOneTime(TestusecaseRunner?.java:381) at com.pushtotest.testmaker.XSTest.xml.TestScenario.TestscenarioRunner?.runFunctionaltest(TestscenarioRunner?.java:288) at com.pushtotest.testmaker.XSTest.xml.TestScenario.TestscenarioRunner?.access$000(TestscenarioRunner?.java:91) at com.pushtotest.testmaker.XSTest.xml.TestScenario.TestscenarioRunner?$FunctionalTest?.run(TestscenarioRunner?.java:272)

Could it be that the ScriptRunner? cannot access your script file? Maybe something to do with the way the file path is written?

Turns out that the problem here is that the script runner class was opening the script file, catching exceptions, and ignoring them. :-( So when the problem bites you later, all you get is the NPE.

Attached is a patch to fix this, and the other problem (missing langtype not caught). Also, a typo fixed in the method name "argumentsFormCallScript()".

My fix for the missing langtype attribute is probably not ideal... I tested for it everywhere that I could see it would cause a NPE. Probably would be better to test for it when the <run> element is first processed, and reject it if there is no langtype attribute. But I don't know where to find that.

Note also, I have not yet been able to build TestMaker from source, so I don't know for sure that this patch compiles or works.

Lars

*** TestMaker/src/com/pushtotest/testmaker/XSTest/xml/TestScenario/ScriptRunner.java.orig Mon Aug 13 11:35:00 2007 --- TestMaker/src/com/pushtotest/testmaker/XSTest/xml/TestScenario/ScriptRunner.java Mon Oct 1 17:28:33 2007 *************** *** 236,241 **** --- 236,245 ----

*Need all calls */

public Method methodFromCall(CallT call){

+ if (!call.getLangtype()) { + System.out.println("Missing langtype attribute."); + return null; + }

if (call.getLangtype().equalsIgnoreCase("java")){

return methodFromCallJava(call);

} else if (call.getLangtype().equalsIgnoreCase("soapui")){

*************** *** 244,250 ****

return methodFromCallTestGen(call);

} else

return methodFromCallScript(call);

! /*System.out.println("Unknow languaje type");

return null;*/

}

--- 248,254 ----

return methodFromCallTestGen(call);

} else

return methodFromCallScript(call);

! /*System.out.println("Unknown language type");

return null;*/

}

*************** *** 378,389 ****

CallT otherCall = calls.get(i); if (otherCall.getName() != null &&

otherCall.getName().equalsIgnoreCase(call.getName()) && otherCall.getLangtype().equalsIgnoreCase(call.getLangtype())){ return objects.get(i);

}

}

}

! if (call.getLangtype().equalsIgnoreCase("soapui")){

return null;

} else if (call.getLangtype().equalsIgnoreCase("java")){

return objectFromCallJava(call);

--- 382,397 ----

CallT otherCall = calls.get(i); if (otherCall.getName() != null &&

otherCall.getName().equalsIgnoreCase(call.getName()) &&

+ otherCall.getLangtype() &&

otherCall.getLangtype().equalsIgnoreCase(call.getLangtype())){ return objects.get(i);

}

}

}

! if (!call.getLangtype()) { ! System.out.println("Missing langtype attribute."); ! return objectFromCallScript(call); ! } else if (call.getLangtype().equalsIgnoreCase("soapui")) {

return null;

} else if (call.getLangtype().equalsIgnoreCase("java")){

return objectFromCallJava(call);

*************** *** 411,424 ****

public Object[] argumentsFromCall(CallT call){

! if (call.getLangtype().equalsIgnoreCase("soapui"))

return this.argumentsFromCallSoapui(call);

else if (call.getLangtype().equalsIgnoreCase("java")){

return this.argumentsFromCallJava(Loader,call,dpls,actualMessageSize);

} else if (call.getLangtype().equalsIgnoreCase("TestGen4Web")){

return this.argumentsFromCallTestGen(call);

} else

! return argumentsFormCallScript(call,dpls,actualMessageSize);

}

--- 419,435 ----

public Object[] argumentsFromCall(CallT call){

! ! if (!call.getLangtype()) { ! System.out.println("Missing langtype attribute."); ! } else if (call.getLangtype().equalsIgnoreCase("soapui"))

return this.argumentsFromCallSoapui(call);

else if (call.getLangtype().equalsIgnoreCase("java")){

return this.argumentsFromCallJava(Loader,call,dpls,actualMessageSize);

} else if (call.getLangtype().equalsIgnoreCase("TestGen4Web")){

return this.argumentsFromCallTestGen(call);

} else

! return argumentsFromCallScript(call,dpls,actualMessageSize);

}

*************** *** 432,451 ****

private Object getScriptObject(CallT call){

for (CallT otherCall : scriptMap.keySet()){

if (otherCall.getName() != null &&

! otherCall.getName().equalsIgnoreCase(call.getName()) && ! otherCall.getLangtype().equalsIgnoreCase(call.getLangtype())){ ! return scriptMap.get(otherCall); ! }

} return null;

}

/**

*Create the arguments from the script

! *Alos it create the engines ! *that is istored in my obj*/

Object myobj;

! public Object[] argumentsFormCallScript (CallT call,HashMap? dpls,int amz){

Object argsScript[]; ScriptEngine? engine; if ("jython".equalsIgnoreCase(call.getLangtype())){

--- 443,462 ----

private Object getScriptObject(CallT call){

for (CallT otherCall : scriptMap.keySet()){

if (otherCall.getName() != null &&

! otherCall.getName().equalsIgnoreCase(call.getName()) && ! call.getLangType() && otherCall.getLangtype() && ! otherCall.getLangtype().equalsIgnoreCase(call.getLangtype())){ ! return scriptMap.get(otherCall); ! }

} return null;

}

/**

*Create the arguments from the script

! *Also create the engines that are stored in my obj */

Object myobj;

! public Object[] argumentsFromCallScript (CallT call,HashMap? dpls,int amz){

Object argsScript[]; ScriptEngine? engine; if ("jython".equalsIgnoreCase(call.getLangtype())){

*************** *** 483,489 ****

try {

java.net.URL myfile = new java.net.URL(file); file = myfile.getPath();

! } catch (Exception e){}

java.io.FileReader? f = new java.io.FileReader?(file);

--- 494,502 ----

try {

java.net.URL myfile = new java.net.URL(file); file = myfile.getPath();

! } catch (Exception e){ ! e.printStackTrace(); ! }

java.io.FileReader? f = new java.io.FileReader?(file);

*************** *** 846,855 ****

return;

//Not java not implemented String lang = call.getLangtype();

! if (lang.equalsIgnoreCase("java") && ! lang.equalsIgnoreCase("python")&& ! lang.equalsIgnoreCase("soapui") && ! lang.equalsIgnoreCase("testgen4web"))

return ;

if (lang.compareTo("python") == 0){

jythonCall(call);

--- 859,871 ----

return;

//Not java not implemented String lang = call.getLangtype();

! // This could never happen. Did he mean to put ! before equals...()? ! // Maybe this was changed from compareTo to equalsIgnoreCase, forgetting that ! // with the former, 0 means equal, and with the latter, true means equal. ! if (!lang.equalsIgnoreCase("java") && ! !lang.equalsIgnoreCase("python")&& ! !lang.equalsIgnoreCase("soapui") && ! !lang.equalsIgnoreCase("testgen4web"))

return ;

if (lang.compareTo("python") == 0){

jythonCall(call);

Change History

10/05/07 16:52:56 changed by fcohen

  • status changed from new to closed.
  • resolution set to duplicate.

03/11/08 10:33:39 changed by root

  • milestone changed.

Milestone release deleted