@Test
  public void testFindWithin1() throws Exception {
    ODocument parent1 =
        new ODocument("Node")
            .field("title", "ref1")
            .field("titleasc", "ref1")
            .field("description", "desc")
            .field("descriptionMarkup", "default")
            .field("created", 1L)
            .field("modified", 2L);
    parent1.save();
    ODocument parent2 =
        new ODocument("Node")
            .field("title", "ref2")
            .field("titleasc", "ref2")
            .field("description", "desc")
            .field("descriptionMarkup", "default")
            .field("created", 1L)
            .field("modified", 2L);
    parent2.save();

    String id1 = parent1.getIdentity().toString();
    String id2 = parent2.getIdentity().toString();

    IPeriod period1 = new Period();
    period1.setFromEntry("1.1585");
    period1.setToEntry("2.1585");
    period1.setCreated(1L);
    period1.setModified(2L);
    period1.setParentId(id1);
    repository.save(period1);

    IPeriod period2 = new Period();
    period2.setFromEntry("1929");
    period2.setToEntry("1930");
    period2.setCreated(1L);
    period2.setModified(2L);
    period2.setParentId(id1);
    repository.save(period2);

    IPeriod period3 = new Period();
    period3.setFromEntry("1.1.1700");
    period3.setToEntry("5.6.1702");
    period3.setCreated(1L);
    period3.setModified(2L);
    period3.setParentId(id2);
    repository.save(period3);

    IPeriod period4 = new Period();
    period4.setFromEntry(null);
    period4.setToEntry("1596");
    period4.setCreated(1L);
    period4.setModified(2L);
    period4.setParentId(id1);
    repository.save(period4);

    IPeriod period5 = new Period();
    period5.setFromEntry("5.1.901");
    period5.setToEntry(null);
    period5.setCreated(1L);
    period5.setModified(2L);
    period5.setParentId(id1);
    repository.save(period5);

    IPeriod period6 = new Period();
    period6.setFromEntry("19.6.1601");
    period6.setToEntry("19.6.1601");
    period6.setCreated(1L);
    period6.setModified(2L);
    period6.setParentId(id2);
    repository.save(period6);

    // 1-1-1585 to 18-6-1601
    DateTime start =
        new DateTime().withYear(1585).withMonthOfYear(1).withDayOfMonth(1).withTime(0, 0, 0, 0);
    DateTime end =
        new DateTime().withYear(1601).withMonthOfYear(6).withDayOfMonth(18).withTime(0, 0, 0, 0);

    List<IPeriod> periods;

    periods = repository.findWithin(start, end);
    assertEquals(3, periods.size());
    assertEquals(null, periods.get(0).getFromEntry());
    assertEquals("1596", periods.get(0).getToEntry());
    assertEquals("5.1.901", periods.get(1).getFromEntry());
    assertEquals(null, periods.get(1).getToEntry());
    assertEquals("1.1585", periods.get(2).getFromEntry());
    assertEquals("2.1585", periods.get(2).getToEntry());
  }
  @Test
  public void testFindWithin() throws Exception {
    ODocument parent1 =
        new ODocument("Node")
            .field("title", "ref1")
            .field("titleasc", "ref1")
            .field("titleasc", "ref1")
            .field("description", "desc")
            .field("descriptionMarkup", "default")
            .field("created", 1L)
            .field("modified", 2L);
    parent1.save();
    ODocument parent2 =
        new ODocument("Node")
            .field("title", "ref2")
            .field("titleasc", "ref2")
            .field("titleasc", "ref2")
            .field("description", "desc")
            .field("descriptionMarkup", "default")
            .field("created", 1L)
            .field("modified", 2L);
    parent2.save();

    String id1 = parent1.getIdentity().toString();
    String id2 = parent2.getIdentity().toString();

    IPeriod period1 = new Period();
    period1.setFromEntry("1.1585");
    period1.setToEntry("2.1585");
    period1.setCreated(1L);
    period1.setModified(2L);
    period1.setParentId(id1);
    repository.save(period1);

    IPeriod period2 = new Period();
    period2.setFromEntry("1929");
    period2.setToEntry("1930");
    period2.setCreated(1L);
    period2.setModified(2L);
    period2.setParentId(id1);
    repository.save(period2);

    IPeriod period3 = new Period();
    period3.setFromEntry("1.1.1700");
    period3.setToEntry("5.6.1702");
    period3.setCreated(1L);
    period3.setModified(2L);
    period3.setParentId(id2);
    repository.save(period3);

    IPeriod period4 = new Period();
    period4.setFromEntry(null);
    period4.setToEntry("1596");
    period4.setCreated(1L);
    period4.setModified(2L);
    period4.setParentId(id1);
    repository.save(period4);

    IPeriod period5 = new Period();
    period5.setFromEntry("5.1.901");
    period5.setToEntry(null);
    period5.setCreated(1L);
    period5.setModified(2L);
    period5.setParentId(id1);
    repository.save(period5);

    IPeriod period6 = new Period();
    period6.setFromEntry("19.6.1601");
    period6.setToEntry("19.6.1601");
    period6.setCreated(1L);
    period6.setModified(2L);
    period6.setParentId(id2);
    repository.save(period6);

    List<IPeriod> periods;

    // first, the simple cases:
    // all entries up to 18-6-1601
    periods = repository.findWithin(null, 2305982L);
    assertEquals(3, periods.size());
    assertEquals(null, periods.get(0).getFromEntry());
    assertEquals("1596", periods.get(0).getToEntry());
    assertEquals("5.1.901", periods.get(1).getFromEntry());
    assertEquals(null, periods.get(1).getToEntry());
    assertEquals("1.1585", periods.get(2).getFromEntry());
    assertEquals("2.1585", periods.get(2).getToEntry());

    // all entries on and after 1-1-1585
    periods = repository.findWithin(2299970L, null);
    assertEquals(5, periods.size());
    assertEquals(null, periods.get(0).getFromEntry());
    assertEquals("1596", periods.get(0).getToEntry());
    assertEquals("1.1585", periods.get(1).getFromEntry());
    assertEquals("2.1585", periods.get(1).getToEntry());
    assertEquals("19.6.1601", periods.get(2).getFromEntry());
    assertEquals("19.6.1601", periods.get(2).getToEntry());
    assertEquals("1.1.1700", periods.get(3).getFromEntry());
    assertEquals("5.6.1702", periods.get(3).getToEntry());
    assertEquals("1929", periods.get(4).getFromEntry());
    assertEquals("1930", periods.get(4).getToEntry());

    // 1-1-1585 to 18-6-1601
    periods = repository.findWithin(2299970L, 2305982L);
    assertEquals(3, periods.size());
    assertEquals(null, periods.get(0).getFromEntry());
    assertEquals("1596", periods.get(0).getToEntry());
    assertEquals("5.1.901", periods.get(1).getFromEntry());
    assertEquals(null, periods.get(1).getToEntry());
    assertEquals("1.1585", periods.get(2).getFromEntry());
    assertEquals("2.1585", periods.get(2).getToEntry());
  }