1 18 23 24 package org.apache.roller.business; 25 26 import java.util.List ; 27 import java.util.Map ; 28 import junit.framework.Test; 29 import junit.framework.TestCase; 30 import junit.framework.TestSuite; 31 import org.apache.commons.logging.Log; 32 import org.apache.commons.logging.LogFactory; 33 import org.apache.roller.TestUtils; 34 import org.apache.roller.model.RollerFactory; 35 import org.apache.roller.model.WeblogManager; 36 import org.apache.roller.pojos.UserData; 37 import org.apache.roller.pojos.WeblogEntryData; 38 import org.apache.roller.pojos.WebsiteData; 39 40 41 44 public class WeblogEntryTest extends TestCase { 45 46 public static Log log = LogFactory.getLog(WeblogEntryTest.class); 47 48 UserData testUser = null; 49 WebsiteData testWeblog = null; 50 51 52 public WeblogEntryTest(String name) { 53 super(name); 54 } 55 56 57 public static Test suite() { 58 return new TestSuite(WeblogEntryTest.class); 59 } 60 61 62 65 public void setUp() throws Exception { 66 67 try { 68 testUser = TestUtils.setupUser("entryTestUser"); 69 testWeblog = TestUtils.setupWeblog("entryTestWeblog", testUser); 70 TestUtils.endSession(true); 71 } catch (Exception ex) { 72 log.error(ex); 73 throw new Exception ("Test setup failed", ex); 74 } 75 } 76 77 public void tearDown() throws Exception { 78 79 try { 80 TestUtils.teardownWeblog(testWeblog.getId()); 81 TestUtils.teardownUser(testUser.getId()); 82 TestUtils.endSession(true); 83 } catch (Exception ex) { 84 log.error(ex); 85 throw new Exception ("Test teardown failed", ex); 86 } 87 } 88 89 90 93 public void testWeblogEntryCRUD() throws Exception { 94 95 WeblogManager mgr = RollerFactory.getRoller().getWeblogManager(); 96 WeblogEntryData entry = null; 97 98 WeblogEntryData testEntry = new WeblogEntryData(); 99 testEntry.setTitle("entryTestEntry"); 100 testEntry.setLink("testEntryLink"); 101 testEntry.setText("blah blah entry"); 102 testEntry.setAnchor("testEntryAnchor"); 103 testEntry.setPubTime(new java.sql.Timestamp (new java.util.Date ().getTime())); 104 testEntry.setUpdateTime(new java.sql.Timestamp (new java.util.Date ().getTime())); 105 testEntry.setWebsite(testWeblog); 106 testEntry.setCreator(testUser); 107 testEntry.setCategory(testWeblog.getDefaultCategory()); 108 109 mgr.saveWeblogEntry(testEntry); 111 String id = testEntry.getId(); 112 TestUtils.endSession(true); 113 114 entry = mgr.getWeblogEntry(id); 116 assertNotNull(entry); 117 assertEquals(testEntry, entry); 118 119 entry.setTitle("testtest"); 121 mgr.saveWeblogEntry(entry); 122 TestUtils.endSession(true); 123 124 entry = null; 126 entry = mgr.getWeblogEntry(id); 127 assertNotNull(entry); 128 assertEquals("testtest", entry.getTitle()); 129 130 mgr.removeWeblogEntry(entry); 132 TestUtils.endSession(true); 133 134 entry = null; 136 entry = mgr.getWeblogEntry(id); 137 assertNull(entry); 138 } 139 140 141 144 public void testWeblogEntryLookups() throws Exception { 145 146 WeblogManager mgr = RollerFactory.getRoller().getWeblogManager(); 147 WeblogEntryData entry = null; 148 List entries = null; 149 Map entryMap = null; 150 151 WeblogEntryData entry1 = TestUtils.setupWeblogEntry("entry1", testWeblog.getDefaultCategory(), testWeblog, testUser); 153 WeblogEntryData entry2 = TestUtils.setupWeblogEntry("entry2", testWeblog.getDefaultCategory(), testWeblog, testUser); 154 WeblogEntryData entry3 = TestUtils.setupWeblogEntry("entry3", testWeblog.getDefaultCategory(), testWeblog, testUser); 155 156 entry1.setLocale("en_US"); 158 mgr.saveWeblogEntry(entry1); 159 entry2.setLocale("ja_JP"); 160 entry2.setPinnedToMain(Boolean.TRUE); 161 entry2.setUpdateTime(new java.sql.Timestamp (entry2.getUpdateTime().getTime()+8822384)); 162 entry2.setPubTime(entry2.getUpdateTime()); 163 mgr.saveWeblogEntry(entry2); 164 entry3.setStatus(WeblogEntryData.DRAFT); 165 entry3.setUpdateTime(new java.sql.Timestamp (entry3.getUpdateTime().getTime()+348829384)); 166 entry3.setPubTime(entry3.getUpdateTime()); 167 mgr.saveWeblogEntry(entry3); 168 169 TestUtils.endSession(true); 170 171 log.debug("entry1 = "+entry1.getUpdateTime()); 172 log.debug("entry2 = "+entry2.getUpdateTime()); 173 log.debug("entry3 = "+entry3.getUpdateTime()); 174 175 entry = null; 177 entry = mgr.getWeblogEntry(entry1.getId()); 178 assertNotNull(entry); 179 assertEquals(entry1.getAnchor(), entry.getAnchor()); 180 181 entry = null; 183 entry = mgr.getWeblogEntryByAnchor(testWeblog, entry1.getAnchor()); 184 assertNotNull(entry); 185 assertEquals(entry1.getTitle(), entry.getTitle()); 186 187 entries = null; 189 entries = mgr.getWeblogEntries(testWeblog, null, null, null, null, null, null, null, 0, -1); 190 assertNotNull(entries); 191 assertEquals(3, entries.size()); 192 assertEquals(entry3, entries.get(0)); 193 194 entries = null; 196 entries = mgr.getWeblogEntries(testWeblog.getDefaultCategory(), false); 197 assertNotNull(entries); 198 assertEquals(3, entries.size()); 199 200 entries = null; 202 entries = mgr.getWeblogEntries(testWeblog, null, null, null, null, WeblogEntryData.PUBLISHED, null, null, 0, -1); 203 assertNotNull(entries); 204 assertEquals(2, entries.size()); 205 206 entries = null; 208 entries = mgr.getWeblogEntries(testWeblog, null, entry2.getPubTime(), entry2.getPubTime(), null, null, null, null, 0, -1); 209 assertNotNull(entries); 210 assertEquals(1, entries.size()); 211 assertEquals(entry2, entries.get(0)); 212 213 entries = null; 215 entries = mgr.getWeblogEntries(testWeblog, null, null, null, null, null, null, null, 0, 2); 216 assertNotNull(entries); 217 assertEquals(2, entries.size()); 218 219 entries = null; 221 entries = mgr.getWeblogEntries(testWeblog, null, null, null, testWeblog.getDefaultCategory().getName(), null, null, null, 0, -1); 222 assertNotNull(entries); 223 assertEquals(3, entries.size()); 224 225 entries = null; 227 entries = mgr.getWeblogEntries(testWeblog, null, null, null, null, null, null, null, 1, 1); 228 assertNotNull(entries); 229 assertEquals(1, entries.size()); 230 assertEquals(entry2, entries.get(0)); 231 232 entries = null; 234 entries = mgr.getWeblogEntries(testWeblog, null, null, null, null, null, null, "en_US", 0, -1); 235 assertNotNull(entries); 236 assertEquals(1, entries.size()); 237 assertEquals(entry1, entries.get(0)); 238 239 entries = null; 241 entries = mgr.getWeblogEntriesPinnedToMain(new Integer (5)); 242 assertNotNull(entries); 243 assertEquals(1, entries.size()); 244 assertEquals(entry2, entries.get(0)); 245 246 entries = null; 248 entries = mgr.getNextEntries(entry1, null, null, 5); 249 assertNotNull(entries); 250 assertEquals(1, entries.size()); 251 assertEquals(entry2, entries.get(0)); 252 253 entry = null; 255 entry = mgr.getNextEntry(entry1, null, null); 256 assertNotNull(entry); 257 assertEquals(entry2, entry); 258 259 entries = null; 261 entries = mgr.getPreviousEntries(entry2, null, null, 5); 262 assertNotNull(entries); 263 assertEquals(1, entries.size()); 264 assertEquals(entry1, entries.get(0)); 265 266 entry = null; 268 entry = mgr.getPreviousEntry(entry2, null, null); 269 assertNotNull(entry); 270 assertEquals(entry1, entry); 271 272 entryMap = null; 274 entryMap = mgr.getWeblogEntryObjectMap(testWeblog, null, null, null, null, null, 0, -1); 275 assertNotNull(entryMap); 276 assertTrue(entryMap.keySet().size() > 1); 277 278 entryMap = null; 280 entryMap = mgr.getWeblogEntryStringMap(testWeblog, null, null, null, null, null, 0, -1); 281 assertNotNull(entryMap); 282 assertTrue(entryMap.keySet().size() > 1); 283 284 TestUtils.teardownWeblogEntry(entry1.getId()); 286 TestUtils.teardownWeblogEntry(entry2.getId()); 287 TestUtils.teardownWeblogEntry(entry3.getId()); 288 TestUtils.endSession(true); 289 } 290 291 292 295 public void testCreateAnchor() throws Exception { 296 297 WeblogManager mgr = RollerFactory.getRoller().getWeblogManager(); 298 WeblogEntryData entry = null; 299 List entries = null; 300 301 WeblogEntryData entry1 = TestUtils.setupWeblogEntry("entry1", testWeblog.getDefaultCategory(), testWeblog, testUser); 303 TestUtils.endSession(true); 304 305 String anchor = mgr.createAnchor(entry1); 307 assertNotNull(anchor); 308 assertNotSame("entry1", anchor); 309 310 WeblogEntryData entry2 = TestUtils.setupWeblogEntry(anchor, testWeblog.getDefaultCategory(), testWeblog, testUser); 312 TestUtils.endSession(true); 313 assertNotNull(entry2); 314 315 TestUtils.teardownWeblogEntry(entry1.getId()); 317 TestUtils.teardownWeblogEntry(entry2.getId()); 318 TestUtils.endSession(true); 319 } 320 321 322 325 public void testEntryAttributeCRUD() throws Exception { 326 327 } 329 330 } 331 | Popular Tags |