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 org.junit.Test;
24 import org.onap.dmaap.dbcapi.model.ApiError;
26 import javax.ws.rs.core.Response;
28 import static javax.ws.rs.core.Response.Status.NOT_FOUND;
29 import static javax.ws.rs.core.Response.Status.SERVICE_UNAVAILABLE;
30 import static javax.ws.rs.core.Response.Status.UNAUTHORIZED;
31 import static org.junit.Assert.assertEquals;
33 public class ResponseBuilderTest {
35 private static final String OBJECT = "Objcect";
36 private static final String MESSAGE = "msg";
37 private static final int CODE = 100;
38 private ResponseBuilder responseBuilder = new ResponseBuilder();
41 public void success_shouldCreateResponseWithOKStatusCode() {
43 Response response = responseBuilder.success(OBJECT);
45 assertEquals(OBJECT, response.getEntity());
46 assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
50 public void success_shouldCreateResponseWithDefinedStatusCode() {
52 Response response = responseBuilder.success(CODE, OBJECT);
54 assertEquals(OBJECT, response.getEntity());
55 assertEquals(CODE, response.getStatus());
59 public void unauthorized_shouldCreateCorrectResponse() {
61 ApiError error = new ApiError(UNAUTHORIZED.getStatusCode(), MESSAGE, "Authorization");
62 Response response = responseBuilder.unauthorized(MESSAGE);
64 assertEquals(error, response.getEntity());
65 assertEquals(error.getCode(), response.getStatus());
69 public void unavailable_shouldCreateCorrectResponse() {
71 ApiError error = new ApiError(SERVICE_UNAVAILABLE.getStatusCode(),
72 "Request is unavailable due to unexpected condition");
73 Response response = responseBuilder.unavailable();
75 assertEquals(error, response.getEntity());
76 assertEquals(error.getCode(), response.getStatus());
80 public void notFound_shouldCreateCorrectResponse() {
81 ApiError error = new ApiError(NOT_FOUND.getStatusCode(), "Requested object not found");
82 Response response = responseBuilder.notFound();
84 assertEquals(error, response.getEntity());
85 assertEquals(error.getCode(), response.getStatus());
89 public void error_shouldCreateCorrectResponse() {
90 ApiError error = new ApiError(CODE, "Some Error");
91 Response response = responseBuilder.error(error);
93 assertEquals(error, response.getEntity());
94 assertEquals(error.getCode(), response.getStatus());