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 org.mockito.junit.jupiter.MockitoSettings;
29 import org.mockito.quality.Strictness;
30 import javax.ws.rs.container.ContainerRequestContext;
31 import javax.ws.rs.container.ContainerResponseContext;
32 import javax.ws.rs.core.MediaType;
33 import javax.ws.rs.core.MultivaluedMap;
34 import java.io.IOException;
35 import static org.junit.Assert.assertEquals;
36 import static org.junit.Assert.assertNull;
37 import static org.mockito.Mockito.when;
39 @ExtendWith(MockitoExtension.class)
40 public class ResponseHeaderManipulationTest {
43 private ResponseHeaderManipulation responseHeaderManipulation;
46 private ContainerRequestContext mockRequestContext;
49 private ContainerResponseContext mockResponseContext;
52 private MultivaluedMap<String, Object> mockResponseHeaders;
56 when(mockResponseContext.getHeaders()).thenReturn(mockResponseHeaders);
60 public void testFilterWithContentType() throws IOException {
61 when(mockResponseContext.getHeaderString("Content-Type")).thenReturn(MediaType.APPLICATION_JSON);
62 responseHeaderManipulation.filter(mockRequestContext, mockResponseContext);
64 assertEquals("application/json",mockResponseContext.getHeaderString("Content-Type"));
68 public void testFilterWithNoContentType() throws IOException {
69 // Arrange: Simulate Accept header with "*/*" and no Content-Type set
70 when(mockRequestContext.getHeaderString("Accept")).thenReturn("*/*");
72 responseHeaderManipulation.filter(mockRequestContext, mockResponseContext);
74 assertEquals("*/*",mockRequestContext.getHeaderString("Accept"));
78 public void testFilterWithNullAcceptHeader() throws IOException {
79 // Arrange: Simulate null Accept header
80 when(mockRequestContext.getHeaderString("Accept")).thenReturn(null);
81 responseHeaderManipulation.filter(mockRequestContext, mockResponseContext);
83 assertNull(mockRequestContext.getHeaderString("Accept"));
87 public void testFilterWithEmptyAcceptHeader() throws IOException {
88 // Arrange: Simulate empty Accept header and no Content-Type set
89 when(mockRequestContext.getHeaderString("Accept")).thenReturn("");
90 when(mockResponseContext.getHeaderString("Content-Type")).thenReturn(null);
92 responseHeaderManipulation.filter(mockRequestContext, mockResponseContext);
93 assertEquals("", mockRequestContext.getHeaderString("Accept"));