24 changed files with 210 additions and 408 deletions
@ -0,0 +1,50 @@ |
|||||||
|
/* |
||||||
|
* Copyright 2012-2025 the original author or authors. |
||||||
|
* |
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||||
|
* you may not use this file except in compliance with the License. |
||||||
|
* You may obtain a copy of the License at |
||||||
|
* |
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* |
||||||
|
* Unless required by applicable law or agreed to in writing, software |
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||||
|
* See the License for the specific language governing permissions and |
||||||
|
* limitations under the License. |
||||||
|
*/ |
||||||
|
|
||||||
|
package org.springframework.boot.build; |
||||||
|
|
||||||
|
import org.gradle.api.Project; |
||||||
|
import org.gradle.api.artifacts.ConfigurationContainer; |
||||||
|
import org.gradle.api.component.AdhocComponentWithVariants; |
||||||
|
import org.gradle.api.plugins.JavaTestFixturesPlugin; |
||||||
|
|
||||||
|
/** |
||||||
|
* Conventions that are applied in the presence of the {@link JavaTestFixturesPlugin}. |
||||||
|
* When the plugin is applied: |
||||||
|
* |
||||||
|
* <ul> |
||||||
|
* <li>Publishing of the test fixtures is disabled. |
||||||
|
* </ul> |
||||||
|
* |
||||||
|
* @author Andy Wilkinson |
||||||
|
*/ |
||||||
|
class TestFixturesConventions { |
||||||
|
|
||||||
|
void apply(Project project) { |
||||||
|
project.getPlugins().withType(JavaTestFixturesPlugin.class, (testFixtures) -> disablePublishing(project)); |
||||||
|
} |
||||||
|
|
||||||
|
private void disablePublishing(Project project) { |
||||||
|
ConfigurationContainer configurations = project.getConfigurations(); |
||||||
|
AdhocComponentWithVariants javaComponent = (AdhocComponentWithVariants) project.getComponents() |
||||||
|
.getByName("java"); |
||||||
|
javaComponent.withVariantsFromConfiguration(configurations.getByName("testFixturesApiElements"), |
||||||
|
(variant) -> variant.skip()); |
||||||
|
javaComponent.withVariantsFromConfiguration(configurations.getByName("testFixturesRuntimeElements"), |
||||||
|
(variant) -> variant.skip()); |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
@ -1,79 +0,0 @@ |
|||||||
/* |
|
||||||
* Copyright 2012-2023 the original author or authors. |
|
||||||
* |
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
||||||
* you may not use this file except in compliance with the License. |
|
||||||
* You may obtain a copy of the License at |
|
||||||
* |
|
||||||
* https://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
* |
|
||||||
* Unless required by applicable law or agreed to in writing, software |
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS, |
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
||||||
* See the License for the specific language governing permissions and |
|
||||||
* limitations under the License. |
|
||||||
*/ |
|
||||||
|
|
||||||
package org.springframework.boot.actuate.autoconfigure.web.servlet; |
|
||||||
|
|
||||||
import java.util.Arrays; |
|
||||||
|
|
||||||
import jakarta.servlet.ServletContext; |
|
||||||
|
|
||||||
import org.springframework.boot.testsupport.web.servlet.MockServletWebServer.RegisteredFilter; |
|
||||||
import org.springframework.boot.testsupport.web.servlet.MockServletWebServer.RegisteredServlet; |
|
||||||
import org.springframework.boot.web.server.WebServer; |
|
||||||
import org.springframework.boot.web.servlet.ServletContextInitializer; |
|
||||||
import org.springframework.boot.web.servlet.server.AbstractServletWebServerFactory; |
|
||||||
import org.springframework.boot.web.servlet.server.ServletWebServerFactory; |
|
||||||
|
|
||||||
import static org.mockito.Mockito.spy; |
|
||||||
|
|
||||||
/** |
|
||||||
* Mock {@link ServletWebServerFactory}. |
|
||||||
* |
|
||||||
* @author Phillip Webb |
|
||||||
* @author Andy Wilkinson |
|
||||||
*/ |
|
||||||
public class MockServletWebServerFactory extends AbstractServletWebServerFactory { |
|
||||||
|
|
||||||
private MockServletWebServer webServer; |
|
||||||
|
|
||||||
@Override |
|
||||||
public WebServer getWebServer(ServletContextInitializer... initializers) { |
|
||||||
this.webServer = spy(new MockServletWebServer(mergeInitializers(initializers), getPort())); |
|
||||||
return this.webServer; |
|
||||||
} |
|
||||||
|
|
||||||
public MockServletWebServer getWebServer() { |
|
||||||
return this.webServer; |
|
||||||
} |
|
||||||
|
|
||||||
public ServletContext getServletContext() { |
|
||||||
return (getWebServer() != null) ? getWebServer().getServletContext() : null; |
|
||||||
} |
|
||||||
|
|
||||||
public RegisteredServlet getRegisteredServlet(int index) { |
|
||||||
return (getWebServer() != null) ? getWebServer().getRegisteredServlet(index) : null; |
|
||||||
} |
|
||||||
|
|
||||||
public RegisteredFilter getRegisteredFilter(int index) { |
|
||||||
return (getWebServer() != null) ? getWebServer().getRegisteredFilters(index) : null; |
|
||||||
} |
|
||||||
|
|
||||||
static class MockServletWebServer extends org.springframework.boot.testsupport.web.servlet.MockServletWebServer |
|
||||||
implements WebServer { |
|
||||||
|
|
||||||
MockServletWebServer(ServletContextInitializer[] initializers, int port) { |
|
||||||
super(Arrays.stream(initializers) |
|
||||||
.map((initializer) -> (Initializer) initializer::onStartup) |
|
||||||
.toArray(Initializer[]::new), port); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void start() { |
|
||||||
} |
|
||||||
|
|
||||||
} |
|
||||||
|
|
||||||
} |
|
||||||
@ -1,90 +0,0 @@ |
|||||||
/* |
|
||||||
* Copyright 2012-2021 the original author or authors. |
|
||||||
* |
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
||||||
* you may not use this file except in compliance with the License. |
|
||||||
* You may obtain a copy of the License at |
|
||||||
* |
|
||||||
* https://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
* |
|
||||||
* Unless required by applicable law or agreed to in writing, software |
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS, |
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
||||||
* See the License for the specific language governing permissions and |
|
||||||
* limitations under the License. |
|
||||||
*/ |
|
||||||
|
|
||||||
package org.springframework.boot.autoconfigure.web.reactive; |
|
||||||
|
|
||||||
import java.util.Map; |
|
||||||
|
|
||||||
import org.springframework.boot.web.reactive.server.AbstractReactiveWebServerFactory; |
|
||||||
import org.springframework.boot.web.reactive.server.ReactiveWebServerFactory; |
|
||||||
import org.springframework.boot.web.server.WebServer; |
|
||||||
import org.springframework.http.server.reactive.HttpHandler; |
|
||||||
|
|
||||||
import static org.mockito.Mockito.spy; |
|
||||||
|
|
||||||
/** |
|
||||||
* Mock {@link ReactiveWebServerFactory}. |
|
||||||
* |
|
||||||
* @author Brian Clozel |
|
||||||
*/ |
|
||||||
public class MockReactiveWebServerFactory extends AbstractReactiveWebServerFactory { |
|
||||||
|
|
||||||
private MockReactiveWebServer webServer; |
|
||||||
|
|
||||||
@Override |
|
||||||
public WebServer getWebServer(HttpHandler httpHandler) { |
|
||||||
this.webServer = spy(new MockReactiveWebServer(httpHandler, getPort())); |
|
||||||
return this.webServer; |
|
||||||
} |
|
||||||
|
|
||||||
public MockReactiveWebServer getWebServer() { |
|
||||||
return this.webServer; |
|
||||||
} |
|
||||||
|
|
||||||
static class MockReactiveWebServer implements WebServer { |
|
||||||
|
|
||||||
private final int port; |
|
||||||
|
|
||||||
private HttpHandler httpHandler; |
|
||||||
|
|
||||||
private Map<String, HttpHandler> httpHandlerMap; |
|
||||||
|
|
||||||
MockReactiveWebServer(HttpHandler httpHandler, int port) { |
|
||||||
this.httpHandler = httpHandler; |
|
||||||
this.port = port; |
|
||||||
} |
|
||||||
|
|
||||||
MockReactiveWebServer(Map<String, HttpHandler> httpHandlerMap, int port) { |
|
||||||
this.httpHandlerMap = httpHandlerMap; |
|
||||||
this.port = port; |
|
||||||
} |
|
||||||
|
|
||||||
HttpHandler getHttpHandler() { |
|
||||||
return this.httpHandler; |
|
||||||
} |
|
||||||
|
|
||||||
Map<String, HttpHandler> getHttpHandlerMap() { |
|
||||||
return this.httpHandlerMap; |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void start() { |
|
||||||
|
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void stop() { |
|
||||||
|
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public int getPort() { |
|
||||||
return this.port; |
|
||||||
} |
|
||||||
|
|
||||||
} |
|
||||||
|
|
||||||
} |
|
||||||
@ -1,79 +0,0 @@ |
|||||||
/* |
|
||||||
* Copyright 2012-2023 the original author or authors. |
|
||||||
* |
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
||||||
* you may not use this file except in compliance with the License. |
|
||||||
* You may obtain a copy of the License at |
|
||||||
* |
|
||||||
* https://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
* |
|
||||||
* Unless required by applicable law or agreed to in writing, software |
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS, |
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
||||||
* See the License for the specific language governing permissions and |
|
||||||
* limitations under the License. |
|
||||||
*/ |
|
||||||
|
|
||||||
package org.springframework.boot.autoconfigure.web.servlet; |
|
||||||
|
|
||||||
import java.util.Arrays; |
|
||||||
|
|
||||||
import jakarta.servlet.ServletContext; |
|
||||||
|
|
||||||
import org.springframework.boot.testsupport.web.servlet.MockServletWebServer.RegisteredFilter; |
|
||||||
import org.springframework.boot.testsupport.web.servlet.MockServletWebServer.RegisteredServlet; |
|
||||||
import org.springframework.boot.web.server.WebServer; |
|
||||||
import org.springframework.boot.web.servlet.ServletContextInitializer; |
|
||||||
import org.springframework.boot.web.servlet.server.AbstractServletWebServerFactory; |
|
||||||
import org.springframework.boot.web.servlet.server.ServletWebServerFactory; |
|
||||||
|
|
||||||
import static org.mockito.Mockito.spy; |
|
||||||
|
|
||||||
/** |
|
||||||
* Mock {@link ServletWebServerFactory}. |
|
||||||
* |
|
||||||
* @author Phillip Webb |
|
||||||
* @author Andy Wilkinson |
|
||||||
*/ |
|
||||||
public class MockServletWebServerFactory extends AbstractServletWebServerFactory { |
|
||||||
|
|
||||||
private MockServletWebServer webServer; |
|
||||||
|
|
||||||
@Override |
|
||||||
public WebServer getWebServer(ServletContextInitializer... initializers) { |
|
||||||
this.webServer = spy(new MockServletWebServer(mergeInitializers(initializers), getPort())); |
|
||||||
return this.webServer; |
|
||||||
} |
|
||||||
|
|
||||||
public MockServletWebServer getWebServer() { |
|
||||||
return this.webServer; |
|
||||||
} |
|
||||||
|
|
||||||
public ServletContext getServletContext() { |
|
||||||
return (getWebServer() != null) ? getWebServer().getServletContext() : null; |
|
||||||
} |
|
||||||
|
|
||||||
public RegisteredServlet getRegisteredServlet(int index) { |
|
||||||
return (getWebServer() != null) ? getWebServer().getRegisteredServlet(index) : null; |
|
||||||
} |
|
||||||
|
|
||||||
public RegisteredFilter getRegisteredFilter(int index) { |
|
||||||
return (getWebServer() != null) ? getWebServer().getRegisteredFilters(index) : null; |
|
||||||
} |
|
||||||
|
|
||||||
static class MockServletWebServer extends org.springframework.boot.testsupport.web.servlet.MockServletWebServer |
|
||||||
implements WebServer { |
|
||||||
|
|
||||||
MockServletWebServer(ServletContextInitializer[] initializers, int port) { |
|
||||||
super(Arrays.stream(initializers) |
|
||||||
.map((initializer) -> (Initializer) initializer::onStartup) |
|
||||||
.toArray(Initializer[]::new), port); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void start() { |
|
||||||
} |
|
||||||
|
|
||||||
} |
|
||||||
|
|
||||||
} |
|
||||||
@ -1,56 +0,0 @@ |
|||||||
/* |
|
||||||
* Copyright 2012-2023 the original author or authors. |
|
||||||
* |
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
||||||
* you may not use this file except in compliance with the License. |
|
||||||
* You may obtain a copy of the License at |
|
||||||
* |
|
||||||
* https://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
* |
|
||||||
* Unless required by applicable law or agreed to in writing, software |
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS, |
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
||||||
* See the License for the specific language governing permissions and |
|
||||||
* limitations under the License. |
|
||||||
*/ |
|
||||||
|
|
||||||
package org.springframework.boot.testsupport.web.servlet; |
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test; |
|
||||||
|
|
||||||
import org.springframework.mock.web.MockSessionCookieConfig; |
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat; |
|
||||||
|
|
||||||
/** |
|
||||||
* Tests for {@link MockServletWebServer}. |
|
||||||
* |
|
||||||
* @author Stephane Nicoll |
|
||||||
*/ |
|
||||||
class MockServletWebServerTests { |
|
||||||
|
|
||||||
@Test |
|
||||||
void servletContextIsConfigured() { |
|
||||||
MockServletWebServer server = TestMockServletWebServer.create(); |
|
||||||
assertThat(server.getServletContext()).isNotNull(); |
|
||||||
} |
|
||||||
|
|
||||||
@Test |
|
||||||
void servletContextHasSessionCookieConfigConfigured() { |
|
||||||
MockServletWebServer server = TestMockServletWebServer.create(); |
|
||||||
assertThat(server.getServletContext().getSessionCookieConfig()).isInstanceOf(MockSessionCookieConfig.class); |
|
||||||
} |
|
||||||
|
|
||||||
private static final class TestMockServletWebServer extends MockServletWebServer { |
|
||||||
|
|
||||||
private TestMockServletWebServer(Initializer[] initializers, int port) { |
|
||||||
super(initializers, port); |
|
||||||
} |
|
||||||
|
|
||||||
static MockServletWebServer create(Initializer... initializers) { |
|
||||||
return new TestMockServletWebServer(initializers, 8080); |
|
||||||
} |
|
||||||
|
|
||||||
} |
|
||||||
|
|
||||||
} |
|
||||||
@ -0,0 +1,70 @@ |
|||||||
|
/* |
||||||
|
* Copyright 2012-2025 the original author or authors. |
||||||
|
* |
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||||
|
* you may not use this file except in compliance with the License. |
||||||
|
* You may obtain a copy of the License at |
||||||
|
* |
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* |
||||||
|
* Unless required by applicable law or agreed to in writing, software |
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||||
|
* See the License for the specific language governing permissions and |
||||||
|
* limitations under the License. |
||||||
|
*/ |
||||||
|
|
||||||
|
package org.springframework.boot.web.reactive.server; |
||||||
|
|
||||||
|
import java.util.Map; |
||||||
|
|
||||||
|
import org.springframework.boot.web.server.WebServer; |
||||||
|
import org.springframework.http.server.reactive.HttpHandler; |
||||||
|
|
||||||
|
/** |
||||||
|
* A mock reactive {@link WebServer}. |
||||||
|
* |
||||||
|
* @author Brian Clozel |
||||||
|
*/ |
||||||
|
public class MockReactiveWebServer implements WebServer { |
||||||
|
|
||||||
|
private final int port; |
||||||
|
|
||||||
|
private HttpHandler httpHandler; |
||||||
|
|
||||||
|
private Map<String, HttpHandler> httpHandlerMap; |
||||||
|
|
||||||
|
MockReactiveWebServer(HttpHandler httpHandler, int port) { |
||||||
|
this.httpHandler = httpHandler; |
||||||
|
this.port = port; |
||||||
|
} |
||||||
|
|
||||||
|
MockReactiveWebServer(Map<String, HttpHandler> httpHandlerMap, int port) { |
||||||
|
this.httpHandlerMap = httpHandlerMap; |
||||||
|
this.port = port; |
||||||
|
} |
||||||
|
|
||||||
|
public HttpHandler getHttpHandler() { |
||||||
|
return this.httpHandler; |
||||||
|
} |
||||||
|
|
||||||
|
public Map<String, HttpHandler> getHttpHandlerMap() { |
||||||
|
return this.httpHandlerMap; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void start() { |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void stop() { |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public int getPort() { |
||||||
|
return this.port; |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
Loading…
Reference in new issue