-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added test to validate that hibernate properties in environment varia…
…bles do not log a warning unused message when they are in use
- Loading branch information
Showing
6 changed files
with
197 additions
and
0 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -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 |
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
43 changes: 43 additions & 0 deletions
43
.../smallrye-config/src/test/java/io/quarkus/it/smallrye/config/HibernatePropertiesTest.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,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()); | ||
} | ||
} |
75 changes: 75 additions & 0 deletions
75
integration-tests/smallrye-config/src/test/java/io/quarkus/it/smallrye/config/User.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,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); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
...ation-tests/smallrye-config/src/test/java/io/quarkus/it/smallrye/config/UserResource.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.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(); | ||
} | ||
} |
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