use of org.apache.cxf.jaxrs.ext.search.SearchCondition in project cxf by apache.
the class FiqlParserTest method testParseInstantWithDefaultFormat.
@Test
public void testParseInstantWithDefaultFormat() throws SearchParseException, ParseException {
SearchCondition<Condition> filter = parser.parse("instant=le=2010-03-11");
DateFormat df = new SimpleDateFormat(SearchUtils.DEFAULT_DATE_FORMAT);
assertTrue(filter.isMet(new Condition("whatever", 15, null, df.parse("2010-03-11").toInstant())));
assertTrue(filter.isMet(new Condition(null, null, null, df.parse("2010-03-10").toInstant())));
assertFalse(filter.isMet(new Condition("blah", null, null, df.parse("2010-03-12").toInstant())));
assertFalse(filter.isMet(new Condition(null, 123, null, df.parse("2010-03-12").toInstant())));
}
use of org.apache.cxf.jaxrs.ext.search.SearchCondition in project cxf by apache.
the class FiqlParserTest method testParseZonedDateTimeWithDefaultFormat.
@Test
public void testParseZonedDateTimeWithDefaultFormat() throws SearchParseException, ParseException {
SearchCondition<Condition> filter = parser.parse("zonedDateTime=le=2010-03-11T18:00:00+01:00[Europe/Paris]");
DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssZ'['z']'");
assertTrue(filter.isMet(new Condition("whatever", 15, null, ZonedDateTime.parse("2010-03-11T18:00:00+0100[Europe/Paris]", df))));
assertTrue(filter.isMet(new Condition(null, null, null, ZonedDateTime.parse("2010-03-10T22:22:00+0100[Europe/Paris]", df))));
assertFalse(filter.isMet(new Condition("blah", null, null, ZonedDateTime.parse("2010-03-12T00:00:00+0100[Europe/Paris]", df))));
assertFalse(filter.isMet(new Condition(null, 123, null, ZonedDateTime.parse("2010-03-12T00:00:00+0100[Europe/Paris]", df))));
}
use of org.apache.cxf.jaxrs.ext.search.SearchCondition in project cxf by apache.
the class FiqlParserTest method testParseOffsetDateTimeWithCustomFormat.
@Test
public void testParseOffsetDateTimeWithCustomFormat() throws SearchParseException, ParseException {
Map<String, String> props = new HashMap<>();
props.put(SearchUtils.DATE_FORMAT_PROPERTY, "yyyy-MM-dd'T'HH:mm:ssZ");
props.put(SearchUtils.TIMEZONE_SUPPORT_PROPERTY, "true");
parser = new FiqlParser<>(Condition.class, props);
SearchCondition<Condition> filter = parser.parse("offsetDateTime=le=2010-03-11T18:00:00+01:00");
DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssZ");
assertTrue(filter.isMet(new Condition("whatever", 15, null, OffsetDateTime.parse("2010-03-11T18:00:00+0100", df))));
assertTrue(filter.isMet(new Condition(null, null, null, OffsetDateTime.parse("2010-03-10T22:22:00+0100", df))));
assertFalse(filter.isMet(new Condition("blah", null, null, OffsetDateTime.parse("2010-03-12T00:00:00+0100", df))));
assertFalse(filter.isMet(new Condition(null, 123, null, OffsetDateTime.parse("2010-03-12T00:00:00+0100", df))));
}
use of org.apache.cxf.jaxrs.ext.search.SearchCondition in project cxf by apache.
the class FiqlParserTest method testParseComplex1.
@Test
public void testParseComplex1() throws SearchParseException {
SearchCondition<Condition> filter = parser.parse("name==ami*;level=gt=10");
assertEquals(ConditionType.AND, filter.getConditionType());
List<SearchCondition<Condition>> conditions = filter.getSearchConditions();
assertEquals(2, conditions.size());
PrimitiveStatement st1 = conditions.get(0).getStatement();
PrimitiveStatement st2 = conditions.get(1).getStatement();
assertTrue((ConditionType.EQUALS.equals(st1.getCondition()) && ConditionType.GREATER_THAN.equals(st2.getCondition())) || (ConditionType.EQUALS.equals(st2.getCondition()) && ConditionType.GREATER_THAN.equals(st1.getCondition())));
assertTrue(filter.isMet(new Condition("amichalec", 12, new Date())));
assertTrue(filter.isMet(new Condition("ami", 12, new Date())));
assertFalse(filter.isMet(new Condition("ami", 8, null)));
assertFalse(filter.isMet(new Condition("am", 20, null)));
}
use of org.apache.cxf.jaxrs.ext.search.SearchCondition in project cxf by apache.
the class FiqlParserTest method testParseDateDuration.
@Test
public void testParseDateDuration() throws Exception {
SearchCondition<Condition> filter = parser.parse("time=gt=-PT1M");
Date now = new Date();
Date tenMinutesAgo = new Date();
DatatypeFactory.newInstance().newDuration("-PT10M").addTo(tenMinutesAgo);
assertTrue(filter.isMet(new Condition(null, null, now)));
assertFalse(filter.isMet(new Condition(null, null, tenMinutesAgo)));
}
Aggregations