Elffuss BraidHub

kikocis/java-driver public

0fc2037f3536 · 1.2 KiBRawPermalink
1package com.datastax.driver.mapping
2
3import com.datastax.driver.core.CCMTestsSupport
4import com.datastax.driver.mapping.annotations.Column
5import com.datastax.driver.mapping.annotations.PartitionKey
6import com.datastax.driver.mapping.annotations.Table
7import org.testng.annotations.Test
8
9import static org.assertj.core.api.Assertions.assertThat
10
11/**
12 * A simple test to check that mapping a Groovy class works as expected.
13 *
14 * @jira_ticket JAVA-1279
15 */
16public class MapperGroovyTest extends CCMTestsSupport {
17
18 @Table(name = "users")
19 static class User {
20
21 @PartitionKey
22 @Column(name = "user_id")
23 def UUID userId
24
25 def String name
26
27 }
28
29 @Override
30 public void onTestContextInitialized() {
31 execute("CREATE TABLE users (user_id uuid PRIMARY KEY, name text)")
32 }
33
34 @Test(groups = "short")
35 public void should_map_groovy_class() {
36 def mapper = new MappingManager(session()).mapper(User)
37 def user1 = new User()
38 user1.userId = UUID.randomUUID()
39 user1.name = "John Doe"
40 mapper.save user1
41 def user2 = mapper.get user1.userId
42 assertThat(user2.userId).isEqualTo(user1.userId)
43 assertThat(user2.name).isEqualTo(user1.name)
44 }
45
46}
47