PageRenderTime 24ms CodeModel.GetById 12ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 0ms

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

http://thoughtsite.googlecode.com/
Java | 76 lines | 51 code | 19 blank | 6 comment | 2 complexity | 1321daa0a9df1f542176d003cffdb229 MD5 | raw file
 1package com.google.ie.business.dao.impl;
 2
 3import static org.junit.Assert.assertEquals;
 4import static org.junit.Assert.assertNotNull;
 5
 6import com.google.ie.business.domain.EntityIndex;
 7import com.google.ie.business.domain.Idea;
 8import com.google.ie.test.DatastoreTest;
 9
10import org.junit.Before;
11import org.junit.Test;
12
13/**
14 * Test cases for EntityIndexDaoImpl class
15 * 
16 * @author Ashish K. Dahiya
17 */
18public class EntityIndexDaoImplTest extends DatastoreTest {
19
20    private IdeaDaoImpl ideaDao;
21    private EntityIndexDaoImpl entityIndexDao;
22
23    @Before
24    public void setUp() {
25        super.setUp();
26        if (ideaDao == null) {
27            ideaDao = new IdeaDaoImpl();
28            ideaDao.setPersistenceManagerFactory(pmf);
29            entityIndexDao = new EntityIndexDaoImpl();
30            entityIndexDao.setPersistenceManagerFactory(pmf);
31        }
32    }
33
34    @Test
35    // @Transactional
36    public void getUnIndexedIdea() {
37        Idea idea = new Idea();
38        idea.setTitle("Title");
39        ideaDao.saveIdea(idea);
40
41        entityIndexDao.createEntityIndex(idea.getKey());
42
43        EntityIndex entityIndex = entityIndexDao.getUnIndexedEntity();
44
45        assertNotNull(entityIndex);
46    }
47
48    @Test
49    public void updateIdeaIndex() {
50        Idea idea = new Idea();
51        idea.setTitle("Title");
52        ideaDao.saveIdea(idea);
53
54        entityIndexDao.createEntityIndex(idea.getKey());
55
56        EntityIndex entityIndex = entityIndexDao.getUnIndexedEntity();
57        entityIndex.setIndexed(1);
58
59        EntityIndex entityIndex2 = entityIndexDao.updateEntityIndex(entityIndex);
60
61        assertEquals(1, entityIndex2.getIndexed());
62    }
63
64    @SuppressWarnings("cast")
65    @Test
66    public void getEntity() {
67        Idea idea = new Idea();
68        idea.setTitle("Title");
69        idea = ideaDao.saveIdea(idea);
70
71        Idea idea2 = (Idea) entityIndexDao.findEntityByPrimaryKey(Idea.class, idea.getKey());
72
73        assertEquals(idea.getKey(), idea2.getKey());
74    }
75
76}