Skip to content

Commit 29cf6bd

Browse files
author
Denis
authored
Use lookup initializer SPI to create and init Lookup using Spring aware beans (#711)
* fix: initialize Lookup when app context is available * Implement SPI to initialize lookup when app context is available * Allow to use Spring beans in lookup * Make it possible to override Spring application configuration * fix: add configuration to Spring boot auto config fixes #710, #707, #712.
1 parent db61d03 commit 29cf6bd

File tree

12 files changed

+548
-75
lines changed

12 files changed

+548
-75
lines changed

vaadin-spring-tests/test-ts-services-custom-client/src/test/java/com/vaadin/flow/connect/AppViewIT.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919

2020
import org.junit.Assert;
2121
import org.junit.Before;
22+
import org.junit.Ignore;
2223
import org.junit.Test;
2324
import org.openqa.selenium.By;
24-
import org.openqa.selenium.WebElement;
2525
import org.openqa.selenium.support.ui.ExpectedConditions;
2626

2727
import com.vaadin.flow.testutil.ChromeBrowserTest;
@@ -30,6 +30,7 @@
3030
/**
3131
* Class for testing issues in a spring-boot container.
3232
*/
33+
@Ignore("Ignored because of https://github.com/vaadin/flow/issues/9751")
3334
public class AppViewIT extends ChromeBrowserTest {
3435

3536
private void openTestUrl(String url) {
@@ -38,6 +39,7 @@ private void openTestUrl(String url) {
3839

3940
private TestBenchElement mainView;
4041

42+
@Override
4143
@Before
4244
public void setup() throws Exception {
4345
super.setup();

vaadin-spring-tests/test-ts-services/src/test/java/com/vaadin/flow/connect/AppViewIT.java

Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import org.junit.After;
1919
import org.junit.Assert;
2020
import org.junit.Before;
21+
import org.junit.Ignore;
2122
import org.junit.Test;
2223
import org.openqa.selenium.By;
2324
import org.openqa.selenium.WebElement;
@@ -29,6 +30,7 @@
2930
/**
3031
* Class for testing issues in a spring-boot container.
3132
*/
33+
@Ignore("Ignored because of https://github.com/vaadin/flow/issues/9751")
3234
public class AppViewIT extends ChromeBrowserTest {
3335

3436
private void openTestUrl(String url) {
@@ -38,6 +40,7 @@ private void openTestUrl(String url) {
3840
private TestBenchElement testComponent;
3941
private WebElement content;
4042

43+
@Override
4144
@Before
4245
public void setup() throws Exception {
4346
super.setup();
@@ -54,13 +57,15 @@ public void tearDown() {
5457
*/
5558
@Test
5659
public void should_load_web_component() {
57-
WebElement button = testComponent.$(TestBenchElement.class).id("button");
60+
WebElement button = testComponent.$(TestBenchElement.class)
61+
.id("button");
5862
button.click();
5963
verifyContent("Hello World");
6064
}
6165

6266
/**
6367
* Just a control test that assures that webcomponents is working.
68+
*
6469
* @throws Exception
6570
*/
6671
@Test
@@ -73,9 +78,10 @@ public void should_request_connect_service() throws Exception {
7378
}
7479

7580
@Test
76-
public void should_request_packagePrivate_connect_service() throws Exception {
77-
WebElement button = testComponent.$(TestBenchElement.class).id(
78-
"helloFromPackagePrivate");
81+
public void should_request_packagePrivate_connect_service()
82+
throws Exception {
83+
WebElement button = testComponent.$(TestBenchElement.class)
84+
.id("helloFromPackagePrivate");
7985
button.click();
8086

8187
// Wait for the server connect response
@@ -84,33 +90,35 @@ public void should_request_packagePrivate_connect_service() throws Exception {
8490

8591
@Test
8692
public void should_requestAnonymously_connect_service() throws Exception {
87-
WebElement button = testComponent.$(TestBenchElement.class).id(
88-
"helloAnonymous");
93+
WebElement button = testComponent.$(TestBenchElement.class)
94+
.id("helloAnonymous");
8995
button.click();
9096

9197
// Wait for the server connect response
9298
verifyContent("Hello, stranger!");
9399
}
94100

95101
@Test
96-
public void should_requestAnonymously_packagePrivate_connect_service() throws Exception {
97-
WebElement button = testComponent.$(TestBenchElement.class).id(
98-
"helloAnonymousFromPackagePrivate");
102+
public void should_requestAnonymously_packagePrivate_connect_service()
103+
throws Exception {
104+
WebElement button = testComponent.$(TestBenchElement.class)
105+
.id("helloAnonymousFromPackagePrivate");
99106
button.click();
100107

101108
// Wait for the server connect response
102109
verifyContent("Hello from package private endpoint!");
103110
}
104111

105112
@Test
106-
public void should_requestAnonymously_when_CallConnectServiceFromANestedUrl() throws Exception {
113+
public void should_requestAnonymously_when_CallConnectServiceFromANestedUrl()
114+
throws Exception {
107115
openTestUrl("/more/levels/url");
108116

109117
testComponent = $("test-component").first();
110118
content = testComponent.$(TestBenchElement.class).id("content");
111119

112-
WebElement button = testComponent.$(TestBenchElement.class).id(
113-
"helloAnonymous");
120+
WebElement button = testComponent.$(TestBenchElement.class)
121+
.id("helloAnonymous");
114122
button.click();
115123

116124
// Wait for the server connect response
@@ -119,8 +127,8 @@ public void should_requestAnonymously_when_CallConnectServiceFromANestedUrl() th
119127

120128
@Test
121129
public void should_useSendNull_when_paramterIsUndefined() {
122-
WebElement button = testComponent.$(TestBenchElement.class).id(
123-
"echoWithOptional");
130+
WebElement button = testComponent.$(TestBenchElement.class)
131+
.id("echoWithOptional");
124132
button.click();
125133

126134
// Wait for the server connect response
@@ -198,6 +206,7 @@ public void should_checkUser() {
198206
testComponent.$(TestBenchElement.class).id("checkUser").click();
199207
verifyCheckUser("user");
200208
}
209+
201210
@Test
202211
public void should_checkAdminUser() {
203212
login("admin");
@@ -208,14 +217,15 @@ public void should_checkAdminUser() {
208217
@Test
209218
public void should_checkUserFromVaadinRequest() {
210219
login("user");
211-
testComponent.$(TestBenchElement.class).id("checkUserFromVaadinRequest").click();
220+
testComponent.$(TestBenchElement.class).id("checkUserFromVaadinRequest")
221+
.click();
212222
verifyCheckUserFromVaadinRequest("user");
213223
}
214224

215225
@Test
216-
public void should_updateTitleInDOMWithInjectedService(){
217-
Assert.assertEquals("titleRetrievedFromAService",
218-
driver.findElement(By.tagName("title")).getAttribute("textContent"));
226+
public void should_updateTitleInDOMWithInjectedService() {
227+
Assert.assertEquals("titleRetrievedFromAService", driver
228+
.findElement(By.tagName("title")).getAttribute("textContent"));
219229
}
220230

221231
@Test
@@ -230,8 +240,8 @@ public void should_requestAnonymously_after_logout() throws Exception {
230240
Assert.assertNotEquals("CSRF token should change for the new session",
231241
originalCsrfToken, csrfToken);
232242

233-
WebElement button = testComponent.$(TestBenchElement.class).id(
234-
"helloAnonymous");
243+
WebElement button = testComponent.$(TestBenchElement.class)
244+
.id("helloAnonymous");
235245
button.click();
236246

237247
// Wait for the server connect response
@@ -278,7 +288,8 @@ private void verifyCheckUser(String expectedMessage) {
278288
}
279289

280290
private void verifyCheckUserFromVaadinRequest(String expectedMessage) {
281-
testComponent.$(TestBenchElement.class).id("checkUserFromVaadinRequest").click();
291+
testComponent.$(TestBenchElement.class).id("checkUserFromVaadinRequest")
292+
.click();
282293
verifyContent(expectedMessage);
283294
}
284295

vaadin-spring/src/main/java/com/vaadin/flow/spring/SpringApplicationConfigurationFactory.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,9 @@ public class SpringApplicationConfigurationFactory
3939
@Override
4040
protected ApplicationConfigurationImpl doCreate(VaadinContext context,
4141
FallbackChunk chunk, Map<String, String> properties) {
42-
// don't use Spring component and injection because there is no way to
43-
// get the object of this class as a Spring bean (it comes from standard
44-
// WAR Lookup which instantiates everything directly via default CTOR)
4542
VaadinServletContext servletContext = (VaadinServletContext) context;
4643
ApplicationContext appContext = WebApplicationContextUtils
4744
.getWebApplicationContext(servletContext.getContext());
48-
// sometimes for deployable WAR (couldn't find exact circumstances) the
49-
// web app context is not yet available here
50-
if (appContext == null) {
51-
return super.doCreate(context, chunk, properties);
52-
}
5345
Environment env = appContext.getBean(Environment.class);
5446
// Collect any vaadin.XZY properties from application.properties
5547
SpringServlet.PROPERTY_NAMES.stream()

vaadin-spring/src/main/java/com/vaadin/flow/spring/SpringBootAutoConfiguration.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@
3232
import org.springframework.web.context.WebApplicationContext;
3333
import org.springframework.web.socket.server.standard.ServerEndpointExporter;
3434

35-
import com.vaadin.flow.server.Constants;
36-
3735
/**
3836
* Spring boot auto-configuration class for Flow.
3937
*
@@ -44,7 +42,8 @@
4442
@AutoConfigureBefore(WebMvcAutoConfiguration.class)
4543
@ConditionalOnClass(ServletContextInitializer.class)
4644
@EnableConfigurationProperties(VaadinConfigurationProperties.class)
47-
@Import({ VaadinServletConfiguration.class })
45+
@Import({ VaadinApplicationConfiguration.class,
46+
VaadinServletConfiguration.class })
4847
public class SpringBootAutoConfiguration {
4948

5049
@Autowired

0 commit comments

Comments
 (0)