2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2020 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.policy.pdpx.main.rest.serialization;
23 import static org.junit.Assert.assertEquals;
25 import java.io.IOException;
26 import javax.ws.rs.core.Response;
27 import org.junit.Before;
28 import org.junit.Test;
29 import org.onap.policy.common.utils.coder.CoderException;
30 import org.onap.policy.common.utils.coder.StandardCoder;
32 public class TestXacmlXmlExceptionMapper {
33 private XacmlXmlExceptionMapper mapper;
37 mapper = new XacmlXmlExceptionMapper();
41 public void testToResponse() throws CoderException {
42 final IOException writeToEx = new IOException("failed to convert a dom response to a string");
43 final IOException readFromEx = new IOException("failed to decode incoming request string to a dom request");
44 final IOException unexpectedEx = new IOException("unexpected exception");
45 final Response writeToResp = mapper.toResponse(writeToEx);
46 final Response readFromResp = mapper.toResponse(readFromEx);
47 final Response unexpectedResp = mapper.toResponse(unexpectedEx);
49 assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), writeToResp.getStatus());
50 assertEquals("{'errorDetails':'invalid XML xacml response'}".replace('\'', '"'),
51 new StandardCoder().encode(writeToResp.getEntity()));
52 assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), readFromResp.getStatus());
53 assertEquals("{'errorDetails':'invalid XML xacml request'}".replace('\'', '"'),
54 new StandardCoder().encode(readFromResp.getEntity()));
55 assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), unexpectedResp.getStatus());