From 6b51788ee7c2a8b147744bc11d220fb3ed896672 Mon Sep 17 00:00:00 2001 From: Teemu Suo-Anttila Date: Sun, 18 Dec 2016 08:45:05 +0200 Subject: Add CDI dependency version to vaadin-bom (#8020) Unify test UIs and test code for Spring and CDI. --- bom/pom.xml | 6 ++ test/cdi/pom.xml | 76 ++++++++++++++++++++++ .../main/java/com/vaadin/test/cdi/MyVaadinUI.java | 26 ++++++++ .../java/com/vaadin/test/cdi/ThankYouService.java | 7 ++ .../com/vaadin/test/cdi/ThankYouServiceImpl.java | 14 ++++ .../java/com/vaadin/test/cdi/VaadinCDISmokeIT.java | 36 ++++++++++ test/pom.xml | 9 ++- .../src/main/java/com/example/DemoApplication.java | 7 +- .../src/main/java/com/example/ThankYouService.java | 13 ++++ .../test/java/com/example/SpringBootSmokeTest.java | 44 ------------- .../java/com/example/VaadinSpringBootSmokeIT.java | 44 +++++++++++++ 11 files changed, 234 insertions(+), 48 deletions(-) create mode 100644 test/cdi/pom.xml create mode 100644 test/cdi/src/main/java/com/vaadin/test/cdi/MyVaadinUI.java create mode 100644 test/cdi/src/main/java/com/vaadin/test/cdi/ThankYouService.java create mode 100644 test/cdi/src/main/java/com/vaadin/test/cdi/ThankYouServiceImpl.java create mode 100644 test/cdi/src/test/java/com/vaadin/test/cdi/VaadinCDISmokeIT.java create mode 100644 test/spring-boot/src/main/java/com/example/ThankYouService.java delete mode 100644 test/spring-boot/src/test/java/com/example/SpringBootSmokeTest.java create mode 100644 test/spring-boot/src/test/java/com/example/VaadinSpringBootSmokeIT.java diff --git a/bom/pom.xml b/bom/pom.xml index 4788c99576..c9b7178305 100644 --- a/bom/pom.xml +++ b/bom/pom.xml @@ -18,6 +18,7 @@ 2.0-SNAPSHOT 5.0.0.alpha2 + 2.0-SNAPSHOT @@ -111,6 +112,11 @@ vaadin-testbench ${vaadin.testbench.version} + + com.vaadin + vaadin-cdi + ${vaadin.cdi.version} + diff --git a/test/cdi/pom.xml b/test/cdi/pom.xml new file mode 100644 index 0000000000..30398c656e --- /dev/null +++ b/test/cdi/pom.xml @@ -0,0 +1,76 @@ + + + 4.0.0 + + com.vaadin + vaadin-test + 8.0-SNAPSHOT + + vaadin-test-cdi + war + + + + + com.vaadin + vaadin-cdi + + + com.vaadin + vaadin-client-compiled + + + + + javax.enterprise + cdi-api + 1.2 + + + + + ROOT + + + + org.eclipse.jetty + jetty-maven-plugin + ${jetty.version} + + + start-jetty + + + + stop-jetty + + + + + + org.wildfly.plugins + wildfly-maven-plugin + 1.0.2.Final + + + start-wildfly + pre-integration-test + + start + deploy + + + + stop-wildfly + post-integration-test + + shutdown + + + + + + + + diff --git a/test/cdi/src/main/java/com/vaadin/test/cdi/MyVaadinUI.java b/test/cdi/src/main/java/com/vaadin/test/cdi/MyVaadinUI.java new file mode 100644 index 0000000000..58b479b2b1 --- /dev/null +++ b/test/cdi/src/main/java/com/vaadin/test/cdi/MyVaadinUI.java @@ -0,0 +1,26 @@ +package com.vaadin.test.cdi; + +import javax.inject.Inject; + +import com.vaadin.annotations.Theme; +import com.vaadin.cdi.CDIUI; +import com.vaadin.server.VaadinRequest; +import com.vaadin.ui.Button; +import com.vaadin.ui.Notification; +import com.vaadin.ui.UI; + +@Theme("valo") +@CDIUI("") +@SuppressWarnings("serial") +public class MyVaadinUI extends UI { + + @Inject + private ThankYouService service; + + @Override + protected void init(VaadinRequest request) { + setContent(new Button("Click Me", + e -> Notification.show(service.getText()))); + } + +} diff --git a/test/cdi/src/main/java/com/vaadin/test/cdi/ThankYouService.java b/test/cdi/src/main/java/com/vaadin/test/cdi/ThankYouService.java new file mode 100644 index 0000000000..abdcc3bab5 --- /dev/null +++ b/test/cdi/src/main/java/com/vaadin/test/cdi/ThankYouService.java @@ -0,0 +1,7 @@ +package com.vaadin.test.cdi; + +public interface ThankYouService { + + String getText(); + +} diff --git a/test/cdi/src/main/java/com/vaadin/test/cdi/ThankYouServiceImpl.java b/test/cdi/src/main/java/com/vaadin/test/cdi/ThankYouServiceImpl.java new file mode 100644 index 0000000000..fd22f5833a --- /dev/null +++ b/test/cdi/src/main/java/com/vaadin/test/cdi/ThankYouServiceImpl.java @@ -0,0 +1,14 @@ +package com.vaadin.test.cdi; + +import javax.enterprise.context.ApplicationScoped; + +@ApplicationScoped +public class ThankYouServiceImpl implements ThankYouService { + + public static final String THANK_YOU_TEXT = "Thank you for clicking!"; + + @Override + public String getText() { + return THANK_YOU_TEXT; + } +} diff --git a/test/cdi/src/test/java/com/vaadin/test/cdi/VaadinCDISmokeIT.java b/test/cdi/src/test/java/com/vaadin/test/cdi/VaadinCDISmokeIT.java new file mode 100644 index 0000000000..d3244417db --- /dev/null +++ b/test/cdi/src/test/java/com/vaadin/test/cdi/VaadinCDISmokeIT.java @@ -0,0 +1,36 @@ +package com.vaadin.test.cdi; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.openqa.selenium.phantomjs.PhantomJSDriver; + +import com.vaadin.testbench.ScreenshotOnFailureRule; +import com.vaadin.testbench.TestBenchTestCase; +import com.vaadin.testbench.elements.ButtonElement; +import com.vaadin.testbench.elements.NotificationElement; + +public class VaadinCDISmokeIT extends TestBenchTestCase { + + @Rule + public ScreenshotOnFailureRule rule = new ScreenshotOnFailureRule(this, + true); + + @Before + public void setup() { + // Screenshot rule tears down the driver + setDriver(new PhantomJSDriver()); + } + + @Test + public void testPageLoadsAndCanBeInterractedWith() { + getDriver().navigate().to("http://localhost:8080/"); + + $(ButtonElement.class).first().click(); + + Assert.assertTrue($(NotificationElement.class).exists()); + Assert.assertEquals(ThankYouServiceImpl.THANK_YOU_TEXT, + $(NotificationElement.class).first().getText()); + } +} diff --git a/test/pom.xml b/test/pom.xml index 6215d61112..f9a38d0592 100644 --- a/test/pom.xml +++ b/test/pom.xml @@ -15,7 +15,6 @@ 2.1.1 8.0-SNAPSHOT false - 5.0.0.alpha1 @@ -40,6 +39,12 @@ + + javax.servlet + javax.servlet-api + 3.0.1 + + com.vaadin @@ -60,7 +65,6 @@ com.vaadin vaadin-testbench - ${vaadin.testbench.version} test @@ -75,6 +79,7 @@ space in directory vaadinservletconfiguration-widget-set spring-boot + cdi diff --git a/test/spring-boot/src/main/java/com/example/DemoApplication.java b/test/spring-boot/src/main/java/com/example/DemoApplication.java index 9a4edd8769..62e6a76a36 100644 --- a/test/spring-boot/src/main/java/com/example/DemoApplication.java +++ b/test/spring-boot/src/main/java/com/example/DemoApplication.java @@ -1,5 +1,6 @@ package com.example; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @@ -19,11 +20,13 @@ public class DemoApplication { @SpringUI class MyUI extends UI { - public static final String NOTIFICATION_TEXT = "Thank you for clicking."; + + @Autowired + ThankYouService service; @Override protected void init(VaadinRequest request) { setContent(new Button("Click Me!", - e -> Notification.show(NOTIFICATION_TEXT))); + e -> Notification.show(service.getText()))); } } diff --git a/test/spring-boot/src/main/java/com/example/ThankYouService.java b/test/spring-boot/src/main/java/com/example/ThankYouService.java new file mode 100644 index 0000000000..b387046659 --- /dev/null +++ b/test/spring-boot/src/main/java/com/example/ThankYouService.java @@ -0,0 +1,13 @@ +package com.example; + +import org.springframework.stereotype.Service; + +@Service +public class ThankYouService { + + public static final String THANK_YOU_TEXT = "Thank you for clicking."; + + public String getText() { + return THANK_YOU_TEXT; + } +} diff --git a/test/spring-boot/src/test/java/com/example/SpringBootSmokeTest.java b/test/spring-boot/src/test/java/com/example/SpringBootSmokeTest.java deleted file mode 100644 index fe5357579b..0000000000 --- a/test/spring-boot/src/test/java/com/example/SpringBootSmokeTest.java +++ /dev/null @@ -1,44 +0,0 @@ -package com.example; - -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.openqa.selenium.phantomjs.PhantomJSDriver; -import org.springframework.boot.context.embedded.LocalServerPort; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; - -import com.vaadin.testbench.TestBench; -import com.vaadin.testbench.TestBenchTestCase; -import com.vaadin.testbench.elements.ButtonElement; -import com.vaadin.testbench.elements.NotificationElement; -import com.vaadin.testbench.parallel.Browser; - -/** - * @author Vaadin Ltd - * - */ -@RunWith(SpringJUnit4ClassRunner.class) -@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) -public class SpringBootSmokeTest extends TestBenchTestCase { - - @LocalServerPort - Integer port; - - @Before - public void setUp() { - setDriver(TestBench.createDriver(new PhantomJSDriver( - Browser.PHANTOMJS.getDesiredCapabilities()))); - } - - @Test - public void testPageLoadsAndButtonWorks() { - getDriver().navigate().to("http://localhost:" + port + ""); - $(ButtonElement.class).first().click(); - Assert.assertTrue($(NotificationElement.class).exists()); - Assert.assertEquals(MyUI.NOTIFICATION_TEXT, - $(NotificationElement.class).first().getText()); - } -} diff --git a/test/spring-boot/src/test/java/com/example/VaadinSpringBootSmokeIT.java b/test/spring-boot/src/test/java/com/example/VaadinSpringBootSmokeIT.java new file mode 100644 index 0000000000..2f1cb545d8 --- /dev/null +++ b/test/spring-boot/src/test/java/com/example/VaadinSpringBootSmokeIT.java @@ -0,0 +1,44 @@ +package com.example; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.openqa.selenium.phantomjs.PhantomJSDriver; +import org.springframework.boot.context.embedded.LocalServerPort; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +import com.vaadin.testbench.TestBench; +import com.vaadin.testbench.TestBenchTestCase; +import com.vaadin.testbench.elements.ButtonElement; +import com.vaadin.testbench.elements.NotificationElement; +import com.vaadin.testbench.parallel.Browser; + +/** + * @author Vaadin Ltd + * + */ +@RunWith(SpringJUnit4ClassRunner.class) +@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) +public class VaadinSpringBootSmokeIT extends TestBenchTestCase { + + @LocalServerPort + Integer port; + + @Before + public void setUp() { + setDriver(TestBench.createDriver(new PhantomJSDriver( + Browser.PHANTOMJS.getDesiredCapabilities()))); + } + + @Test + public void testPageLoadsAndButtonWorks() { + getDriver().navigate().to("http://localhost:" + port + ""); + $(ButtonElement.class).first().click(); + Assert.assertTrue($(NotificationElement.class).exists()); + Assert.assertEquals(ThankYouService.THANK_YOU_TEXT, + $(NotificationElement.class).first().getText()); + } +} -- cgit v1.2.3