@Test public void remove() throws Exception { try (DbContext dbContext = contextProvider.getDbContext()) { MessageRatingDAO messageRatingDAO = dbContext.getMessageRatingDAO(); PersonDAO personDAO = dbContext.getPersonDAO(); MessageDAO messageDAO = dbContext.getMessageDAO(); Person person = personDAO.getById(118); Message message = messageDAO.getById(2); MessageRating rating = dbContext.getMessageRatingDAO().findRatingByPersonAndMessage(message, person); message.removeMesasgeRating(rating); person.removeMesasgeRating(rating); messageRatingDAO.remove(rating); dbContext.commit(); } try (DbContext dbContext = contextProvider.getDbContext()) { MessageRatingDAO messageRatingDAO = dbContext.getMessageRatingDAO(); MessageDAO messageDAO = dbContext.getMessageDAO(); Message message = messageDAO.getById(2); List<Person> raters = messageRatingDAO.loadAllRatersByMessage(message); assertEquals(0, raters.size()); } }
@BeforeClass public static void setup() throws Exception { DbTestBase.prepare(); try (DbContext dbContext = contextProvider.getDbContext()) { MessageRatingDAO messageRatingDAO = dbContext.getMessageRatingDAO(); PersonDAO personDAO = dbContext.getPersonDAO(); MessageDAO messageDAO = dbContext.getMessageDAO(); Person person = personDAO.getById(118); Message message = messageDAO.getById(2); MessageRating rating = new MessageRating(new Date(), message, person); messageRatingDAO.insert(rating); person = personDAO.getById(114); message = messageDAO.getById(3); rating = new MessageRating(new Date(), message, person); messageRatingDAO.insert(rating); dbContext.commit(); } }
@Test public void loadAllRatersByMessage() throws Exception { try (DbContext dbContext = contextProvider.getDbContext()) { PersonDAO personDAO = dbContext.getPersonDAO(); MessageDAO messageDAO = dbContext.getMessageDAO(); MessageRatingDAO messageRatingDAO = dbContext.getMessageRatingDAO(); Person person = personDAO.getById(108); Message message = messageDAO.getById(1); List<Person> raters = messageRatingDAO.loadAllRatersByMessage(message); assertEquals(person, raters.get(0)); } }
@Test public void findRatingByPersonAndMessage() throws Exception { try (DbContext dbContext = contextProvider.getDbContext()) { PersonDAO personDAO = dbContext.getPersonDAO(); MessageDAO messageDAO = dbContext.getMessageDAO(); MessageRatingDAO messageRatingDAO = dbContext.getMessageRatingDAO(); Person person = personDAO.getById(108); Message message = messageDAO.getById(1); MessageRating rating = messageRatingDAO.findRatingByPersonAndMessage(message, person); assertEquals(message, rating.getMessage()); assertEquals(person, rating.getPerson()); } }
@Test public void insert() throws Exception { try (DbContext dbContext = contextProvider.getDbContext()) { MessageRatingDAO messageRatingDAO = dbContext.getMessageRatingDAO(); PersonDAO personDAO = dbContext.getPersonDAO(); MessageDAO messageDAO = dbContext.getMessageDAO(); Person person = personDAO.getById(104); Message message = messageDAO.getById(4); MessageRating rating = new MessageRating(new Date(), message, person); messageRatingDAO.insert(rating); List<Person> raters = messageRatingDAO.loadAllRatersByMessage(message); assertEquals(person, raters.get(0)); } }