@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()); } }
@After public void teardown() throws Exception { try (DbContext context = contextProvider.getDbContext()) { CommunityDAO communityDAO = context.getCommunityDAO(); for (Community c : toDelete) { communityDAO.remove(c.getCommunityId()); } PersonDAO personDao = context.getPersonDAO(); personDao.remove(plainPerson.getPersonId()); personDao.remove(adminPerson.getPersonId()); personDao.remove(inActivePerson.getPersonId()); context.commit(); } }
@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(); } }