-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add integration test for Kubernetes Service Binding with jdbc datasource
- Loading branch information
Showing
13 changed files
with
412 additions
and
0 deletions.
There are no files selected for viewing
298 changes: 298 additions & 0 deletions
298
integration-tests/kubernetes-service-binding-jdbc/pom.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,298 @@ | ||
<?xml version="1.0"?> | ||
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" | ||
xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<artifactId>quarkus-integration-tests-parent</artifactId> | ||
<groupId>io.quarkus</groupId> | ||
<version>999-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>quarkus-integration-test-k8s-service-binding-jdbc</artifactId> | ||
<name>Quarkus - Integration Tests - Kubernetes Service Binding JDBC</name> | ||
|
||
<properties> | ||
<postgres.image>postgres:13.1</postgres.image> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-resteasy-reactive-jackson</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-hibernate-orm</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-jdbc-postgresql</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-kubernetes-service-binding</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-junit5</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.rest-assured</groupId> | ||
<artifactId>rest-assured</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<!-- Minimal test dependencies to *-deployment artifacts for consistent build order --> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-resteasy-reactive-jackson-deployment</artifactId> | ||
<version>${project.version}</version> | ||
<type>pom</type> | ||
<scope>test</scope> | ||
<exclusions> | ||
<exclusion> | ||
<groupId>*</groupId> | ||
<artifactId>*</artifactId> | ||
</exclusion> | ||
</exclusions> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-hibernate-orm-deployment</artifactId> | ||
<version>${project.version}</version> | ||
<type>pom</type> | ||
<scope>test</scope> | ||
<exclusions> | ||
<exclusion> | ||
<groupId>*</groupId> | ||
<artifactId>*</artifactId> | ||
</exclusion> | ||
</exclusions> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-jdbc-postgresql-deployment</artifactId> | ||
<version>${project.version}</version> | ||
<type>pom</type> | ||
<scope>test</scope> | ||
<exclusions> | ||
<exclusion> | ||
<groupId>*</groupId> | ||
<artifactId>*</artifactId> | ||
</exclusion> | ||
</exclusions> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-kubernetes-service-binding-deployment</artifactId> | ||
<version>${project.version}</version> | ||
<type>pom</type> | ||
<scope>test</scope> | ||
<exclusions> | ||
<exclusion> | ||
<groupId>*</groupId> | ||
<artifactId>*</artifactId> | ||
</exclusion> | ||
</exclusions> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<resources> | ||
<resource> | ||
<directory>src/main/resources</directory> | ||
<filtering>true</filtering> | ||
</resource> | ||
</resources> | ||
<plugins> | ||
<plugin> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-maven-plugin</artifactId> | ||
<version>${project.version}</version> | ||
<executions> | ||
<execution> | ||
<goals> | ||
<goal>build</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-surefire-plugin</artifactId> | ||
<configuration> | ||
<skip>true</skip> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-failsafe-plugin</artifactId> | ||
<configuration> | ||
<skip>true</skip> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
<profiles> | ||
<profile> | ||
<id>test-postgresql</id> | ||
<activation> | ||
<property> | ||
<name>test-containers</name> | ||
</property> | ||
</activation> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<artifactId>maven-surefire-plugin</artifactId> | ||
<configuration> | ||
<skip>false</skip> | ||
<systemPropertyVariables> | ||
<quarkus.kubernetes-service-binding.root> | ||
${project.basedir}/src/test/resources/k8s-sb | ||
</quarkus.kubernetes-service-binding.root> | ||
<quarkus.kubernetes-service-binding.enabled>true</quarkus.kubernetes-service-binding.enabled> | ||
</systemPropertyVariables> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-failsafe-plugin</artifactId> | ||
<configuration> | ||
<skip>false</skip> | ||
<systemPropertyVariables> | ||
<quarkus.kubernetes-service-binding.root> | ||
${project.basedir}/src/test/resources/k8s-sb | ||
</quarkus.kubernetes-service-binding.root> | ||
<quarkus.kubernetes-service-binding.enabled>true</quarkus.kubernetes-service-binding.enabled> | ||
</systemPropertyVariables> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</profile> | ||
|
||
<profile> | ||
<id>native</id> | ||
<activation> | ||
<property> | ||
<name>native</name> | ||
</property> | ||
</activation> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<artifactId>maven-failsafe-plugin</artifactId> | ||
<executions> | ||
<execution> | ||
<goals> | ||
<goal>integration-test</goal> | ||
<goal>verify</goal> | ||
</goals> | ||
<configuration> | ||
<systemPropertyVariables> | ||
<native.image.path> | ||
${project.build.directory}/${project.build.finalName}-runner | ||
</native.image.path> | ||
<systemPropertyVariables> | ||
<quarkus.kubernetes-service-binding.root> | ||
${project.basedir}/src/test/resources/k8s-sb | ||
</quarkus.kubernetes-service-binding.root> | ||
<quarkus.kubernetes-service-binding.enabled>true</quarkus.kubernetes-service-binding.enabled> | ||
</systemPropertyVariables> | ||
</systemPropertyVariables> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
<properties> | ||
<quarkus.package.type>native</quarkus.package.type> | ||
</properties> | ||
</profile> | ||
|
||
<profile> | ||
<id>docker-postgresql</id> | ||
<activation> | ||
<property> | ||
<name>start-containers</name> | ||
</property> | ||
</activation> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>io.fabric8</groupId> | ||
<artifactId>docker-maven-plugin</artifactId> | ||
<configuration> | ||
<images> | ||
<image> | ||
<name>${postgres.image}</name> | ||
<alias>postgresql</alias> | ||
<run> | ||
<env> | ||
<POSTGRES_USER>quarkus_test</POSTGRES_USER> | ||
<POSTGRES_PASSWORD>quarkus_test</POSTGRES_PASSWORD> | ||
<POSTGRES_DB>quarkus_test</POSTGRES_DB> | ||
</env> | ||
<ports> | ||
<port>5431:5432</port> | ||
</ports> | ||
<wait> | ||
<tcp> | ||
<mode>mapped</mode> | ||
<ports> | ||
<port>5432</port> | ||
</ports> | ||
</tcp> | ||
<time>10000</time> | ||
</wait> | ||
</run> | ||
</image> | ||
</images> | ||
<!--Stops all postgres images currently running, not just those we just started. | ||
Useful to stop processes still running from a previously failed integration test run --> | ||
<allContainers>true</allContainers> | ||
</configuration> | ||
<executions> | ||
<execution> | ||
<id>docker-start</id> | ||
<phase>compile</phase> | ||
<goals> | ||
<goal>stop</goal> | ||
<goal>start</goal> | ||
</goals> | ||
</execution> | ||
<execution> | ||
<id>docker-stop</id> | ||
<phase>post-integration-test</phase> | ||
<goals> | ||
<goal>stop</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.codehaus.mojo</groupId> | ||
<artifactId>exec-maven-plugin</artifactId> | ||
<executions> | ||
<execution> | ||
<id>docker-prune</id> | ||
<phase>generate-resources</phase> | ||
<goals> | ||
<goal>exec</goal> | ||
</goals> | ||
<configuration> | ||
<executable>${docker-prune.location}</executable> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</profile> | ||
</profiles> | ||
</project> | ||
|
48 changes: 48 additions & 0 deletions
48
...n-tests/kubernetes-service-binding-jdbc/src/main/java/io/quarkus/it/k8ssb/jdbc/Fruit.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package io.quarkus.it.k8ssb.jdbc; | ||
|
||
import javax.persistence.Column; | ||
import javax.persistence.Entity; | ||
import javax.persistence.GeneratedValue; | ||
import javax.persistence.Id; | ||
import javax.persistence.NamedQuery; | ||
import javax.persistence.QueryHint; | ||
import javax.persistence.SequenceGenerator; | ||
import javax.persistence.Table; | ||
|
||
@Entity | ||
@Table(name = "known_fruits") | ||
@NamedQuery(name = "Fruits.findAll", query = "SELECT f FROM Fruit f ORDER BY f.name", hints = @QueryHint(name = "org.hibernate.cacheable", value = "true")) | ||
public class Fruit { | ||
|
||
@Id | ||
@SequenceGenerator(name = "fruitsSequence", sequenceName = "known_fruits_id_seq", allocationSize = 1, initialValue = 10) | ||
@GeneratedValue(generator = "fruitsSequence") | ||
private Integer id; | ||
|
||
@Column(length = 40, unique = true) | ||
private String name; | ||
|
||
public Fruit() { | ||
} | ||
|
||
public Fruit(String name) { | ||
this.name = name; | ||
} | ||
|
||
public Integer getId() { | ||
return id; | ||
} | ||
|
||
public void setId(Integer id) { | ||
this.id = id; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
} |
28 changes: 28 additions & 0 deletions
28
...kubernetes-service-binding-jdbc/src/main/java/io/quarkus/it/k8ssb/jdbc/FruitResource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package io.quarkus.it.k8ssb.jdbc; | ||
|
||
import java.util.List; | ||
|
||
import javax.inject.Inject; | ||
import javax.persistence.EntityManager; | ||
import javax.ws.rs.Consumes; | ||
import javax.ws.rs.GET; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.Produces; | ||
|
||
import io.smallrye.common.annotation.Blocking; | ||
|
||
@Path("fruits") | ||
public class FruitResource { | ||
|
||
@Inject | ||
EntityManager entityManager; | ||
|
||
@GET | ||
@Blocking | ||
@Produces("application/json") | ||
@Consumes("application/json") | ||
public List<Fruit> get() { | ||
return entityManager.createNamedQuery("Fruits.findAll", Fruit.class) | ||
.getResultList(); | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
integration-tests/kubernetes-service-binding-jdbc/src/main/resources/application.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
quarkus.hibernate-orm.database.generation=drop-and-create | ||
quarkus.hibernate-orm.log.sql=true | ||
quarkus.hibernate-orm.sql-load-script=import.sql |
3 changes: 3 additions & 0 deletions
3
integration-tests/kubernetes-service-binding-jdbc/src/main/resources/import.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
INSERT INTO known_fruits(id, name) VALUES (1, 'Cherry'); | ||
INSERT INTO known_fruits(id, name) VALUES (2, 'Apple'); | ||
INSERT INTO known_fruits(id, name) VALUES (3, 'Banana'); |
Oops, something went wrong.