public void testGetAllStories() throws Exception {
    List<Story> stories = new ArrayList<Story>();
    for (int i = 0; i < 5; i++) {
      Story story = createStory(i);
      stories.add(story);
      boolean result = es.publishStory(story, null);
      assertTrue(es.getErrorMessage(), result);
    }

    // Give elasticsearch some time, its a bit slow. In the head.
    Thread.sleep(4000);

    List<Story> result = es.getStories(0, 10);

    for (Story s : stories) {
      es.deleteStory(s.getId());
    }

    for (Story s : stories) {
      assertTrue("Story missing from results", result.contains(s));
    }

    for (Story s : result) {
      assertEquals(s.getId(), s.getThumbnail().getId());
      assertNotNull(s.getThumbnail().getEncodedBitmap());
    }
  }
  public void testGetStoryFragments() throws Exception {
    Story story = createStory(0);
    List<StoryFragment> fragments = new ArrayList<StoryFragment>();
    fragments.add(createFragment(story.getId(), 0));
    story.setHeadFragmentId(fragments.get(0));

    for (int i = 1; i < 5; i++) {
      fragments.add(createFragment(story.getId(), i));
      story.addFragment(fragments.get(i));
    }

    boolean result = es.publishStory(story, fragments);
    assertTrue(es.getErrorMessage(), result);

    // Elasticsearch must deeply reflect on itself every time you post to it.
    // You know, evaluate what it means to be a web server. If it is okay
    // with us just pushing random objects into it. Maybe it feels violated?
    Thread.sleep(4000);

    Story story2 = es.getStory(story.getId());
    List<StoryFragment> fragments2 = es.getFragmentsForStory(story.getId(), 0, 10);

    try {
      es.deleteStory(story.getId());
    } catch (Exception e) {
    }

    for (StoryFragment f : fragments) {
      deleteFragment(f);
    }

    assertEquals(es.getErrorMessage(), story, story2);
    assertNotNull(es.getErrorMessage(), fragments2);

    for (int i = 0; i < fragments.size(); i++) {
      assertEquals(
          "Image missing",
          fragments.get(i).getMedia(0).getEncodedBitmap(),
          fragments2.get(i).getMedia(0).getEncodedBitmap());
    }
  }
  public void testQueryStories() throws Exception {
    List<Story> stories = new ArrayList<Story>();
    for (int i = 0; i < 5; i++) {
      Story story = createStory(i);
      stories.add(story);
    }

    stories.get(0).setAuthor("Andrew Fontaine");
    stories.get(1).setTitle("Thanks Andrew");
    stories.get(2).setSynopsis("How Andrew ruined civ.");

    for (Story s : stories) {
      boolean result = es.publishStory(s, null);
      assertTrue(es.getErrorMessage(), result);
    }

    // Give elasticsearch some time, it is having a mid life crisis
    // about if it wants to be a server anymore.
    Thread.sleep(4000);

    String filter = "Andrew Fontaine";
    List<Story> result = es.queryStories(filter, 0, 10);

    for (Story s : stories) {
      try {
        es.deleteStory(s.getId());
      } catch (Exception e) {
        // keep on trucking
      }
    }

    assertTrue(result.size() >= 3);
    assertTrue("Story missing from results", result.contains(stories.get(0)));
    assertTrue("Story missing from results", result.contains(stories.get(1)));
    assertTrue("Story missing from results", result.contains(stories.get(2)));

    for (Story s : result) {
      assertEquals(s.getId(), s.getThumbnail().getId());
      assertNotNull(s.getThumbnail().getEncodedBitmap());
    }
  }