1 15 package org.apache.tapestry.record; 16 17 import java.util.Collections ; 18 import java.util.List ; 19 20 import org.apache.hivemind.test.HiveMindTestCase; 21 import org.easymock.MockControl; 22 23 29 public class TestPersistentPropertyData extends HiveMindTestCase 30 { 31 32 public void testStoreChange() 33 { 34 Object newObject1 = new Object (); 35 Object newObject2 = new Object (); 36 37 PersistentPropertyDataEncoder encoder = (PersistentPropertyDataEncoder) newMock(PersistentPropertyDataEncoder.class); 38 39 replayControls(); 40 41 PersistentPropertyData ppd = new PersistentPropertyData(encoder); 42 43 ppd.store("foo", "bar", newObject1); 44 45 assertListsEqual(new Object [] 46 { new PropertyChangeImpl("foo", "bar", newObject1) }, ppd.getPageChanges()); 47 48 50 ppd.store("foo", "bar", newObject2); 51 52 assertListsEqual(new Object [] 53 { new PropertyChangeImpl("foo", "bar", newObject2) }, ppd.getPageChanges()); 54 55 58 verifyControls(); 59 } 60 61 public void testDecode() 62 { 63 Object newObject = new Object (); 64 String encoded = "ENCODED"; 65 List decoded = Collections.singletonList(new PropertyChangeImpl("foo", "bar", newObject)); 66 67 MockControl control = newControl(PersistentPropertyDataEncoder.class); 68 PersistentPropertyDataEncoder encoder = (PersistentPropertyDataEncoder) control.getMock(); 69 70 encoder.decodePageChanges(encoded); 71 control.setReturnValue(decoded); 72 73 replayControls(); 74 75 PersistentPropertyData ppd = new PersistentPropertyData(encoder); 76 77 ppd.storeEncoded(encoded); 78 79 List l1 = ppd.getPageChanges(); 80 81 assertListsEqual(new Object [] 82 { new PropertyChangeImpl("foo", "bar", newObject) }, l1); 83 84 List l2 = ppd.getPageChanges(); 85 86 assertNotSame(l1, l2); 87 88 assertListsEqual(new Object [] 89 { new PropertyChangeImpl("foo", "bar", newObject) }, l2); 90 91 verifyControls(); 92 } 93 94 public void testEncode() 95 { 96 String encoded = "ENCODED"; 97 Object newObject = new Object (); 98 List changes = Collections.singletonList(new PropertyChangeImpl("foo", "bar", newObject)); 99 100 MockControl control = newControl(PersistentPropertyDataEncoder.class); 101 PersistentPropertyDataEncoder encoder = (PersistentPropertyDataEncoder) control.getMock(); 102 103 encoder.encodePageChanges(changes); 104 control.setReturnValue(encoded); 105 106 replayControls(); 107 108 PersistentPropertyData ppd = new PersistentPropertyData(encoder); 109 110 ppd.store("foo", "bar", newObject); 111 112 assertSame(encoded, ppd.getEncoded()); 113 assertSame(encoded, ppd.getEncoded()); 114 115 verifyControls(); 116 } 117 } | Popular Tags |