/**
* Test lookup mechanisms.
*/
public void testWeblogLookups() throws Exception {
UserManager mgr = RollerFactory.getRoller().getUserManager();
WebsiteData weblog = null;
// add test weblogs
WebsiteData testWeblog1 = TestUtils.setupWeblog("testWeblog1", testUser);
WebsiteData testWeblog2 = TestUtils.setupWeblog("testWeblog2", testUser);
TestUtils.endSession(true);
// lookup by id
weblog = mgr.getWebsite(testWeblog1.getId());
assertNotNull(weblog);
assertEquals(testWeblog1.getHandle(), weblog.getHandle());
// lookup by weblog handle
weblog = null;
weblog = mgr.getWebsiteByHandle(testWeblog1.getHandle());
assertNotNull(weblog);
assertEquals(testWeblog1.getHandle(), weblog.getHandle());
// make sure disable weblogs are not returned
weblog.setEnabled(Boolean.FALSE);
mgr.saveWebsite(weblog);
weblog = null;
weblog = mgr.getWebsiteByHandle(testWeblog1.getHandle());
assertNull(weblog);
// restore enabled state
weblog = mgr.getWebsiteByHandle(testWeblog1.getHandle(), Boolean.FALSE);
weblog.setEnabled(Boolean.TRUE);
mgr.saveWebsite(weblog);
TestUtils.endSession(true);
weblog = null;
weblog = mgr.getWebsiteByHandle(testWeblog1.getHandle());
assertNotNull(weblog);
// get all weblogs for user
weblog = null;
List weblogs1 = mgr.getWebsites(testUser, Boolean.TRUE, Boolean.TRUE);
assertEquals(2, weblogs1.size());
weblog = (WebsiteData) weblogs1.get(0);
assertNotNull(weblog);
// make sure disabled weblogs are not returned
weblog.setEnabled(Boolean.FALSE);
mgr.saveWebsite(weblog);
TestUtils.endSession(true);
List weblogs2 = mgr.getWebsites(testUser, Boolean.TRUE, Boolean.TRUE);
assertEquals(1, weblogs2.size());
weblog = (WebsiteData) weblogs2.get(0);
assertNotNull(weblog);
// make sure inactive weblogs are not returned
weblog.setActive(Boolean.FALSE);
mgr.saveWebsite(weblog);
TestUtils.endSession(true);
List weblogs3 = mgr.getWebsites(testUser, Boolean.TRUE, Boolean.TRUE);
assertEquals(0, weblogs3.size());
// remove test weblogs
TestUtils.teardownWeblog(testWeblog1.getId());
TestUtils.teardownWeblog(testWeblog2.getId());