Browse Source

Add CDI dependency version to vaadin-bom (#8020)

Unify test UIs and test code for Spring and CDI.
tags/8.0.0.beta1
Teemu Suo-Anttila 7 years ago
parent
commit
6b51788ee7

+ 6
- 0
bom/pom.xml View File

@@ -18,6 +18,7 @@
<properties>
<vaadin.spring.version>2.0-SNAPSHOT</vaadin.spring.version>
<vaadin.testbench.version>5.0.0.alpha2</vaadin.testbench.version>
<vaadin.cdi.version>2.0-SNAPSHOT</vaadin.cdi.version>
</properties>

<repositories>
@@ -111,6 +112,11 @@
<artifactId>vaadin-testbench</artifactId>
<version>${vaadin.testbench.version}</version>
</dependency>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-cdi</artifactId>
<version>${vaadin.cdi.version}</version>
</dependency>

</dependencies>
</dependencyManagement>

+ 76
- 0
test/cdi/pom.xml View File

@@ -0,0 +1,76 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-test</artifactId>
<version>8.0-SNAPSHOT</version>
</parent>
<artifactId>vaadin-test-cdi</artifactId>
<packaging>war</packaging>


<dependencies>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-cdi</artifactId>
</dependency>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-client-compiled</artifactId>
</dependency>

<!-- CDI API dependency -->
<dependency>
<groupId>javax.enterprise</groupId>
<artifactId>cdi-api</artifactId>
<version>1.2</version>
</dependency>
</dependencies>

<build>
<finalName>ROOT</finalName>
<plugins>
<!-- Disable jetty-plugin -->
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>${jetty.version}</version>
<executions>
<execution>
<id>start-jetty</id>
<phase />
</execution>
<execution>
<id>stop-jetty</id>
<phase />
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.wildfly.plugins</groupId>
<artifactId>wildfly-maven-plugin</artifactId>
<version>1.0.2.Final</version>
<executions>
<execution>
<id>start-wildfly</id>
<phase>pre-integration-test</phase>
<goals>
<goal>start</goal>
<goal>deploy</goal>
</goals>
</execution>
<execution>
<id>stop-wildfly</id>
<phase>post-integration-test</phase>
<goals>
<goal>shutdown</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

</project>

+ 26
- 0
test/cdi/src/main/java/com/vaadin/test/cdi/MyVaadinUI.java View File

@@ -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())));
}

}

+ 7
- 0
test/cdi/src/main/java/com/vaadin/test/cdi/ThankYouService.java View File

@@ -0,0 +1,7 @@
package com.vaadin.test.cdi;

public interface ThankYouService {

String getText();

}

+ 14
- 0
test/cdi/src/main/java/com/vaadin/test/cdi/ThankYouServiceImpl.java View File

@@ -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;
}
}

+ 36
- 0
test/cdi/src/test/java/com/vaadin/test/cdi/VaadinCDISmokeIT.java View File

@@ -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());
}
}

+ 7
- 2
test/pom.xml View File

@@ -15,7 +15,6 @@
<phantomjs.version>2.1.1</phantomjs.version>
<vaadin.version>8.0-SNAPSHOT</vaadin.version>
<failOnMissingWebXml>false</failOnMissingWebXml>
<vaadin.testbench.version>5.0.0.alpha1</vaadin.testbench.version>
</properties>

<repositories>
@@ -40,6 +39,12 @@
<dependencies>

<!-- API DEPENDENCIES -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
</dependency>
<!-- Project modules -->
<dependency>
<groupId>com.vaadin</groupId>
@@ -60,7 +65,6 @@
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-testbench</artifactId>
<version>${vaadin.testbench.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
@@ -75,6 +79,7 @@
<module>space in directory</module>
<module>vaadinservletconfiguration-widget-set</module>
<module>spring-boot</module>
<module>cdi</module>
</modules>

<build>

+ 5
- 2
test/spring-boot/src/main/java/com/example/DemoApplication.java View File

@@ -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())));
}
}

+ 13
- 0
test/spring-boot/src/main/java/com/example/ThankYouService.java View File

@@ -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;
}
}

test/spring-boot/src/test/java/com/example/SpringBootSmokeTest.java → test/spring-boot/src/test/java/com/example/VaadinSpringBootSmokeIT.java View File

@@ -22,7 +22,7 @@ import com.vaadin.testbench.parallel.Browser;
*/
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
public class SpringBootSmokeTest extends TestBenchTestCase {
public class VaadinSpringBootSmokeIT extends TestBenchTestCase {

@LocalServerPort
Integer port;
@@ -38,7 +38,7 @@ public class SpringBootSmokeTest extends TestBenchTestCase {
getDriver().navigate().to("http://localhost:" + port + "");
$(ButtonElement.class).first().click();
Assert.assertTrue($(NotificationElement.class).exists());
Assert.assertEquals(MyUI.NOTIFICATION_TEXT,
Assert.assertEquals(ThankYouService.THANK_YOU_TEXT,
$(NotificationElement.class).first().getText());
}
}

Loading…
Cancel
Save