Skip to content

Commit

Permalink
quarkusio#36594 add automatically @RegisterForReflection on class ann…
Browse files Browse the repository at this point in the history
…otated with @NestedProjectedClass

+ Remove test from PanacheFunctionalityTest, just use TestEndpoint test as requested by @loicmathieu
  • Loading branch information
humcqc committed Jan 31, 2024
1 parent f8b820e commit d101fbe
Show file tree
Hide file tree
Showing 8 changed files with 6 additions and 184 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import io.quarkus.runtime.annotations.RegisterForReflection;

/**
* Define a class that is used for query projection as a nest inside the projected class.
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
@RegisterForReflection
public @interface NestedProjectedClass {
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import io.quarkus.runtime.annotations.RegisterForReflection;

/**
* Define a class that is used for query projection as a nest inside the projected class.
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
@RegisterForReflection
public @interface NestedProjectedClass {
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ public DogDto2(String name, PersonDto2 owner) {
}

@NestedProjectedClass
@RegisterForReflection
public static class PersonDto2 {
public String name;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ public PersonDTO(String uniqueName, String name, AddressDTO address, Description
}

@NestedProjectedClass
@RegisterForReflection
public static class AddressDTO implements Comparable<AddressDTO> {

// Simple field with automatic mapping in constructor
Expand All @@ -42,7 +41,6 @@ public int compareTo(AddressDTO address) {
}

@NestedProjectedClass
@RegisterForReflection
public static class DescriptionDTO {
private final String description;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,115 +239,4 @@ Person getBug7102(Long id) {
void testEnhancement27184DeleteDetached() {
RestAssured.when().get("/test/testEnhancement27184DeleteDetached").then().body(is("OK"));
}

/**
* This test is disabled in native mode as there is no interaction with the quarkus integration test endpoint.
*/
@Test
@Transactional
@DisabledOnIntegrationTest
void testSimpleEntityProjection() {
Person person = new Person();
person.name = "1";
person.uniqueName = "1";
person.persist();
PersonName personName = Person.find(" name = ?1", "1")
.project(PersonName.class)
.firstResult();
person.delete();
Assertions.assertEquals("1", personName.name);
}

/**
* This test is disabled in native mode as there is no interaction with the quarkus integration test endpoint.
*/
@Test
@Transactional
@DisabledOnIntegrationTest
// Test for https://github.com/quarkusio/quarkus/issues/28844
void testSimpleEntityProjection2() {
Person person = new Person();
person.name = "1";
person.uniqueName = "1";
person.persist();
String personName = Person.find("select name from Person2 where name = ?1", "1")
.project(String.class)
.firstResult();
person.delete();
Assertions.assertEquals("1", personName);
}

/**
* This test is disabled in native mode as there is no interaction with the quarkus integration test endpoint.
*/
@Test
@Transactional
@DisabledOnIntegrationTest
void testNestedEntityProjection_WithQuery() {
Person person = new Person();
person.name = "2";
person.uniqueName = "2";
person.address = new Address("street 2");
person.persist();
PersonDTO personDTO = Person.find(
"select uniqueName, name, " +
" new io.quarkus.it.panache.PersonDTO$AddressDTO(address.street)," +
" new io.quarkus.it.panache.PersonDTO$DescriptionDTO(description.size, description.weight)," +
" description.size" +
" from Person2 where name = ?1",
"2")
.project(PersonDTO.class)
.firstResult();
person.delete();
Assertions.assertEquals("2", personDTO.name);
Assertions.assertEquals("street 2", personDTO.address.street);
}

/**
* This test is disabled in native mode as there is no interaction with the quarkus integration test endpoint.
*/
@Test
@Transactional
@DisabledOnIntegrationTest
void testNestedEntityProjection() {
Person person = new Person();
person.name = "3";
person.uniqueName = "3";
person.address = new Address("street 3");
person.description = new PersonDescription();
person.description.weight = 75;
person.description.size = 170;
person.persist();
PersonDTO personDTO = Person.find(" name = ?1", "3")
.project(PersonDTO.class)
.firstResult();
person.delete();
Assertions.assertEquals("3", personDTO.name);
Assertions.assertEquals("street 3", personDTO.address.street);
Assertions.assertEquals(170, personDTO.directHeight);
Assertions.assertEquals(170, personDTO.description.height);
Assertions.assertEquals("Height: 170, weight: 75", personDTO.description.getDescription());
}

/**
* This test is disabled in native mode as there is no interaction with the quarkus integration test endpoint.
*/
@Test
@Transactional
@DisabledOnIntegrationTest
void testDogDto2Projection() {
Person hum = new Person();
hum.name = "hum";
hum.uniqueName = "hum";
Dog kit = new Dog("kit", "bulldog");
hum.dogs.add(kit);
kit.owner = hum;
hum.persist();
DogDto2 dogDto2 = Dog.find(" name = ?1", "kit")
.project(DogDto2.class)
.firstResult();
hum.delete();
Assertions.assertEquals("kit", dogDto2.name);
Assertions.assertEquals("hum", dogDto2.owner.name);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ public DogDto(String name, PersonDto owner) {
}

@NestedProjectedClass
@RegisterForReflection
public static class PersonDto {
public String name;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ public PersonDTO(String uniqueName, String name, AddressDTO address, Description
}

@NestedProjectedClass
@RegisterForReflection
public static class AddressDTO implements Comparable<AddressDTO> {

public final String street;
Expand All @@ -39,7 +38,6 @@ public int compareTo(AddressDTO address) {
}

@NestedProjectedClass
@RegisterForReflection
public static class DescriptionDTO {
private final String description;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -305,71 +305,4 @@ public void testBeerRepository() {
RestAssured.when().get("/test-repo/beers").then().body(is("OK"));
}

@DisabledOnIntegrationTest
@Test
@TestReactiveTransaction
// Test for https://github.com/quarkusio/quarkus/issues/28844
void testSelectNameProjection(UniAsserter asserter) {
Person person = new Person();
person.name = "1";
person.uniqueName = "1";
asserter.execute(() -> person.persist());
asserter.assertThat(
() -> Person.find("select name from Person2 where name = ?1", "1")
.project(String.class)
.firstResult(),
personName -> {
Assertions.assertEquals("1", personName);
});
asserter.execute(() -> person.delete());
}

@DisabledOnIntegrationTest
@Test
@TestReactiveTransaction
void testNestedEntityProjection(UniAsserter asserter) {
Person person = new Person();
person.name = "3";
person.uniqueName = "3";
person.address = new Address("street 3");
person.description = new PersonDescription();
person.description.weight = 75;
person.description.size = 170;
asserter.execute(() -> person.persist());
asserter.assertThat(
() -> Person.find(" name = ?1", "3")
.project(PersonDTO.class)
.firstResult(),
personDTO -> {
Assertions.assertEquals("3", personDTO.name);
Assertions.assertEquals("street 3", personDTO.address.street);
Assertions.assertEquals(170, personDTO.directHeight);
Assertions.assertEquals(170, personDTO.description.height);
Assertions.assertEquals("Height: 170, weight: 75", personDTO.description.getGeneratedDescription());
});
asserter.execute(() -> person.delete());
}

@DisabledOnIntegrationTest
@Test
@TestReactiveTransaction
void testDogDto2Projection(UniAsserter asserter) {
Person hum = new Person();
hum.name = "hum";
hum.uniqueName = "hum";
Dog kit = new Dog("kit", "bulldog");
hum.dogs.add(kit);
kit.owner = hum;
asserter.execute(() -> hum.persist());
asserter.assertThat(
() -> Dog.find(" name = ?1", "kit")
.project(DogDto.class)
.firstResult(),
dogDto -> {
Assertions.assertNotNull(dogDto);
Assertions.assertEquals("kit", dogDto.name);
Assertions.assertEquals("hum", dogDto.owner.name);
});
asserter.execute(() -> hum.delete());
}
}

0 comments on commit d101fbe

Please sign in to comment.