PageRenderTime 525ms CodeModel.GetById 382ms app.highlight 7ms RepoModel.GetById 134ms app.codeStats 0ms

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