diff --git a/integration-tests/smallrye-config/.env b/integration-tests/smallrye-config/.env index 984066a13dd387..5d20f3e113b6fd 100644 --- a/integration-tests/smallrye-config/.env +++ b/integration-tests/smallrye-config/.env @@ -1,2 +1,6 @@ DOTENV_SERVER_NAME=localhost DOTENV_SERVER_PORT=8080 + +_TEST_QUARKUS_DATASOURCE_DB_KIND=h2 +_TEST_QUARKUS_DATASOURCE_JDBC_URL=jdbc:h2:mem:test;MODE=PostgreSQL;DB_CLOSE_DELAY=-1 +_TEST_QUARKUS_HIBERNATE_ORM_DATABASE_GENERATION=drop-and-create diff --git a/integration-tests/smallrye-config/pom.xml b/integration-tests/smallrye-config/pom.xml index cf5a8c414e6895..5967127a6926da 100644 --- a/integration-tests/smallrye-config/pom.xml +++ b/integration-tests/smallrye-config/pom.xml @@ -43,11 +43,27 @@ quarkus-junit5 test + + io.quarkus + quarkus-junit5-internal + test + io.rest-assured rest-assured test + + + io.quarkus + quarkus-hibernate-orm + test + + + io.quarkus + quarkus-jdbc-h2 + test + @@ -116,6 +132,33 @@ + + io.quarkus + quarkus-hibernate-orm-deployment + ${project.version} + pom + test + + + * + * + + + + + io.quarkus + quarkus-jdbc-h2-deployment + ${project.version} + pom + test + + + * + * + + + + diff --git a/integration-tests/smallrye-config/src/test/java/io/quarkus/it/smallrye/config/HibernatePropertiesTest.java b/integration-tests/smallrye-config/src/test/java/io/quarkus/it/smallrye/config/HibernatePropertiesTest.java new file mode 100644 index 00000000000000..95fcd721824dd7 --- /dev/null +++ b/integration-tests/smallrye-config/src/test/java/io/quarkus/it/smallrye/config/HibernatePropertiesTest.java @@ -0,0 +1,43 @@ +package io.quarkus.it.smallrye.config; + +import static io.restassured.RestAssured.given; +import static javax.ws.rs.core.Response.Status.OK; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.util.logging.Level; +import java.util.logging.LogManager; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtensionContext; +import org.junit.jupiter.api.extension.RegisterExtension; + +import io.quarkus.test.InMemoryLogHandler; +import io.quarkus.test.junit.QuarkusTestExtension; + +public class HibernatePropertiesTest { + private static final java.util.logging.Logger rootLogger = LogManager.getLogManager().getLogger("io.quarkus.config"); + private static final InMemoryLogHandler inMemoryLogHandler = new InMemoryLogHandler( + record -> record.getLevel().intValue() >= Level.WARNING.intValue()); + + static { + rootLogger.addHandler(inMemoryLogHandler); + } + + // So we can use .env. We don't have support in the other extensions to pass in external files to the application jar. + @RegisterExtension + static QuarkusTestExtension TEST = new QuarkusTestExtension() { + @Override + public void beforeAll(final ExtensionContext context) throws Exception { + super.beforeAll(context); + assertTrue(inMemoryLogHandler.getRecords().isEmpty()); + } + }; + + @Test + void properties() { + given() + .get("/users") + .then() + .statusCode(OK.getStatusCode()); + } +} diff --git a/integration-tests/smallrye-config/src/test/java/io/quarkus/it/smallrye/config/User.java b/integration-tests/smallrye-config/src/test/java/io/quarkus/it/smallrye/config/User.java new file mode 100644 index 00000000000000..67c9f056c6cff2 --- /dev/null +++ b/integration-tests/smallrye-config/src/test/java/io/quarkus/it/smallrye/config/User.java @@ -0,0 +1,75 @@ +package io.quarkus.it.smallrye.config; + +import java.util.Objects; + +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.Table; + +import org.hibernate.annotations.GenericGenerator; + +@Entity +@Table(name = "users") +public class User { + @Id + @GeneratedValue(generator = "system-uuid") + @GenericGenerator(name = "system-uuid", strategy = "uuid") + private String id; + private String firstName; + private String lastName; + private Integer age; + + public String getId() { + return id; + } + + public User setId(final String id) { + this.id = id; + return this; + } + + public String getFirstName() { + return firstName; + } + + public User setFirstName(final String firstName) { + this.firstName = firstName; + return this; + } + + public String getLastName() { + return lastName; + } + + public User setLastName(final String lastName) { + this.lastName = lastName; + return this; + } + + public Integer getAge() { + return age; + } + + public User setAge(final Integer age) { + this.age = age; + return this; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + final User user = (User) o; + return id.equals(user.id); + } + + @Override + public int hashCode() { + return Objects.hash(id); + } +} diff --git a/integration-tests/smallrye-config/src/test/java/io/quarkus/it/smallrye/config/UserResource.java b/integration-tests/smallrye-config/src/test/java/io/quarkus/it/smallrye/config/UserResource.java new file mode 100644 index 00000000000000..66f7061ff3231c --- /dev/null +++ b/integration-tests/smallrye-config/src/test/java/io/quarkus/it/smallrye/config/UserResource.java @@ -0,0 +1,28 @@ +package io.quarkus.it.smallrye.config; + +import javax.inject.Inject; +import javax.persistence.EntityManager; +import javax.transaction.Transactional; +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("/users") +@Transactional +public class UserResource { + @Inject + EntityManager entityManager; + + @GET + @Produces(MediaType.TEXT_PLAIN) + public Response create() { + User user = new User() + .setFirstName("Naruto") + .setLastName("Uzumaki") + .setAge(17); + entityManager.persist(user); + return Response.ok().entity(user.getId()).build(); + } +} diff --git a/test-framework/junit5-internal/src/main/java/io/quarkus/test/InMemoryLogHandler.java b/test-framework/junit5-internal/src/main/java/io/quarkus/test/InMemoryLogHandler.java index c606b9c80f00d5..7622b6a9a6468a 100644 --- a/test-framework/junit5-internal/src/main/java/io/quarkus/test/InMemoryLogHandler.java +++ b/test-framework/junit5-internal/src/main/java/io/quarkus/test/InMemoryLogHandler.java @@ -40,6 +40,10 @@ public void close() throws SecurityException { this.records.clear(); } + public List getRecords() { + return records; + } + void clearRecords() { this.records.clear(); }