Java Code Examples for cz.jirutka.rsql.parser.RSQLParserException

The following examples show how to use cz.jirutka.rsql.parser.RSQLParserException. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
@Override
public Query convert(@Nonnull String source) {
  Node node;
  try {
    node = rsqlParser.parse(source);
  } catch (RSQLParserException e) {
    Throwable cause = e.getCause();
    if (cause instanceof UnknownOperatorException) {
      String operator = ((UnknownOperatorException) cause).getOperator();
      throw new UnknownQueryOperatorException(operator);
    } else {
      throw new QueryParseException(e);
    }
  }
  return node.accept(rsqlVisitor);
}
 
Example 2
@Test
void testEquals() throws RSQLParserException {
  Attribute nameAttr = when(mock(Attribute.class).getDataType()).thenReturn(STRING).getMock();
  Attribute ageAttr = when(mock(Attribute.class).getDataType()).thenReturn(INT).getMock();
  doReturn(nameAttr).when(entityType).getAttribute("name");
  doReturn(ageAttr).when(entityType).getAttribute("age");

  Query<Entity> q = molgenisRSQL.createQuery("name==piet", repository);
  assertEquals(new QueryImpl<>().eq("name", "piet"), q);

  q = molgenisRSQL.createQuery("name=='piet paulusma'", repository);
  assertEquals(new QueryImpl<>().eq("name", "piet paulusma"), q);

  q = molgenisRSQL.createQuery("age==87", repository);
  assertEquals(new QueryImpl<>().eq("age", 87), q);
}
 
Example 3
@Test
void testComplexQuery() throws RSQLParserException {
  Attribute nameAttr = when(mock(Attribute.class).getDataType()).thenReturn(STRING).getMock();
  Attribute ageAttr = when(mock(Attribute.class).getDataType()).thenReturn(INT).getMock();
  doReturn(nameAttr).when(entityType).getAttribute("name");
  doReturn(ageAttr).when(entityType).getAttribute("age");

  Query<Entity> q =
      molgenisRSQL.createQuery("((name==piet;age==87),(name==klaas;age>100))", repository);
  assertEquals(
      new QueryImpl<>()
          .nest()
          .nest()
          .eq("name", "piet")
          .and()
          .eq("age", 87)
          .unnest()
          .or()
          .nest()
          .eq("name", "klaas")
          .and()
          .gt("age", 100)
          .unnest()
          .unnest(),
      q);
}
 
Example 4
Source Project: pnc   Source File: JavaUtilPredicateTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test(expected = RSQLParserException.class)
public void shouldThrowExceptionOnIncorrectSyntax() throws Exception {
    // given
    String rsql = "error";

    // when //then
    new RSQLNodeTravellerPredicate(TestClass.class, rsql);
}
 
Example 5
@ParameterizedTest
@MethodSource("languageMessageProvider")
@Override
protected void testGetLocalizedMessage(String lang, String message) {
  RSQLParserException ex = mock(RSQLParserException.class);
  when(ex.getLocalizedMessage()).thenReturn("RSQL MESSAGE");
  Throwable cause = new IllegalAccessException("Query cannot be null");
  when(ex.getCause()).thenReturn(cause);
  assertExceptionMessageEquals(new QueryParseException(ex), lang, message);
}
 
Example 6
private Set<Sid> getSidsFromQuery(String queryString) {
  Set<Sid> sids = Collections.emptySet();
  if (!Strings.isNullOrEmpty(queryString)) {
    try {
      Node node = rsqlParser.parse(queryString);
      PermissionsQuery permissionsQuery = node.accept(new PermissionRsqlVisitor());
      sids =
          new LinkedHashSet<>(
              userRoleTools.getSids(permissionsQuery.getUsers(), permissionsQuery.getRoles()));
    } catch (RSQLParserException e) {
      throw new PermissionQueryParseException(e);
    }
  }
  return sids;
}
 
Example 7
@ParameterizedTest
@MethodSource("languageMessageProvider")
@Override
protected void testGetLocalizedMessage(String lang, String message) {
  RSQLParserException cause = mock(RSQLParserException.class);
  when(cause.getLocalizedMessage()).thenReturn("bacause");
  ExceptionMessageTest.assertExceptionMessageEquals(
      new PermissionQueryParseException(cause), lang, message);
}
 
Example 8
@Test
void testGreaterThanOrEqual() throws RSQLParserException {
  Attribute ageAttr = when(mock(Attribute.class).getDataType()).thenReturn(INT).getMock();
  doReturn(ageAttr).when(entityType).getAttribute("age");

  Query<Entity> q = molgenisRSQL.createQuery("age>=87", repository);
  assertEquals(new QueryImpl<>().ge("age", 87), q);
}
 
Example 9
@Test
void testGreaterThan() throws RSQLParserException {
  Attribute ageAttr = when(mock(Attribute.class).getDataType()).thenReturn(INT).getMock();
  doReturn(ageAttr).when(entityType).getAttribute("age");

  Query<Entity> q = molgenisRSQL.createQuery("age>87", repository);
  assertEquals(new QueryImpl<>().gt("age", 87), q);
}
 
Example 10
@Test
void testLessThanOrEqual() throws RSQLParserException {
  Attribute ageAttr = when(mock(Attribute.class).getDataType()).thenReturn(INT).getMock();
  doReturn(ageAttr).when(entityType).getAttribute("age");

  Query<Entity> q = molgenisRSQL.createQuery("age<=87", repository);
  assertEquals(new QueryImpl<>().le("age", 87), q);
}
 
Example 11
@Test
void testLessThan() throws RSQLParserException {
  Attribute ageAttr = when(mock(Attribute.class).getDataType()).thenReturn(INT).getMock();
  doReturn(ageAttr).when(entityType).getAttribute("age");

  Query<Entity> q = molgenisRSQL.createQuery("age<87", repository);
  assertEquals(new QueryImpl<>().lt("age", 87), q);
}
 
Example 12
@Test
void testAnd() throws RSQLParserException {
  Attribute nameAttr = when(mock(Attribute.class).getDataType()).thenReturn(STRING).getMock();
  Attribute ageAttr = when(mock(Attribute.class).getDataType()).thenReturn(INT).getMock();
  doReturn(nameAttr).when(entityType).getAttribute("name");
  doReturn(ageAttr).when(entityType).getAttribute("age");

  // ';' and 'and' or synonyms

  Query<Entity> q = molgenisRSQL.createQuery("name==piet and age==87", repository);
  assertEquals(new QueryImpl<>().nest().eq("name", "piet").and().eq("age", 87).unnest(), q);

  q = molgenisRSQL.createQuery("name==piet;age==87", repository);
  assertEquals(new QueryImpl<>().nest().eq("name", "piet").and().eq("age", 87).unnest(), q);
}
 
Example 13
@Test
void testOr() throws RSQLParserException {
  Attribute nameAttr = when(mock(Attribute.class).getDataType()).thenReturn(STRING).getMock();
  Attribute ageAttr = when(mock(Attribute.class).getDataType()).thenReturn(INT).getMock();
  doReturn(nameAttr).when(entityType).getAttribute("name");
  doReturn(ageAttr).when(entityType).getAttribute("age");

  // ',' and 'or' or synonyms

  Query<Entity> q = molgenisRSQL.createQuery("name==piet or age==87", repository);
  assertEquals(new QueryImpl<>().nest().eq("name", "piet").or().eq("age", 87).unnest(), q);

  q = molgenisRSQL.createQuery("name==piet,age==87", repository);
  assertEquals(new QueryImpl<>().nest().eq("name", "piet").or().eq("age", 87).unnest(), q);
}
 
Example 14
@Test
void testGreaterThanOnNonNumericalAttribute() throws RSQLParserException {
  Attribute nameAttr = when(mock(Attribute.class).getDataType()).thenReturn(STRING).getMock();
  doReturn(nameAttr).when(entityType).getAttribute("name");

  assertThrows(
      IllegalArgumentException.class, () -> molgenisRSQL.createQuery("name>87", repository));
}
 
Example 15
@Test
void testGreaterThanWithNonNumericalArg() throws RSQLParserException {
  Attribute ageAttr = when(mock(Attribute.class).getDataType()).thenReturn(INT).getMock();
  doReturn(ageAttr).when(entityType).getAttribute("age");

  assertThrows(
      NumberFormatException.class, () -> molgenisRSQL.createQuery("age>bogus", repository));
}
 
Example 16
public QueryParseException(RSQLParserException parseException) {
  super(ERROR_CODE);
  this.parseException = requireNonNull(parseException);
}
 
Example 17
public PermissionQueryParseException(RSQLParserException cause) {
  super(ERROR_CODE, cause);
  this.cause = requireNonNull(cause);
}
 
Example 18
@Test
void testUnknowAttribute() throws RSQLParserException {
  assertThrows(
      UnknownAttributeException.class,
      () -> molgenisRSQL.createQuery("nonexistingattribute==piet", repository));
}