/
HstorePathTest.java
50 lines (41 loc) · 1.5 KB
/
HstorePathTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package com.pallasathenagroup.querydsl;
import com.google.common.collect.ImmutableMap;
import com.querydsl.jpa.impl.JPAQuery;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import static com.pallasathenagroup.querydsl.QHstoreEntity.hstoreEntity;
import static org.hibernate.testing.transaction.TransactionUtil.doInJPA;
import static org.junit.Assert.assertEquals;
@Ignore("No Hstore extension enabled on CI")
public class HstorePathTest extends BaseCoreFunctionalTestCase {
@Override
protected Class<?>[] getAnnotatedClasses() {
return new Class<?>[] { HstoreEntity.class };
}
@Before
public void setUp() {
doInJPA(this::sessionFactory, entityManager -> {
HstoreEntity entity = new HstoreEntity();
entity.hstore = ImmutableMap.of("a", "b");
entityManager.persist(entity);
});
}
@Override
protected boolean isCleanupTestDataRequired() {
return true;
}
@Test
public void getFieldAsText() {
doInJPA(this::sessionFactory, entityManager -> {
String result = new JPAQuery<HstoreEntity>(entityManager, ExtendedHQLTemplates.DEFAULT)
.from(hstoreEntity)
.select(
HibernateTypesExpressions.asHstore(hstoreEntity.hstore).get("a")
)
.fetchOne();
assertEquals("b", result);
});
}
}