Search in sources :

Example 16 with SearchCondition

use of org.apache.cxf.jaxrs.ext.search.SearchCondition in project cxf by apache.

the class FiqlParserTest method testParseLocalDateTimeWithCustomFormat.

@Test
public void testParseLocalDateTimeWithCustomFormat() throws SearchParseException, ParseException {
    Map<String, String> props = new HashMap<>();
    props.put(SearchUtils.DATE_FORMAT_PROPERTY, "yyyy-MM-dd'T'HH:mm:ss");
    props.put(SearchUtils.TIMEZONE_SUPPORT_PROPERTY, "false");
    parser = new FiqlParser<>(Condition.class, props);
    SearchCondition<Condition> filter = parser.parse("localDateTime=le=2010-03-11T18:00:00");
    DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss");
    assertTrue(filter.isMet(new Condition("whatever", 15, null, LocalDateTime.parse("2010-03-11T18:00:00", df))));
    assertTrue(filter.isMet(new Condition(null, null, null, LocalDateTime.parse("2010-03-10T22:22:00", df))));
    assertFalse(filter.isMet(new Condition("blah", null, null, LocalDateTime.parse("2010-03-12T00:00:00", df))));
    assertFalse(filter.isMet(new Condition(null, 123, null, LocalDateTime.parse("2010-03-12T00:00:00", df))));
}
Also used : SearchCondition(org.apache.cxf.jaxrs.ext.search.SearchCondition) HashMap(java.util.HashMap) DateTimeFormatter(java.time.format.DateTimeFormatter) Test(org.junit.Test)

Example 17 with SearchCondition

use of org.apache.cxf.jaxrs.ext.search.SearchCondition in project cxf by apache.

the class FiqlParserTest method testParseDateWithCustomFormat.

@Test
public void testParseDateWithCustomFormat() throws SearchParseException, ParseException {
    Map<String, String> props = new HashMap<>();
    props.put(SearchUtils.DATE_FORMAT_PROPERTY, "yyyy-MM-dd'T'HH:mm:ss");
    props.put(SearchUtils.TIMEZONE_SUPPORT_PROPERTY, "false");
    parser = new FiqlParser<>(Condition.class, props);
    SearchCondition<Condition> filter = parser.parse("time=le=2010-03-11T18:00:00");
    DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
    assertTrue(filter.isMet(new Condition("whatever", 15, df.parse("2010-03-11T18:00:00"))));
    assertTrue(filter.isMet(new Condition(null, null, df.parse("2010-03-10T22:22:00"))));
    assertFalse(filter.isMet(new Condition("blah", null, df.parse("2010-03-12T00:00:00"))));
    assertFalse(filter.isMet(new Condition(null, 123, df.parse("2010-03-12T00:00:00"))));
}
Also used : SearchCondition(org.apache.cxf.jaxrs.ext.search.SearchCondition) HashMap(java.util.HashMap) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) SimpleDateFormat(java.text.SimpleDateFormat) Test(org.junit.Test)

Example 18 with SearchCondition

use of org.apache.cxf.jaxrs.ext.search.SearchCondition in project cxf by apache.

the class FiqlParserTest method testParseLevel.

@Test
public void testParseLevel() throws SearchParseException {
    SearchCondition<Condition> filter = parser.parse("level=gt=10");
    assertTrue(filter.isMet(new Condition("whatever", 15, new Date())));
    assertTrue(filter.isMet(new Condition(null, 15, null)));
    assertFalse(filter.isMet(new Condition("blah", 5, new Date())));
    assertFalse(filter.isMet(new Condition("foobar", 0, null)));
}
Also used : SearchCondition(org.apache.cxf.jaxrs.ext.search.SearchCondition) Date(java.util.Date) LocalDate(java.time.LocalDate) Test(org.junit.Test)

Example 19 with SearchCondition

use of org.apache.cxf.jaxrs.ext.search.SearchCondition in project cxf by apache.

the class FiqlParserTest method testParseComplex2.

@Test
public void testParseComplex2() throws SearchParseException {
    SearchCondition<Condition> filter = parser.parse("name==ami*,level=gt=10");
    assertEquals(ConditionType.OR, 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("ami", 0, new Date())));
    assertTrue(filter.isMet(new Condition("foo", 20, null)));
    assertFalse(filter.isMet(new Condition("foo", 0, null)));
}
Also used : SearchCondition(org.apache.cxf.jaxrs.ext.search.SearchCondition) SearchCondition(org.apache.cxf.jaxrs.ext.search.SearchCondition) PrimitiveStatement(org.apache.cxf.jaxrs.ext.search.PrimitiveStatement) Date(java.util.Date) LocalDate(java.time.LocalDate) Test(org.junit.Test)

Example 20 with SearchCondition

use of org.apache.cxf.jaxrs.ext.search.SearchCondition in project cxf by apache.

the class FiqlParserTest method testParseDateWithDefaultFormat.

@Test
public void testParseDateWithDefaultFormat() throws SearchParseException, ParseException {
    SearchCondition<Condition> filter = parser.parse("time=le=2010-03-11T18:00:00.000+00:00");
    DateFormat df = new SimpleDateFormat(SearchUtils.DEFAULT_DATE_FORMAT);
    assertTrue(filter.isMet(new Condition("whatever", 15, df.parse("2010-03-11T18:00:00.000+0000"))));
    assertTrue(filter.isMet(new Condition(null, null, df.parse("2010-03-10T22:22:00.000+0000"))));
    assertFalse(filter.isMet(new Condition("blah", null, df.parse("2010-03-12T00:00:00.000+0000"))));
    assertFalse(filter.isMet(new Condition(null, 123, df.parse("2010-03-12T00:00:00.000+0000"))));
}
Also used : SearchCondition(org.apache.cxf.jaxrs.ext.search.SearchCondition) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) SimpleDateFormat(java.text.SimpleDateFormat) Test(org.junit.Test)

Aggregations

SearchCondition (org.apache.cxf.jaxrs.ext.search.SearchCondition)21 Test (org.junit.Test)18 DateTimeFormatter (java.time.format.DateTimeFormatter)7 Date (java.util.Date)7 LocalDate (java.time.LocalDate)6 HashMap (java.util.HashMap)4 DateFormat (java.text.DateFormat)3 SimpleDateFormat (java.text.SimpleDateFormat)3 AndSearchCondition (org.apache.cxf.jaxrs.ext.search.AndSearchCondition)2 PrimitiveSearchCondition (org.apache.cxf.jaxrs.ext.search.PrimitiveSearchCondition)2 PrimitiveStatement (org.apache.cxf.jaxrs.ext.search.PrimitiveStatement)2 SearchParseException (org.apache.cxf.jaxrs.ext.search.SearchParseException)2 LocalDateTime (java.time.LocalDateTime)1 ArrayList (java.util.ArrayList)1 OrSearchCondition (org.apache.cxf.jaxrs.ext.search.OrSearchCondition)1 SBThreadLocalVisitorState (org.apache.cxf.jaxrs.ext.search.visitor.SBThreadLocalVisitorState)1 ODataApplicationException (org.apache.olingo.odata2.api.exception.ODataApplicationException)1 ODataMessageException (org.apache.olingo.odata2.api.exception.ODataMessageException)1 FilterExpression (org.apache.olingo.odata2.api.uri.expression.FilterExpression)1 Criteria (org.opennms.core.criteria.Criteria)1