2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2025 Deutsche Telekom. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
20 package org.onap.aai.schemaservice.interceptors.post;
22 import org.junit.jupiter.api.BeforeEach;
23 import org.junit.jupiter.api.Test;
24 import org.junit.jupiter.api.extension.ExtendWith;
25 import org.mockito.InjectMocks;
26 import org.mockito.Mock;
27 import org.mockito.junit.jupiter.MockitoExtension;
28 import javax.ws.rs.container.ContainerRequestContext;
29 import javax.ws.rs.container.ContainerResponseContext;
30 import javax.ws.rs.core.MediaType;
31 import javax.ws.rs.core.MultivaluedMap;
32 import java.io.IOException;
33 import static org.junit.Assert.assertEquals;
34 import static org.junit.Assert.assertNull;
35 import static org.mockito.Mockito.when;
37 @ExtendWith(MockitoExtension.class)
38 public class ResponseHeaderManipulationTest {
41 private ResponseHeaderManipulation responseHeaderManipulation;
44 private ContainerRequestContext mockRequestContext;
47 private ContainerResponseContext mockResponseContext;
50 private MultivaluedMap<String, Object> mockResponseHeaders;
54 when(mockResponseContext.getHeaders()).thenReturn(mockResponseHeaders);
58 public void testFilterWithContentType() throws IOException {
59 when(mockResponseContext.getHeaderString("Content-Type")).thenReturn(MediaType.APPLICATION_JSON);
60 responseHeaderManipulation.filter(mockRequestContext, mockResponseContext);
62 assertEquals("application/json",mockResponseContext.getHeaderString("Content-Type"));
66 public void testFilterWithNoContentType() throws IOException {
67 // Arrange: Simulate Accept header with "*/*" and no Content-Type set
68 when(mockRequestContext.getHeaderString("Accept")).thenReturn("*/*");
70 responseHeaderManipulation.filter(mockRequestContext, mockResponseContext);
72 assertEquals("*/*",mockRequestContext.getHeaderString("Accept"));
76 public void testFilterWithNullAcceptHeader() throws IOException {
77 // Arrange: Simulate null Accept header
78 when(mockRequestContext.getHeaderString("Accept")).thenReturn(null);
79 responseHeaderManipulation.filter(mockRequestContext, mockResponseContext);
81 assertNull(mockRequestContext.getHeaderString("Accept"));
85 public void testFilterWithEmptyAcceptHeader() throws IOException {
86 // Arrange: Simulate empty Accept header and no Content-Type set
87 when(mockRequestContext.getHeaderString("Accept")).thenReturn("");
88 when(mockResponseContext.getHeaderString("Content-Type")).thenReturn(null);
90 responseHeaderManipulation.filter(mockRequestContext, mockResponseContext);
91 assertEquals("", mockRequestContext.getHeaderString("Accept"));