super.setUp();
this.init();
}
public void testAddGetComment() throws Throwable{
Comment comment = null;
try {
IContentManager contentManager = (IContentManager) this.getService(JacmsSystemConstants.CONTENT_MANAGER);
Content content = contentManager.loadContent("ART1", true);
if (content==null){
fail();
}
List<String> listaIds = this._commentManager.searchCommentIds(null);
assertEquals(0,listaIds.size());
comment = createNewComment();
comment.setContentId(content.getId());
this._commentManager.addComment(comment);
assertNotNull(comment.getId());
IComment commentRead = this._commentManager.getComment(comment.getId());
assertEquals(comment.getComment(), commentRead.getComment());
assertEquals(comment.getStatus(), commentRead.getStatus());
assertEquals(comment.getUsername(), commentRead.getUsername());
assertEquals(comment.getId(), commentRead.getId());
assertEquals(Comment.STATUS_TO_APPROVE, commentRead.getStatus());
CommentSearchBean searchBean = new CommentSearchBean();
searchBean.setComment("Testo ");
listaIds = this._commentManager.searchCommentIds(searchBean);
assertEquals(1, listaIds.size());
// Ricerca per data successiva a publicazione
searchBean = new CommentSearchBean();
searchBean.setComment("Testo ");
searchBean.setCreationFROMDate(new Date(System.currentTimeMillis()+24*60*60*1000));
searchBean.setStatus(0);
searchBean.setUsername("username");
listaIds = this._commentManager.searchCommentIds(searchBean);
assertEquals(0, listaIds.size());
// Ricerca elemento esatto con qualsiasi stato
searchBean = new CommentSearchBean();
searchBean.setComment("Testo ");
searchBean.setCreationFROMDate(new Date(System.currentTimeMillis()));
searchBean.setStatus(0);
searchBean.setUsername("username");
listaIds = this._commentManager.searchCommentIds(searchBean);
assertEquals(1, listaIds.size());
// Ricerca per commento errato
searchBean = new CommentSearchBean();
searchBean.setComment("ciccio");
listaIds = this._commentManager.searchCommentIds(searchBean);
assertEquals(0, listaIds.size());
// Ricerca per titolo errato
searchBean = new CommentSearchBean();
searchBean.setComment("ciccio");
searchBean.setStatus(Comment.STATUS_NOT_APPROVED);
listaIds = this._commentManager.searchCommentIds(searchBean);
assertEquals(0, listaIds.size());
// Ricerca per titolo errato
searchBean = new CommentSearchBean();
searchBean.setStatus(Comment.STATUS_TO_APPROVE);
listaIds = this._commentManager.searchCommentIds(searchBean);
assertEquals(1, listaIds.size());
} catch (Throwable t) {
t.printStackTrace();
throw t;
} finally {
if (comment != null ){
this._commentManager.deleteComment(comment.getId());
}
}
}