Skip to content

Commit

Permalink
Issue 4740 - JPA integration tests should run on every build (#5080)
Browse files Browse the repository at this point in the history
Signed-off-by: Tomáš Kraus <tomas.kraus@oracle.com>

Signed-off-by: Tomáš Kraus <tomas.kraus@oracle.com>
  • Loading branch information
Tomas-Kraus authored Oct 5, 2022
1 parent 4633b5e commit 85e4a84
Show file tree
Hide file tree
Showing 16 changed files with 81 additions and 256 deletions.
142 changes: 37 additions & 105 deletions tests/integration/jpa/appl/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@
<artifactId>jandex</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.jboss</groupId>
<artifactId>jboss-transaction-spi-jakarta</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
Expand All @@ -120,13 +125,6 @@

<build>
<resources>
<resource>
<directory>${basedir}/src/main/resources</directory>
<excludes>
<exclude>META-INF/microprofile-config.properties</exclude>
<exclude>META-INF/persistence.xml</exclude>
</excludes>
</resource>
<resource>
<directory>${basedir}/src/main/resources/META-INF</directory>
<targetPath>META-INF</targetPath>
Expand All @@ -136,6 +134,13 @@
</includes>
<filtering>true</filtering>
</resource>
<resource>
<directory>${basedir}/src/main/resources</directory>
<excludes>
<exclude>META-INF/microprofile-config.properties</exclude>
<exclude>META-INF/persistence.xml</exclude>
</excludes>
</resource>
</resources>
<pluginManagement>
<plugins>
Expand Down Expand Up @@ -227,6 +232,9 @@
<threadCount>10</threadCount>
<systemPropertyVariables>
<junit.jupiter.extensions.autodetection.enabled>true</junit.jupiter.extensions.autodetection.enabled>
<db.user>${db.user}</db.user>
<db.password>${db.password}</db.password>
<db.url>${db.url}</db.url>
</systemPropertyVariables>
</configuration>
<executions>
Expand Down Expand Up @@ -319,10 +327,11 @@
<plugin>
<groupId>io.fabric8</groupId>
<artifactId>docker-maven-plugin</artifactId>
<!-- Docker container need to start before Helidon application (pre-integration-test phase). -->
<executions>
<execution>
<id>start</id>
<phase>pre-integration-test</phase>
<phase>package</phase>
<goals>
<goal>start</goal>
</goals>
Expand All @@ -339,21 +348,22 @@
</plugins>
</build>
</profile>

<!-- Test with in memory H2 database. Default test profile. Active until db property is set. -->
<profile>
<id>h2</id>
<activation>
<property>
<name>h2</name>
<name>!db</name>
</property>
</activation>
<properties>
<db.port>9092</db.port>
<db.host>localhost</db.host>
<db.database>pokemon</db.database>
<db.database>test</db.database>
<db.user>sa</db.user>
<db.password></db.password>
<db.roootpw>root</db.roootpw>
<db.url>jdbc:h2:tcp://${db.host}:${db.port}/test</db.url>
<db.url>jdbc:h2:mem:test;INIT=SET TRACE_LEVEL_FILE=4</db.url>
<hibernate.dialect>org.hibernate.dialect.H2Dialect</hibernate.dialect>
<db.datasource>org.h2.jdbcx.JdbcDataSource</db.datasource>
</properties>
Expand All @@ -362,77 +372,19 @@
<groupId>io.helidon.integrations.db</groupId>
<artifactId>h2</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<configuration>
<systemPropertyVariables>
<db.user>${db.user}</db.user>
<db.password>${db.password}</db.password>
<db.url>${db.url}</db.url>
</systemPropertyVariables>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<executions>
<execution>
<id>start-db</id>
<phase>pre-integration-test</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>java</executable>
<arguments>
<argument>-classpath</argument>
<argument>${project.build.directory}/libs/h2-${version.lib.h2}.jar</argument>
<argument>${mainClassH2}</argument>
<argument>-tcp</argument>
<argument>-tcpPassword</argument>
<argument>${h2.db.password}</argument>
<argument>-tcpPort</argument>
<argument>${h2.db.port}</argument>
<argument>-baseDir</argument>
<argument>${project.build.directory}/h2</argument>
<argument>-ifNotExists</argument>
</arguments>
<async>true</async>
</configuration>
</execution>
<execution>
<id>stop-db</id>
<phase>post-integration-test</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>java</executable>
<arguments>
<argument>-classpath</argument>
<argument>${project.build.directory}/libs/h2-${version.lib.h2}.jar</argument>
<argument>${mainClassH2}</argument>
<argument>-tcpShutdown</argument>
<argument>tcp://localhost:${h2.db.port}</argument>
<argument>-tcpPassword</argument>
<argument>${h2.db.password}</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>mysql</id>
<activation>
<property>
<name>mysql</name>
<name>db</name>
<value>mysql</value>
</property>
</activation>
<properties>
Expand All @@ -444,7 +396,7 @@
<db.password>password</db.password>
<db.roootpw>root</db.roootpw>
<db.url>jdbc:mysql://${db.host}:${db.port}/${db.database}?${db.args}</db.url>
<hibernate.dialect>org.hibernate.dialect.MySQL5Dialect</hibernate.dialect>
<hibernate.dialect>org.hibernate.dialect.MySQL8Dialect</hibernate.dialect>
<db.datasource>com.mysql.cj.jdbc.MysqlDataSource</db.datasource>
<db.driver>com.mysql.cj.jdbc.Driver</db.driver>
</properties>
Expand All @@ -462,17 +414,6 @@
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<configuration>
<systemPropertyVariables>
<db.user>${db.user}</db.user>
<db.password>${db.password}</db.password>
<db.url>${db.url}</db.url>
</systemPropertyVariables>
</configuration>
</plugin>
<plugin>
<groupId>io.fabric8</groupId>
<artifactId>docker-maven-plugin</artifactId>
Expand All @@ -493,13 +434,14 @@
<port>${db.host}:${db.port}:3306</port>
</ports>
<wait>
<tcp>
<!--tcp>
<host>127.0.0.1</host>
<ports>
<port>${db.port}</port>
</ports>
</tcp>
</tcp-->
<time>120000</time>
<log>MySQL init process done. Ready for start up.</log>
</wait>
</run>
</image>
Expand All @@ -515,7 +457,8 @@
<id>pgsql</id>
<activation>
<property>
<name>pgsql</name>
<name>db</name>
<value>pgsql</value>
</property>
</activation>
<properties>
Expand All @@ -525,8 +468,8 @@
<db.user>user</db.user>
<db.password>password</db.password>
<db.url>jdbc:postgresql://${db.host}:${db.port}/${db.database}</db.url>
<hibernate.dialect>org.hibernate.dialect.PostgreSQL10Dialect</hibernate.dialect>
<db.datasource>org.postgresql.jdbc3.Jdbc3PoolingDataSource</db.datasource>
<hibernate.dialect>org.hibernate.dialect.PostgreSQLDialect</hibernate.dialect>
<db.datasource>org.postgresql.ds.PGSimpleDataSource</db.datasource>
<db.driver>org.postgresql.Driver</db.driver>
</properties>
<dependencies>
Expand All @@ -543,17 +486,6 @@
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<configuration>
<systemPropertyVariables>
<db.user>${db.user}</db.user>
<db.password>${db.password}</db.password>
<db.url>${db.url}</db.url>
</systemPropertyVariables>
</configuration>
</plugin>
<plugin>
<groupId>io.fabric8</groupId>
<artifactId>docker-maven-plugin</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020, 2021 Oracle and/or its affiliates.
* Copyright (c) 2020, 2022 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -56,13 +56,13 @@ public TestResult setup(TestResult result) {
final String dbPassword = config.getProperty("javax.sql.DataSource.test.dataSource.password");
final String dbUrl = config.getProperty("javax.sql.DataSource.test.dataSource.url");
if (dbUser == null) {
throw new IllegalStateException("Database user name was not set!");
throw new IllegalStateException("Database user name was not set, check javax.sql.DataSource.test.dataSource.user property! ");
}
if (dbPassword == null) {
throw new IllegalStateException("Database user password was not set!");
throw new IllegalStateException("Database user password was not set, check javax.sql.DataSource.test.dataSource.password property!");
}
if (dbUrl == null) {
throw new IllegalStateException("Database URL was not set!");
throw new IllegalStateException("Database URL was not set, check javax.sql.DataSource.test.dataSource.url property!");
}
try {
conn = DriverManager.getConnection(dbUrl, dbUser, dbPassword);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020, 2021 Oracle and/or its affiliates.
* Copyright (c) 2020, 2022 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -193,7 +193,6 @@ public TestResult testUpdateSaffron(TestResult result) {
City city = em.find(City.class, cities[0].getId());
stadium = city.getStadium();
Trainer trainer = stadium.getTrainer();
em.refresh(trainer);
pokemons = trainer.getPokemons();
result.assertEquals(trainer.getName(), "Janine");
for (Pokemon pokemon : pokemons) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (c) 2020 Oracle and/or its affiliates.
# Copyright (c) 2020, 2022 Oracle and/or its affiliates.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -17,4 +17,3 @@
# Byte code for JPA must be generated at compile time.
# This is a limitation of native image
hibernate.bytecode.provider=none

Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,13 @@ public static void waitForDatabase() {
final String dbUrl = System.getProperty("db.url");
boolean connected = false;
if (dbUser == null) {
throw new IllegalStateException("Database user name was not set!");
throw new IllegalStateException("Database user name was not set, check db.user property!");
}
if (dbPassword == null) {
throw new IllegalStateException("Database user password was not set!");
throw new IllegalStateException("Database user password was not set, check db.password property!");
}
if (dbUrl == null) {
throw new IllegalStateException("Database URL was not set!");
throw new IllegalStateException("Database URL was not set, check db.url property");
}
long endTm = 1000 * TIMEOUT + System.currentTimeMillis();
while (true) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020, 2021 Oracle and/or its affiliates.
* Copyright (c) 2020, 2022 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -21,14 +21,7 @@
import java.util.Objects;
import java.util.logging.Logger;

import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.JoinTable;
import jakarta.persistence.ManyToMany;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.UniqueConstraint;
import jakarta.persistence.*;

/**
* Pokemon entity.
Expand All @@ -39,7 +32,7 @@ public class Pokemon implements Serializable {
private static final Logger LOGGER = Logger.getLogger(Pokemon.class.getName());

@Id
@GeneratedValue
@GeneratedValue(strategy = GenerationType.TABLE)
private int id;

@ManyToOne
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020, 2021 Oracle and/or its affiliates.
* Copyright (c) 2020, 2022 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -18,6 +18,7 @@
import java.util.Objects;

import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.MappedSuperclass;

Expand All @@ -28,7 +29,7 @@
public class Settlement {

@Id
@GeneratedValue
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;

private String name;
Expand Down
Loading

0 comments on commit 85e4a84

Please sign in to comment.