-
Notifications
You must be signed in to change notification settings - Fork 76
/
DatastaxMapperUDTTest.java
81 lines (61 loc) · 2.87 KB
/
DatastaxMapperUDTTest.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package org.sfm.datastax;
import com.datastax.driver.core.ResultSet;
import com.datastax.driver.core.Session;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.sfm.datastax.beans.DbObjectsWithUDT;
import org.sfm.datastax.beans.DbObjectsWithUDTTupleList;
import org.sfm.reflect.ReflectionService;
import org.sfm.utils.LibrarySets;
import org.sfm.utils.MultiClassLoaderJunitRunner;
import java.util.Arrays;
import java.util.Iterator;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
@RunWith(MultiClassLoaderJunitRunner.class)
@LibrarySets(
librarySets = {
//IFJAVA8_START
"http://repo1.maven.org/maven2/com/datastax/cassandra/cassandra-driver-core/3.0.3/cassandra-driver-core-3.0.3.jar",
//IFJAVA8_END
"http://repo1.maven.org/maven2/com/datastax/cassandra/cassandra-driver-core/2.1.8/cassandra-driver-core-2.1.8.jar"
},
includes={ReflectionService.class, DatastaxCrud.class, DatastaxCrudTest.class},
excludes = { "org.junit", "org.sfm.datastax.DatastaxCrudTest", "io.netty"},
names={"v303", "v218"}
)
public class DatastaxMapperUDTTest extends AbstractDatastaxTest {
@Test
public void testMapUDT() throws Exception {
testInSession(new Callback() {
@Override
public void call(Session session) throws Exception {
final DatastaxMapper<DbObjectsWithUDT> mapper = DatastaxMapperFactory.newInstance().mapTo(DbObjectsWithUDT.class);
ResultSet rs = session.execute("select id, t from dbobjects_udt");
final Iterator<DbObjectsWithUDT> iterator = mapper.iterator(rs);
DbObjectsWithUDT next = iterator.next();
assertEquals(1, next.getId());
assertEquals("t1", next.getT().str);
assertEquals(12l, next.getT().l);
assertFalse(iterator.hasNext());
}
});
}
@Test
public void testMapUDTTupleList() throws Exception {
testInSession(new Callback() {
@Override
public void call(Session session) throws Exception {
final DatastaxMapper<DbObjectsWithUDTTupleList> mapper = DatastaxMapperFactory.newInstance().mapTo(DbObjectsWithUDTTupleList.class);
ResultSet rs = session.execute("select id, t from dbobjects_udttyplelist");
final Iterator<DbObjectsWithUDTTupleList> iterator = mapper.iterator(rs);
DbObjectsWithUDTTupleList next = iterator.next();
assertEquals(1, next.getId());
assertEquals("t1", next.getT().str);
assertEquals(Long.valueOf(12l), next.getT().t.first());
assertEquals(Arrays.asList(13, 14), next.getT().t.second());
assertFalse(iterator.hasNext());
}
});
}
}