Skip to content

Commit

Permalink
Adds integration tests for postgresql devservices
Browse files Browse the repository at this point in the history
* Fixs maven module to run tests
* Fixs formatting
* Fixs modules name
* Adds configuration to skip tests by default
  • Loading branch information
netodevel committed Oct 13, 2021
1 parent 756aaaa commit 43eb305
Show file tree
Hide file tree
Showing 18 changed files with 292 additions and 2 deletions.
148 changes: 148 additions & 0 deletions integration-tests/devservices-postgresql/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
<?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>quarkus-integration-tests-parent</artifactId>
<groupId>io.quarkus</groupId>
<version>999-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>quarkus-integration-test-devservices-postgresql</artifactId>
<name>Quarkus - Integration Tests - DevService Postgresql</name>

<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-jsonb</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>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-agroal</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-jdbc-postgresql</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-hibernate-orm-panache</artifactId>
</dependency>

<!-- Minimal test dependencies to *-deployment artifacts for consistent build order -->
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-hibernate-orm-panache-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-resteasy-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-resteasy-jsonb-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-agroal-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>
</dependencies>

<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
<plugin>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>build</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.example.postgresql.devservice;

import javax.persistence.Entity;
import javax.persistence.Table;

import io.quarkus.hibernate.orm.panache.PanacheEntity;

@Table
@Entity(name = "persons")
public class Person extends PanacheEntity {

public String name;
public Integer age;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.example.postgresql.devservice;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

@Path("/persons")
@Produces(MediaType.APPLICATION_JSON)
public class PersonResource {

@GET
public Response findAllPersons() {
return Response.ok(Person.findAll().list()).build();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
quarkus.hibernate-orm.database.generation=drop-and-create
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.example.postgresql.devservice;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

import com.example.postgresql.devservice.profile.DevServiceCustomPortProfile;
import com.example.postgresql.devservice.utils.SocketKit;

import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.junit.TestProfile;

@QuarkusTest
@TestProfile(DevServiceCustomPortProfile.class)
public class DevServicePostgresEnableITest {

@Test
@DisplayName("should start the postgres container when devservices is enabled with a custom port")
public void shouldStartPostgresContainer() {
Assertions.assertTrue(SocketKit.isPortAlreadyUsed(5432));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.example.postgresql.devservice;

import static org.junit.jupiter.api.Assertions.assertEquals;

import java.util.List;

import javax.transaction.Transactional;

import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

import io.quarkus.test.junit.QuarkusTest;
import io.restassured.RestAssured;

@QuarkusTest
class PersonResourceTest {

@BeforeEach
@Transactional
public void setUp() {
var personOne = new Person();
personOne.age = 27;
personOne.name = "netodevel";
personOne.persist();

var otherPerson = new Person();
otherPerson.age = 27;
otherPerson.name = "fake_name";
otherPerson.persist();
}

@AfterEach
@Transactional
public void tearDown() {
Person.deleteAll();
}

@Test
@DisplayName("given the use of devservices then it should a return a list of persons")
public void shouldReturnListPersons() {
List<Person> personList = RestAssured.get("/persons")
.then()
.extract().jsonPath().getList(".");
assertEquals(2, personList.size());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.example.postgresql.devservice.profile;

import java.util.Collections;
import java.util.Map;

import io.quarkus.test.junit.QuarkusTestProfile;

public class DevServiceCustomPortProfile implements QuarkusTestProfile {

@Override
public Map<String, String> getConfigOverrides() {
return Collections.singletonMap("quarkus.datasource.devservices.port", "5432");
}

@Override
public String getConfigProfile() {
return "test";
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.example.postgresql.devservice.utils;

import java.io.IOException;
import java.net.Socket;

public class SocketKit {

public static boolean isPortAlreadyUsed(Integer port) {
try (Socket ignored = new Socket("localhost", port)) {
ignored.close();
return true;
} catch (IOException ignored) {
return false;
}
}

}
File renamed without changes.
6 changes: 4 additions & 2 deletions integration-tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
<name>Quarkus - Integration Tests</name>

<packaging>pom</packaging>

<properties>
<maven.deploy.skip>true</maven.deploy.skip>
<gpg.skip>true</gpg.skip>
Expand Down Expand Up @@ -280,7 +279,6 @@
<module>logging-min-level-unset</module>
<module>logging-min-level-set</module>
<module>logging-panache</module>
<module>redis-devservices</module>

<!-- gRPC tests -->
<module>grpc-tls</module>
Expand All @@ -295,6 +293,10 @@
<module>grpc-hibernate-reactive</module>
<module>google-cloud-functions-http</module>
<module>google-cloud-functions</module>

<!-- DevServices tests -->
<module>devservices-postgresql</module>
<module>devservices-redis</module>
</modules>
</profile>

Expand Down

0 comments on commit 43eb305

Please sign in to comment.