/src/test/java/com/google/ie/business/dao/impl/CommentDaoImplTest.java

http://thoughtsite.googlecode.com/ · Java · 74 lines · 55 code · 9 blank · 10 comment · 0 complexity · 2210e3fe18bcae4107899d52257b460f MD5 · raw file

  1. // Copyright 2009 Google Inc. All Rights Reserved.
  2. /**
  3. *
  4. */
  5. package com.google.ie.business.dao.impl;
  6. import com.google.ie.business.domain.Idea;
  7. import com.google.ie.business.domain.IdeaComment;
  8. import com.google.ie.business.domain.ProjectComment;
  9. import com.google.ie.dto.RetrievalInfo;
  10. import com.google.ie.test.DatastoreTest;
  11. import org.junit.Before;
  12. import org.junit.Test;
  13. import junit.framework.Assert;
  14. /**
  15. * Test cases for CommentDaoImpl class
  16. *
  17. * @author Charanjeet singh
  18. *
  19. */
  20. public class CommentDaoImplTest extends DatastoreTest {
  21. private CommentDaoImpl commentDao = new CommentDaoImpl();
  22. private IdeaDaoImpl ideaDao = new IdeaDaoImpl();
  23. @Before
  24. public void setUp() {
  25. super.setUp();
  26. commentDao.setPersistenceManagerFactory(pmf);
  27. ideaDao.setPersistenceManagerFactory(pmf);
  28. }
  29. @Test
  30. public void saveComment() {
  31. IdeaComment comment = new IdeaComment();
  32. comment.setText("Test_Comment");
  33. Assert.assertNotNull(commentDao.saveComment(comment));
  34. Assert.assertEquals("Test_Comment", commentDao.saveComment(comment).getText());
  35. }
  36. @Test
  37. public void getIdeaComments() {
  38. Idea idea = new Idea();
  39. idea.setTitle("Test Idea");
  40. idea = ideaDao.saveIdea(idea);
  41. IdeaComment comment = new IdeaComment();
  42. comment.setIdeaKey(idea.getKey());
  43. comment.setText("Test_Comment");
  44. comment.setStatus(IdeaComment.STATUS_SAVED);
  45. comment = (IdeaComment) commentDao.saveComment(comment);
  46. RetrievalInfo retrievalParam = createDummyRetrievalParam(0, 1,
  47. "createdOn", DaoConstants.ORDERING_DESCENDING);
  48. Assert.assertNotNull(commentDao.getComments(comment.getIdeaKey(),
  49. retrievalParam, "ideaKey"));
  50. Assert.assertEquals("Test_Comment", commentDao.getComments(comment.getIdeaKey(),
  51. retrievalParam, "ideaKey").get(0).getText());
  52. }
  53. @Test
  54. public void getProjectComments() {
  55. ProjectComment comment = new ProjectComment();
  56. comment.setProjectKey("newProjectKey");
  57. comment.setText("Test_Comment");
  58. comment.setStatus(IdeaComment.STATUS_SAVED);
  59. commentDao.saveComment(comment);
  60. RetrievalInfo retrievalParam = createDummyRetrievalParam(0, 1,
  61. "createdOn", DaoConstants.ORDERING_DESCENDING);
  62. Assert.assertEquals("Test_Comment", commentDao.getComments("newProjectKey",
  63. retrievalParam, "projectKey").get(0).getText());
  64. }
  65. }