/**
* Test lookup mechanisms ...
*/
public void testWeblogEntryLookups() throws Exception {
WeblogManager mgr = RollerFactory.getRoller().getWeblogManager();
WeblogEntryData entry = null;
List entries = null;
Map entryMap = null;
// setup some test entries to use
WeblogEntryData entry1 = TestUtils.setupWeblogEntry("entry1", testWeblog.getDefaultCategory(), testWeblog, testUser);
WeblogEntryData entry2 = TestUtils.setupWeblogEntry("entry2", testWeblog.getDefaultCategory(), testWeblog, testUser);
WeblogEntryData entry3 = TestUtils.setupWeblogEntry("entry3", testWeblog.getDefaultCategory(), testWeblog, testUser);
// make a couple changes
entry1.setLocale("en_US");
mgr.saveWeblogEntry(entry1);
entry2.setLocale("ja_JP");
entry2.setPinnedToMain(Boolean.TRUE);
entry2.setUpdateTime(new java.sql.Timestamp(entry2.getUpdateTime().getTime()+8822384));
entry2.setPubTime(entry2.getUpdateTime());
mgr.saveWeblogEntry(entry2);
entry3.setStatus(WeblogEntryData.DRAFT);
entry3.setUpdateTime(new java.sql.Timestamp(entry3.getUpdateTime().getTime()+348829384));
entry3.setPubTime(entry3.getUpdateTime());
mgr.saveWeblogEntry(entry3);
TestUtils.endSession(true);
log.debug("entry1 = "+entry1.getUpdateTime());
log.debug("entry2 = "+entry2.getUpdateTime());
log.debug("entry3 = "+entry3.getUpdateTime());
// get entry by id
entry = null;
entry = mgr.getWeblogEntry(entry1.getId());
assertNotNull(entry);
assertEquals(entry1.getAnchor(), entry.getAnchor());
// get entry by anchor
entry = null;
entry = mgr.getWeblogEntryByAnchor(testWeblog, entry1.getAnchor());
assertNotNull(entry);
assertEquals(entry1.getTitle(), entry.getTitle());
// get all entries for weblog
entries = null;
entries = mgr.getWeblogEntries(testWeblog, null, null, null, null, null, null, null, 0, -1);
assertNotNull(entries);
assertEquals(3, entries.size());
assertEquals(entry3, entries.get(0));
// get all entries in category
entries = null;
entries = mgr.getWeblogEntries(testWeblog.getDefaultCategory(), false);
assertNotNull(entries);
assertEquals(3, entries.size());
// get all published entries only
entries = null;
entries = mgr.getWeblogEntries(testWeblog, null, null, null, null, WeblogEntryData.PUBLISHED, null, null, 0, -1);
assertNotNull(entries);
assertEquals(2, entries.size());
// get all entries in date range
entries = null;
entries = mgr.getWeblogEntries(testWeblog, null, entry2.getPubTime(), entry2.getPubTime(), null, null, null, null, 0, -1);
assertNotNull(entries);
assertEquals(1, entries.size());
assertEquals(entry2, entries.get(0));
// get all entries, limited to maxSize
entries = null;
entries = mgr.getWeblogEntries(testWeblog, null, null, null, null, null, null, null, 0, 2);
assertNotNull(entries);
assertEquals(2, entries.size());
// get all entries in category
entries = null;
entries = mgr.getWeblogEntries(testWeblog, null, null, null, testWeblog.getDefaultCategory().getName(), null, null, null, 0, -1);
assertNotNull(entries);
assertEquals(3, entries.size());
// get all entries, limited by offset/range
entries = null;
entries = mgr.getWeblogEntries(testWeblog, null, null, null, null, null, null, null, 1, 1);
assertNotNull(entries);
assertEquals(1, entries.size());
assertEquals(entry2, entries.get(0));
// get all entries, limited by locale
entries = null;
entries = mgr.getWeblogEntries(testWeblog, null, null, null, null, null, null, "en_US", 0, -1);
assertNotNull(entries);
assertEquals(1, entries.size());
assertEquals(entry1, entries.get(0));
// get pinned entries only
entries = null;
entries = mgr.getWeblogEntriesPinnedToMain(new Integer(5));
assertNotNull(entries);
assertEquals(1, entries.size());
assertEquals(entry2, entries.get(0));
// get next entries
entries = null;
entries = mgr.getNextEntries(entry1, null, null, 5);
assertNotNull(entries);
assertEquals(1, entries.size());
assertEquals(entry2, entries.get(0));
// get next entry
entry = null;
entry = mgr.getNextEntry(entry1, null, null);
assertNotNull(entry);
assertEquals(entry2, entry);
// get previous entries
entries = null;
entries = mgr.getPreviousEntries(entry2, null, null, 5);
assertNotNull(entries);
assertEquals(1, entries.size());
assertEquals(entry1, entries.get(0));
// get previous entry
entry = null;
entry = mgr.getPreviousEntry(entry2, null, null);
assertNotNull(entry);
assertEquals(entry1, entry);
// get object map
entryMap = null;
entryMap = mgr.getWeblogEntryObjectMap(testWeblog, null, null, null, null, null, 0, -1);
assertNotNull(entryMap);
assertTrue(entryMap.keySet().size() > 1);
// get string map
entryMap = null;
entryMap = mgr.getWeblogEntryStringMap(testWeblog, null, null, null, null, null, 0, -1);
assertNotNull(entryMap);
assertTrue(entryMap.keySet().size() > 1);
// teardown our test entries
TestUtils.teardownWeblogEntry(entry1.getId());