1 package org.onap.sdc.dcae.utils;
3 import org.junit.Assert;
4 import org.junit.Before;
6 import org.junit.runner.RunWith;
7 import org.mockito.InjectMocks;
8 import org.mockito.runners.MockitoJUnitRunner;
9 import org.springframework.http.HttpHeaders;
10 import org.springframework.http.HttpStatus;
11 import org.springframework.http.client.ClientHttpResponse;
12 import org.springframework.web.client.HttpClientErrorException;
13 import org.springframework.web.client.HttpServerErrorException;
15 import java.io.IOException;
16 import java.io.InputStream;
18 @RunWith(MockitoJUnitRunner.class)
19 public class SDCResponseErrorHandlerTest {
21 private SDCResponseErrorHandler classUnderTest;
22 private ClientHttpResponse clientHttpResponse;
23 private HttpStatus httpStatus;
27 clientHttpResponse = new ClientHttpResponse() {
29 public HttpStatus getStatusCode() throws IOException {
34 public int getRawStatusCode() throws IOException {
39 public String getStatusText() throws IOException {
49 public InputStream getBody() throws IOException {
54 public HttpHeaders getHeaders() {
55 return new HttpHeaders();
60 @Test(expected = HttpClientErrorException.class)
61 public void handleError_haveError_throwsClientException() throws IOException {
62 httpStatus = HttpStatus.EXPECTATION_FAILED;
63 classUnderTest.handleError(clientHttpResponse);
66 @Test(expected = HttpServerErrorException.class)
67 public void handleError_haveError_throwsServerException() throws IOException {
68 httpStatus = HttpStatus.BAD_GATEWAY;
69 classUnderTest.handleError(clientHttpResponse);
73 public void hasError_haveClientError_returnTrue() throws IOException {
74 httpStatus = HttpStatus.EXPECTATION_FAILED;
75 boolean result = classUnderTest.hasError(clientHttpResponse);
76 Assert.assertTrue(result);
80 public void hasError_haveServerError_returnTrue() throws IOException {
81 httpStatus = HttpStatus.BAD_GATEWAY;
82 boolean result = classUnderTest.hasError(clientHttpResponse);
83 Assert.assertTrue(result);
87 public void hasError_200OK_returnFalse() throws IOException {
88 httpStatus = HttpStatus.OK;
89 boolean result = classUnderTest.hasError(clientHttpResponse);
90 Assert.assertFalse(result);