/** Tests the body. */ public void testBody() { comment.setBody(""); assertEquals("", comment.getBody()); // FIXME should be null comment.setBody(null); assertEquals("", comment.getBody()); // FIXME should be null comment.setBody("Here is some text"); assertEquals("Here is some text", comment.getBody()); }
public UserComment createEntryComment(String userId, long partId, UserComment newComment) { Entry entry = dao.get(partId); if (entry == null) return null; authorization.canRead(userId, entry); Account account = accountController.getByEmail(userId); Comment comment = new Comment(); comment.setAccount(account); comment.setEntry(entry); comment.setBody(newComment.getMessage()); comment.setCreationTime(new Date()); comment = commentDAO.create(comment); if (newComment.getSamples() != null) { SampleDAO sampleDAO = DAOFactory.getSampleDAO(); for (PartSample partSample : newComment.getSamples()) { Sample sample = sampleDAO.get(partSample.getId()); if (sample == null) continue; comment.getSamples().add(sample); sample.getComments().add(comment); } } comment = commentDAO.update(comment); return comment.toDataTransferObject(); }
public UserComment updateEntryComment( String userId, long partId, long commentId, UserComment userComment) { Entry entry = dao.get(partId); if (entry == null) return null; authorization.canRead(userId, entry); Comment comment = commentDAO.get(commentId); if (comment == null) return createEntryComment(userId, partId, userComment); if (comment.getEntry().getId() != partId) return null; if (userComment.getMessage() == null || userComment.getMessage().isEmpty()) return null; comment.setBody(userComment.getMessage()); comment.setModificationTime(new Date()); return commentDAO.update(comment).toDataTransferObject(); }
/** * Select all data. * * @return the list of Items */ public Map<String, Comment> selectAllCommentMap() { Map<String, Comment> map = new HashMap<String, Comment>(); Cursor cursor = this.db.rawQuery("SELECT * FROM " + TABLE_COMMENTS, null); if (cursor.moveToFirst()) { do { Comment c = new Comment(); c.setChatterId(cursor.getString(1)); c.setCommentId(cursor.getString(2)); c.setAuthor(cursor.getString(3)); c.setBody(cursor.getString(4)); map.put(c.getCommentId(), c); } while (cursor.moveToNext()); } if (cursor != null && !cursor.isClosed()) { cursor.close(); } return map; }
/** Tests for the truncated body. */ public void testTruncatedBody() { comment.setBody(null); assertEquals("", comment.getTruncatedBody()); comment.setBody("1234567890"); assertEquals("1234567890", comment.getTruncatedBody()); comment.setBody("Here is <b>some</b> <i>HTML</i>."); assertEquals("Here is some HTML.", comment.getTruncatedBody()); comment.setBody("Here is <some> text."); assertEquals("Here is some text.", comment.getTruncatedBody()); comment.setBody("1234567890123456789012345678901234567890123456789012345678901234567890"); assertEquals("12345678901234567890...", comment.getTruncatedBody()); comment.setBody("1234567890 123456789012345678901234567890123456789012345678901234567890"); assertEquals("1234567890 12345678901234567890...", comment.getTruncatedBody()); comment.setBody( "<p>" + "You can grab the source for Pebble 1.6 by doing the following:<pre> cvs -d:pserver:[email protected]:/cvsroot/pebble login \n" + " cvs -d:pserver:[email protected]:/cvsroot/pebble checkout -r v1_6_0 pebble</pre>\n" + "When prompted for a password, just press enter (there is no password).\n" + "</p>"); assertEquals( "You can grab the source for Pebble 1.6 by doing the following: cvs -d:pserver:anonymous...", comment.getTruncatedBody()); comment.setBody( "<p>" + "123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 " + "123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 " + "123456789 123456789 123456789 123456789 12345678Wünsche"); assertEquals( "123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 ...", comment.getTruncatedBody()); }