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.net.URI;
10 import java.util.concurrent.atomic.AtomicInteger;
11
12 import static org.junit.Assert.assertEquals;
13
14 public final class TestUriBackup extends AbstractTestTypeBackup {
15 @Test
16 @NonTransactional
17 public void testSimpleEntityWithValue() throws Exception {
18 testBackupValue(new URI("file://some-uri"));
19 }
20
21 @Test
22 @NonTransactional
23 public void testSimpleEntityWithNull() throws Exception {
24 testBackupValue(null);
25 }
26
27 private void testBackupValue(final URI value) throws Exception {
28 final AtomicInteger eId = new AtomicInteger(-1);
29 testBackupType(new BackupType<Integer>() {
30 @Override
31 public Class<? extends RawEntity<Integer>> getEntityClass() {
32 return SimpleEntity.class;
33 }
34
35 @Override
36 public void createData(EntityManager em) throws Exception {
37 SimpleEntity e = em.create(SimpleEntity.class);
38 e.setValue(value);
39 e.save();
40 eId.set(e.getID());
41 }
42
43 @Override
44 public void checkData(EntityManager em) throws Exception {
45 assertEquals(value, em.get(SimpleEntity.class, eId.get()).getValue());
46 }
47 });
48 }
49
50 public static interface SimpleEntity extends Entity {
51 public URI getValue();
52
53 public void setValue(URI value);
54 }
55 }