PageRenderTime 434ms CodeModel.GetById 211ms app.highlight 4ms RepoModel.GetById 217ms app.codeStats 0ms

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

http://thoughtsite.googlecode.com/
Java | 65 lines | 45 code | 15 blank | 5 comment | 2 complexity | 4cc55da396482b0213e8d420176390c6 MD5 | raw file
 1package com.google.ie.business.dao.impl;
 2
 3import static org.junit.Assert.assertEquals;
 4
 5import com.google.appengine.api.datastore.DatastoreServiceFactory;
 6import com.google.appengine.api.datastore.Query;
 7import com.google.ie.business.domain.IdeaVote;
 8import com.google.ie.test.DatastoreTest;
 9
10import org.junit.Before;
11import org.junit.Test;
12
13/**
14 * Test case for VoteDaoImpl class.
15 * 
16 * @author gmaurya
17 */
18public class VoteDaoImplTest extends DatastoreTest {
19
20    private VoteDaoImpl voteDao;
21
22    @Before
23    public void setUp() {
24        super.setUp();
25        if (voteDao == null) {
26            voteDao = new VoteDaoImpl();
27            voteDao.setPersistenceManagerFactory(pmf);
28        }
29    }
30
31    @Test
32    public void addVote() {
33
34        IdeaVote vote = new IdeaVote();
35        vote.setCreatorKey("creatorKey");
36        vote.setIdeaKey("ideaKey");
37        vote.setVotePoints(15);
38        vote.setPositiveVote(true);
39
40        voteDao.saveVote(vote);
41        Query query = new Query(IdeaVote.class.getSimpleName());
42        assertEquals(1, DatastoreServiceFactory.getDatastoreService().prepare(query)
43                        .countEntities());
44
45    }
46
47    @Test
48    public void isIdeaAlreadyVotedByUser() {
49
50        IdeaVote vote = new IdeaVote();
51        vote.setCreatorKey("userKey");
52        vote.setIdeaKey("ideaKey");
53        vote.setVotePoints(15);
54        vote.setPositiveVote(true);
55        voteDao.saveVote(vote);
56
57        assertEquals(true, voteDao.isIdeaAlreadyVotedByUser("userKey", "ideaKey"));
58    }
59
60    @Test
61    public void ideaNotVotedByUser() {
62
63        assertEquals(false, voteDao.isIdeaAlreadyVotedByUser("userKey", "ideaKey"));
64    }
65}