How To Shorten the Length of a String Parameter
SOLVED- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
How To Shorten the Length of a String Parameter
Hi, Everybody!...
I wish to load test a SOAP web service. One of the parameters needs to be unique for each invocation. I am presently using ${=java.util.UUID.randomUUID()}. Lamentably, I am getting the following error: String '<some UUID string>' is too long (length: 36, maximum allowed: 35).
How can I shorten the length of the parameter?
Please advise.
Solved! Go to Solution.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Does it have to be 35 chars in length or will 13 suffice?
If the dynamic UUID generator is too long i tend to use a generator sourced via current timestamp in milliseconds.
I.e. ${=System.currentTimeMillis()} and this just generated the value of 1651104947608
Oh...all credit for this goes to @nmrao....he showed me this.
If you want to continue using a UUID, we could put a bit of groovy together to strip out the hyphens from the UUID, but that'll require a separate groovy script (about 2 lines) rather than just using the dynamic scripting ${=path.to.method()} approach
Cheers,
Rich
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
hello @juliobello
richie pointed you in a good direction. You can actually put full groovy script into the ${= } syntax...
Here is some groovy code that would work if it was in a groovy test step:
def tmpUUID = java.util.UUID.randomUUID().toString();
tmpUUID = tmpUUID.replaceAll("-", "");
return tmpUUID;
You can compress that and use it in place of your current dynamic property...
Instead of:
${=java.util.UUID.randomUUID()}
Try:
${=def tmpUUID=java.util.UUID.randomUUID().toString();tmpUUID=tmpUUID.replaceAll("-", "")}
Regards,
Todd
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi, Richie...
There is nothing "sacred" about the parameter format, other than the fact that it must be 35 characters or less. It does not have to be a UUID. It was the first "random string generator" I found. A timestamp in milliseconds will suffice.
I am new to this "groovy" scripting language. I am interested in knowing for my edification how to "substring" a string.
Where is the complete "groovy" scripting language library specification?
Thank-you!
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi, Todd...
I did not know that one can actually put full groovy script into the ${= } syntax.
I already accepted Richie's response as a solution. I don't know if I can also "accept" your solution.
I am new to this "groovy" scripting language. For my edification, I am interested in knowing how to "substring" a string.
Where is the complete "groovy" scripting language library specification?
Thank-you for your response.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
For future reference if @TNeuschwanger or @nmrao or @ChrisAdams or @KarelHusa suggests stuff, id always go with their approaches rather mine cos my groovy skills bite.....the only reason i know any groovy is cos the above lads taught me!
I've switched the Accepted Solution from mine to Todd's as this is the better "fix" in this case (and Todd's actually taught me something new, so nice one for that!)
Cheers,
Rich
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi, Richie...
Thank-you for getting back to me. Apparently, I can also accept your solution too!
Hi, @TNeuschwanger or @nmrao or @ChrisAdams or @KarelHusa
Where is the latest, complete, official "groovy" scripting language library specification?
Thank-you for your response.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
hello @juliobello
Groovy is supported by the Apache Software Foundation.
The latest, complete, official "groovy" scripting language library specification will be found at:
https://groovy-lang.org/documentation.html
Regards,
Todd
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank-you, Todd...
I'm assuming SmartBear's Groovy implementation is faithful to the groovy-lang.org documentation(?).
And here's a kudo... 😀
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
hello @juliobello
I will answer with my own assumption 🙂 ...
You can check out the version of groovy supported in ReadyAPI by reviewing the content of the "lib" folder where you installed ReadyAPI at. I suspect the Smartbear implementation is what they get from the groovy distribution from Apache and don't supply many if any adjustments to that.
The distribution of Groovy included in the most recent version of ReadyAPI (as seen by version number on groovy jar files) looks to be that of Groovy version 3.0.6.
The Groovy language is mature enough that any version greater that 2.0 covers everything I have ever needed from it. The topic of Smartbear implementation of Groovy has never crossed my mind since I have never encountered a conflict. I am perfectly satisfied with the implementation even though it seems to be a couple minor version increments behind.
Regards,
Todd
