59ce0c1ce9f4bd363d015457aa1d554acf849cce
[policy/common.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP
4  * ================================================================================
5  * Copyright (C) 2019 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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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=========================================================
19  */
20
21 package org.onap.policy.common.endpoints.http.server.test;
22
23 import static org.junit.Assert.assertEquals;
24
25 import com.google.gson.JsonSyntaxException;
26 import javax.ws.rs.core.Response;
27 import org.junit.Before;
28 import org.junit.Test;
29 import org.onap.policy.common.endpoints.http.server.JsonExceptionMapper;
30 import org.onap.policy.common.utils.coder.CoderException;
31 import org.onap.policy.common.utils.coder.StandardCoder;
32
33 public class JsonExceptionMapperTest {
34     private JsonExceptionMapper mapper;
35
36     @Before
37     public void setUp() {
38         mapper = new JsonExceptionMapper();
39     }
40
41     @Test
42     public void testToResponse() throws CoderException {
43         JsonSyntaxException ex = new JsonSyntaxException("expected exception");
44         Response resp = mapper.toResponse(ex);
45
46         assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), resp.getStatus());
47         assertEquals("{'errorDetails':'Invalid request'}".replace('\'', '"'),
48                         new StandardCoder().encode(resp.getEntity()));
49     }
50 }