added svcapi ui and camunda code
[it/otf.git] / otf-service-api / src / test / java / org / oran / otf / api / tests / unit / utility / BuildResponseTest.java
1 /*  Copyright (c) 2019 AT&T Intellectual Property.                             #\r
2 #                                                                              #\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
6 #                                                                              #\r
7 #       http://www.apache.org/licenses/LICENSE-2.0                             #\r
8 #                                                                              #\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
15 \r
16 \r
17 package org.oran.otf.api.tests.unit.utility;\r
18 \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
23 \r
24 import javax.ws.rs.core.Response;\r
25 \r
26 public class BuildResponseTest {\r
27     @Test\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
32     }\r
33 \r
34     @Test\r
35     public void badRequestWithMessageTest() {\r
36         Response badResponse = Utilities.Http.BuildResponse.badRequestWithMessage("this is bad");\r
37         OTFApiResponse response = (OTFApiResponse) badResponse.getEntity();\r
38 \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
43     }\r
44     @Test\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
49     }\r
50     @Test\r
51     public void internalServerErrorWithMessageTest(){\r
52         Response badResponse = Utilities.Http.BuildResponse.internalServerErrorWithMessage("internal error");\r
53         OTFApiResponse response = (OTFApiResponse) badResponse.getEntity();\r
54 \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
59     }\r
60 \r
61     @Test\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
66 \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
73     }\r
74 }\r