@Test @Transactional public void testAddContactToGroupAndGroupConstituent() throws Exception { groupService.create(group); groupService.addAggregation(committee, group); Contact contact = new Contact(); contact.setFirstName("Test Contact"); contact.setEmail("*****@*****.**"); contactService.create(contact); contactService.addContactToCommittee(contact, committee); contactService.addToGroup(contact, group); contact = contactService.findById(contact.getId()); assertTrue(contact.getGroups().contains(group)); assertTrue(contact.getCommittees().contains(committee)); committee = committeeService.findById(committee.getId()); assertTrue(committee.getMembers().contains(contact)); group = groupService.findById(group.getId()); assertTrue(group.getTopLevelMembers().contains(contact)); }
@Test public void testRemoveAggregation() throws Exception { String id = groupService.create(group); groupService.addAggregation(committee, group); Group fromDb = groupService.findById(id); assertEquals(1, fromDb.getAggregations().size()); assertEquals(1, fromDb.getAggregations().iterator().next().getGroups().size()); Aggregation aggregation = committeeService.findById(committee.getId()); assertEquals(1, aggregation.getGroups().size()); groupService.removeAggregation(committee, fromDb); fromDb = groupService.findById(id); assertEquals(0, fromDb.getAggregations().size()); aggregation = committeeService.findById(committee.getId()); assertEquals(0, aggregation.getGroups().size()); }
@Test @Transactional public void testAddContactToMultipleGroupsMultipleConstituents() throws Exception { groupService.create(group); groupService.addAggregation(committee, group); groupService.addAggregation(event, group); Group secondGroup = new Group(); secondGroup.setGroupName("Second Group"); groupService.create(secondGroup); groupService.addAggregation(committee, secondGroup); groupService.addAggregation(event, secondGroup); Contact contact = new Contact(); contact.setFirstName("Test Contact"); contact.setEmail("*****@*****.**"); contactService.create(contact); contactService.addContactToCommittee(contact, committee); contactService.attendEvent(contact, event); contactService.addToGroup(contact, group); contactService.addToGroup(contact, secondGroup); contact = contactService.findById(contact.getId()); group = groupService.findById(group.getId()); secondGroup = groupService.findById(secondGroup.getId()); event = eventService.findById(event.getId()); committee = committeeService.findById(committee.getId()); assertTrue(contact.getGroups().contains(group)); assertTrue(contact.getGroups().contains(secondGroup)); assertTrue(contact.getCommittees().contains(committee)); assertTrue(contact.getAttendedEvents().contains(event)); assertTrue(event.getAttendees().contains(contact)); assertTrue(event.getGroups().contains(group)); assertTrue(event.getGroups().contains(secondGroup)); assertTrue(committee.getMembers().contains(contact)); assertTrue(committee.getGroups().contains(group)); assertTrue(committee.getGroups().contains(secondGroup)); assertTrue(group.getTopLevelMembers().contains(contact)); assertTrue(group.getAggregations().contains(committee)); assertTrue(group.getAggregations().contains(event)); assertTrue(secondGroup.getTopLevelMembers().contains(contact)); assertTrue(secondGroup.getAggregations().contains(committee)); assertTrue(secondGroup.getAggregations().contains(event)); }
@Test public void testRemoveContactFromAggregation() throws Exception { groupService.create(group); groupService.addAggregation(committee, group); group = groupService.findById(group.getId()); assertEquals( committee.getMembers().size(), group.getAggregations().iterator().next().getAggregationMembers().size()); contactService.removeContactFromCommittee(first, committee); committee = committeeService.findById(committee.getId()); group = groupService.findById(group.getId()); assertEquals( committee.getMembers().size(), group.getAggregations().iterator().next().getAggregationMembers().size()); }
@Test public void testDeleteGroup() throws Exception { groupService.create(group); groupService.addAggregation(committee, group); group = groupService.findById(group.getId()); contactService.addToGroup(topLevel, group); groupService.delete(group); Group groupFromDb = groupService.findById(group.getId()); assertNull(groupFromDb); Aggregation fromDb = committeeService.findById(committee.getId()); assertNotNull(fromDb); assertEquals(0, fromDb.getGroups().size()); assertEquals(committee.getAggregationMembers().size(), fromDb.getAggregationMembers().size()); Contact topLevelFromDb = contactService.findById(topLevel.getId()); assertNotNull(topLevelFromDb); assertEquals(0, topLevelFromDb.getGroups().size()); }