/adapters/mongodb/src/test/java/org/atomhopper/mongodb/domain/PersistedEntryTest.java

https://github.com/rackerlabs/atom-hopper · Java · 92 lines · 75 code · 17 blank · 0 comment · 0 complexity · 31ae0992de6c9f83b21a0ed242669576 MD5 · raw file

  1. package org.atomhopper.mongodb.domain;
  2. import java.util.Calendar;
  3. import java.util.Date;
  4. import java.util.TimeZone;
  5. import java.util.UUID;
  6. import static junit.framework.Assert.*;
  7. import org.junit.Before;
  8. import org.junit.Test;
  9. import org.junit.experimental.runners.Enclosed;
  10. import org.junit.runner.RunWith;
  11. @RunWith(Enclosed.class)
  12. public class PersistedEntryTest {
  13. public static class WhenUsingPersistedEntries {
  14. private PersistedEntry persistedEntry;
  15. private PersistedCategory persistedCategory;
  16. private final String ID = UUID.randomUUID().toString();
  17. private final String ENTRY_BODY = "body";
  18. private final String FEED = "namespace/feed";
  19. private final String PERSISTED_CATEGORY_VALUE1 = "MyCategory1";
  20. private final String PERSISTED_CATEGORY_VALUE2 = "MyCategory2";
  21. @Before
  22. public void setUp() throws Exception {
  23. persistedEntry = new PersistedEntry();
  24. persistedCategory = new PersistedCategory(PERSISTED_CATEGORY_VALUE1);
  25. persistedEntry.setEntryId(ID);
  26. persistedEntry.setEntryBody(ENTRY_BODY);
  27. persistedEntry.setFeed(FEED);
  28. persistedEntry.addCategory(persistedCategory);
  29. }
  30. @Test
  31. public void shouldReturnCreationDate() throws Exception {
  32. assertNotNull(persistedEntry.getCreationDate());
  33. }
  34. @Test
  35. public void shouldReturnDateLastUpdated() throws Exception {
  36. assertNotNull(persistedEntry.getDateLastUpdated());
  37. }
  38. @Test
  39. public void shouldSetDateFields() throws Exception {
  40. final Calendar localNow = Calendar.getInstance(TimeZone.getDefault());
  41. localNow.setTimeInMillis(System.currentTimeMillis());
  42. Date dateToSet = localNow.getTime();
  43. persistedEntry.setCreationDate(dateToSet);
  44. assertEquals("The creation date should be able to be set and read back", dateToSet, persistedEntry.getCreationDate());
  45. persistedEntry.setDateLastUpdated(dateToSet);
  46. assertEquals("The date last updated should be able to be set and read back", dateToSet, persistedEntry.getDateLastUpdated());
  47. }
  48. @Test
  49. public void shouldReturnId() throws Exception {
  50. assertEquals("IDs should match", ID, persistedEntry.getEntryId());
  51. }
  52. @Test
  53. public void shouldReturnEntryBody() throws Exception {
  54. assertEquals("Entry body should match", ENTRY_BODY, persistedEntry.getEntryBody());
  55. }
  56. @Test
  57. public void shouldReturnFeed() throws Exception {
  58. assertEquals("Feed should match", FEED, persistedEntry.getFeed());
  59. }
  60. @Test
  61. public void shouldContainCategories() throws Exception {
  62. assertNotNull(persistedEntry.getCategories());
  63. }
  64. @Test
  65. public void shouldGetAndSetCategory() throws Exception {
  66. assertEquals("Category should match", PERSISTED_CATEGORY_VALUE1, persistedCategory.getValue());
  67. persistedCategory.setValue(PERSISTED_CATEGORY_VALUE2);
  68. assertEquals("Category should match", PERSISTED_CATEGORY_VALUE2, persistedCategory.getValue());
  69. }
  70. @Test
  71. public void shouldDisplayContentsViaToString() throws Exception {
  72. assertNotNull(persistedEntry.toString());
  73. }
  74. }
  75. }