Browse Source

Automatic test for OSGi/karaf

tags/8.1.1
Ilia Motornyi 2 years ago
parent
commit
456f14f5e5

+ 1
- 0
.gitignore View File

@@ -12,6 +12,7 @@
/extras

uitest/src/main/themes/VAADIN/themes/**/styles.css
test/servlet-containers/karaf/vaadin-karaf-bundle1/src/main/resources/VAADIN/themes/karaftesttheme/styles.css

# Persisted scss cache files
uitest/src/main/themes/VAADIN/themes/**/styles.scss.cache

+ 1
- 0
test/pom.xml View File

@@ -105,6 +105,7 @@
<module>servlet-containers/generic</module>
<module>cdi</module>
<module>servlet-containers/jsp-integration</module>
<module>servlet-containers/karaf</module>
<module>bean-api-validation</module>
<module>bean-impl-validation</module>
<module>dependency-rewrite-addon</module>

+ 31
- 0
test/servlet-containers/karaf/README.md View File

@@ -0,0 +1,31 @@
Automatic test for Karaf deployment
===

What is tested
---
* Multiple applications are deployed and work properly
* Default widgetset works
* Custom widgetset works
* Custom theme works

Tips and Tricks
---
* Karaf is downloaded and deployed by maven karaf plugin
* Karaf is run as a background process using maven `exec:exec` goal
* Karaf is shut down using maven `karaf:client` goal during `post-integration-test` phase
* All required karaf features and project bundles are deployed using maven karaf plugin with `client` goal

Running and stopping karaf manually
---
* To start karaf as a foreground process and deploy both vaadin bundles and two existing applications, run `mvn -f karaf-run-pom.xml clean karaf:run`
in `karaf-run` module
* To start karaf as a background process and deploy both vaadin bundles and two existing applications, run `mvn clean pre-integration-test`
in `karaf-run` module
* Karaf console is available via ssh at `127.0.0.0:8101` port, username/password is `karaf/karaf`
* To stop background karaf process, run `mvn karaf:client@karaf-client-shutdown`
in `karaf-run` module

Potential problems
---
* Maven executable should be in `PATH`
* Background karaf process may be left running for 10 minutes if the build fails prior `integration-test` phase.

+ 21
- 0
test/servlet-containers/karaf/karaf-run/karaf-run-pom.xml View File

@@ -0,0 +1,21 @@
<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/xsd/maven-4.0.0.xsd">
<artifactId>karaf-runner</artifactId>
<groupId>com.vaadin</groupId>
<version>8.1-SNAPSHOT</version>
<modelVersion>4.0.0</modelVersion>
<build>
<plugins>
<plugin>
<groupId>org.apache.karaf.tooling</groupId>
<artifactId>karaf-maven-plugin</artifactId>
<version>4.0.8</version>
<configuration>
<deployProjectArtifact>false</deployProjectArtifact>
<startSsh>true</startSsh>
</configuration>
</plugin>
</plugins>
</build>
</project>

+ 122
- 0
test/servlet-containers/karaf/karaf-run/pom.xml View File

@@ -0,0 +1,122 @@
<?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/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>vaadin-test-karaf</artifactId>
<groupId>com.vaadin</groupId>
<relativePath>..</relativePath>
<version>8.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>karaf-run</artifactId>
<name>Vaadin Karaf Test Runner</name>

<dependencies>
<!--Vaadin dependencies should not be in a classpath-->
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-server</artifactId>
<version>${vaadin.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-themes</artifactId>
<version>${vaadin.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.6.0</version>
<executions>
<execution>
<phase>pre-integration-test</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>mvn</executable>
<async>true</async>
<asyncDestroyOnShutdown>true</asyncDestroyOnShutdown>
<commandlineArgs>-f karaf-run-pom.xml karaf:run</commandlineArgs>
</configuration>
</execution>
</executions>

</plugin>
<plugin>
<groupId>org.apache.karaf.tooling</groupId>
<artifactId>karaf-maven-plugin</artifactId>
<version>4.0.8</version>
<executions>
<execution>
<id>karaf-client-ctrl</id>
<phase>pre-integration-test</phase>
<goals>
<goal>client</goal>
</goals>
<configuration>
<delay>5</delay>
<attempts>150</attempts>
<commands>
<!--Scheduled shutdown in 15 minutes-->
<command>shutdown -f +10</command>
<command>feature:install http</command>
<command>feature:install http-whiteboard</command>
<command>bundle:install -s mvn:org.jsoup/jsoup/1.8.3</command>
<command>bundle:install -s mvn:com.vaadin.external/gentyref/1.2.0.vaadin1</command>
<command>bundle:install -s mvn:com.vaadin/vaadin-shared/${vaadin.version}</command>
<command>bundle:install -s mvn:com.vaadin/vaadin-server/${vaadin.version}</command>
<command>bundle:install -s mvn:com.vaadin/vaadin-osgi-integration/${vaadin.version}</command>
<command>bundle:install -s mvn:com.vaadin/vaadin-client-compiled/${vaadin.version}</command>
<command>bundle:install -s mvn:com.vaadin/vaadin-themes/${vaadin.version}</command>
<command>
<![CDATA[bundle:install -s file:./../vaadin-karaf-bundle1/target/vaadin-karaf-bundle1-${project.version}.jar]]></command>
<command>
<![CDATA[bundle:install -s file:./../vaadin-karaf-bundle2/target/vaadin-karaf-bundle2-${project.version}.jar]]></command>
</commands>
</configuration>
</execution>
<execution>
<id>karaf-client-shutdown</id>
<phase>post-integration-test</phase>
<goals>
<goal>client</goal>
</goals>
<configuration>
<delay>5</delay>
<attempts>10</attempts>
<commands>
<command>system:shutdown -f</command>
</commands>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.19.1</version>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
<configuration>
<environmentVariables>
<vaadin.version>${vaadin.version}</vaadin.version>
</environmentVariables>
</configuration>
</plugin>
</plugins>
</build>
</project>

+ 67
- 0
test/servlet-containers/karaf/karaf-run/src/test/java/com/vaadin/test/osgi/KarafIntegrationIT.java View File

@@ -0,0 +1,67 @@
/*
* Copyright 2000-2017 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.test.osgi;

import com.vaadin.testbench.TestBenchTestCase;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.phantomjs.PhantomJSDriver;

import static org.junit.Assert.assertEquals;

public class KarafIntegrationIT extends TestBenchTestCase {

private static final String URL_PREFIX = "http://localhost:8181/";
private static final String APP1_URL = URL_PREFIX + "myapp1";
private static final String APP2_URL = URL_PREFIX + "myapp2";


@Test
public void testApp1() {
runBasicTest(APP1_URL, "bar");
//App theme should make a button pink
WebElement element = getDriver().findElement(By.className("v-button"));
String buttonColor = element.getCssValue("color");
assertEquals("rgba(255, 128, 128, 1)", buttonColor);
}

@Test
public void testApp2() {
runBasicTest(APP2_URL, "foo");
}

private void runBasicTest(String app1Url, String text) {
getDriver().navigate().to(app1Url);
getDriver().findElement(By.className("v-textfield")).sendKeys(text);
getDriver().findElement(By.className("v-button")).click();
String foundText = getDriver().findElement(By.className("v-label")).getText();
assertEquals("Thanks " + text + ", it works!", foundText);
}


@Before
public void setup() {
setDriver(new PhantomJSDriver());
}

@After
public void teardown() {
getDriver().quit();
}
}

+ 37
- 0
test/servlet-containers/karaf/pom.xml View File

@@ -0,0 +1,37 @@
<?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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-test</artifactId>
<version>8.1-SNAPSHOT</version>
<relativePath>../..</relativePath>
</parent>
<artifactId>vaadin-test-karaf</artifactId>
<packaging>pom</packaging>
<name>Vaadin Karaf TestRoot</name>

<modules>
<module>vaadin-karaf-bundle1</module>
<module>vaadin-karaf-bundle2</module>
<module>karaf-run</module>
</modules>

<properties>
<karaf.plugin.version>4.0.8</karaf.plugin.version>
<vaadin.widgetset.mode>local</vaadin.widgetset.mode>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
</plugins>

</build>
</project>

+ 6
- 0
test/servlet-containers/karaf/vaadin-karaf-bundle1/bnd.bnd View File

@@ -0,0 +1,6 @@
Bundle-Name: ${project.name}
Bundle-Version: ${project.version}
Bundle-SymbolicName: ${project.groupId}.${project.artifactId}
Export-Package: com.vaadin.test.osgi.myapplication1
Import-Package: *
Web-ContentPath: /myapp1

+ 164
- 0
test/servlet-containers/karaf/vaadin-karaf-bundle1/pom.xml View File

@@ -0,0 +1,164 @@
<?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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-test-karaf</artifactId>
<version>8.1-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>
<artifactId>vaadin-karaf-bundle1</artifactId>
<packaging>jar</packaging>
<name>Vaadin Karaf test bundle 1</name>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-bom</artifactId>
<version>${vaadin.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-server</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-client-compiled</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-themes</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-osgi-integration</artifactId>
<version>8.1.0.beta1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>osgi.core</artifactId>
<version>6.0.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>osgi.annotation</artifactId>
<version>6.0.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>osgi.cmpn</artifactId>
<version>6.0.0</version>
<scope>provided</scope>
</dependency>
<!-- For compiling WidgetSet -->
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-client</artifactId>
<version>${vaadin.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>


<build>
<plugins>
<plugin>
<groupId>biz.aQute.bnd</groupId>
<artifactId>bnd-maven-plugin</artifactId>
<version>3.3.0</version>
<executions>
<execution>
<goals>
<goal>bnd-process</goal>
</goals>
<configuration>

</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-maven-plugin</artifactId>
<version>${vaadin.plugin.version}</version>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>compile-theme</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
<configuration>
<archive>
<manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
</archive>
</configuration>
</plugin>
</plugins>
</build>

<profiles>
<profile>
<!-- Vaadin pre-release repositories -->
<id>vaadin-prerelease</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>

<repositories>
<repository>
<id>vaadin-prereleases</id>
<url>http://maven.vaadin.com/vaadin-prereleases</url>
</repository>
<repository>
<id>vaadin-snapshots</id>
<url>https://oss.sonatype.org/content/repositories/vaadin-snapshots/</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>vaadin-prereleases</id>
<url>http://maven.vaadin.com/vaadin-prereleases</url>
</pluginRepository>
<pluginRepository>
<id>vaadin-snapshots</id>
<url>https://oss.sonatype.org/content/repositories/vaadin-snapshots/</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>

</project>

+ 14
- 0
test/servlet-containers/karaf/vaadin-karaf-bundle1/src/main/java/com/vaadin/test/osgi/myapplication1/CustomWidgetSet.java View File

@@ -0,0 +1,14 @@
package com.vaadin.test.osgi.myapplication1;

import com.vaadin.osgi.resources.OsgiVaadinTheme;
import com.vaadin.osgi.resources.OsgiVaadinWidgetset;
import com.vaadin.ui.themes.ValoTheme;
import org.osgi.service.component.annotations.Component;

@Component
public class CustomWidgetSet implements OsgiVaadinWidgetset {
@Override
public String getName() {
return "com.vaadin.test.osgi.widgetset.CustomWidgetSet";
}
}

+ 13
- 0
test/servlet-containers/karaf/vaadin-karaf-bundle1/src/main/java/com/vaadin/test/osgi/myapplication1/KarafTestTheme.java View File

@@ -0,0 +1,13 @@
package com.vaadin.test.osgi.myapplication1;

import com.vaadin.osgi.resources.OsgiVaadinTheme;
import com.vaadin.ui.themes.ValoTheme;
import org.osgi.service.component.annotations.Component;

@Component
public class KarafTestTheme extends ValoTheme implements OsgiVaadinTheme {
@Override
public String getName() {
return "karaftesttheme";
}
}

+ 45
- 0
test/servlet-containers/karaf/vaadin-karaf-bundle1/src/main/java/com/vaadin/test/osgi/myapplication1/MyUI.java View File

@@ -0,0 +1,45 @@
package com.vaadin.test.osgi.myapplication1;

import javax.servlet.annotation.WebServlet;

import com.vaadin.annotations.Theme;
import com.vaadin.annotations.Widgetset;
import org.osgi.service.component.annotations.Component;

import com.vaadin.annotations.VaadinServletConfiguration;
import com.vaadin.server.VaadinRequest;
import com.vaadin.server.VaadinServlet;
import com.vaadin.ui.Button;
import com.vaadin.ui.Label;
import com.vaadin.ui.TextField;
import com.vaadin.ui.UI;
import com.vaadin.ui.VerticalLayout;

@Theme("karaftesttheme")
@Widgetset("com.vaadin.test.osgi.widgetset.CustomWidgetSet")
public class MyUI extends UI {

@Override
protected void init(VaadinRequest vaadinRequest) {
final VerticalLayout layout = new VerticalLayout();

final TextField name = new TextField();
name.setCaption("Type your name here:");

Button button = new Button("Click Me");
button.addClickListener(e -> {
layout.addComponent(new Label("Thanks " + name.getValue() + ", it works!"));
});

layout.addComponents(name, button);

setContent(layout);
}

@Component(service = VaadinServlet.class)
@WebServlet(urlPatterns = "/myapp1/*", name = "MyUIServlet", asyncSupported = true)
@VaadinServletConfiguration(ui = MyUI.class, productionMode = false)
public static class MyUIServlet extends VaadinServlet {
}

}

+ 12
- 0
test/servlet-containers/karaf/vaadin-karaf-bundle1/src/main/resources/VAADIN/themes/karaftesttheme/styles.scss View File

@@ -0,0 +1,12 @@
@import "../valo/valo.scss";

@mixin karaftesttheme {
@include valo;
.v-button {
color: rgba(255, 128, 128, 1)
}
}

.karaftesttheme {
@include karaftesttheme;
}

+ 7
- 0
test/servlet-containers/karaf/vaadin-karaf-bundle1/src/main/resources/com/vaadin/test/osgi/widgetset/CustomWidgetSet.gwt.xml View File

@@ -0,0 +1,7 @@
<module>
<!-- Hint for WidgetSetBuilder not to automatically update the file -->
<!-- WS Compiler: manually edited -->

<inherits name="com.vaadin.DefaultWidgetSet" />

</module>

+ 5
- 0
test/servlet-containers/karaf/vaadin-karaf-bundle2/bnd.bnd View File

@@ -0,0 +1,5 @@
Bundle-Name: ${project.name}
Bundle-Version: ${project.version}
Bundle-SymbolicName: ${project.groupId}.${project.artifactId}
Import-Package: *
Web-ContentPath: /myapp2

+ 154
- 0
test/servlet-containers/karaf/vaadin-karaf-bundle2/pom.xml View File

@@ -0,0 +1,154 @@
<?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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<artifactId>vaadin-test-karaf</artifactId>
<groupId>com.vaadin</groupId>
<relativePath>..</relativePath>
<version>8.1-SNAPSHOT</version>
</parent>
<artifactId>vaadin-karaf-bundle2</artifactId>
<packaging>jar</packaging>
<name>Vaadin Karaf test bundle 2</name>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-bom</artifactId>
<version>${vaadin.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-server</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-client-compiled</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-themes</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-osgi-integration</artifactId>
<version>8.1.0.beta1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>osgi.core</artifactId>
<version>6.0.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>osgi.annotation</artifactId>
<version>6.0.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>osgi.cmpn</artifactId>
<version>6.0.0</version>
<scope>provided</scope>
</dependency>
</dependencies>


<build>
<plugins>
<plugin>
<groupId>biz.aQute.bnd</groupId>
<artifactId>bnd-maven-plugin</artifactId>
<version>3.3.0</version>
<executions>
<execution>
<goals>
<goal>bnd-process</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-maven-plugin</artifactId>
<version>${vaadin.plugin.version}</version>
<executions>
<execution>
<phase>process-resources</phase>
<goals>
<goal>compile-theme</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
<configuration>
<archive>
<manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
</archive>
</configuration>
</plugin>
</plugins>
</build>

<profiles>
<profile>
<!-- Vaadin pre-release repositories -->
<id>vaadin-prerelease</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>

<repositories>
<repository>
<id>vaadin-prereleases</id>
<url>http://maven.vaadin.com/vaadin-prereleases</url>
</repository>
<repository>
<id>vaadin-snapshots</id>
<url>https://oss.sonatype.org/content/repositories/vaadin-snapshots/</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>vaadin-prereleases</id>
<url>http://maven.vaadin.com/vaadin-prereleases</url>
</pluginRepository>
<pluginRepository>
<id>vaadin-snapshots</id>
<url>https://oss.sonatype.org/content/repositories/vaadin-snapshots/</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>

</project>

+ 42
- 0
test/servlet-containers/karaf/vaadin-karaf-bundle2/src/main/java/com/vaadin/test/osgi/myapplication/MyUI.java View File

@@ -0,0 +1,42 @@
package com.vaadin.test.osgi.myapplication;

import javax.servlet.annotation.WebServlet;

import com.vaadin.annotations.Theme;
import org.osgi.service.component.annotations.Component;

import com.vaadin.annotations.VaadinServletConfiguration;
import com.vaadin.server.VaadinRequest;
import com.vaadin.server.VaadinServlet;
import com.vaadin.ui.Button;
import com.vaadin.ui.Label;
import com.vaadin.ui.TextField;
import com.vaadin.ui.UI;
import com.vaadin.ui.VerticalLayout;

public class MyUI extends UI {

@Override
protected void init(VaadinRequest vaadinRequest) {
final VerticalLayout layout = new VerticalLayout();

final TextField name = new TextField();
name.setCaption("Type your name here:");

Button button = new Button("Click Me");
button.addClickListener(e -> {
layout.addComponent(new Label("Thanks " + name.getValue() + ", it works!"));
});

layout.addComponents(name, button);

setContent(layout);
}

@Component(service = VaadinServlet.class)
@WebServlet(urlPatterns = "/myapp2/*", name = "MyUIServlet", asyncSupported = true)
@VaadinServletConfiguration(ui = MyUI.class, productionMode = false)
public static class MyUIServlet extends VaadinServlet {
}

}

Loading…
Cancel
Save