package jboss.ws;
import static org.junit.Assert.assertEquals;
import java.io.IOException;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.methods.GetMethod;
import org.junit.Test;
public class TestRestPersonService {
@Test
public void testGetXml() throws HttpException, IOException {
HttpClient client = new HttpClient();
GetMethod method = new GetMethod(
"http://localhost:8080/iJBossWS/rest/personservice/xml/person/David/F");
int status = client.executeMethod(method);
assertEquals(200, status);
String returnedValue = method.getResponseBodyAsString();
String expectedValue = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><person><firstName>David</firstName><lastName>F</lastName></person>";
assertEquals(expectedValue, returnedValue);
}
@Test
public void testGetJSON() throws HttpException, IOException {
HttpClient client = new HttpClient();
GetMethod method = new GetMethod(
"http://localhost:8080/iJBossWS/rest/personservice/json/person/David/F");
int status = client.executeMethod(method);
assertEquals(200, status);
String returnedValue = method.getResponseBodyAsString();
System.out.println(returnedValue);
String expectedValue = "{\"firstName\":\"David\",\"lastName\":\"F\"}";
assertEquals(expectedValue, returnedValue);
}
}