forked from quarkusio/quarkus
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve MongoDB tests on Java records
- Loading branch information
1 parent
4ddba5b
commit d9412b5
Showing
7 changed files
with
27 additions
and
62 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
4 changes: 4 additions & 0 deletions
4
...ests/mongodb-panache/src/main/java/io/quarkus/it/mongodb/panache/record/PersonRecord.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,4 @@ | ||
package io.quarkus.it.mongodb.panache.record; | ||
|
||
public record PersonRecord(String firstName, String lastName, Status status) { | ||
} |
9 changes: 9 additions & 0 deletions
9
...db-panache/src/main/java/io/quarkus/it/mongodb/panache/record/PersonRecordRepository.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,9 @@ | ||
package io.quarkus.it.mongodb.panache.record; | ||
|
||
import jakarta.enterprise.context.ApplicationScoped; | ||
|
||
import io.quarkus.mongodb.panache.PanacheMongoRepository; | ||
|
||
@ApplicationScoped | ||
public class PersonRecordRepository implements PanacheMongoRepository<PersonRecord> { | ||
} |
16 changes: 8 additions & 8 deletions
16
...ts/mongodb-panache/src/main/java/io/quarkus/it/mongodb/panache/record/PersonResource.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 |
---|---|---|
@@ -1,24 +1,24 @@ | ||
package io.quarkus.it.mongodb.panache.record; | ||
|
||
import java.net.URI; | ||
import java.util.List; | ||
|
||
import jakarta.inject.Inject; | ||
import jakarta.ws.rs.GET; | ||
import jakarta.ws.rs.POST; | ||
import jakarta.ws.rs.Path; | ||
import jakarta.ws.rs.core.Response; | ||
|
||
@Path("/mongo/persons") | ||
@Path("/persons/record") | ||
public class PersonResource { | ||
@Inject | ||
PersonRecordRepository personRecordRepository; | ||
|
||
@GET | ||
public List<PersonName> getPersons() { | ||
return PersonWithRecord.findAll().project(PersonName.class).list(); | ||
return personRecordRepository.findAll().project(PersonName.class).list(); | ||
} | ||
|
||
@POST | ||
public Response addPerson(PersonWithRecord person) { | ||
person.persist(); | ||
String id = person.id.toString(); | ||
return Response.created(URI.create("/persons/entity/" + id)).build(); | ||
public void addPerson(PersonRecord person) { | ||
personRecordRepository.persist(person); | ||
} | ||
} |
9 changes: 0 additions & 9 deletions
9
.../mongodb-panache/src/main/java/io/quarkus/it/mongodb/panache/record/PersonWithRecord.java
This file was deleted.
Oops, something went wrong.
33 changes: 0 additions & 33 deletions
33
...db-panache/src/test/java/io/quarkus/it/mongodb/panache/record/MongodbPanacheRecordIT.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 |
---|---|---|
@@ -1,40 +1,7 @@ | ||
package io.quarkus.it.mongodb.panache.record; | ||
|
||
import static io.restassured.RestAssured.given; | ||
import static io.restassured.RestAssured.when; | ||
import static org.hamcrest.CoreMatchers.is; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import io.quarkus.test.junit.QuarkusIntegrationTest; | ||
import io.restassured.http.ContentType; | ||
|
||
@QuarkusIntegrationTest | ||
class MongodbPanacheRecordIT extends MongodbPanacheRecordTest { | ||
|
||
private static final String ROOT_URL = "/mongo/persons"; | ||
|
||
@Test | ||
void testRecordInPanache() { | ||
var person1 = new PersonWithRecord(); | ||
person1.firstname = "Loïc"; | ||
person1.lastname = "Mathieu"; | ||
person1.status = Status.ALIVE; | ||
var person2 = new PersonWithRecord(); | ||
person1.firstname = "Zombie"; | ||
person2.lastname = "Zombie"; | ||
person2.status = Status.DEAD; | ||
|
||
given().body(person1).contentType(ContentType.JSON) | ||
.when().post(ROOT_URL) | ||
.then().statusCode(201); | ||
given().body(person2).contentType(ContentType.JSON) | ||
.when().post(ROOT_URL) | ||
.then().statusCode(201); | ||
|
||
when().get(ROOT_URL) | ||
.then() | ||
.statusCode(200) | ||
.body("size()", is(2)); | ||
} | ||
} |
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