Forum Discussion
JHunt
8 years agoCommunity Hero
The Java code that you linked to works just fine as Groovy for me. I only made the syntax a bit more Groovy below, but I didn't need to in order to run it.
You have asked in the wrong forum for help with a DataGen (that would need to go to the SoapUI Pro forum), but we can do this with a Groovy script too:
Closure<Boolean> luhn = { String num ->
int sum = 0
boolean alternate = false
for (int i = num.length() - 1; i >= 0; i--) {
int n = Integer.parseInt(num.substring(i, i + 1))
if (alternate) {
n *= 2;
if (n > 9) {
n = (n % 10) + 1
}
}
sum += n
alternate = !alternate
}
return (sum % 10 == 0)
}
int next (Closure c, int x) {
final int MAX = 9999999999
for (i = x + 1; i <= MAX; i++) {
if (c(i.toString())) return i
}
throw new Exception ("No more in range")
}
int tin = 1234567890
(1..5).each {
tin = next (luhn, tin)
context.tin = tin
testRunner.runTestStepByName("SOAP Request")
}
return null
This is finding the next 5 numbers starting after 1234567890 and sending a test request for each of them. See the screenshot for how you might set up the test case. We are using the context to hold a value to be used in another step.