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 TestEnumBackup extends AbstractTestTypeBackup {
14 @Test
15 @NonTransactional
16 public void testSimpleEntityWithValueOne() throws Exception {
17 testBackupWithValue(Value.ONE);
18 }
19
20 @Test
21 @NonTransactional
22 public void testSimpleEntityWithValueTwo() throws Exception {
23 testBackupWithValue(Value.TWO);
24 }
25
26 @Test
27 @NonTransactional
28 public void testSimpleEntityWithNull() throws Exception {
29 testBackupWithValue(null);
30 }
31
32 private void testBackupWithValue(final Value value) throws Exception {
33 final AtomicInteger eId = new AtomicInteger(-1);
34 testBackupType(new BackupType<Integer>() {
35 @Override
36 public Class<? extends RawEntity<Integer>> getEntityClass() {
37 return SimpleEntity.class;
38 }
39
40 @Override
41 public void createData(EntityManager em) throws Exception {
42 SimpleEntity e = em.create(SimpleEntity.class);
43 e.setValue(value);
44 e.save();
45 eId.set(e.getID());
46 }
47
48 @Override
49 public void checkData(EntityManager em) throws Exception {
50 assertEquals(value, em.get(SimpleEntity.class, eId.get()).getValue());
51 }
52 });
53 }
54
55 public static interface SimpleEntity extends Entity {
56 public Value getValue();
57
58 public void setValue(Value value);
59 }
60
61 public static enum Value {
62 ONE, TWO
63 }
64 }