Vim – tips and tricks

Record a macro that will delete everything after matching character and repeat it N-times.
In this example we’re going to use ‘=’ as the matching character.

qaf=DāŽq

Where:
‘qa’ – to start recording and save it under ‘a’ buffer
‘f=’ – find ‘=’ character
‘D’ – Delete everything to the EOL
‘āŽ’ – press ‘enter’ to go to the beginning of next line
‘q’ – to stop recording the macro

then to repeat the macro N-times, i.e. repeat it 5 times:

5@a

‘5’ – the number of times you’d like to repeat the macro
‘@a’ – play macro recorded under ‘a’ buffer

VIM macro delete everything after matching character and repeat N-times

VIM macro delete everything after matching character and repeat N-times

SoapUI: add custom query param to all service requests

I had a busy day today with SoapUI šŸ™‚

Another script for you guys, will add/remove query parameter to all service resources.

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

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

String paramName = "debug"
String paramValue = "true"
int addCnt = 0;
int remCnt = 0;
int errCnt = 0;
int noOfOper = ops.size()

for (RestResource res : ops)
{
	res.each{
		oper -> 
			Boolean result = toggleDebug(oper, paramName, paramValue)
			if ( result == null) 
				{ 
					errCnt++; 
				}
			else if (result) 
				{ 
					remCnt++; 
				}
			else if ( !result )
				{
					addCnt++;
				}
	}
}

log.info "DEBUG parameter was ADDED: " + addCnt + " times, REMOVED: " + remCnt + " times. Errors: " + errCnt + ". Number of all srvs operations: " + noOfOper

public Boolean toggleDebug(RestResource oper, String paramName, String paramValue)
{
		if ( oper.getProperties().containsKey(paramName) )
		{
			oper.removeProperty(paramName)
			log.info "DEBUG mode query param was REMOWED from operation: '"  + oper.getName() + "'"
			return true;
		}
		else
		{
			oper.addProperty(paramName)
			oper.getProperties()[paramName].setDefaultValue(paramValue)
			log.info "DEBUG mode query param was ADDED to operation: '"  + oper.getName() + "' with value: " + paramValue
			return false;
		}
		return null;
}

SoapUI: switching between different project configurations

Woohoo!

Today I’ve got another SoapUI script, that can be used to quickly change between project configurations for different environments, i.e.: DEV, STAGING, PROD etc.

Before you start executing the script below, create two text files in the same dir as your SoapUI project file, named:
DEV.properties
STAGE.properties

Once you’re done, execute the script.
In result it will create/update project property called “MainEdnpoint”.

Later on, you can take advantage of such property by replacing all the service endopoints by only one value:
${#Project#MainEdnpoint}
This way, all your request will point at the host you want to currently run test against. This is very simple & flexible way to manage you scripts for all different environments.

Same way you can add another property, like: “serviceContext” which will point at current context path independent from any changes made by devs/ops
To use this property, just change you service request path:
from i.e: /service-v0.1/listPosts
to: /${#Project#serviceContext}/listPosts

String env = "DEV"
def filename = context.expand( '${projectDir}'+File.separator+File.separator+env+'.properties' )
def file = new java.io.File( filename )

if( file.exists() )
{
	def props = new java.util.Properties()
	props.load( new java.io.FileReader( file ))

	def propsMap = [:]

	propsMap.put("MainEdnpoint", props.get( "MainEdnpoint" ) )
	// add your subsequent property names here

	propsMap.each() {
		key, value ->
		checkAndSetProperty(key, value)
	}
}
else log.info( "Missing [" + filename + "]" )


public void checkAndSetProperty(def propName, def prop)
{
	// get test project object
	def project = testRunner.testCase.testSuite.getProject()

	if( prop != null && prop.trim().length() > 0 ) 
	{
		project.setPropertyValue( propName , prop )
	}
	else
	{
		log.info( "Property " + propName + " in configuration file has an empty value. Project property was cleared!!!!" )
		project.setPropertyValue( propName , "" )
	}
}