2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 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.apihandlerinfra.exceptions;
24 import static org.junit.Assert.assertEquals;
25 import java.io.IOException;
26 import javax.ws.rs.core.HttpHeaders;
27 import javax.ws.rs.core.Response;
28 import javax.xml.bind.Marshaller;
29 import org.apache.http.HttpStatus;
30 import org.junit.Test;
31 import org.junit.runner.RunWith;
32 import org.mockito.InjectMocks;
33 import org.mockito.Mock;
34 import org.mockito.junit.MockitoJUnitRunner;
35 import org.onap.so.apihandler.common.ErrorNumbers;
38 @RunWith(MockitoJUnitRunner.class)
39 public class ApiExceptionMapperTest {
42 private HttpHeaders headers;
44 private Marshaller marshaller;
47 ApiExceptionMapper mapper = new ApiExceptionMapper();
50 public void testValidateResponse() {
51 ValidateException validateException =
52 new ValidateException.Builder("Test Message", HttpStatus.SC_BAD_REQUEST, ErrorNumbers.SVC_BAD_PARAMETER)
54 Response resp = mapper.toResponse((ApiException) validateException);
56 assertEquals(resp.getStatus(), HttpStatus.SC_BAD_REQUEST);
60 public void testBPMNFailureResponse() {
61 BPMNFailureException bpmnException = new BPMNFailureException.Builder("Test Message", HttpStatus.SC_NOT_FOUND,
62 ErrorNumbers.SVC_BAD_PARAMETER).build();
63 Response resp = mapper.toResponse((ApiException) bpmnException);
65 assertEquals(resp.getStatus(), HttpStatus.SC_NOT_FOUND);
69 public void testClientConnectionResponse() {
70 ClientConnectionException clientConnectionException = new ClientConnectionException.Builder("test",
71 HttpStatus.SC_INTERNAL_SERVER_ERROR, ErrorNumbers.SVC_BAD_PARAMETER).build();
72 Response resp = mapper.toResponse((ApiException) clientConnectionException);
74 assertEquals(resp.getStatus(), HttpStatus.SC_INTERNAL_SERVER_ERROR);
78 public void testVFModuleResponse() {
79 VfModuleNotFoundException vfModuleException = new VfModuleNotFoundException.Builder("Test Message",
80 HttpStatus.SC_CONFLICT, ErrorNumbers.SVC_BAD_PARAMETER).build();
81 Response resp = mapper.toResponse((ApiException) vfModuleException);
83 assertEquals(resp.getStatus(), HttpStatus.SC_CONFLICT);
87 public void testDuplicateRequestResponse() throws IOException {
88 DuplicateRequestException duplicateRequestException = new DuplicateRequestException.Builder("Test1", "Test2",
89 "Test3", "Test4", HttpStatus.SC_BAD_GATEWAY, ErrorNumbers.SVC_BAD_PARAMETER).build();
90 Response resp = mapper.toResponse((ApiException) duplicateRequestException);
92 assertEquals(resp.getStatus(), HttpStatus.SC_BAD_GATEWAY);