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

Move Java 17 records tests to their respective modules #37458

Merged
merged 1 commit into from
Dec 4, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.quarkus.it.hibernate.panache.person;
package io.quarkus.hibernate.orm.panache.deployment.test.record;

import jakarta.persistence.Entity;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.quarkus.it.hibernate.panache.person;
package io.quarkus.hibernate.orm.panache.deployment.test.record;

import io.quarkus.runtime.annotations.RegisterForReflection;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package io.quarkus.hibernate.orm.panache.deployment.test.record;

import static org.junit.jupiter.api.Assertions.assertEquals;

import jakarta.transaction.Transactional;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import io.quarkus.test.QuarkusUnitTest;

class RecordInPanacheTest {

@RegisterExtension
static QuarkusUnitTest runner = new QuarkusUnitTest()
.withApplicationRoot((jar) -> jar
.addAsResource("application-test.properties", "application.properties")
.addClasses(Person.class, PersonName.class, Status.class));

@Test
@Transactional
void testRecordInPanache() {
var person1 = new Person();
person1.firstname = "Loïc";
person1.lastname = "Mathieu";
person1.status = Status.ALIVE;
person1.persist();

var person2 = new Person();
person1.firstname = "Zombie";
person2.lastname = "Zombie";
person2.status = Status.DEAD;
person2.persist();

assertEquals(2L, Person.count());

}

@Test
@Transactional
void testHqlPanacheProject() {
var mark = new Person();
mark.firstname = "Mark";
mark.lastname = "Mark";
mark.persistAndFlush();

var hqlWithoutSpace = """
select
firstname,
lastname
from
io.quarkus.hibernate.orm.panache.deployment.test.record.Person
where
firstname = ?1
""";
var persistedWithoutSpace = Person.find(hqlWithoutSpace, "Mark").project(PersonName.class).firstResult();
assertEquals("Mark", persistedWithoutSpace.firstname());

// We need to escape the whitespace in Java otherwise the compiler removes it.
var hqlWithSpace = """
select\s
firstname,
lastname
from
io.quarkus.hibernate.orm.panache.deployment.test.record.Person
where
firstname = ?1
""";
var persistedWithSpace = Person.find(hqlWithSpace, "Mark").project(PersonName.class).firstResult();
assertEquals("Mark", persistedWithSpace.firstname());
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.quarkus.it.hibernate.panache.person;
package io.quarkus.hibernate.orm.panache.deployment.test.record;

public enum Status {
DEAD("I'm a Zombie"),
Expand Down
143 changes: 0 additions & 143 deletions integration-tests/java-17/pom.xml

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package io.quarkus.it.mongodb.panache.person;
package io.quarkus.it.mongodb.panache.record;

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

@ProjectionFor(Person.class)
@ProjectionFor(PersonWithRecord.class)
public record PersonName(String firstName, String lastName) {
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.quarkus.it.mongodb.panache.person;
package io.quarkus.it.mongodb.panache.record;

import java.net.URI;
import java.util.List;
Expand All @@ -12,11 +12,11 @@
public class PersonResource {
@GET
public List<PersonName> getPersons() {
return Person.findAll().project(PersonName.class).list();
return PersonWithRecord.findAll().project(PersonName.class).list();
}

@POST
public Response addPerson(Person person) {
public Response addPerson(PersonWithRecord person) {
person.persist();
String id = person.id.toString();
return Response.created(URI.create("/persons/entity/" + id)).build();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package io.quarkus.it.mongodb.panache.person;
package io.quarkus.it.mongodb.panache.record;

import io.quarkus.mongodb.panache.PanacheMongoEntity;

public class Person extends PanacheMongoEntity {
public class PersonWithRecord extends PanacheMongoEntity {
public String firstname;
public String lastname;
public Status status = Status.ALIVE;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.quarkus.it.mongodb.panache.person;
package io.quarkus.it.mongodb.panache.record;

public enum Status {
DEAD("I'm a Zombie"),
Expand Down
Loading
Loading