@Test public void createConfirmed() throws Exception { toDelete.add(chatService.createChatCommunity(adminPerson.getUserName(), "confirmed", false)); try (DbContext context = contextProvider.getDbContext()) { context.clearCache(); Community c = context.getCommunityDAO().getByName("confirmed"); assertTrue(c.isConfirmed()); } }
@Test public void sanityPersonCommunity() throws Exception { toDelete.add(chatService.createChatCommunity(plainPerson.getUserName(), "sanityR", false)); try (DbContext context = contextProvider.getDbContext()) { context.clearCache(); Person person = context.getPersonDAO().getById(plainPerson.getPersonId()); assertEquals(1, person.getCreatedCommunities().size()); assertEquals("sanityR", person.getCreatedCommunities().get(0).getName()); } }
@Test public void createUnconfirmed() throws Exception { toDelete.add(chatService.createChatCommunity(plainPerson.getUserName(), "unconfirmed", false)); /* one would expect this to work, albeit it does not... curse jpa, curse curse curse * I guess it is ok, since the entities are detached anyway... * * assertEquals(1, plainPerson.getMemberships().size() ); */ try (DbContext context = contextProvider.getDbContext()) { context.clearCache(); Community c = context.getCommunityDAO().getByName("unconfirmed"); assertFalse(c.isConfirmed()); Person p = context.getPersonDAO().getById(plainPerson.getPersonId()); assertEquals(1, p.getMemberships().size()); assertEquals("unconfirmed", p.getMemberships().get(0).getCommunity().getName()); } }
@Before public void setup() throws Exception { contextProvider = new DbContextProviderImpl(); chatService = new ChatServiceImpl(); chatService.setDbContext(contextProvider); try (DbContext context = contextProvider.getDbContext()) { context.persist(plainPerson); adminPerson.setIsAdmin(true); context.persist(adminPerson); inActivePerson.setIsActive(false); context.persist(inActivePerson); context.commit(); } }
@Test(expected = EntityNotFoundException.class) public void unknownPerson() throws Exception { toDelete.add(chatService.createChatCommunity("gustl", "confirmed", false)); }
@Test(expected = IllegalStateException.class) public void inActivePerson() throws Exception { toDelete.add(chatService.createChatCommunity(inActivePerson.getUserName(), "confirmed", false)); }
@Test(expected = DuplicateEntityException.class) public void duplicate() throws Exception { toDelete.add(chatService.createChatCommunity(adminPerson.getUserName(), "confirmed", false)); toDelete.add(chatService.createChatCommunity(adminPerson.getUserName(), "confirmed", false)); }