|
4 | 4 | */
|
5 | 5 | package org.hibernate.orm.test.jpa.criteria.basic;
|
6 | 6 |
|
7 |
| -import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate; |
8 |
| - |
9 |
| -import java.util.Arrays; |
10 |
| -import java.util.List; |
11 |
| -import java.util.Locale; |
12 |
| - |
13 |
| -import jakarta.persistence.Column; |
14 |
| -import jakarta.persistence.Entity; |
15 |
| -import jakarta.persistence.Id; |
16 | 7 | import jakarta.persistence.criteria.CriteriaBuilder;
|
17 | 8 | import jakarta.persistence.criteria.CriteriaQuery;
|
18 | 9 | import jakarta.persistence.criteria.Expression;
|
19 | 10 | import jakarta.persistence.criteria.Path;
|
20 | 11 | import jakarta.persistence.criteria.Root;
|
21 |
| - |
22 | 12 | import org.hibernate.dialect.H2Dialect;
|
23 |
| -import org.hibernate.testing.RequiresDialect; |
| 13 | +import org.hibernate.testing.orm.domain.StandardDomainModel; |
| 14 | +import org.hibernate.testing.orm.domain.helpdesk.Ticket; |
| 15 | +import org.hibernate.testing.orm.junit.DomainModel; |
24 | 16 | import org.hibernate.testing.orm.junit.JiraKey;
|
25 |
| -import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; |
26 |
| -import org.junit.Assert; |
27 |
| -import org.junit.Before; |
28 |
| -import org.junit.Test; |
| 17 | +import org.hibernate.testing.orm.junit.RequiresDialect; |
| 18 | +import org.hibernate.testing.orm.junit.SessionFactory; |
| 19 | +import org.hibernate.testing.orm.junit.SessionFactoryScope; |
| 20 | +import org.junit.jupiter.api.Test; |
29 | 21 |
|
30 |
| -/** |
31 |
| - * @author Jeremy Carnus |
32 |
| - * @author Guillaume Smet |
33 |
| - */ |
| 22 | +import java.util.Arrays; |
| 23 | + |
| 24 | +@SuppressWarnings("JUnitMalformedDeclaration") |
34 | 25 | @JiraKey(value = "HHH-12989")
|
35 |
| -public class InWithHeterogeneousCollectionTest extends BaseCoreFunctionalTestCase { |
| 26 | +@RequiresDialect(value = H2Dialect.class, comment = "Not dialect specific") |
| 27 | +@DomainModel(standardModels = StandardDomainModel.HELPDESK) |
| 28 | +@SessionFactory |
| 29 | +public class InWithHeterogeneousCollectionTest { |
36 | 30 |
|
37 | 31 | @Test
|
38 |
| - @RequiresDialect(H2Dialect.class) |
39 |
| - public void testCaseClause() { |
40 |
| - doInHibernate( this::sessionFactory, session -> { |
41 |
| - CriteriaBuilder cb = session.getCriteriaBuilder(); |
42 |
| - |
43 |
| - CriteriaQuery<Event> criteria = cb.createQuery( Event.class ); |
44 |
| - |
45 |
| - Root<Event> eventRoot = criteria.from( Event.class ); |
46 |
| - Path<String> namePath = eventRoot.get( "name" ); |
47 |
| - Path<String> tagPath = eventRoot.get( "tag" ); |
48 |
| - |
49 |
| - Expression<String> expression = cb.function( |
50 |
| - "lower", |
51 |
| - String.class, |
52 |
| - namePath ); |
53 |
| - |
54 |
| - criteria.select( eventRoot ); |
55 |
| - criteria.where( tagPath.in( Arrays.asList( expression, "my-tag" ) ) ); |
56 |
| - List<Event> resultList = session.createQuery( criteria ).getResultList(); |
57 |
| - |
58 |
| - Assert.assertEquals( 2, resultList.size() ); |
59 |
| - } ); |
60 |
| - } |
61 |
| - |
62 |
| - @Before |
63 |
| - public void setup() { |
64 |
| - doInHibernate( this::sessionFactory, session -> { |
65 |
| - session.persist( new Event( 1L, "EventName1", "EventName1".toLowerCase( Locale.ROOT ) ) ); |
66 |
| - session.persist( new Event( 2L, "EventName2", "my-tag" ) ); |
| 32 | + public void testHeterogeneousInExpressions(SessionFactoryScope sessions) { |
| 33 | + sessions.inTransaction( (session) -> { |
| 34 | + final CriteriaBuilder cb = session.getCriteriaBuilder(); |
| 35 | + |
| 36 | + final CriteriaQuery<Ticket> criteria = cb.createQuery( Ticket.class ); |
| 37 | + final Root<Ticket> root = criteria.from( Ticket.class ); |
| 38 | + final Path<String> keyPath = root.get( "key" ); |
| 39 | + final Expression<String> lowercaseKey = cb.lower( keyPath ); |
| 40 | + criteria.where( keyPath.in( Arrays.asList( lowercaseKey, "HHH-1" ) ) ); |
| 41 | + session.createQuery( criteria ).getResultList(); |
67 | 42 | } );
|
68 | 43 | }
|
69 |
| - |
70 |
| - @Override |
71 |
| - protected Class<?>[] getAnnotatedClasses() { |
72 |
| - return new Class[]{ Event.class }; |
73 |
| - } |
74 |
| - |
75 |
| - @Entity(name = "Event") |
76 |
| - public static class Event { |
77 |
| - |
78 |
| - @Id |
79 |
| - private Long id; |
80 |
| - |
81 |
| - @Column |
82 |
| - private String name; |
83 |
| - |
84 |
| - @Column |
85 |
| - private String tag; |
86 |
| - |
87 |
| - protected Event() { |
88 |
| - } |
89 |
| - |
90 |
| - public Event(Long id, String name, String tag) { |
91 |
| - this.id = id; |
92 |
| - this.name = name; |
93 |
| - this.tag = tag; |
94 |
| - } |
95 |
| - |
96 |
| - public String getName() { |
97 |
| - return name; |
98 |
| - } |
99 |
| - |
100 |
| - public String getTag() { |
101 |
| - return tag; |
102 |
| - } |
103 |
| - } |
104 | 44 | }
|
0 commit comments