-
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-18894 Simplified test case selecting (non-managed) enum constant …
…as column
- Loading branch information
Showing
1 changed file
with
64 additions
and
0 deletions.
There are no files selected for viewing
64 changes: 64 additions & 0 deletions
64
hibernate-core/src/test/java/org/hibernate/orm/test/query/SelectUnknownEnumLiteralTest.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,64 @@ | ||
/* | ||
* SPDX-License-Identifier: LGPL-2.1-or-later | ||
* Copyright Red Hat Inc. and Hibernate Authors | ||
*/ | ||
package org.hibernate.orm.test.query; | ||
|
||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.Tuple; | ||
import org.hibernate.testing.orm.junit.DomainModel; | ||
import org.hibernate.testing.orm.junit.SessionFactory; | ||
import org.hibernate.testing.orm.junit.SessionFactoryScope; | ||
import org.junit.jupiter.api.AfterAll; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.List; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
@DomainModel(annotatedClasses = SelectUnknownEnumLiteralTest.Transaction.class) | ||
@SessionFactory | ||
public class SelectUnknownEnumLiteralTest { | ||
|
||
@BeforeAll | ||
void setup(SessionFactoryScope scope) { | ||
scope.inTransaction( em -> em.persist( new Transaction( 1L, "abc" ) ) ); | ||
} | ||
|
||
@AfterAll | ||
void clean(SessionFactoryScope scope) { | ||
scope.inTransaction( em -> em.createMutationQuery( "delete from Transaction" ).executeUpdate() ); | ||
} | ||
|
||
@Test | ||
void test(SessionFactoryScope scope) { | ||
final List<Tuple> tuples = scope.fromSession( em -> | ||
em.createQuery( | ||
"SELECT org.hibernate.orm.test.query.SelectUnknownEnumLiteralTest$Type.TRANSACTION, e.id, e.reference FROM Transaction e", | ||
Tuple.class ).getResultList() ); | ||
assertEquals( 1, tuples.size() ); | ||
assertEquals( Type.TRANSACTION, tuples.get( 0 ).get( 0 ) ); | ||
assertEquals( 1L, tuples.get( 0 ).get( 1 ) ); | ||
} | ||
|
||
@Entity(name = "Transaction") | ||
static class Transaction { | ||
@Id | ||
Long id; | ||
String reference; | ||
|
||
Transaction() { | ||
} | ||
|
||
Transaction(Long id, String reference) { | ||
this.id = id; | ||
this.reference = reference; | ||
} | ||
} | ||
|
||
enum Type { | ||
TRANSACTION, DIRECT_DEBIT_GROUP, DIRECT_DEBIT | ||
} | ||
} |