Skip to content

Commit

Permalink
Use lookup initializer SPI to create and init Lookup using Spring awa…
Browse files Browse the repository at this point in the history
…re 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.
  • Loading branch information
Denis authored Jan 7, 2021
1 parent db61d03 commit 29cf6bd
Show file tree
Hide file tree
Showing 12 changed files with 548 additions and 75 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@

import org.junit.Assert;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.ExpectedConditions;

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

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

private TestBenchElement mainView;

@Override
@Before
public void setup() throws Exception {
super.setup();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
Expand All @@ -29,6 +30,7 @@
/**
* Class for testing issues in a spring-boot container.
*/
@Ignore("Ignored because of https://github.com/vaadin/flow/issues/9751")
public class AppViewIT extends ChromeBrowserTest {

private void openTestUrl(String url) {
Expand All @@ -38,6 +40,7 @@ private void openTestUrl(String url) {
private TestBenchElement testComponent;
private WebElement content;

@Override
@Before
public void setup() throws Exception {
super.setup();
Expand All @@ -54,13 +57,15 @@ public void tearDown() {
*/
@Test
public void should_load_web_component() {
WebElement button = testComponent.$(TestBenchElement.class).id("button");
WebElement button = testComponent.$(TestBenchElement.class)
.id("button");
button.click();
verifyContent("Hello World");
}

/**
* Just a control test that assures that webcomponents is working.
*
* @throws Exception
*/
@Test
Expand All @@ -73,9 +78,10 @@ public void should_request_connect_service() throws Exception {
}

@Test
public void should_request_packagePrivate_connect_service() throws Exception {
WebElement button = testComponent.$(TestBenchElement.class).id(
"helloFromPackagePrivate");
public void should_request_packagePrivate_connect_service()
throws Exception {
WebElement button = testComponent.$(TestBenchElement.class)
.id("helloFromPackagePrivate");
button.click();

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

@Test
public void should_requestAnonymously_connect_service() throws Exception {
WebElement button = testComponent.$(TestBenchElement.class).id(
"helloAnonymous");
WebElement button = testComponent.$(TestBenchElement.class)
.id("helloAnonymous");
button.click();

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

@Test
public void should_requestAnonymously_packagePrivate_connect_service() throws Exception {
WebElement button = testComponent.$(TestBenchElement.class).id(
"helloAnonymousFromPackagePrivate");
public void should_requestAnonymously_packagePrivate_connect_service()
throws Exception {
WebElement button = testComponent.$(TestBenchElement.class)
.id("helloAnonymousFromPackagePrivate");
button.click();

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

@Test
public void should_requestAnonymously_when_CallConnectServiceFromANestedUrl() throws Exception {
public void should_requestAnonymously_when_CallConnectServiceFromANestedUrl()
throws Exception {
openTestUrl("/more/levels/url");

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

WebElement button = testComponent.$(TestBenchElement.class).id(
"helloAnonymous");
WebElement button = testComponent.$(TestBenchElement.class)
.id("helloAnonymous");
button.click();

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

@Test
public void should_useSendNull_when_paramterIsUndefined() {
WebElement button = testComponent.$(TestBenchElement.class).id(
"echoWithOptional");
WebElement button = testComponent.$(TestBenchElement.class)
.id("echoWithOptional");
button.click();

// Wait for the server connect response
Expand Down Expand Up @@ -198,6 +206,7 @@ public void should_checkUser() {
testComponent.$(TestBenchElement.class).id("checkUser").click();
verifyCheckUser("user");
}

@Test
public void should_checkAdminUser() {
login("admin");
Expand All @@ -208,14 +217,15 @@ public void should_checkAdminUser() {
@Test
public void should_checkUserFromVaadinRequest() {
login("user");
testComponent.$(TestBenchElement.class).id("checkUserFromVaadinRequest").click();
testComponent.$(TestBenchElement.class).id("checkUserFromVaadinRequest")
.click();
verifyCheckUserFromVaadinRequest("user");
}

@Test
public void should_updateTitleInDOMWithInjectedService(){
Assert.assertEquals("titleRetrievedFromAService",
driver.findElement(By.tagName("title")).getAttribute("textContent"));
public void should_updateTitleInDOMWithInjectedService() {
Assert.assertEquals("titleRetrievedFromAService", driver
.findElement(By.tagName("title")).getAttribute("textContent"));
}

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

WebElement button = testComponent.$(TestBenchElement.class).id(
"helloAnonymous");
WebElement button = testComponent.$(TestBenchElement.class)
.id("helloAnonymous");
button.click();

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

private void verifyCheckUserFromVaadinRequest(String expectedMessage) {
testComponent.$(TestBenchElement.class).id("checkUserFromVaadinRequest").click();
testComponent.$(TestBenchElement.class).id("checkUserFromVaadinRequest")
.click();
verifyContent(expectedMessage);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,9 @@ public class SpringApplicationConfigurationFactory
@Override
protected ApplicationConfigurationImpl doCreate(VaadinContext context,
FallbackChunk chunk, Map<String, String> properties) {
// don't use Spring component and injection because there is no way to
// get the object of this class as a Spring bean (it comes from standard
// WAR Lookup which instantiates everything directly via default CTOR)
VaadinServletContext servletContext = (VaadinServletContext) context;
ApplicationContext appContext = WebApplicationContextUtils
.getWebApplicationContext(servletContext.getContext());
// sometimes for deployable WAR (couldn't find exact circumstances) the
// web app context is not yet available here
if (appContext == null) {
return super.doCreate(context, chunk, properties);
}
Environment env = appContext.getBean(Environment.class);
// Collect any vaadin.XZY properties from application.properties
SpringServlet.PROPERTY_NAMES.stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.socket.server.standard.ServerEndpointExporter;

import com.vaadin.flow.server.Constants;

/**
* Spring boot auto-configuration class for Flow.
*
Expand All @@ -44,7 +42,8 @@
@AutoConfigureBefore(WebMvcAutoConfiguration.class)
@ConditionalOnClass(ServletContextInitializer.class)
@EnableConfigurationProperties(VaadinConfigurationProperties.class)
@Import({ VaadinServletConfiguration.class })
@Import({ VaadinApplicationConfiguration.class,
VaadinServletConfiguration.class })
public class SpringBootAutoConfiguration {

@Autowired
Expand Down
Loading

0 comments on commit 29cf6bd

Please sign in to comment.