/vaadin-jooq-template

Primary LanguageJavaApache License 2.0Apache-2.0

Vaadin/jOOQ Template

CI Quality Gate Status

Introduction

This is a template project, based on my experience and my opinion, that shows how to integrate Vaadin and jOOQ and how to test it with Karibu Testing and Playwright.

It uses Testcontainers for generating the jOOQ classes and integration testing and Flyway for the database migrations.

This project can be used as a starting point to create your own Vaadin application with jOOQ. It contains all the necessary configurations and some examples to get you started.

Running the Application

Before running the application, the jOOQ metamodel has to be generated using the Maven plugin:

./mvnw compile

Then you can run the application with a database started by Testcontainers from your IDE using the TestVjApplication.

Important: This class uses the Spring Boot Testcontainers support, introduced with Spring Boot 3.1. Thus, Docker or Testcontainers Cloud must be running on your local computer.

Testing the Application

There are two base classes:

  • KaribuTest can be used for fast browser-less testing, aka UI unit test. Karibu sets up a Vaadin mock environment.
  • PlaywrightIT configures Playwright for E2E tests. This class uses SpringBootTest at a random port.

The Playwright test uses Mopo, which simplifies the testing of Vaadin applications with Playwright.

Deploying to Production

To create a production build, call mvnw clean package -Pproduction (Windows), or ./mvnw clean package -Pproduction (Mac & Linux).

This will build a JAR file with all the dependencies and front-end resources, ready to be deployed. You can find the file in the target folder after the build completes.

Once the JAR file is built, you can run it using java -jar target/vaadin-jooq-template-<version>.jar

Project structure

  • layout/MainLayout.java in src/main/java contains the navigation setup using App Layout.
  • views package in src/main/java contains the server-side Java views of your application.
  • themes folder in frontend/ contains the custom CSS styles.

Security Configuration

The example uses JWT authentication for a better developer experience (for example, you don't have to re-log in during development). Read more in the blog of Matti Tahvonen.

Useful links

Vaadin

jOOQ

Spring Boot

Testcontainers

Karibu Testing

Playwright