update link to upper-constraints.txt
[dmaap/buscontroller.git] / dmaap-bc / src / test / java / org / onap / dmaap / dbcapi / resources / ResponseBuilderTest.java
1 /*
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
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.dmaap.dbcapi.resources;
22
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;
27
28 import jakarta.ws.rs.core.Response;
29 import org.junit.Test;
30 import org.onap.dmaap.dbcapi.model.ApiError;
31
32 public class ResponseBuilderTest {
33
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();
38
39     @Test
40     public void success_shouldCreateResponseWithOKStatusCode() {
41
42         Response response = responseBuilder.success(OBJECT);
43
44         assertEquals(OBJECT, response.getEntity());
45         assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
46     }
47
48     @Test
49     public void success_shouldCreateResponseWithDefinedStatusCode() {
50
51         Response response = responseBuilder.success(CODE, OBJECT);
52
53         assertEquals(OBJECT, response.getEntity());
54         assertEquals(CODE, response.getStatus());
55     }
56
57     @Test
58     public void unauthorized_shouldCreateCorrectResponse() {
59
60         ApiError error = new ApiError(UNAUTHORIZED.getStatusCode(), MESSAGE, "Authorization");
61         Response response = responseBuilder.unauthorized(MESSAGE);
62
63         assertEquals(error, response.getEntity());
64         assertEquals(error.getCode(), response.getStatus());
65     }
66
67     @Test
68     public void unavailable_shouldCreateCorrectResponse() {
69
70         ApiError error = new ApiError(SERVICE_UNAVAILABLE.getStatusCode(),
71                 "Request is unavailable due to unexpected condition");
72         Response response = responseBuilder.unavailable();
73
74         assertEquals(error, response.getEntity());
75         assertEquals(error.getCode(), response.getStatus());
76     }
77
78     @Test
79     public void notFound_shouldCreateCorrectResponse() {
80         ApiError error = new ApiError(NOT_FOUND.getStatusCode(), "Requested object not found");
81         Response response = responseBuilder.notFound();
82
83         assertEquals(error, response.getEntity());
84         assertEquals(error.getCode(), response.getStatus());
85     }
86
87     @Test
88     public void error_shouldCreateCorrectResponse() {
89         ApiError error = new ApiError(CODE, "Some Error");
90         Response response = responseBuilder.error(error);
91
92         assertEquals(error, response.getEntity());
93         assertEquals(error.getCode(), response.getStatus());
94     }
95 }