JSON Project
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
JSON Project
Now that my Groovy script is working, I am working to add the script to other projects. Most of my projects are XML so they are straight forward. I am one project which is JSON and I am not sure how to create testStep for it.
In this JSON, the working API has the following attributes:
1. Method: PUT
2. Endpoint: https://10.14.151.51:8443
3. Resource: /rem/sentinel/api/hssdata/subscriberdata/sip:+13313140097@ims.mnc130.mcc302.3gppnetwork.org
4. Parameters: ?selectionKey=Metaswitch::::&rhinoInstanceId=Local
Screenshot is attached. Tel-Number is the only input parameter to put in the Resource and the JSON body. So, my plan is to create a Groovy to read a file of Tel-number and then execute the testStep one by one.
Can I create a Groovy for JSON? I tried and somehow I cannot using property for Tel-Number in the Resource field.
Any help is appreciated.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Major improvement here. When I created the teststep, I used REST instead of HTTP. Now my Groovy is working (below) but I have challenge to produce a proper log.
For this particular API, it does not return any XML response is it is successful. If error, it would response with something like this:
<error>
<type>EntityNotFound</type>
<message>Subscriber data could not be found for IMS user identity "sip:+13313140098@ims.mnc330.mcc302.3gppnetwork.org" and selection key "Meswitch::::"</message>
</error>
With my Groovy below,
if the API is successful, my Groovy would throw an error "Null PointerException" because there is no XML response.
If the API fail, the Groovy would not output the 'type' and 'message'.
In summary, the Groovy can now execute the teststep but would not give me proper log.
----------------------------------------------------------------------------------------------------------------------------------------------
// TAS-PUT Input file: 13313140097
import java.text.SimpleDateFormat
def date = new Date()
def file_date = new SimpleDateFormat("dd_MM_yyyy_HH_mm_ss")
def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context)
def csvFilePath = "C:\\Gemalto-Groovy\\msisdn-list.csv"
def reportFile = "C:\\Gemalto-Groovy\\Reports\\TAS-PUT-"+file_date.format(date)+".log"
testRunner.testCase.setPropertyValue( "TARGET-1", "" )
context.fileReader = new BufferedReader(new FileReader(csvFilePath))
File report = new File(reportFile)
rowsData = context.fileReader.readLines()
int rowsize = rowsData.size()
report.text = "TAS-PUT "+file_date.format(date)
report << "\n"
for(int i =0; i < rowsize; i++)
{
def log_date = new Date()
def sdf = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss")
rowdata = rowsData[i]
String[] data = rowdata.split(",")
testRunner.testCase.setPropertyValue( "TARGET-1", data[0] )
testRunner.runTestStepByName( "PT-Groovy-TAS-PUT")
tStep = testRunner.testCase.getTestStepByName("PT-Groovy-TAS-PUT")
def xmlResponse = tStep.getPropertyValue("Response")
def holder = groovyUtils.getXmlHolder(xmlResponse)
def xml = new XmlSlurper().parseText(xmlResponse)
def MESSAGE1 = xml.error.@type.text()
def MESSAGE2 = xml.error.@message.text()
log.info " Seq="+i+" "+data[0] + " " + MESSAGE1 + " " + MESSAGE2
report << "\n"+"Seq="+i+" "+sdf.format(log_date)+" "+data[0] + " " + MESSAGE1 + " " + MESSAGE2
}
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Found something. I found the request status in the "raw" section of the response (2 responses below).
It would be great to output the http status (204, 404, etc), <error><type> and the fist 40 characters of </type><message> to the log file.
If successful:
HTTP/1.1 204
Set-Cookie: JSESSIONID=74923744E8EDE0851B18B94B038A3EF3; Path=/rem; Secure; HttpOnly
Date: Fri, 02 Jul 2021 20:35:53 GMT
If failed:
HTTP/1.1 404
Set-Cookie: JSESSIONID=32BFDA1AF3461B6B4EB81CFE1ED18770; Path=/rem; Secure; HttpOnly
Content-Type: application/xml
Content-Length: 280
Date: Fri, 02 Jul 2021 20:33:19 GMT
<?xml version="1.0" encoding="UTF-8" standalone="yes"?><error><type>EntityNotFound</type><message>Subscriber data could not be found for IMS user identity "sip:+13313140098@ims.mnc130.mcc302.3gppnetwork.org" and selection key "Metaswitch::::"</message></error>
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Sorry about these many posts. I worked on the Groovy today and I can now output some sort of log but the useful info (log.info below). I did try context.expand earlier but it did not work for me.
Based on the raw API responses on my previous post, I would like to output only the pertinent info like the http status (204, 404, etc), <error><type> if any and the first 40 characters of </type><message> if any.
Any suggestion is appreciated.
testRunner.testCase.setPropertyValue( "TARGET-1", data[0] )
testRunner.runTestStepByName( "PT-Groovy-TAS-PUT")
tStep = testRunner.testCase.getTestStepByName("PT-Groovy-TAS-PUT")
def header = tStep.getTestRequest().response.responseHeaders
log.info " Seq="+i+" "+data[0] + " " + header
report << "\n"+"Seq="+i+" "+sdf.format(log_date)+" "+data[0] + " " + header
Sat Jul 03 14:13:40 EDT 2021:INFO: Seq=0 14313140097 [#status#:[HTTP/1.1 204 ], Date:[Sat, 03 Jul 2021 18:13:40 GMT]]
Sat Jul 03 14:13:40 EDT 2021:INFO: Seq=1 14313140098 [#status#:[HTTP/1.1 404 ], Content-Length:[280], Date:[Sat, 03 Jul 2021 18:13:40 GMT], Content-Type:[application/xml]]
Sat Jul 03 14:13:40 EDT 2021:INFO: Seq=2 14313140883 [#status#:[HTTP/1.1 204 ], Date:[Sat, 03 Jul 2021 18:13:40 GMT]]
Sat Jul 03 14:13:41 EDT 2021:INFO: Seq=3 14313140884 [#status#:[HTTP/1.1 204 ], Date:[Sat, 03 Jul 2021 18:13:40 GMT]]
Sat Jul 03 14:13:41 EDT 2021:INFO: Seq=4 14313140928 [#status#:[HTTP/1.1 404 ], Content-Length:[280], Date:[Sat, 03 Jul 2021 18:13:41 GMT], Content-Type:[application/xml]]
Sat Jul 03 14:13:41 EDT 2021:INFO: Seq=5 14313140038 [#status#:[HTTP/1.1 404 ], Content-Length:[280], Date:[Sat, 03 Jul 2021 18:13:41 GMT], Content-Type:[application/xml]]
Sat Jul 03 14:13:42 EDT 2021:INFO: Seq=6 14313141288 [#status#:[HTTP/1.1 204 ], Date:[Sat, 03 Jul 2021 18:13:41 GMT]]
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Any suggestions to improve on my log output?
So far, by using “def header = tStep.getTestRequest().response.responseHeaders”, I can output the whole response to the API. This is OK but not ideal. When I execute the testStep thousands of times, I would like to import the log file into EXCEL to analyze the results. I am hoping to output only the following:
1. http status (204, 404, etc)
2. <error><type> if any
3. First 40 characters of </type><message>

- « Previous
-
- 1
- 2
- Next »
- « Previous
-
- 1
- 2
- Next »