2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.so.apihandler.recipe;
23 import static org.junit.Assert.assertEquals;
25 import java.io.ByteArrayInputStream;
26 import java.io.IOException;
28 import org.springframework.http.HttpStatus;
29 import org.springframework.http.client.ClientHttpResponse;
30 import org.junit.Before;
31 import org.junit.Test;
32 import org.mockito.Mockito;
34 public class CamundaClientErrorHandlerTest {
36 private ClientHttpResponse clientHttpResponse;
37 private CamundaClientErrorHandler clientErrorHandler;
40 public void before() {
41 clientHttpResponse = Mockito.mock(ClientHttpResponse.class);
42 clientErrorHandler = new CamundaClientErrorHandler();
46 public void handleError_SERVER_ERROR_Test() throws IOException {
47 Mockito.when(clientHttpResponse.getStatusCode()).thenReturn(HttpStatus.INTERNAL_SERVER_ERROR);
48 Mockito.when(clientHttpResponse.getBody()).thenReturn(new ByteArrayInputStream("{}".getBytes()));
49 clientErrorHandler.handleError(clientHttpResponse);
50 boolean serverHasError = clientErrorHandler.hasError(clientHttpResponse);
51 assertEquals(true, serverHasError);
55 public void handleError_CLIENT_ERROR_Test() throws IOException {
56 Mockito.when(clientHttpResponse.getStatusCode()).thenReturn(HttpStatus.BAD_REQUEST);
57 Mockito.when(clientHttpResponse.getBody()).thenReturn(new ByteArrayInputStream("{}".getBytes()));
58 clientErrorHandler.handleError(clientHttpResponse);
59 boolean clientHasError = clientErrorHandler.hasError(clientHttpResponse);
60 assertEquals(true, clientHasError);
64 public void handleError_SUCCESS_Test() throws IOException {
65 Mockito.when(clientHttpResponse.getStatusCode()).thenReturn(HttpStatus.ACCEPTED);
66 Mockito.when(clientHttpResponse.getBody()).thenReturn(new ByteArrayInputStream("{}".getBytes()));
67 clientErrorHandler.handleError(clientHttpResponse);
68 boolean hasNoError = clientErrorHandler.hasError(clientHttpResponse);
69 assertEquals(false, hasNoError);