@Test
public void testAddFollower()
{
DomainGroup group = jpaGroupMapper.findByShortName("group1");
Person fordp2 = jpaPersonMapper.findByAccountId("fordp2");
Person csagan = jpaPersonMapper.findByAccountId("csagan");
// Verify initial state
assertFalse(jpaGroupMapper.isFollowing("fordp2", "group1"));
assertFalse(jpaGroupMapper.isFollowing("csagan", "group1"));
assertEquals(0, fordp2.getFollowingCount());
assertEquals(0, fordp2.getGroupCount());
assertEquals(0, csagan.getFollowingCount());
assertEquals(1, csagan.getGroupCount());
// ford wants to follow the group
jpaGroupMapper.addFollower(fordp2.getId(), group.getId());
getEntityManager().clear();
fordp2 = jpaPersonMapper.findByAccountId("fordp2");
csagan = jpaPersonMapper.findByAccountId("csagan");
// verify new state
assertTrue(jpaGroupMapper.isFollowing("fordp2", "group1"));
// Test case insensitivity (everything should be lower cased by the mapper).
assertTrue(jpaGroupMapper.isFollowing("fordp2", "Group1"));
assertFalse(jpaGroupMapper.isFollowing("csagan", "group1"));
assertEquals(0, fordp2.getFollowingCount());
assertEquals(1, fordp2.getGroupCount());
assertEquals(0, csagan.getFollowingCount());
assertEquals(1, csagan.getGroupCount());
// csagan wants to follow the group
jpaGroupMapper.addFollower(csagan.getId(), group.getId());
getEntityManager().clear();
fordp2 = jpaPersonMapper.findByAccountId("fordp2");
csagan = jpaPersonMapper.findByAccountId("csagan");
// verify new state
assertTrue(jpaGroupMapper.isFollowing("fordp2", "group1"));
assertTrue(jpaGroupMapper.isFollowing("csagan", "group1"));
// and verify csagan's counts after the change
assertEquals(0, csagan.getFollowingCount());
assertEquals(2, csagan.getGroupCount());
}