private Boolean castResultToBoolean(Object scriptResult2) { try { hasNext = (Boolean) scriptResult2; if (hasNext == null) { hasNext = false; SoapUI.ensureGroovyLog().error("You must return Boolean value from groovy script!"); } } catch (Exception e) { hasNext = false; SoapUI.ensureGroovyLog().error("You must return Boolean value from groovy script!"); } return hasNext; }
@Override protected void execute( SecurityTestRunner securityTestRunner, TestStep testStep, SecurityTestRunContext context) { scriptEngine.setScript(groovyscc.getExecuteScript().getStringValue()); scriptEngine.setVariable("context", context); scriptEngine.setVariable("testStep", testStep); scriptEngine.setVariable("securityScan", this); scriptEngine.setVariable("parameters", parameters); scriptEngine.setVariable("log", SoapUI.ensureGroovyLog()); try { scriptResult = scriptEngine.run(); hasNext = castResultToBoolean(scriptResult); XmlObjectTreeModel model = null; for (SecurityCheckedParameter scp : getParameterHolder().getParameterList()) { if (parameters.containsKey(scp.getLabel()) && parameters.get(scp.getLabel()) != null) { if (scp.isChecked() && scp.getXpath().trim().length() > 0) { model = SecurityScanUtil.getXmlObjectTreeModel(testStep, scp); XmlTreeNode[] treeNodes = null; treeNodes = model.selectTreeNodes(context.expand(scp.getXpath())); if (treeNodes.length > 0) { XmlTreeNode mynode = treeNodes[0]; mynode.setValue(1, parameters.get(scp.getLabel())); } updateRequestProperty(testStep, scp.getName(), model.getXmlObject().toString()); } else { updateRequestProperty(testStep, scp.getName(), parameters.get(scp.getLabel())); } } else if (parameters.containsKey(scp.getLabel()) && parameters.get(scp.getLabel()) == null) { // clears null values form parameters parameters.remove(scp.getLabel()); } } MessageExchange message = (MessageExchange) testStep.run((TestCaseRunner) securityTestRunner, context); createMessageExchange(clearNullValues(parameters), message, context); } catch (Exception e) { SoapUI.logError(e); hasNext = false; } finally { // if( scriptResult != null ) // { // getTestStep().getProperty( "Request" ).setValue( ( String // )scriptResult ); // // getTestStep().run( ( TestCaseRunner )securityTestRunner, // ( TestCaseRunContext )securityTestRunner.getRunContext() ); // } } }
public TestStepResult run(TestCaseRunner testRunner, TestCaseRunContext context) { SoapUI.ensureGroovyLog(); WsdlTestStepResult result = new WsdlTestStepResult(this); Logger log = (Logger) context.getProperty("log"); if (log == null) log = logger; try { if (scriptText.trim().length() > 0) synchronized (this) { scriptEngine.setVariable("context", context); scriptEngine.setVariable("testRunner", testRunner); scriptEngine.setVariable("log", log); result.setTimeStamp(System.currentTimeMillis()); result.startTimer(); scriptResult = scriptEngine.run(); result.stopTimer(); if (scriptResult != null) { result.addMessage("Script-result: " + scriptResult.toString()); // FIXME The property should not me hard coded firePropertyValueChanged("result", null, String.valueOf(result)); } } // testRunner status may have been changed by script.. Status testRunnerStatus = testRunner.getStatus(); if (testRunnerStatus == Status.FAILED) result.setStatus(TestStepStatus.FAILED); else if (testRunnerStatus == Status.CANCELED) result.setStatus(TestStepStatus.CANCELED); else result.setStatus(TestStepStatus.OK); } catch (Throwable e) { String errorLineNumber = GroovyUtils.extractErrorLineNumber(e); SoapUI.logError(e); result.stopTimer(); result.addMessage(e.toString()); if (errorLineNumber != null) result.addMessage("error at line: " + errorLineNumber); result.setError(e); result.setStatus(TestStepStatus.FAILED); } finally { if (!isForLoadTest()) setIcon(result.getStatus() == TestStepStatus.FAILED ? failedIcon : okIcon); if (scriptEngine != null) scriptEngine.clearVariables(); } return result; }
public Logger getLogger() { SoapUI.ensureGroovyLog(); return logger; }