2 * ============LICENSE_START=======================================================
3 * PNF-REGISTRATION-HANDLER
4 * ================================================================================
5 * Copyright (C) 2019 NOKIA 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.dmaap.dbcapi.resources;
23 import static jakarta.ws.rs.core.Response.Status.NOT_FOUND;
24 import static jakarta.ws.rs.core.Response.Status.SERVICE_UNAVAILABLE;
25 import static jakarta.ws.rs.core.Response.Status.UNAUTHORIZED;
26 import static org.junit.Assert.assertEquals;
28 import jakarta.ws.rs.core.Response;
29 import org.junit.Test;
30 import org.onap.dmaap.dbcapi.model.ApiError;
32 public class ResponseBuilderTest {
34 private static final String OBJECT = "Objcect";
35 private static final String MESSAGE = "msg";
36 private static final int CODE = 100;
37 private ResponseBuilder responseBuilder = new ResponseBuilder();
40 public void success_shouldCreateResponseWithOKStatusCode() {
42 Response response = responseBuilder.success(OBJECT);
44 assertEquals(OBJECT, response.getEntity());
45 assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
49 public void success_shouldCreateResponseWithDefinedStatusCode() {
51 Response response = responseBuilder.success(CODE, OBJECT);
53 assertEquals(OBJECT, response.getEntity());
54 assertEquals(CODE, response.getStatus());
58 public void unauthorized_shouldCreateCorrectResponse() {
60 ApiError error = new ApiError(UNAUTHORIZED.getStatusCode(), MESSAGE, "Authorization");
61 Response response = responseBuilder.unauthorized(MESSAGE);
63 assertEquals(error, response.getEntity());
64 assertEquals(error.getCode(), response.getStatus());
68 public void unavailable_shouldCreateCorrectResponse() {
70 ApiError error = new ApiError(SERVICE_UNAVAILABLE.getStatusCode(),
71 "Request is unavailable due to unexpected condition");
72 Response response = responseBuilder.unavailable();
74 assertEquals(error, response.getEntity());
75 assertEquals(error.getCode(), response.getStatus());
79 public void notFound_shouldCreateCorrectResponse() {
80 ApiError error = new ApiError(NOT_FOUND.getStatusCode(), "Requested object not found");
81 Response response = responseBuilder.notFound();
83 assertEquals(error, response.getEntity());
84 assertEquals(error.getCode(), response.getStatus());
88 public void error_shouldCreateCorrectResponse() {
89 ApiError error = new ApiError(CODE, "Some Error");
90 Response response = responseBuilder.error(error);
92 assertEquals(error, response.getEntity());
93 assertEquals(error.getCode(), response.getStatus());