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.schema.StringLength;
7   import net.java.ao.test.jdbc.NonTransactional;
8   import org.junit.Test;
9   
10  import java.util.concurrent.atomic.AtomicInteger;
11  
12  import static org.junit.Assert.assertEquals;
13  
14  public final class TestClobBackup extends AbstractTestTypeBackup {
15      private static String SMALL_CLOB = "Some small sample";
16  
17      // over 4000 bytes, as Oracle has issues with that.
18      private static String LARGE_CLOB;
19  
20      static {
21          int size = 8100;
22          StringBuilder sb = new StringBuilder(size);
23          for (int i = 0; i < size / 10; i++) {
24              sb.append("0123456789#");
25          }
26          LARGE_CLOB = sb.append(size).toString();
27      }
28  
29      @Test
30      @NonTransactional
31      public void testSimpleEntityWithSmallClob() throws Exception {
32          testBackupWithValue(SMALL_CLOB);
33      }
34  
35      @Test
36      @NonTransactional
37      public void testSimpleEntityWithLargeClob() throws Exception {
38          testBackupWithValue(LARGE_CLOB);
39      }
40  
41      @Test
42      @NonTransactional
43      public void testSimpleEntityWithNull() throws Exception {
44          testBackupWithValue(null);
45      }
46  
47      private void testBackupWithValue(final String value) throws Exception {
48          final AtomicInteger eId = new AtomicInteger(-1);
49          testBackupType(new BackupType<Integer>() {
50              @Override
51              public Class<? extends RawEntity<Integer>> getEntityClass() {
52                  return SimpleEntity.class;
53              }
54  
55              @Override
56              public void createData(EntityManager em) throws Exception {
57                  SimpleEntity e = em.create(SimpleEntity.class);
58                  e.setValue(value);
59                  e.save();
60                  eId.set(e.getID());
61              }
62  
63              @Override
64              public void checkData(EntityManager em) throws Exception {
65                  assertEquals(value, em.get(SimpleEntity.class, eId.get()).getValue());
66              }
67          });
68      }
69  
70      public static interface SimpleEntity extends Entity {
71          @StringLength(StringLength.UNLIMITED)
72          public String getValue();
73  
74          @StringLength(StringLength.UNLIMITED)
75          public void setValue(String value);
76      }
77  }