/** Test add follower. */ @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()); }
/** * Test get followers. Dataset.xml has one follower for the group, so we should start with 1 and * then see 3. */ @Test public void testGetFollowers() { final int maxFollowers = 10; DomainGroup group = jpaGroupMapper.findByShortName("group1"); Person fordp2 = jpaPersonMapper.findByAccountId("fordp2"); Person csagan = jpaPersonMapper.findByAccountId("csagan"); PagedSet<Person> followers = jpaGroupMapper.getFollowers("group1", 0, maxFollowers); assertEquals(3, followers.getTotal()); jpaGroupMapper.addFollower(fordp2.getId(), group.getId()); jpaGroupMapper.addFollower(csagan.getId(), group.getId()); followers = jpaGroupMapper.getFollowers("group1", 0, maxFollowers); assertEquals(5, followers.getTotal()); }
/** Test addFollower when the person's already following the group. */ @Test public void testAddFollowerWhenAlreadyFollowing() { final long personId = 99L; final long groupId = 1L; Person p = jpaPersonMapper.findById(personId); DomainGroup g = jpaGroupMapper.findById(groupId); int initialGroupsCount = p.getGroupCount(); int initialFollowersCount = g.getFollowersCount(); // invoke SUT jpaGroupMapper.addFollower(p.getId(), g.getId()); // clear the entity manager, reload the entities, and assert the counts haven't changed getEntityManager().clear(); p = jpaPersonMapper.findById(personId); g = jpaGroupMapper.findById(groupId); assertEquals(initialGroupsCount, p.getGroupCount()); assertEquals(initialFollowersCount, g.getFollowersCount()); }