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