--- /dev/null
+/* Copyright (c) 2019 AT&T Intellectual Property. #\r
+# #\r
+# Licensed under the Apache License, Version 2.0 (the "License"); #\r
+# you may not use this file except in compliance with the License. #\r
+# You may obtain a copy of the License at #\r
+# #\r
+# http://www.apache.org/licenses/LICENSE-2.0 #\r
+# #\r
+# Unless required by applicable law or agreed to in writing, software #\r
+# distributed under the License is distributed on an "AS IS" BASIS, #\r
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #\r
+# See the License for the specific language governing permissions and #\r
+# limitations under the License. #\r
+##############################################################################*/\r
+\r
+\r
+package org.oran.otf.api.tests.unit.utility;\r
+\r
+import org.oran.otf.api.Utilities;\r
+import org.oran.otf.common.model.local.OTFApiResponse;\r
+import org.junit.Assert;\r
+import org.junit.Test;\r
+\r
+import javax.ws.rs.core.Response;\r
+\r
+public class BuildResponseTest {\r
+ @Test\r
+ public void badResponseTest(){\r
+ Response badResponse = Utilities.Http.BuildResponse.badRequest();\r
+ Assert.assertNotNull(badResponse);\r
+ Assert.assertEquals(badResponse.getStatus(),400);\r
+ }\r
+\r
+ @Test\r
+ public void badRequestWithMessageTest() {\r
+ Response badResponse = Utilities.Http.BuildResponse.badRequestWithMessage("this is bad");\r
+ OTFApiResponse response = (OTFApiResponse) badResponse.getEntity();\r
+\r
+ Assert.assertNotNull(badResponse);\r
+ Assert.assertEquals(badResponse.getStatus(),400);\r
+ Assert.assertEquals(response.getStatusCode(), 400);\r
+ Assert.assertEquals(response.getMessage(), "this is bad");\r
+ }\r
+ @Test\r
+ public void internalServerErrorTest(){\r
+ Response badResponse = Utilities.Http.BuildResponse.internalServerError();\r
+ Assert.assertNotNull(badResponse);\r
+ Assert.assertEquals(badResponse.getStatus(),500);\r
+ }\r
+ @Test\r
+ public void internalServerErrorWithMessageTest(){\r
+ Response badResponse = Utilities.Http.BuildResponse.internalServerErrorWithMessage("internal error");\r
+ OTFApiResponse response = (OTFApiResponse) badResponse.getEntity();\r
+\r
+ Assert.assertNotNull(badResponse);\r
+ Assert.assertEquals(badResponse.getStatus(),500);\r
+ Assert.assertEquals(response.getStatusCode(), 500);\r
+ Assert.assertEquals(response.getMessage(), "internal error");\r
+ }\r
+\r
+ @Test\r
+ public void unauthorizedTest(){\r
+ Response basicUnauthorizedResponse= Utilities.Http.BuildResponse.unauthorized();\r
+ Response unauthorizedMsgResponse = Utilities.Http.BuildResponse.unauthorizedWithMessage("unauthorized");\r
+ OTFApiResponse response = (OTFApiResponse) unauthorizedMsgResponse.getEntity();\r
+\r
+ Assert.assertNotNull(basicUnauthorizedResponse);\r
+ Assert.assertNotNull(unauthorizedMsgResponse);\r
+ Assert.assertEquals(basicUnauthorizedResponse.getStatus(),401);\r
+ Assert.assertEquals(unauthorizedMsgResponse.getStatus(),401);\r
+ Assert.assertEquals(response.getStatusCode(),401);\r
+ Assert.assertEquals(response.getMessage(),"unauthorized");\r
+ }\r
+}\r