1 /* Copyright (c) 2019 AT&T Intellectual Property. #
\r
3 # Licensed under the Apache License, Version 2.0 (the "License"); #
\r
4 # you may not use this file except in compliance with the License. #
\r
5 # You may obtain a copy of the License at #
\r
7 # http://www.apache.org/licenses/LICENSE-2.0 #
\r
9 # Unless required by applicable law or agreed to in writing, software #
\r
10 # distributed under the License is distributed on an "AS IS" BASIS, #
\r
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
\r
12 # See the License for the specific language governing permissions and #
\r
13 # limitations under the License. #
\r
14 ##############################################################################*/
\r
17 package org.oran.otf.api.tests.unit.utility;
\r
19 import org.oran.otf.api.Utilities;
\r
20 import org.oran.otf.common.model.local.OTFApiResponse;
\r
21 import org.junit.Assert;
\r
22 import org.junit.Test;
\r
24 import javax.ws.rs.core.Response;
\r
26 public class BuildResponseTest {
\r
28 public void badResponseTest(){
\r
29 Response badResponse = Utilities.Http.BuildResponse.badRequest();
\r
30 Assert.assertNotNull(badResponse);
\r
31 Assert.assertEquals(badResponse.getStatus(),400);
\r
35 public void badRequestWithMessageTest() {
\r
36 Response badResponse = Utilities.Http.BuildResponse.badRequestWithMessage("this is bad");
\r
37 OTFApiResponse response = (OTFApiResponse) badResponse.getEntity();
\r
39 Assert.assertNotNull(badResponse);
\r
40 Assert.assertEquals(badResponse.getStatus(),400);
\r
41 Assert.assertEquals(response.getStatusCode(), 400);
\r
42 Assert.assertEquals(response.getMessage(), "this is bad");
\r
45 public void internalServerErrorTest(){
\r
46 Response badResponse = Utilities.Http.BuildResponse.internalServerError();
\r
47 Assert.assertNotNull(badResponse);
\r
48 Assert.assertEquals(badResponse.getStatus(),500);
\r
51 public void internalServerErrorWithMessageTest(){
\r
52 Response badResponse = Utilities.Http.BuildResponse.internalServerErrorWithMessage("internal error");
\r
53 OTFApiResponse response = (OTFApiResponse) badResponse.getEntity();
\r
55 Assert.assertNotNull(badResponse);
\r
56 Assert.assertEquals(badResponse.getStatus(),500);
\r
57 Assert.assertEquals(response.getStatusCode(), 500);
\r
58 Assert.assertEquals(response.getMessage(), "internal error");
\r
62 public void unauthorizedTest(){
\r
63 Response basicUnauthorizedResponse= Utilities.Http.BuildResponse.unauthorized();
\r
64 Response unauthorizedMsgResponse = Utilities.Http.BuildResponse.unauthorizedWithMessage("unauthorized");
\r
65 OTFApiResponse response = (OTFApiResponse) unauthorizedMsgResponse.getEntity();
\r
67 Assert.assertNotNull(basicUnauthorizedResponse);
\r
68 Assert.assertNotNull(unauthorizedMsgResponse);
\r
69 Assert.assertEquals(basicUnauthorizedResponse.getStatus(),401);
\r
70 Assert.assertEquals(unauthorizedMsgResponse.getStatus(),401);
\r
71 Assert.assertEquals(response.getStatusCode(),401);
\r
72 Assert.assertEquals(response.getMessage(),"unauthorized");
\r