expectedWeblogTags.put("one", new Integer(2));
expectedWeblogTags.put("two", new Integer(2));
expectedWeblogTags.put("three", new Integer(1));
for (Iterator it = tags.iterator(); it.hasNext();) {
TagStat stat = (TagStat) it.next();
if (!expectedWeblogTags.containsKey(stat.getName()))
fail("Unexpected tagName.");
Integer expectedCount = (Integer)expectedWeblogTags.get(stat.getName());
assertEquals(expectedCount.intValue(), stat.getCount());
}
// now add another entry in another blog
testWeblog2 = TestUtils.getManagedWebsite(testWeblog2);
testUser = TestUtils.getManagedUser(testUser);
entry = TestUtils.setupWeblogEntry("entry3",
testWeblog2.getDefaultCategory(), testWeblog2, testUser);
entry.addTag("one");
entry.addTag("three");
entry.addTag("four");
mgr.saveWeblogEntry(entry);
TestUtils.endSession(true);
// let's fetch "site" tags now
tags = mgr.getTags(null, null, null, -1);
assertEquals(4, tags.size());
HashMap expectedSiteTags = new HashMap();
expectedSiteTags.put("one", new Integer(3));
expectedSiteTags.put("two", new Integer(2));
expectedSiteTags.put("three", new Integer(2));
expectedSiteTags.put("four", new Integer(1));
for (Iterator it = tags.iterator(); it.hasNext();) {
TagStat stat = (TagStat) it.next();
if (!expectedSiteTags.containsKey(stat.getName()))
fail("Unexpected tagName.");
Integer expectedCount = (Integer) expectedSiteTags.get(stat.getName());
assertEquals(expectedCount.intValue(), stat.getCount());
}
TestUtils.endSession(true);
testWeblog = TestUtils.getManagedWebsite(testWeblog);
entry = mgr.getWeblogEntryByAnchor(testWeblog, "entry2");
List updateTags = new ArrayList();
updateTags.add("one");
updateTags.add("three");
updateTags.add("five");
entry.updateTags(updateTags);
mgr.saveWeblogEntry(entry);
TestUtils.endSession(true);
testWeblog = TestUtils.getManagedWebsite(testWeblog);
tags = mgr.getTags(testWeblog, null, null, -1);
assertEquals(4, tags.size());
expectedWeblogTags = new HashMap();
expectedWeblogTags.put("one", new Integer(2));
expectedWeblogTags.put("two", new Integer(1));
expectedWeblogTags.put("three", new Integer(1));
expectedWeblogTags.put("five", new Integer(1));
for (Iterator it = tags.iterator(); it.hasNext();) {
TagStat stat = (TagStat) it.next();
if (!expectedWeblogTags.containsKey(stat.getName()))
fail("Unexpected tagName.");
Integer expectedCount =
(Integer)expectedWeblogTags.get(stat.getName());
assertEquals(stat.getName(),
expectedCount.intValue(), stat.getCount());
}
tags = mgr.getTags(null, null, null, -1);
assertEquals(5, tags.size());
expectedSiteTags = new HashMap();
expectedSiteTags.put("one", new Integer(3));
expectedSiteTags.put("two", new Integer(1));
expectedSiteTags.put("three", new Integer(2));
expectedSiteTags.put("four", new Integer(1));
expectedSiteTags.put("five", new Integer(1));
for (Iterator it = tags.iterator(); it.hasNext();) {
TagStat stat = (TagStat) it.next();
if (!expectedSiteTags.containsKey(stat.getName()))
fail("Unexpected tagName.");
Integer expectedCount = (Integer)expectedSiteTags.get(stat.getName());
assertEquals(stat.getName(), expectedCount.intValue(), stat.getCount());
}
TestUtils.teardownWeblog(testWeblog2.getId());
TestUtils.endSession(true);