-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathStringFunctionsTest.java
More file actions
75 lines (63 loc) · 2.29 KB
/
StringFunctionsTest.java
File metadata and controls
75 lines (63 loc) · 2.29 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package tech.ydb.hibernate.string;
import org.hibernate.cfg.AvailableSettings;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
import tech.ydb.test.junit5.YdbHelperExtension;
import java.util.List;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static tech.ydb.hibernate.TestUtils.*;
/**
* @author Ainur Mukhtarov
*/
public class StringFunctionsTest {
@RegisterExtension
private static final YdbHelperExtension ydb = new YdbHelperExtension();
@BeforeAll
static void beforeAll() {
SESSION_FACTORY = basedConfiguration()
.addAnnotatedClass(StringEntity.class)
.setProperty(AvailableSettings.URL, jdbcUrl(ydb))
.buildSessionFactory();
}
@Test
void lowerFunctionTest() {
inTransaction(session -> assertEquals("lower text 123", session
.createQuery("select lower('LoWer Text 123')")
.getSingleResult()));
}
@Test
void upperFunctionTest() {
inTransaction(session -> assertEquals("UPPER TEXT 123", session
.createQuery("select upper('UpPer Text 123')")
.getSingleResult()));
}
@Test
void concatFunctionTest() {
inTransaction(session -> assertEquals("123", session
.createQuery("select concat('1', '2', '3')")
.getSingleResult()));
inTransaction(session -> assertEquals("text", session
.createQuery("select concat('text')")
.getSingleResult()));
}
@Test
void lowerOnColumnWithLikeTest() {
inTransaction(session -> {
StringEntity entity = new StringEntity();
entity.id = 1;
entity.name = "test entity";
session.persist(entity);
});
inTransaction(session -> {
List<StringEntity> result = session
.createQuery(
"select e from StringEntity e where lower(e.name) like lower(concat('%', :search, '%'))",
StringEntity.class
)
.setParameter("search", "test")
.getResultList();
assertEquals(1, result.size());
});
}
}