-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HHH-16572 - Skip enhancement for PROPERTY attributes with mismatched …
…field and method names Signed-off-by: Scott Marlow <smarlow@redhat.com>
- Loading branch information
1 parent
ab9e671
commit faebabd
Showing
3 changed files
with
209 additions
and
30 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
87 changes: 87 additions & 0 deletions
87
...test/java/org/hibernate/orm/test/bytecode/enhancement/access/InvalidPropertyNameTest.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,87 @@ | ||
package org.hibernate.orm.test.bytecode.enhancement.access; | ||
|
||
import jakarta.persistence.*; | ||
import org.hibernate.testing.bytecode.enhancement.extension.BytecodeEnhanced; | ||
import org.hibernate.testing.orm.junit.*; | ||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
@DomainModel( | ||
annotatedClasses = { | ||
InvalidPropertyNameTest.SomeEntity.class, | ||
} | ||
) | ||
@SessionFactory | ||
@JiraKey("HHH-16572") | ||
@BytecodeEnhanced | ||
public class InvalidPropertyNameTest { | ||
|
||
|
||
@Test | ||
@FailureExpected(jiraKey = "HHH-16572") | ||
public void test(SessionFactoryScope scope) { | ||
scope.inTransaction( session -> { | ||
session.persist( new SomeEntity( 1L, "field", "property" ) ); | ||
} ); | ||
|
||
scope.inTransaction( session -> { | ||
SomeEntity entity = session.get( SomeEntity.class, 1L ); | ||
assertThat( entity.property ).isEqualTo( "from getter: property" ); | ||
|
||
entity.setPropertyMethod( "updated" ); | ||
} ); | ||
|
||
scope.inTransaction( session -> { | ||
SomeEntity entity = session.get( SomeEntity.class, 1L ); | ||
assertThat( entity.property ).isEqualTo( "from getter: updated" ); | ||
} ); | ||
} | ||
|
||
@AfterEach | ||
public void cleanup(SessionFactoryScope scope) { | ||
// uncomment the following when @FailureExpected is removed above | ||
// scope.inTransaction( session -> { | ||
// session.remove( session.get( SomeEntity.class, 1L ) ); | ||
// PropertyAccessTest} ); | ||
} | ||
|
||
@Entity | ||
@Table(name = "SOME_ENTITY") | ||
static class SomeEntity { | ||
@Id | ||
Long id; | ||
|
||
@Basic | ||
String field; | ||
|
||
String property; | ||
|
||
public SomeEntity() { | ||
} | ||
|
||
public SomeEntity(Long id, String field, String property) { | ||
this.id = id; | ||
this.field = field; | ||
this.property = property; | ||
} | ||
|
||
/** | ||
* The following property accessor methods are purposely named incorrectly to | ||
* not match the "property" field. The HHH-16572 change ensures that | ||
* this entity is not (bytecode) enhanced. Eventually further changes will be made | ||
* such that this entity is enhanced in which case the FailureExpected can be removed | ||
* and the cleanup() uncommented. | ||
*/ | ||
@Basic | ||
@Access(AccessType.PROPERTY) | ||
public String getPropertyMethod() { | ||
return "from getter: " + property; | ||
} | ||
|
||
public void setPropertyMethod(String property) { | ||
this.property = property; | ||
} | ||
} | ||
} |
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