HttpRestClient { public String sendRequest(final String sessionId, Request request) throws SDKBadRequestException { if (request.getType() == null) { throw new SDKBadRequestException(SDKErrorEnum.badRequestError, "Request type (method) is missing!"); } URI uri = buildURI(request); LOGGER.debug("Using URL: " + uri.toString()); HttpRequestBase requestBase; switch (request.getType()) { case POST: HttpPost post = new HttpPost(uri); fillRequestEntity(post, request); requestBase = post; break; case GET: requestBase = new HttpGet(uri); break; case PATCH: HttpPatch patch = new HttpPatch(uri); fillRequestEntity(patch, request); requestBase = patch; break; case PUT: HttpPut put = new HttpPut(uri); fillRequestEntity(put, request); requestBase = put; break; case DELETE: requestBase = new HttpDelete(uri); break; default: LOGGER.error("Request type not supported."); throw new SDKBadRequestException(SDKErrorEnum.badRequestError, SdkConstants.APPLIANCE); } for (Header header : request.getHeaders()) { requestBase.addHeader(header); } if (StringUtils.isNotBlank(sessionId)) { requestBase.setHeader(SdkConstants.AUTH_HEADER, sessionId); } return getResponse(sessionId, requestBase, request.isForceReturnTask(), request.getDownloadPath()); } HttpRestClient(SDKConfiguration sdkConfiguration, SSLContext sslContext); @VisibleForTesting protected  HttpRestClient(SDKConfiguration sdkConfiguration,
            ObjectToJsonConverter converter,
            CloseableHttpClient httpClient); void shutdown(); String sendRequest(final String sessionId, Request request);  }
@Test public void testSendRequestPost() { Mockito.when(responseStatus.getStatusCode()).thenReturn(201); String result = restClient.sendRequest(SESSION_ID, new Request(HttpMethod.POST, "")); assertNotNull(result); }
@Test public void testSendRequestResetResponse() { Mockito.when(responseStatus.getStatusCode()).thenReturn(205); String result = restClient.sendRequest(SESSION_ID, new Request(HttpMethod.GET, "")); assertNotNull(result); }
@Test public void testSendRequestPartialResponse() { Mockito.when(responseStatus.getStatusCode()).thenReturn(206); String result = restClient.sendRequest(SESSION_ID, new Request(HttpMethod.GET, "")); assertNotNull(result); }
@Test (expected = SDKApplianceNotReachableException.class) public void testSendRequestMultiChoiceResponse() { Mockito.when(responseStatus.getStatusCode()).thenReturn(300); restClient.sendRequest(SESSION_ID, new Request(HttpMethod.GET, "")); fail("Exception should have been raised"); }
@Test (expected = SDKApplianceNotReachableException.class) public void testSendRequestMovedPermResponse() { Mockito.when(responseStatus.getStatusCode()).thenReturn(301); restClient.sendRequest(SESSION_ID, new Request(HttpMethod.GET, "")); fail("Exception should have been raised"); }
@Test (expected = SDKApplianceNotReachableException.class) public void testSendRequestMovedTempResponse() { Mockito.when(responseStatus.getStatusCode()).thenReturn(302); restClient.sendRequest(SESSION_ID, new Request(HttpMethod.GET, "")); fail("Exception should have been raised"); }
@Test (expected = SDKApplianceNotReachableException.class) public void testSendRequestSeeOtherResponse() { Mockito.when(responseStatus.getStatusCode()).thenReturn(303); restClient.sendRequest(SESSION_ID, new Request(HttpMethod.GET, "")); fail("Exception should have been raised"); }
@Test (expected = SDKApplianceNotReachableException.class) public void testSendRequestNotModifiedResponse() { Mockito.when(responseStatus.getStatusCode()).thenReturn(304); restClient.sendRequest(SESSION_ID, new Request(HttpMethod.GET, "")); fail("Exception should have been raised"); }
@Test (expected = SDKApplianceNotReachableException.class) public void testSendRequestUseProxyResponse() { Mockito.when(responseStatus.getStatusCode()).thenReturn(305); restClient.sendRequest(SESSION_ID, new Request(HttpMethod.GET, "")); fail("Exception should have been raised"); }
@Test (expected = SDKBadRequestException.class) public void testSendRequestBadRequestResponse() { Mockito.when(responseStatus.getStatusCode()).thenReturn(400); restClient.sendRequest(SESSION_ID, new Request(HttpMethod.GET, "")); fail("Exception should have been raised"); }
@Test (expected = SDKUnauthorizedException.class) public void testSendRequestUnauthorizedResponse() { Mockito.when(responseStatus.getStatusCode()).thenReturn(401); restClient.sendRequest(SESSION_ID, new Request(HttpMethod.GET, "")); fail("Exception should have been raised"); }
@Test public void testSendRequestPostNoBody() { String result = restClient.sendRequest(SESSION_ID, new Request(HttpMethod.POST, "")); assertNotNull(result); }
@Test (expected = SDKApplianceNotReachableException.class) public void testSendRequestPaymentRequiredResponse() { Mockito.when(responseStatus.getStatusCode()).thenReturn(402); restClient.sendRequest(SESSION_ID, new Request(HttpMethod.GET, "")); fail("Exception should have been raised"); }
@Test (expected = SDKForbiddenException.class) public void testSendRequestForbiddenResponse() { Mockito.when(responseStatus.getStatusCode()).thenReturn(403); restClient.sendRequest(SESSION_ID, new Request(HttpMethod.GET, "")); fail("Exception should have been raised"); }
@Test (expected = SDKResourceNotFoundException.class) public void testSendRequestNotFoundResponse() { Mockito.when(responseStatus.getStatusCode()).thenReturn(404); restClient.sendRequest(SESSION_ID, new Request(HttpMethod.GET, "")); fail("Exception should have been raised"); }
@Test (expected = SDKMethodNotAllowed.class) public void testSendRequestBadMethodResponse() { Mockito.when(responseStatus.getStatusCode()).thenReturn(405); restClient.sendRequest(SESSION_ID, new Request(HttpMethod.GET, "")); fail("Exception should have been raised"); }
@Test (expected = SDKApplianceNotReachableException.class) public void testSendRequestNotAcceptableResponse() { Mockito.when(responseStatus.getStatusCode()).thenReturn(406); restClient.sendRequest(SESSION_ID, new Request(HttpMethod.GET, "")); fail("Exception should have been raised"); }
@Test (expected = SDKApplianceNotReachableException.class) public void testSendRequestProxyAuthResponse() { Mockito.when(responseStatus.getStatusCode()).thenReturn(407); restClient.sendRequest(SESSION_ID, new Request(HttpMethod.GET, "")); fail("Exception should have been raised"); }
@Test (expected = SDKApplianceNotReachableException.class) public void testSendRequestClientTimeoutResponse() { Mockito.when(responseStatus.getStatusCode()).thenReturn(408); restClient.sendRequest(SESSION_ID, new Request(HttpMethod.GET, "")); fail("Exception should have been raised"); }
@Test (expected = SDKInternalServerErrorException.class) public void testSendRequestConflictResponse() { Mockito.when(responseStatus.getStatusCode()).thenReturn(409); restClient.sendRequest(SESSION_ID, new Request(HttpMethod.GET, "")); fail("Exception should have been raised"); }
@Test (expected = SDKApplianceNotReachableException.class) public void testSendRequestGoneResponse() { Mockito.when(responseStatus.getStatusCode()).thenReturn(410); restClient.sendRequest(SESSION_ID, new Request(HttpMethod.GET, "")); fail("Exception should have been raised"); }
@Test (expected = SDKApplianceNotReachableException.class) public void testSendRequestLengthRequiredResponse() { Mockito.when(responseStatus.getStatusCode()).thenReturn(411); restClient.sendRequest(SESSION_ID, new Request(HttpMethod.GET, "")); fail("Exception should have been raised"); }
@Test public void testSendRequestGet() { String result = restClient.sendRequest(SESSION_ID, new Request(HttpMethod.GET, "")); assertNotNull(result); }
@Test (expected = SDKInternalServerErrorException.class) public void testSendRequestPreconFailedResponse() { Mockito.when(responseStatus.getStatusCode()).thenReturn(412); restClient.sendRequest(SESSION_ID, new Request(HttpMethod.GET, "")); fail("Exception should have been raised"); }
@Test (expected = SDKApplianceNotReachableException.class) public void testSendRequestEntityTooLargeResponse() { Mockito.when(responseStatus.getStatusCode()).thenReturn(413); restClient.sendRequest(SESSION_ID, new Request(HttpMethod.GET, "")); fail("Exception should have been raised"); }
@Test (expected = SDKApplianceNotReachableException.class) public void testSendRequestUriTooLongResponse() { Mockito.when(responseStatus.getStatusCode()).thenReturn(414); restClient.sendRequest(SESSION_ID, new Request(HttpMethod.GET, "")); fail("Exception should have been raised"); }
@Test (expected = SDKInternalServerErrorException.class) public void testSendRequestUnsupportedTypeResponse() { Mockito.when(responseStatus.getStatusCode()).thenReturn(415); restClient.sendRequest(SESSION_ID, new Request(HttpMethod.GET, "")); fail("Exception should have been raised"); }
@Test (expected = SDKInternalServerErrorException.class) public void testSendRequestInternalErrorResponse() { Mockito.when(responseStatus.getStatusCode()).thenReturn(500); restClient.sendRequest(SESSION_ID, new Request(HttpMethod.GET, "")); fail("Exception should have been raised"); }
@Test (expected = SDKApplianceNotReachableException.class) public void testSendRequestNotImplementedResponse() { Mockito.when(responseStatus.getStatusCode()).thenReturn(501); restClient.sendRequest(SESSION_ID, new Request(HttpMethod.GET, "")); fail("Exception should have been raised"); }
@Test (expected = SDKApplianceNotReachableException.class) public void testSendRequestBadGatewayResponse() { Mockito.when(responseStatus.getStatusCode()).thenReturn(502); restClient.sendRequest(SESSION_ID, new Request(HttpMethod.GET, "")); fail("Exception should have been raised"); }
@Test (expected = SDKInternalServerErrorException.class) public void testSendRequestUnavailableResponse() { Mockito.when(responseStatus.getStatusCode()).thenReturn(503); restClient.sendRequest(SESSION_ID, new Request(HttpMethod.GET, "")); fail("Exception should have been raised"); }
@Test (expected = SDKApplianceNotReachableException.class) public void testSendRequestGatewayTimeoutResponse() { Mockito.when(responseStatus.getStatusCode()).thenReturn(504); restClient.sendRequest(SESSION_ID, new Request(HttpMethod.GET, "")); fail("Exception should have been raised"); }
@Test (expected = SDKApplianceNotReachableException.class) public void testSendRequestHttpVersionNotSupportedResponse() { Mockito.when(responseStatus.getStatusCode()).thenReturn(505); restClient.sendRequest(SESSION_ID, new Request(HttpMethod.GET, "")); fail("Exception should have been raised"); }
@Test public void testSendRequestPatch() { Mockito.when(responseStatus.getStatusCode()).thenReturn(202); String result = restClient.sendRequest(SESSION_ID, new Request(HttpMethod.PATCH, "")); assertNotNull(result); }
@Test (expected = SDKApplianceNotReachableException.class) public void testSendRequestNotReachableResponse() { Mockito.when(responseStatus.getStatusCode()).thenReturn(999); restClient.sendRequest(SESSION_ID, new Request(HttpMethod.GET, "")); fail("Exception should have been raised"); }
@Test (expected = SDKBadRequestException.class) public void testSendRequestInvalidRequestType() { restClient.sendRequest(SESSION_ID, new Request(null, "")); fail("Exception should have been raised"); }
@Test public void testSendRequestForceReturnTask() { Request request = new Request(HttpMethod.POST, ""); request.setForceReturnTask(true); String result = restClient.sendRequest(SESSION_ID, request); assertNotNull(result); }
@Test public void testSendRequestStringBody() { String result = restClient.sendRequest(SESSION_ID, new Request(HttpMethod.POST, "", "")); assertNotNull(result); }
@Test public void testSendRequestWithUriParameters() { Request request = new Request(HttpMethod.GET, ""); request.addQuery(new UrlParameter("filter", "name='anyName")); String result = restClient.sendRequest(SESSION_ID, request); assertNotNull(result); }
@Test (expected = SDKBadRequestException.class) public void testSendRequestWithBadUriParameters() { Request request = new Request(HttpMethod.GET, "http :"); request.addQuery(new UrlParameter("filter", "name='anyName")); String result = restClient.sendRequest(SESSION_ID, request); assertNotNull(result); }
@Test public void testSendRequestPatchNoBody() { String result = restClient.sendRequest(SESSION_ID, new Request(HttpMethod.PATCH, "")); assertNotNull(result); }
@Test public void testSendRequestPut() { String result = restClient.sendRequest(SESSION_ID, new Request(HttpMethod.PUT, "")); assertNotNull(result); }
@Test public void testSendRequestPutNoBody() { String result = restClient.sendRequest(SESSION_ID, new Request(HttpMethod.PUT, "")); assertNotNull(result); }
@Test public void testSendRequestDelete() { String result = restClient.sendRequest(SESSION_ID, new Request(HttpMethod.DELETE, "")); assertNotNull(result); }
@Test public void testSendRequestNotAuthoritativeResponse() { Mockito.when(responseStatus.getStatusCode()).thenReturn(203); String result = restClient.sendRequest(SESSION_ID, new Request(HttpMethod.GET, "")); assertNotNull(result); }
@Test public void testSendRequestNoContentResponse() throws Exception { Mockito.when(responseEntity.getContent()).thenReturn(new ByteArrayInputStream("".getBytes())); Mockito.when(responseStatus.getStatusCode()).thenReturn(204); String result = restClient.sendRequest(SESSION_ID, new Request(HttpMethod.GET, "")); assertNotNull(result); assertEquals("Return must be \"{}\"", "{}", result); }