DefaultHttpJsonRequest implements HttpJsonRequest { @Override public HttpJsonResponse request() throws IOException, ServerException, UnauthorizedException, ForbiddenException, NotFoundException, ConflictException, BadRequestException { if (method == null) { throw new IllegalStateException("Could not perform request, request method wasn't set"); } return doRequest(timeout, url, method, body, queryParams); } protected  DefaultHttpJsonRequest(String url); protected  DefaultHttpJsonRequest(Link link); @Override HttpJsonRequest setMethod(@NotNull String method); @Override HttpJsonRequest setBody(@NotNull Object body); @Override HttpJsonRequest setBody(@NotNull Map<String, String> map); @Override HttpJsonRequest setBody(@NotNull List<?> list); @Override HttpJsonRequest addQueryParam(@NotNull String name, @NotNull Object value); @Override HttpJsonRequest setTimeout(int timeout); @Override HttpJsonResponse request();  }
@Test(expectedExceptions = BadRequestException.class) public void shouldThrowBadRequestExceptionWhenResponseCodeIs400(ITestContext ctx) throws Exception { new DefaultHttpJsonRequest(getUrl(ctx) + "/400/response-code-test").useGetMethod().request(); }
@Test(expectedExceptions = UnauthorizedException.class) public void shouldThrowUnauthorizedExceptionWhenResponseCodeIs401(ITestContext ctx) throws Exception { new DefaultHttpJsonRequest(getUrl(ctx) + "/401/response-code-test").useGetMethod().request(); }
@Test(expectedExceptions = ForbiddenException.class) public void shouldThrowForbiddenExceptionWhenResponseCodeIs403(ITestContext ctx) throws Exception { new DefaultHttpJsonRequest(getUrl(ctx) + "/403/response-code-test").useGetMethod().request(); }
@Test(expectedExceptions = NotFoundException.class) public void shouldThrowNotFoundExceptionWhenResponseCodeIs404(ITestContext ctx) throws Exception { new DefaultHttpJsonRequest(getUrl(ctx) + "/404/response-code-test").useGetMethod().request(); }
@Test(expectedExceptions = ConflictException.class) public void shouldThrowConflictExceptionWhenResponseCodeIs409(ITestContext ctx) throws Exception { new DefaultHttpJsonRequest(getUrl(ctx) + "/409/response-code-test").useGetMethod().request(); }
@Test(expectedExceptions = ServerException.class) public void shouldThrowServerExceptionWhenResponseCodeIs500(ITestContext ctx) throws Exception { new DefaultHttpJsonRequest(getUrl(ctx) + "/500/response-code-test").useGetMethod().request(); }
@Test(expectedExceptions = ServerException.class) public void shouldThrowServerExceptionWhenResponseWithAnyOtherResponseCode(ITestContext ctx) throws Exception { new DefaultHttpJsonRequest(getUrl(ctx) + "/501/response-code-test").useGetMethod().request(); }
@Test(expectedExceptions = IOException.class) public void shouldThrowIOExceptionIfServerReturnsTypeDifferentFromApplicationJson(ITestContext ctx) throws Exception { new DefaultHttpJsonRequest(getUrl(ctx) + "/text-plain").useGetMethod().request(); }
@Test public void shouldReadJsonObjectBodyAsString(ITestContext ctx) throws Exception { final DefaultHttpJsonRequest request = new DefaultHttpJsonRequest(getUrl(ctx) + "/application-json"); request.useGetMethod(); assertEquals(request.request().asString(), TestService.JSON_OBJECT); }
@Test public void shouldUseTokenFromCurrentContextForAuthorization(ITestContext ctx) throws Exception { final EnvironmentContext context = new EnvironmentContext(); context.setUser(TEST_USER); EnvironmentContext.setCurrent(context); new DefaultHttpJsonRequest(getUrl(ctx) + "/token").usePostMethod().request(); }