コード例 #1
0
  @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());
    }
  }
コード例 #2
0
  @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();
    }
  }
コード例 #3
0
  @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));
    }
  }
コード例 #4
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());
    }
  }
コード例 #5
0
  @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));
    }
  }