Skip to content

Commit

Permalink
Added test to validate that hibernate properties in environment varia…
Browse files Browse the repository at this point in the history
…bles do not log a warning unused message when they are in use
  • Loading branch information
radcortez committed Jun 18, 2021
1 parent d4a513e commit 1513f7e
Show file tree
Hide file tree
Showing 6 changed files with 197 additions and 0 deletions.
4 changes: 4 additions & 0 deletions integration-tests/smallrye-config/.env
Original file line number Diff line number Diff line change
@@ -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
43 changes: 43 additions & 0 deletions integration-tests/smallrye-config/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,27 @@
<artifactId>quarkus-junit5</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5-internal</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<scope>test</scope>
</dependency>
<!-- For https://github.com/quarkusio/quarkus/issues/17818 -->
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-hibernate-orm</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-jdbc-h2</artifactId>
<scope>test</scope>
</dependency>


<!-- Minimal test dependencies to *-deployment artifacts for consistent build order -->
Expand Down Expand Up @@ -116,6 +132,33 @@
</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-h2-deployment</artifactId>
<version>${project.version}</version>
<type>pom</type>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>

</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
@@ -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());
}
}
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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.APPLICATION_JSON)
public Response create() {
User user = new User()
.setFirstName("Naruto")
.setLastName("Uzumaki")
.setAge(17);
entityManager.persist(user);
return Response.ok().entity(user.getId()).build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ public void close() throws SecurityException {
this.records.clear();
}

public List<LogRecord> getRecords() {
return records;
}

void clearRecords() {
this.records.clear();
}
Expand Down

0 comments on commit 1513f7e

Please sign in to comment.