Hey nmrao
Yay! ok - got it working - I was getting this weird error where instead of a 200 - it was failing and the returned status was 301 (permanently moved) - but I got it working - I ran the exact same test step (using the OTB functionality) and noticed that even though it's http - there must be some FWD or redirect cos the RAW of the OTB rest step indicated it was https.
Once I'd changed it to https in the script I started getting the 200!
Also - I wanted to parameterize the template parameters (see below) - but it wasn't working - I kept getting unable to find namespace response
i.e. i wanted to change this line
def binding = def binding [namespace : 'certification-nomenclature', dataset : 'certification-nomenclature']
parameterizing the namespace and dataset values so they are picked up from properties set on the testcase
i tried
def binding = [namespace : '${#TestCase#namespace}' , dataset : '${#TestCase#dataset}']
but I still got the 'unable to find namespace' message
so (after engaging my brain) I tried
def binding = [namespace : context.expand( '${#TestCase#namespace}') , dataset : context.expand('${#TestCase#dataset}')]
and it worked - yay!
SO - just in case anyone else needs to do this - I'm repeating the working script below:
import wslite.rest.*
def serviceHost = 'https://endpointvalue'
//Below to handle template parameter, additional $ required before
def getNamespaceDatasetPath = '''/api/1/${namespace}/${dataset}'''
//define all template param values as shown below - add as many as you want in here - the parameters are saved as properties on the TestCase object in the test
def binding = [namespace : context.expand( '${#TestCase#namespace}') , dataset : context.expand('${#TestCase#dataset}')]
def template = new groovy.text.SimpleTemplateEngine().createTemplate(getNamespaceDatasetPath)
def queryParams = [:]
//Get the properties of Property Test step - this code here grabs properties and their values and builds the REST requests Query Parameters (both names and values)
context.testCase.testSteps["Properties"].properties.each {
queryParams[it.key] = it.value.value
}
def client = new RESTClient(serviceHost)
def response = client.get(path: template.make(binding) as String,
accept: ContentType.JSON,
query : queryParams
)
assert response.statusCode == 200
log.info groovy.json.JsonOutput.prettyPrint(response.text)
Thank you!!!!!!!!
marking as solved, more Kudos and changing the title of the post so its a little more concise to enable people searching
richie