package testingWS;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
import com.sun.jersey.api.client.WebResource;
import com.sun.jersey.test.framework.AppDescriptor;
import com.sun.jersey.test.framework.JerseyTest;
import com.sun.jersey.test.framework.WebAppDescriptor;
//jettison reads and writes json
import org.codehaus.jettison.json.JSONException;
import org.codehaus.jettison.json.JSONObject;
public class TestingUsingJerseyTestFrameWork extends JerseyTest {
@Override
protected AppDescriptor configure() {
// traffic logging
// enable(TestProperties.LOG_TRAFFIC);
//If set to true the property enables basic logging of the request and response flow on both - client and server
return new WebAppDescriptor.Builder().build();
}
@Test
public void testUser() throws JSONException{
WebResource webResource = client().resource("http://localhost:8080/");
JSONObject json =webResource.path("/abc/users/id/12") .get(JSONObject.class);
// String jsonStringObj = json.toString();
//String jsonStringObj = json.toString();
// Gson gson = new Gson();
/* User obj = gson.fromJson(jsonStringObj, User.class);*/
assertEquals(12,json.get("id"));
assertEquals("Tim", json.get("firstName"));
assertEquals("Tester", json.get("lastName"));
}
@Test
public void testTrack() throws JSONException{
WebResource webResource = client().resource("http://localhost:8080/");
JSONObject json =webResource.path("/abc/users/get").get(JSONObject.class);
//String jsonStringObj = json.toString();
/* Gson gson = new Gson();
User obj = gson.fromJson(jsonStringObj, User.class);*/
assertEquals("Mr. Big",json.get("singer"));
assertEquals("Wild World", json.get("title"));
}
}
No comments:
Post a Comment