|
1 | 1 | /* |
2 | | - * Copyright 2012-2023 the original author or authors. |
| 2 | + * Copyright 2012-2025 the original author or authors. |
3 | 3 | * |
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | 5 | * you may not use this file except in compliance with the License. |
|
16 | 16 |
|
17 | 17 | package org.springframework.boot.autoconfigure.jersey; |
18 | 18 |
|
| 19 | +import java.util.Collections; |
| 20 | + |
19 | 21 | import com.fasterxml.jackson.databind.ObjectMapper; |
20 | 22 | import com.fasterxml.jackson.module.jakarta.xmlbind.JakartaXmlBindAnnotationIntrospector; |
| 23 | +import jakarta.servlet.ServletContext; |
| 24 | +import jakarta.servlet.ServletException; |
21 | 25 | import org.glassfish.jersey.server.ResourceConfig; |
22 | 26 | import org.junit.jupiter.api.Test; |
23 | 27 |
|
24 | 28 | import org.springframework.boot.autoconfigure.AutoConfigurations; |
25 | 29 | import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration; |
| 30 | +import org.springframework.boot.autoconfigure.jersey.JerseyAutoConfiguration.JerseyWebApplicationInitializer; |
26 | 31 | import org.springframework.boot.test.context.FilteredClassLoader; |
27 | 32 | import org.springframework.boot.test.context.runner.WebApplicationContextRunner; |
| 33 | +import org.springframework.boot.testsupport.classpath.ClassPathExclusions; |
28 | 34 | import org.springframework.boot.web.servlet.FilterRegistrationBean; |
29 | 35 | import org.springframework.context.annotation.Bean; |
30 | 36 | import org.springframework.context.annotation.Configuration; |
| 37 | +import org.springframework.mock.web.MockServletContext; |
31 | 38 | import org.springframework.web.filter.RequestContextFilter; |
32 | 39 |
|
33 | 40 | import static org.assertj.core.api.Assertions.assertThat; |
@@ -106,6 +113,22 @@ void whenJacksonJaxbModuleIsNotAvailableTheObjectMapperCustomizationBacksOff() { |
106 | 113 | .stream() |
107 | 114 | .filter(JakartaXmlBindAnnotationIntrospector.class::isInstance)).isEmpty(); |
108 | 115 | }); |
| 116 | + |
| 117 | + } |
| 118 | + |
| 119 | + @Test |
| 120 | + void webApplicationIntializerDisablesJerseysWebApplicationInitializer() throws ServletException { |
| 121 | + ServletContext context = new MockServletContext(); |
| 122 | + new JerseyWebApplicationInitializer().onStartup(context); |
| 123 | + assertThat(context.getInitParameter("contextConfigLocation")).isEqualTo("<NONE>"); |
| 124 | + } |
| 125 | + |
| 126 | + @Test |
| 127 | + @ClassPathExclusions("jersey-spring6-*.jar") |
| 128 | + void webApplicationInitializerHasNoEffectWhenJerseyIsAbsent() throws ServletException { |
| 129 | + ServletContext context = new MockServletContext(); |
| 130 | + new JerseyWebApplicationInitializer().onStartup(context); |
| 131 | + assertThat(Collections.list(context.getInitParameterNames())).isEmpty(); |
109 | 132 | } |
110 | 133 |
|
111 | 134 | @Configuration(proxyBeanMethods = false) |
|
0 commit comments