Skip to content

Instantly share code, notes, and snippets.

@djangofan
Created May 20, 2012 21:37
Show Gist options
  • Save djangofan/2759637 to your computer and use it in GitHub Desktop.
Save djangofan/2759637 to your computer and use it in GitHub Desktop.
Example of testing a web service using Java com.jayway.restassured
package test.ra;
//import static com.jayway.restassured.specification.ResponseSpecification.*;
//import static com.jayway.restassured.matcher.RestAssuredMatchers.*;
//import static org.hamcrest.Matchers.*;
import static com.jayway.restassured.RestAssured.*;
import static com.jayway.restassured.path.xml.XmlPath.*;
import com.jayway.restassured.path.xml.element.Node;
// RestAssured source: http://grepcode.com/file/repo1.maven.org/maven2/com.jayway.restassured/rest-assured/1.6/com/jayway/restassured/RestAssured.java#RestAssured
// URL: http://services.aonaware.com/DictService/DictService.asmx/Define?word=string
// WSDL: http://services.aonaware.com/DictService/DictService.asmx?WSDL
public class RATest {
public static void main(String[] args) {
baseURI = "http://services.aonaware.com";
port = 80;
String defCandidate = "fastidious";
String xml = get("/DictService/DictService.asmx/Define?word=" + defCandidate ).andReturn().asString();
int items = from(xml).get("WordDefinition.Definitions.Definition.size()");
System.out.println("\n\n");
System.out.println("Number of definitions returned: " + items);
for( int i=0; i<items ; i++ ) {
int defNum = i + 1;
Node def = from(xml).get("WordDefinition.Definitions.Definition[" + i + "]");
String returnedWord = def.getNode("Word").value();
String dictName = def.getNode("Dictionary").getNode("Name").value();
String definition = def.getNode("WordDefinition").value();
System.out.println("Definition " + defNum + ": ");
System.out.println("Word: " + returnedWord );
System.out.println("Dictionary: " + dictName );
System.out.println("Definition: " + definition );
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment