Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. package jboss.ws;
  2.  
  3. import static org.junit.Assert.assertEquals;
  4.  
  5. import java.io.IOException;
  6.  
  7. import org.apache.commons.httpclient.HttpClient;
  8. import org.apache.commons.httpclient.HttpException;
  9. import org.apache.commons.httpclient.methods.GetMethod;
  10. import org.junit.Test;
  11.  
  12. public class TestRestPersonService {
  13.  
  14.     @Test
  15.     public void testGetXml() throws HttpException, IOException {
  16.         HttpClient client = new HttpClient();
  17.         GetMethod method = new GetMethod(
  18.                 "http://localhost:8080/iJBossWS/rest/personservice/xml/person/David/F");
  19.         int status = client.executeMethod(method);
  20.         assertEquals(200, status);
  21.         String returnedValue = method.getResponseBodyAsString();
  22.         String expectedValue = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><person><firstName>David</firstName><lastName>F</lastName></person>";
  23.         assertEquals(expectedValue, returnedValue);
  24.     }
  25.  
  26.     @Test
  27.     public void testGetJSON() throws HttpException, IOException {
  28.         HttpClient client = new HttpClient();
  29.         GetMethod method = new GetMethod(
  30.                 "http://localhost:8080/iJBossWS/rest/personservice/json/person/David/F");
  31.         int status = client.executeMethod(method);
  32.         assertEquals(200, status);
  33.         String returnedValue = method.getResponseBodyAsString();
  34.         System.out.println(returnedValue);
  35.         String expectedValue = "{\"firstName\":\"David\",\"lastName\":\"F\"}";
  36.         assertEquals(expectedValue, returnedValue);
  37.     }
  38.  
  39. }