e6f7a3663ad0cedaa2222ad3a9cc081a37ad8932
[so.git] / mso-api-handlers / mso-api-handler-common / src / test / java / org / onap / so / apihandler / common / ResponseHandlerTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Modifications Copyright (C) 2018 IBM.
8  * ================================================================================
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  * 
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  * 
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  * ============LICENSE_END=========================================================
21  */
22
23 package org.onap.so.apihandler.common;
24
25
26 import java.io.IOException;
27 import org.junit.Rule;
28 import org.junit.Test;
29 import org.junit.rules.ExpectedException;
30 import org.junit.runner.RunWith;
31 import org.mockito.InjectMocks;
32 import org.mockito.Spy;
33 import org.mockito.junit.MockitoJUnitRunner;
34 import org.onap.so.apihandlerinfra.exceptions.BPMNFailureException;
35 import org.springframework.http.ResponseEntity;
36
37 @RunWith(MockitoJUnitRunner.class)
38 public class ResponseHandlerTest {
39
40     @Spy
41     @InjectMocks
42     private ResponseHandler responseHandler;
43
44     @Rule
45     public ExpectedException thrown = ExpectedException.none();
46
47     @Test
48     public void acceptedResponseTest() throws IOException, BPMNFailureException {
49         ResponseEntity<String> camundaResponse = ResponseEntity.noContent().build();
50         thrown.expect(BPMNFailureException.class);
51         thrown.expectMessage("Request Failed due to BPEL error with HTTP Status = 204");
52         responseHandler.acceptedResponse(camundaResponse);
53     }
54
55     @Test
56     public void acceptedOrNoContentResponseTest() throws IOException, BPMNFailureException {
57         ResponseEntity<String> camundaResponse = ResponseEntity.badRequest().build();
58         thrown.expect(BPMNFailureException.class);
59         thrown.expectMessage("Request Failed due to BPEL error with HTTP Status = 400");
60         responseHandler.acceptedOrNoContentResponse(camundaResponse);
61
62     }
63
64 }