SoapUI: change paths for all REST service resources

Phew…
Finally I’ve managed to find a way to change all the resource paths in SoapUI’s REST service resources.

This solution can be helpful if you need to quickly add/change path parameter(s) to/in all service requests.

Quick explanation: Script below adds/removes a “?debug” or “&debug” param to all resource defined in your REST service.

import com.eviware.soapui.impl.rest.RestResource

def project = testRunner.testCase.testSuite.getProject()
String restServiceName = "your_rest_service_name"
List<RestResource> ops = project.getInterfaces()[restServiceName].getOperationList()

for (RestResource res : ops)
{
	res.each{
		op -> toggleDebug(op)
	}
}

public void toggleDebug(RestResource op)
{
	String path = op.getFullPath();

	if ( path.contains("&debug") || path.contains("?debug") )
	{
		if (path.contains("&debug"))
			{
				path = path.replaceAll("&debug","")
			}
		if (path.contains("/?debug"))
			{
				path = path.replaceAll("\\?debug","")
			}
		op.setPath(path)
		log.info "DEBUG mode DISABLED for operation: '" + op.getName() + "'. New path: "  + path
	}
	else
	{
		if (path.contains("?"))
			{
				path += "&debug"
			}
		else
			{
				path += "?debug"
			}
		op.setPath(path)
		log.info "DEBUG mode ENABLED for operation: '" + op.getName() + "'. New path: "  + path
	}
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s