Submit and vote on feature ideas.

Welcome to the new Parasoft forums! We hope you will enjoy the site and try out some of the new features, like sharing an idea you may have for one of our products or following a category.

Custom Assertions in Java

Options
LegacyForum
LegacyForum Posts: 1,664 ✭✭
edited December 2016 in SOAtest
Hello Everyone,

Below is an example of a Java script that can be used as a custom assertion in an assertor tool in SOAtest. This script gets a value from a data source, prints that value along with the response value, and returns a boolean value based on whether or not the response value contains the data source value.

CODE
package examples;

import com.parasoft.api.*;

public class Comparison {

//Compares a value from a database data source to a value returned in a SOAP response
public boolean compareToDatabase(Object input, ScriptingContext context)
throws com.parasoft.data.DataSourceException {

//Gets values from database data source named "Books"
String value = context.getValue("Books", "Book");

//Prints database data source values along with SOAP response values in a message to the console
Application.showMessage("Value from database is " + value + ".\nValue from SOAP response is " + input.toString() + ".");

//Verifies that the SOAP response value contains the database data source value
return input.toString().contains(value);
}

}


Enjoy!

Regards,
Adam
Tagged:

Tagged