Search in sources :

Example 1 with BaseCriteria

use of com.manydesigns.elements.fields.search.BaseCriteria in project Portofino by ManyDesigns.

the class DateSearchFieldTest method testRange.

public void testRange() {
    setupFields();
    MutableHttpServletRequest request = new MutableHttpServletRequest();
    String minDate = "1999-01-01";
    String maxDate = "1999-02-01";
    request.setParameter("date_min", minDate);
    request.setParameter("date_max", maxDate);
    dateField.readFromRequest(request);
    assertTrue(dateField.validate());
    date = (Date) dateField.getMinValue();
    DateTime dateTime = DateTimeFormat.forPattern("yyyy-MM-dd").parseDateTime(minDate);
    assertEquals(new DateTime(date.getTime()), dateTime);
    assertEquals(minDate, dateField.getMinStringValue());
    date = (Date) dateField.getMaxValue();
    dateTime = DateTimeFormat.forPattern("yyyy-MM-dd").parseDateTime(maxDate);
    assertEquals(new DateTime(date.getTime()), dateTime);
    assertEquals(maxDate, dateField.getMaxStringValue());
    BaseCriteria criteria = new BaseCriteria();
    dateField.configureCriteria(criteria);
    assertEquals(dateField.getMinValue(), ((BaseCriteria.BetweenCriterion) criteria.get(0)).getMin());
    assertEquals(dateField.getMaxValue(), ((BaseCriteria.BetweenCriterion) criteria.get(0)).getMax());
    // Invers
    request.setParameter("date_min", maxDate);
    request.setParameter("date_max", minDate);
    dateField.readFromRequest(request);
    assertTrue(dateField.validate());
    date = (Date) dateField.getMinValue();
    dateTime = DateTimeFormat.forPattern("yyyy-MM-dd").parseDateTime(minDate);
    assertEquals(new DateTime(date.getTime()), dateTime);
    assertEquals(maxDate, dateField.getMinStringValue());
    date = (Date) dateField.getMaxValue();
    dateTime = DateTimeFormat.forPattern("yyyy-MM-dd").parseDateTime(maxDate);
    assertEquals(new DateTime(date.getTime()), dateTime);
    assertEquals(minDate, dateField.getMaxStringValue());
    criteria = new BaseCriteria();
    dateField.configureCriteria(criteria);
    assertEquals(dateField.getMinValue(), ((BaseCriteria.BetweenCriterion) criteria.get(0)).getMin());
    assertEquals(dateField.getMaxValue(), ((BaseCriteria.BetweenCriterion) criteria.get(0)).getMax());
}
Also used : BaseCriteria(com.manydesigns.elements.fields.search.BaseCriteria) MutableHttpServletRequest(com.manydesigns.elements.servlet.MutableHttpServletRequest) DateTime(org.joda.time.DateTime)

Aggregations

BaseCriteria (com.manydesigns.elements.fields.search.BaseCriteria)1 MutableHttpServletRequest (com.manydesigns.elements.servlet.MutableHttpServletRequest)1 DateTime (org.joda.time.DateTime)1