assertEquals(3, activityDTO.getCommentCount());
assertEquals(5L, activityDTO.getFirstComment().getId());
assertEquals(7, activityDTO.getLastComment().getId());
// Create the insertRequest and insert the comment via sut.
InsertActivityCommentRequest insertRequest = new InsertActivityCommentRequest(smithersId, activityId, is1000);
CommentDTO result = sut.execute(insertRequest);
// Grab entity id for later use
long newCommentId = result.getId();
// flush and clear entityManager before query the DB.
getEntityManager().flush();
getEntityManager().clear();
// Query comment from DB to assert that record was inserted in.
Comment comment = (Comment) getEntityManager().createQuery("FROM Comment where id = :commentId").setParameter(
"commentId", newCommentId).getSingleResult();
// verify correct values were inserted into DB.
assertNotNull(comment);
assertEquals(smithersId, comment.getAuthor().getId());
assertEquals(activityId, comment.getTarget().getId());
assertEquals(is1000, comment.getBody());
// Get the activity DTO and assert is was updated correctly by sut.
activityDTO = activityMapper.execute(activityIds).get(0);
assertEquals(activityId, activityDTO.getId());
assertEquals(4, activityDTO.getCommentCount());
assertEquals(5L, activityDTO.getFirstComment().getId());
assertEquals(newCommentId, activityDTO.getLastComment().getId());
// Insert another comment to make sure first/last comment works.
insertRequest.setContent("another comment");
result = sut.execute(insertRequest);
// Get the activity DTO and assert is was updated correctly.
activityDTO = activityMapper.execute(activityIds).get(0);
assertEquals(5L, activityDTO.getFirstComment().getId());