| 1 | package com.datastax.driver.mapping |
| 2 | |
| 3 | import com.datastax.driver.core.CCMTestsSupport |
| 4 | import com.datastax.driver.mapping.annotations.Column |
| 5 | import com.datastax.driver.mapping.annotations.PartitionKey |
| 6 | import com.datastax.driver.mapping.annotations.Table |
| 7 | import org.testng.annotations.Test |
| 8 | |
| 9 | import 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 | */ |
| 16 | public 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 | |