log.info("BEGIN");
Weblog testWeblog1 = null;
Weblog testWeblog2 = null;
try {
UserManager mgr = WebloggerFactory.getWeblogger().getUserManager();
Weblog weblog = null;
// add test weblogs
testWeblog1 = TestUtils.setupWeblog("testWeblog1", testUser);
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);
TestUtils.endSession(true);
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(TestUtils.getManagedUser(testUser), Boolean.TRUE, Boolean.TRUE, null, null, 0, -1);
assertEquals(2, weblogs1.size());
weblog = (Weblog) weblogs1.get(0);
assertNotNull(weblog);
// testing paging
List weblogs11 = mgr.getWebsites(TestUtils.getManagedUser(testUser), Boolean.TRUE, Boolean.TRUE, null, null, 0, 1);
assertEquals(1, weblogs11.size());
List weblogs12 = mgr.getWebsites(TestUtils.getManagedUser(testUser), Boolean.TRUE, Boolean.TRUE, null, null, 1, 1);
assertEquals(1, weblogs12.size());
// make sure disabled weblogs are not returned
weblog.setEnabled(Boolean.FALSE);
mgr.saveWebsite(weblog);
TestUtils.endSession(true);
List weblogs2 = mgr.getWebsites(TestUtils.getManagedUser(testUser), Boolean.TRUE, Boolean.TRUE, null, null, 0, -1);
assertEquals(1, weblogs2.size());
weblog = (Weblog) 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(TestUtils.getManagedUser(testUser), Boolean.TRUE, Boolean.TRUE, null, null, 0, -1);
assertEquals(0, weblogs3.size());
} catch(Throwable t) {
log.error("Exception running test", t);
throw (Exception) t;