Fix minor warnings in code
[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.InjectMocks;
35 import org.mockito.Mock;
36 import org.mockito.MockitoAnnotations;
37 import org.springframework.http.ResponseEntity;
38 import org.springframework.http.ResponseEntity.BodyBuilder;
39
40 public class PapRestControllerV1Test {
41
42     @Mock
43     SecurityContext mockSecurityContext;
44
45     private AutoCloseable closeable;
46     private BodyBuilder bldr;
47
48     @Before
49     public void setUp() {
50         bldr = ResponseEntity.ok();
51         closeable = MockitoAnnotations.openMocks(this);
52     }
53
54     @After
55     public void after() throws Exception {
56         closeable.close();
57     }
58
59     @Test
60     public void testAddVersionControlHeaders() {
61         ResponseEntity<Object> resp = PapRestControllerV1.addVersionControlHeaders(bldr).build();
62         assertEquals("0", resp.getHeaders().get(PapRestControllerV1.VERSION_MINOR_NAME).get(0));
63         assertEquals("0", resp.getHeaders().get(PapRestControllerV1.VERSION_PATCH_NAME).get(0));
64         assertEquals("1.0.0", resp.getHeaders().get(PapRestControllerV1.VERSION_LATEST_NAME).get(0));
65     }
66
67     @Test
68     public void testAddLoggingHeaders_Null() {
69         ResponseEntity<Object> resp = PapRestControllerV1.addLoggingHeaders(bldr, null).build();
70         assertNotNull(resp.getHeaders().get(PapRestControllerV1.REQUEST_ID_NAME));
71     }
72
73     @Test
74     public void testAddLoggingHeaders_NonNull() {
75         UUID uuid = UUID.randomUUID();
76         ResponseEntity<Object> resp = PapRestControllerV1.addLoggingHeaders(bldr, uuid).build();
77         assertEquals(uuid.toString(), resp.getHeaders().get(PapRestControllerV1.REQUEST_ID_NAME).get(0));
78     }
79
80     @Test
81     public void testGetPrincipal() {
82         assertThat(new PapRestControllerV1().getPrincipal()).isEmpty();
83     }
84 }