View Javadoc
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 TestStringBackup extends AbstractTestTypeBackup {
14      @Test
15      @NonTransactional
16      public void testSimpleEntityWithValue() throws Exception {
17          testBackupWithValue("Some small sample");
18      }
19  
20      @Test
21      @NonTransactional
22      public void testSimpleEntityWithNull() throws Exception {
23          testBackupWithValue("Some small sample");
24      }
25  
26      private void testBackupWithValue(final String value) throws Exception {
27          final AtomicInteger eId = new AtomicInteger(-1);
28          testBackupType(new BackupType<Integer>() {
29              @Override
30              public Class<? extends RawEntity<Integer>> getEntityClass() {
31                  return SimpleEntity.class;
32              }
33  
34              @Override
35              public void createData(EntityManager em) throws Exception {
36                  SimpleEntity e = em.create(SimpleEntity.class);
37                  e.setValue(value);
38                  e.save();
39                  eId.set(e.getID());
40              }
41  
42              @Override
43              public void checkData(EntityManager em) throws Exception {
44                  assertEquals(value, em.get(SimpleEntity.class, eId.get()).getValue());
45              }
46          });
47      }
48  
49      public static interface SimpleEntity extends Entity {
50          public String getValue();
51  
52          public void setValue(String value);
53      }
54  }