1 15 package org.apache.tapestry.form; 16 17 import org.apache.tapestry.form.ListEditMap; 18 import org.apache.tapestry.junit.TapestryTestCase; 19 import org.apache.tapestry.spec.BeanLifecycle; 20 21 27 28 public class TestListEditMap extends TapestryTestCase 29 { 30 31 private ListEditMap create() 32 { 33 ListEditMap m = new ListEditMap(); 34 35 m.add("request", BeanLifecycle.REQUEST); 36 m.add("page", BeanLifecycle.PAGE); 37 m.add("render", BeanLifecycle.RENDER); 38 39 return m; 40 } 41 42 public void testAdd() 43 { 44 ListEditMap m = create(); 45 46 assertEquals("render", m.getKey()); 47 48 checkList("keys", new Object [] 49 { "request", "page", "render" }, m.getKeys()); 50 checkList("all values", new Object [] 51 { BeanLifecycle.REQUEST, BeanLifecycle.PAGE, BeanLifecycle.RENDER }, m.getAllValues()); 52 checkList("all values", new Object [] 53 { BeanLifecycle.REQUEST, BeanLifecycle.PAGE, BeanLifecycle.RENDER }, m.getValues()); 54 55 assertTrue(m.getDeletedKeys().isEmpty()); 56 } 57 58 public void testGet() 59 { 60 ListEditMap m = create(); 61 62 m.setKey("page"); 63 64 assertEquals("page", m.getKey()); 65 assertSame(BeanLifecycle.PAGE, m.getValue()); 66 } 67 68 public void testGetUnknown() 69 { 70 ListEditMap m = create(); 71 72 m.setKey("unknown"); 73 74 assertNull(m.getValue()); 75 } 76 77 public void testMarkDeleted() 78 { 79 ListEditMap m = create(); 80 81 m.setKey("page"); 82 83 assertEquals(false, m.isDeleted()); 84 85 m.setDeleted(true); 86 87 assertEquals(true, m.isDeleted()); 88 89 checkList("all values", new Object [] 90 { BeanLifecycle.REQUEST, BeanLifecycle.PAGE, BeanLifecycle.RENDER }, m.getAllValues()); 91 92 checkList("undeleted values", new Object [] 93 { BeanLifecycle.REQUEST, BeanLifecycle.RENDER }, m.getValues()); 94 95 checkList("deleted keys", new Object [] 96 { "page" }, m.getDeletedKeys()); 97 } 98 99 public void testMarkAlreadyDeleted() 100 { 101 ListEditMap m = create(); 102 103 m.setKey("page"); 104 105 assertEquals(false, m.isDeleted()); 106 107 m.setDeleted(false); 108 109 assertEquals(false, m.isDeleted()); 110 } 111 112 public void testMarkMultipleDeleted() 113 { 114 ListEditMap m = create(); 115 116 m.setKey("page"); 117 m.setDeleted(true); 118 119 m.setKey("render"); 120 assertEquals(false, m.isDeleted()); 121 m.setDeleted(true); 122 123 assertEquals(true, m.isDeleted()); 124 125 checkList("undeleted values", new Object [] 126 { BeanLifecycle.REQUEST }, m.getValues()); 127 } 128 129 public void testDeleteUndelete() 130 { 131 ListEditMap m = create(); 132 133 m.setKey("page"); 134 m.setDeleted(true); 135 m.setDeleted(false); 136 137 m.setKey("render"); 138 m.setDeleted(true); 139 140 checkList("undeleted values", new Object [] 141 { BeanLifecycle.REQUEST, BeanLifecycle.PAGE }, m.getValues()); 142 } 143 144 145 146 public void testPurgeDeletedKeys() 147 { 148 ListEditMap m = create(); 149 150 m.setKey("render"); 151 m.setDeleted(true); 152 153 checkList("deleted keys before purge", new Object [] 154 { "render" }, m.getDeletedKeys()); 155 156 m.purgeDeletedKeys(); 157 158 checkList("all values after purge", new Object [] 159 { BeanLifecycle.REQUEST, BeanLifecycle.PAGE }, m.getAllValues()); 160 checkList("keys after purge", new Object [] 161 { "request", "page" }, m.getKeys()); 162 163 assertTrue(m.getDeletedKeys().isEmpty()); 164 165 m.purgeDeletedKeys(); 166 167 checkList("all values after second purge", new Object [] 168 { BeanLifecycle.REQUEST, BeanLifecycle.PAGE }, m.getAllValues()); 169 checkList("keys after second purge", new Object [] 170 { "request", "page" }, m.getKeys()); 171 } 172 173 } | Popular Tags |