コード例 #1
0
 public void testAddRatingToComment() throws Throwable {
   IRating rating = null;
   Comment comment = null;
   int COMMENT_ID = -1;
   try {
     comment = createNewComment();
     comment.setContentId(CONTENT_ID);
     this._commentManager.addComment(comment);
     List<String> listaCommenti = this._commentManager.searchCommentIds(null);
     assertEquals(1, listaCommenti.size());
     COMMENT_ID = Integer.parseInt(listaCommenti.get(0));
     this._retingManager.addRatingToComment(COMMENT_ID, 1);
     rating = this._retingManager.getCommentRating(COMMENT_ID);
     assertNotNull(rating);
     assertEquals(1, rating.getVoters());
     assertEquals(1, rating.getSumvote());
     // Inserimento di altri 3 voti:
     this._retingManager.addRatingToComment(COMMENT_ID, 1);
     this._retingManager.addRatingToComment(COMMENT_ID, 2);
     this._retingManager.addRatingToComment(COMMENT_ID, 4);
     rating = this._retingManager.getCommentRating(COMMENT_ID);
     assertNotNull(rating);
     assertEquals(4, rating.getVoters());
     assertEquals(8, rating.getSumvote());
   } catch (Throwable t) {
     t.printStackTrace();
     throw t;
   } finally {
     if (comment != null) {
       this._commentManager.deleteComment(comment.getId());
     }
   }
 }
コード例 #2
0
 public void testAddRatingToContent() throws Throwable {
   IRating rating = null;
   try {
     Content content = _contentManager.loadContent(CONTENT_ID, true);
     if (content == null) {
       fail();
     }
     this._retingManager.addRatingToContent(CONTENT_ID, 1);
     rating = this._retingManager.getContentRating(CONTENT_ID);
     assertNotNull(rating);
     assertEquals(1, rating.getVoters());
     assertEquals(1, rating.getSumvote());
     // Inserimento di altri 3 voti:
     this._retingManager.addRatingToContent(CONTENT_ID, 1);
     this._retingManager.addRatingToContent(CONTENT_ID, 2);
     this._retingManager.addRatingToContent(CONTENT_ID, 4);
     rating = this._retingManager.getContentRating(CONTENT_ID);
     assertNotNull(rating);
     assertEquals(4, rating.getVoters());
     assertEquals(8, rating.getSumvote());
   } catch (Throwable t) {
     throw t;
   } finally {
     if (rating != null) {
       ((RatingDAO) ((RatingManager) this._retingManager).getRatingDAO())
           .removeContentRating(rating.getContentId());
     }
   }
 }