Replace SpringFox with SpringDoc in policy-pap
[policy/pap.git] / main / src / test / java / org / onap / policy / pap / main / rest / PapRestControllerV1Test.java
1 /*
2  * ============LICENSE_START=======================================================
3  * ONAP PAP
4  * ================================================================================
5  * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
6  * Modifications Copyright (C) 2021 Nordix Foundation.
7  * Modifications Copyright (C) 2021 Bell Canada. All rights reserved.
8  * ================================================================================
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  * ============LICENSE_END=========================================================
21  */
22
23 package org.onap.policy.pap.main.rest;
24
25 import static org.assertj.core.api.Assertions.assertThat;
26 import static org.junit.Assert.assertEquals;
27 import static org.junit.Assert.assertNotNull;
28
29 import java.util.UUID;
30 import javax.ws.rs.core.SecurityContext;
31 import org.junit.After;
32 import org.junit.Before;
33 import org.junit.Test;
34 import org.mockito.Mock;
35 import org.mockito.MockitoAnnotations;
36 import org.springframework.http.ResponseEntity;
37 import org.springframework.http.ResponseEntity.BodyBuilder;
38
39 public class PapRestControllerV1Test {
40
41     @Mock
42     SecurityContext mockSecurityContext;
43
44     private AutoCloseable closeable;
45     private BodyBuilder bldr;
46
47     @Before
48     public void setUp() {
49         bldr = ResponseEntity.ok();
50         closeable = MockitoAnnotations.openMocks(this);
51     }
52
53     @After
54     public void after() throws Exception {
55         closeable.close();
56     }
57
58     @Test
59     public void testAddVersionControlHeaders() {
60         ResponseEntity<Object> resp = PapRestControllerV1.addVersionControlHeaders(bldr).build();
61         assertEquals("0", resp.getHeaders().get(PapRestControllerV1.VERSION_MINOR_NAME).get(0));
62         assertEquals("0", resp.getHeaders().get(PapRestControllerV1.VERSION_PATCH_NAME).get(0));
63         assertEquals("1.0.0", resp.getHeaders().get(PapRestControllerV1.VERSION_LATEST_NAME).get(0));
64     }
65
66     @Test
67     public void testAddLoggingHeaders_Null() {
68         ResponseEntity<Object> resp = PapRestControllerV1.addLoggingHeaders(bldr, null).build();
69         assertNotNull(resp.getHeaders().get(PapRestControllerV1.REQUEST_ID_NAME));
70     }
71
72     @Test
73     public void testAddLoggingHeaders_NonNull() {
74         UUID uuid = UUID.randomUUID();
75         ResponseEntity<Object> resp = PapRestControllerV1.addLoggingHeaders(bldr, uuid).build();
76         assertEquals(uuid.toString(), resp.getHeaders().get(PapRestControllerV1.REQUEST_ID_NAME).get(0));
77     }
78
79     @Test
80     public void testGetPrincipal() {
81         assertThat(new PapRestControllerV1().getPrincipal()).isEmpty();
82     }
83 }