View Javadoc

1   package net.sf.ehcache.store.compound;
2   
3   import net.sf.ehcache.Element;
4   import net.sf.ehcache.store.DefaultElementValueComparator;
5   import org.junit.Assert;
6   import org.junit.Test;
7   
8   import java.util.Arrays;
9   
10  /***
11   * @author Ludovic Orban
12   */
13  public class PartialSerializationCopyStrategyTest {
14  
15      @Test
16      public void test() throws Exception {
17          final DefaultElementValueComparator comparator = new DefaultElementValueComparator();
18          final ReadWriteSerializationCopyStrategy copyStrategy = new ReadWriteSerializationCopyStrategy();
19  
20          {
21              Element storageValue = copyStrategy.copyForWrite(null);
22              // null element stays null
23              Assert.assertNull(storageValue);
24              Assert.assertNull(copyStrategy.copyForRead(storageValue));
25          }
26  
27          {
28              Element storageValue = copyStrategy.copyForWrite(new Element(1, null));
29              // null value stays null
30              Assert.assertNull(storageValue.getObjectValue());
31              Assert.assertNull(copyStrategy.copyForRead(storageValue).getObjectValue());
32          }
33  
34          {
35              Element storageValue = copyStrategy.copyForWrite(new Element(1, "one"));
36              // element values are stored as byte[]
37              Assert.assertTrue(storageValue.getObjectValue() instanceof byte[]);
38              Assert.assertTrue(comparator.equals(new Element(1, "one"), copyStrategy.copyForRead(storageValue)));
39          }
40  
41          {
42              final short[][] value = {
43                      new short[]{1},
44                      new short[]{1, 2},
45                      new short[]{1, 2, 3}
46              };
47              Element storageValue = copyStrategy.copyForWrite(new Element(1, value));
48              // element values are stored as byte[]
49              Assert.assertTrue(storageValue.getObjectValue() instanceof byte[]);
50              Assert.assertTrue(Arrays.deepEquals(new Object[]{value}, new Object[]{copyStrategy.copyForRead(storageValue).getObjectValue()}));
51          }
52  
53      }
54  
55  }