Groovy Script set timezone for timestamp - groovy

I've been struggling to set the Time zone inside a GroovyScript. By now I have found out that the following code returns the actual time stamp from my location.
javax.xml.datatype.DatatypeFactory.newInstance()
.newXMLGregorianCalendar( GregorianCalendar.getInstance() ).toString()[0..21] + "Z"
Now I need it to return the date and time in UTC specifically, so it has the main server's timezone and could be run from any other location.
All these are run in a GroovyScript test step in SoapUi and it will be used as a variable inside a WSDL request.
Note: This will be used as a single liner in the Custom Properties of a Soap Project.

One of the solution:
System.setProperty('user.timezone', 'UTC')
def gc= new GregorianCalendar()
the second is:
c = Calendar.instance
c.timeZone = TimeZone.getTimeZone("UTC")
The first solution work with a GregorianCalanedar which easy to convert to xml date. But I think best solution work with Calendar.
I don't test these codes! Please check it!

Related

JDBC variable names when called in the groovy script not giving the correct value for a CSV parameterization

I have a JMeter test where a CSV file containing multiple rows of comma separated values example:- internalID,drivername, usreg,canadareg. I am basically using the CSV file to compare the values with the database table values. To compare the values to database values, I am adding a JDBC request with a query 'select internalID,drivername,usreg,canadareg from data where internalid ='${internalID'}' and providing the variables names to store the column data result. I use the groovy JSR233 and call the variables names in the script by declaring String a = vars.get("dintID_${counter}") where dintID is the variable name provided in the JDBC . The issue is when I run the script the first line of data in CSV files gets executed successfully, then the second line data in CSV file is passed to SQL statement correct, however the vars.get("dintid_${counter}") always stays at previous record meaning it does not go to next internalid(dintID). I have checked that my counter is incrementing. No idea how to resolve the issue. Does anyone know what mistake I am doing.
If you take a look at JSR223 Sampler documentation you will see that:
The JSR223 test elements have a feature (compilation) that can significantly increase performance. To benefit from this feature:
Use Script files instead of inlining them. This will make JMeter compile them if this feature is available on ScriptEngine and cache them.
Or Use Script Text and check Cache compiled script if available property.
When using this feature, ensure your script code does not use JMeter variables or JMeter function calls directly in script code as caching would only cache first replacement. Instead use script parameters.
So if the counter is a JMeter Variable - it will always be the initial value and it won't increment on subsequent iterations.
So you need to change the line to:
String a = vars.get('dintID_' + vars.get('counter'))
More information on Groovy scripting in JMeter: Apache Groovy - Why and How You Should Use It

SoapUI: Transfer groovy script results using Property Transfer

I am an absolute noob in SoapUI. I am looking out for answer on this but somehow could not really find it.
I am in a situation where I would like to transfer two of the groovy scripts's results to another Groovyscript. Unfortunately, while using Property Transfer, the destined groovy script gets fully overriden by the return value by the source script. How shall I approach this?
Please find below the example for the same:
As you may see, I would like to pass the value of the transferred result of generateCreated and generateNonce to the generatePassword script in testRunner.testCase.getPropertyValue("Nonce") and testRunner.testCase.getPropertyValue("Created")
But this just doesnt seem to work for me.
You don't need a Property Transfer teststep for that.
You just let your first two scripts run - as you already are doing.
Then in your third Groovy Script, you just pull the results into variables.
This can be done using something like
def result = context.expand( '${Groovy Script#result}' )
In your case above, I suspect you would adjust that to something like
def created = context.expand( '${generateCreated#result}' )
def nonce = context.expand( '${generateNonce#result}' )
Insert those lines in your script whereever you need those variables, and then you have the variables "created" and "nonce" holding the results.

Node.js - Oracle DB and fetchAsString format

I am stuck on a problem and I am not sure what is the best way to solve it. I have a date column that I want to select and I want to fetch it as a string. Which is great, node-oracledb module has this option with fetchAsString mehotd. But it fetches the date like this for example 10-JAN-16 and I want to fetch it like this 10-01-2016. Is there a way to do that from the node-oracledb module, or I should modify the date after I get the result from the query?
UPDATE: I mean solution without to_char in the query and without query modifications
Check out this section of my series on Working with Dates in JavaScript, JSON, and Oracle Database:
https://dzone.com/articles/working-with-dates-using-the-nodejs-driver
The logon trigger shows an example of using alter session to set the default date format. Keep in mind that there is NLS_DATE_FORMAT, NLS_TIMESTAMP_FORMAT, NLS_TIMESTAMP_TZ_FORMAT.
I only show NLS_TIMESTAMP_TZ_FORMAT because I convert to that type in the examples that follow as I need to do some time zone conversion for the date format I'm using.
Another way to set the NLS parameters is to use environment variables of the same name. Note that this method will not work unless you set the NLS_LANG environment variable as well.

Call test suite property within the request in SoapUi

all
I am using free version of SoapUI.
What I have is a test suite with many test cases. In each test case there is a request where I need to specify a date. So I want to create a general script for all cases and just call the result of it in each request I need.
What I do:
1. I have test suite SaveOperation where in SetupScript window at the bottom I write script:
def sdf = new java.text.SimpleDateFormat("yyyy-MM-dd")
def windowClosed = sdf.format(new Date()-20)
log.info(windowClosed)
2. In this test suite I have many test cases as I wrote. So when for example in test case named SaveValid I need to specify Date parameter I write the following right in the xml request (in date parameter):
${#SaveOperation#windowClosed}
But it doesn't work. Could anyone suggest what is wrong with this way?
thank you in advance
You have the correct approach. log.info() will only write the information to a log.
change
log.info(windowClosed)
to
testSuite.setPropertyValue("windowClosed", windowClosed.toString())
and then refer to it as:
${#TestSuite#windowClosed}

getXmlHolder and context.expand - What does the arguments description mean

I am trying to insert values into the Request and Capture the response from the soapui pro Testsuite/testcase/testStep, using groovy script, without creating any property or assertions using soapui pro wizard. Everything i am trying to do using groovy script file in Soapui pro. But after 11 days of my self learning process I am forced to ask the in the forum:
I went thru almost 100 sites talking about how to capture request/response value.
But none explains the following:
getXmlHolder ("DeliverStatus#Request")
what does "deliveryStatus" & "Request" means and what does it contains. Which part of xml file is it. What does it signify
context.expand
For all my attempts i have got Null exception.
But i have been able to successfull script using groovy in the "Script tab in the Response section". But unable to do in using testsuite Groovy Script.
Please help.. Thanking all in advance
Regards
Am
DeliverStatus is basically meaningless - it is the name of your test step.
Request means that you look at the XML request that will be sent by SoapUI.
You can replace Request with Response and get the result of the API call.
context.expend allows you to get the value of the request or the response as well as specific XPaths within them. I'm not familiar with the getXmlHolder method - but it looks like it gets an XML string as input (can be a fragment) and turns it into an object you can work with.
My recommendation - if you are not using it already, is to right click on the Groovy editing area and choose Get Data --> Test Suite --> Test Case --> Test Step --> Response --> and navigate to the path in the response to which you want to access.
This will set the value of that XML fragment into a string variable of your choosing.
Afterwards you can use the getXmlHolder to convert that string into an object.
I also recommend using the XmlSlurper for parsing an XML string into an object.

Resources