public static MockWsResponse createJson(String json) { return new MockWsResponse() .setContentType(MediaTypes.JSON) .setContentType(json); } }
private MockWsResponse newResponse() { return new MockWsResponse().setRequestUrl("https://local/api/issues/search"); }
@Test public void test_call() throws Exception { new BaseService(wsConnector, "api/issues") { public void test() throws IOException { GetRequest get = new GetRequest(path("issue")).setMediaType(MediaTypes.JSON); when(wsConnector.call(get)).thenReturn(new MockWsResponse().setContent("ok")); WsResponse response = call(get); assertThat(response.content()).isEqualTo("ok"); } }.test(); }
@Test public void fail_if_http_error() { new BaseService(wsConnector, "api/issues") { public void test() { GetRequest get = new GetRequest(path("issue")).setParam("key", "ABC"); when(wsConnector.call(get)).thenReturn(new MockWsResponse().setCode(403).setRequestUrl("https://local/foo").setContent("error")); try { call(get, Testing.Fake.parser()); fail(); } catch (HttpException e) { assertThat(e.code()).isEqualTo(403); } } }.test(); }
public void test() throws IOException { GetRequest get = new GetRequest(path("issue")).setMediaType(MediaTypes.JSON); when(wsConnector.call(get)).thenReturn(new MockWsResponse().setContent("ok")); WsResponse response = call(get); assertThat(response.content()).isEqualTo("ok"); }
public void test() { GetRequest get = new GetRequest(path("issue")).setParam("key", "ABC"); when(wsConnector.call(get)).thenReturn(new MockWsResponse().setCode(403).setRequestUrl("https://local/foo").setContent("error")); try { call(get, Testing.Fake.parser()); fail(); } catch (HttpException e) { assertThat(e.code()).isEqualTo(403); } }
private static WsResponse newProtobufFakeResponse() { Testing.Fake message = Testing.Fake.newBuilder().setLabel("ok").build(); return new MockWsResponse().setContent(message.toByteArray()); } }
public static MockWsResponse createJson(String json) { return new MockWsResponse() .setContentType(MediaTypes.JSON) .setContentType(json); } }