Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve MongoDB tests on Java records #37624

Merged
merged 1 commit into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

import io.quarkus.mongodb.panache.common.ProjectionFor;

@ProjectionFor(PersonWithRecord.class)
@ProjectionFor(PersonRecord.class)
public record PersonName(String firstName, String lastName) {
}
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) {
}
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> {
}
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);
}
}

This file was deleted.

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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,19 @@
@QuarkusTestResource(MongoReplicaSetTestResource.class)
class MongodbPanacheRecordTest {

private static final String ROOT_URL = "/mongo/persons";
private static final String ROOT_URL = "/persons/record";

@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;
var person1 = new PersonRecord("Loïc", "Mathieu", Status.ALIVE);
var person2 = new PersonRecord("Zombie", "Zombie", Status.DEAD);

given().body(person1).contentType(ContentType.JSON)
.when().post(ROOT_URL)
.then().statusCode(201);
.then().statusCode(204);
given().body(person2).contentType(ContentType.JSON)
.when().post(ROOT_URL)
.then().statusCode(201);
.then().statusCode(204);

when().get(ROOT_URL)
.then()
Expand Down