2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
6 * Modifications Copyright (C) 2021, 2023 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
13 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
23 package org.onap.policy.pap.main.rest;
25 import static org.assertj.core.api.Assertions.assertThat;
26 import static org.junit.jupiter.api.Assertions.assertEquals;
27 import static org.junit.jupiter.api.Assertions.assertNotNull;
29 import jakarta.ws.rs.core.SecurityContext;
30 import java.util.UUID;
31 import org.junit.jupiter.api.AfterEach;
32 import org.junit.jupiter.api.BeforeEach;
33 import org.junit.jupiter.api.Test;
34 import org.mockito.Mock;
35 import org.mockito.MockitoAnnotations;
36 import org.springframework.http.ResponseEntity;
37 import org.springframework.http.ResponseEntity.BodyBuilder;
39 class PapRestControllerV1Test {
42 SecurityContext mockSecurityContext;
44 private AutoCloseable closeable;
45 private BodyBuilder bldr;
49 bldr = ResponseEntity.ok();
50 closeable = MockitoAnnotations.openMocks(this);
54 public void after() throws Exception {
59 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));
67 void testAddLoggingHeaders_Null() {
68 ResponseEntity<Object> resp = PapRestControllerV1.addLoggingHeaders(bldr, null).build();
69 assertNotNull(resp.getHeaders().get(PapRestControllerV1.REQUEST_ID_NAME));
73 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));
80 void testGetPrincipal() {
81 assertThat(new PapRestControllerV1().getPrincipal()).isEmpty();