-
Notifications
You must be signed in to change notification settings - Fork 167
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…19944) Co-authored-by: Mikhail Shabarov <61410877+mshabarov@users.noreply.github.com>
- Loading branch information
1 parent
1d19d44
commit 7127763
Showing
2 changed files
with
63 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
...ring/src/test/java/com/vaadin/flow/spring/SpringBootAutoConfigurationConditionalTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
* Copyright 2000-2023 Vaadin Ltd. | ||
* | ||
* 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 | ||
* | ||
* http://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 com.vaadin.flow.spring; | ||
|
||
import org.junit.Test; | ||
import org.springframework.boot.autoconfigure.AutoConfigurations; | ||
import org.springframework.boot.test.context.runner.WebApplicationContextRunner; | ||
import org.springframework.boot.web.servlet.ServletRegistrationBean; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.web.context.WebApplicationContext; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
public class SpringBootAutoConfigurationConditionalTest { | ||
|
||
@Test | ||
public void customServletRegistrationBean() { | ||
new WebApplicationContextRunner() | ||
.withConfiguration(AutoConfigurations | ||
.of(SpringBootAutoConfiguration.class)) | ||
.withUserConfiguration( | ||
ServletRegistrationBeanConfiguration.class) | ||
.run(context -> assertThat(context) | ||
.getBean(ServletRegistrationBean.class).isInstanceOf( | ||
ServletRegistrationBeanConfiguration.MockServletRegistrationBean.class)); | ||
} | ||
|
||
@Configuration(proxyBeanMethods = false) | ||
public static class ServletRegistrationBeanConfiguration { | ||
|
||
@Bean | ||
public ServletRegistrationBean<SpringServlet> servletRegistrationBean( | ||
final WebApplicationContext webApplicationContext) { | ||
return new MockServletRegistrationBean(webApplicationContext); | ||
} | ||
|
||
public static class MockServletRegistrationBean | ||
extends ServletRegistrationBean<SpringServlet> { | ||
|
||
public MockServletRegistrationBean( | ||
final WebApplicationContext webApplicationContext) { | ||
super(new SpringServlet(webApplicationContext, false)); | ||
} | ||
} | ||
|
||
} | ||
} |