Skip to content

Commit

Permalink
Merge pull request quarkusio#37458 from gsmet/move-java-17-tests
Browse files Browse the repository at this point in the history
Move Java 17 records tests to their respective modules
  • Loading branch information
rsvoboda authored Dec 4, 2023
2 parents 4ef6171 + 170ad57 commit f1b034a
Show file tree
Hide file tree
Showing 14 changed files with 98 additions and 266 deletions.
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

0 comments on commit f1b034a

Please sign in to comment.