/
FluentHibernateResultTransformerTest.java
53 lines (40 loc) · 1.96 KB
/
FluentHibernateResultTransformerTest.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
51
52
53
package com.github.fluent.hibernate.transformer;
import static com.github.fluent.hibernate.test.util.FluentHibernateTestData.ROOT_NAME_A;
import static com.github.fluent.hibernate.test.util.FluentHibernateTestData.ROOT_NAME_B;
import static com.github.fluent.hibernate.test.util.FluentHibernateTestData.STATIONAR_NAME_A;
import static com.github.fluent.hibernate.test.util.FluentHibernateTestData.STATIONAR_NAME_B;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.List;
import org.junit.Test;
import com.github.fluent.hibernate.H;
import com.github.fluent.hibernate.internal.util.InternalUtils;
import com.github.fluent.hibernate.test.persistent.Root;
import com.github.fluent.hibernate.test.persistent.RootStationar;
import com.github.fluent.hibernate.test.persistent.Stationar;
import com.github.fluent.hibernate.test.util.RootEnvironmentBaseTest;
/**
*
* @author V.Ladynev
*/
public class FluentHibernateResultTransformerTest extends RootEnvironmentBaseTest {
@Test
public void transformStationar() {
H.saveOrUpdateAll(rootsAB());
transform(ROOT_NAME_A, STATIONAR_NAME_A);
transform(ROOT_NAME_B, STATIONAR_NAME_B);
}
private void transform(String rootName, String stationarName) {
List<Root> roots = H.<Root> request(Root.class).proj(Root.ROOT_NAME)
.innerJoin("stationarFrom.stationar", "stationar")
.proj("stationar.name", "stationarFrom.stationar.name")
.eq(Root.ROOT_NAME, rootName).transform(Root.class).list();
Root root = InternalUtils.CollectionUtils.first(roots);
assertThat(root).isNotNull();
assertThat(root.getRootName()).isEqualTo(rootName);
RootStationar stationarFrom = root.getStationarFrom();
assertThat(stationarFrom).isNotNull();
Stationar stationar = stationarFrom.getStationar();
assertThat(stationar).isNotNull();
assertThat(stationar.getName()).isEqualTo(stationarName);
}
}