Migrate pap startup & controllers to spring boot
[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     @InjectMocks
46     PapRestControllerV1 mockController;
47
48     private AutoCloseable closeable;
49     private BodyBuilder bldr;
50
51     @Before
52     public void setUp() {
53         bldr = ResponseEntity.ok();
54         closeable = MockitoAnnotations.openMocks(this);
55     }
56
57     @After
58     public void after() throws Exception {
59         closeable.close();
60     }
61
62     @Test
63     public void testAddVersionControlHeaders() {
64         ResponseEntity<Object> resp = mockController.addVersionControlHeaders(bldr).build();
65         assertEquals("0", resp.getHeaders().get(PapRestControllerV1.VERSION_MINOR_NAME).get(0));
66         assertEquals("0", resp.getHeaders().get(PapRestControllerV1.VERSION_PATCH_NAME).get(0));
67         assertEquals("1.0.0", resp.getHeaders().get(PapRestControllerV1.VERSION_LATEST_NAME).get(0));
68     }
69
70     @Test
71     public void testAddLoggingHeaders_Null() {
72         ResponseEntity<Object> resp = mockController.addLoggingHeaders(bldr, null).build();
73         assertNotNull(resp.getHeaders().get(PapRestControllerV1.REQUEST_ID_NAME));
74     }
75
76     @Test
77     public void testAddLoggingHeaders_NonNull() {
78         UUID uuid = UUID.randomUUID();
79         ResponseEntity<Object> resp = mockController.addLoggingHeaders(bldr, uuid).build();
80         assertEquals(uuid.toString(), resp.getHeaders().get(PapRestControllerV1.REQUEST_ID_NAME).get(0));
81     }
82
83     @Test
84     public void testGetPrincipal() {
85         assertThat(new PapRestControllerV1().getPrincipal()).isEmpty();
86     }
87 }