1 package com.atlassian.activeobjects.backup.types;
2
3 import net.java.ao.Entity;
4 import net.java.ao.EntityManager;
5 import net.java.ao.RawEntity;
6 import net.java.ao.test.jdbc.NonTransactional;
7 import org.junit.Test;
8
9 import java.util.concurrent.atomic.AtomicInteger;
10
11 import static org.junit.Assert.assertEquals;
12
13 public final class TestDoubleBackup extends AbstractTestTypeBackup {
14 @Test
15 @NonTransactional
16 public void testSimpleEntityWithNegativeValue() throws Exception {
17 testBackupWithValue(-1.8d);
18 }
19
20 @Test
21 @NonTransactional
22 public void testSimpleEntityWithZero() throws Exception {
23 testBackupWithValue(0d);
24 }
25
26 @Test
27 @NonTransactional
28 public void testSimpleEntityWithPositiveValue() throws Exception {
29 testBackupWithValue(1.2d);
30 }
31
32 @Test
33 @NonTransactional
34 public void testSimpleEntityWithNull() throws Exception {
35 testBackupWithValue(null);
36 }
37
38 private void testBackupWithValue(final Double value) throws Exception {
39 final AtomicInteger eId = new AtomicInteger(-1);
40 testBackupType(new BackupType<Integer>() {
41 @Override
42 public Class<? extends RawEntity<Integer>> getEntityClass() {
43 return SimpleEntity.class;
44 }
45
46 @Override
47 public void createData(EntityManager em) throws Exception {
48 SimpleEntity e = em.create(SimpleEntity.class);
49 e.setValue(value);
50 e.save();
51 eId.set(e.getID());
52 }
53
54 @Override
55 public void checkData(EntityManager em) throws Exception {
56 final Double actual = em.get(SimpleEntity.class, eId.get()).getValue();
57 assertEquals(value, actual);
58 }
59 });
60 }
61
62 public static interface SimpleEntity extends Entity {
63 public Double getValue();
64
65 public void setValue(Double value);
66 }
67 }