/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

  1. package com.google.ie.business.dao.impl;
  2. import static org.junit.Assert.assertEquals;
  3. import static org.junit.Assert.assertNotNull;
  4. import com.google.ie.business.domain.EntityIndex;
  5. import com.google.ie.business.domain.Idea;
  6. import com.google.ie.test.DatastoreTest;
  7. import org.junit.Before;
  8. import org.junit.Test;
  9. /**
  10. * Test cases for EntityIndexDaoImpl class
  11. *
  12. * @author Ashish K. Dahiya
  13. */
  14. public class EntityIndexDaoImplTest extends DatastoreTest {
  15. private IdeaDaoImpl ideaDao;
  16. private EntityIndexDaoImpl entityIndexDao;
  17. @Before
  18. public void setUp() {
  19. super.setUp();
  20. if (ideaDao == null) {
  21. ideaDao = new IdeaDaoImpl();
  22. ideaDao.setPersistenceManagerFactory(pmf);
  23. entityIndexDao = new EntityIndexDaoImpl();
  24. entityIndexDao.setPersistenceManagerFactory(pmf);
  25. }
  26. }
  27. @Test
  28. // @Transactional
  29. public void getUnIndexedIdea() {
  30. Idea idea = new Idea();
  31. idea.setTitle("Title");
  32. ideaDao.saveIdea(idea);
  33. entityIndexDao.createEntityIndex(idea.getKey());
  34. EntityIndex entityIndex = entityIndexDao.getUnIndexedEntity();
  35. assertNotNull(entityIndex);
  36. }
  37. @Test
  38. public void updateIdeaIndex() {
  39. Idea idea = new Idea();
  40. idea.setTitle("Title");
  41. ideaDao.saveIdea(idea);
  42. entityIndexDao.createEntityIndex(idea.getKey());
  43. EntityIndex entityIndex = entityIndexDao.getUnIndexedEntity();
  44. entityIndex.setIndexed(1);
  45. EntityIndex entityIndex2 = entityIndexDao.updateEntityIndex(entityIndex);
  46. assertEquals(1, entityIndex2.getIndexed());
  47. }
  48. @SuppressWarnings("cast")
  49. @Test
  50. public void getEntity() {
  51. Idea idea = new Idea();
  52. idea.setTitle("Title");
  53. idea = ideaDao.saveIdea(idea);
  54. Idea idea2 = (Idea) entityIndexDao.findEntityByPrimaryKey(Idea.class, idea.getKey());
  55. assertEquals(idea.getKey(), idea2.getKey());
  56. }
  57. }