Search in sources :

Example 6 with RSQLParser

use of cz.jirutka.rsql.parser.RSQLParser in project tutorials by eugenp.

the class RsqlIntegrationTest method givenFirstAndLastName_whenGettingListOfUsers_thenCorrect.

@Test
public void givenFirstAndLastName_whenGettingListOfUsers_thenCorrect() {
    final Node rootNode = new RSQLParser().parse("firstName==john;lastName==doe");
    final Specification<User> spec = rootNode.accept(new CustomRsqlVisitor<User>());
    final List<User> results = repository.findAll(spec);
    assertThat(userJohn, isIn(results));
    assertThat(userTom, not(isIn(results)));
}
Also used : User(org.baeldung.persistence.model.User) RSQLParser(cz.jirutka.rsql.parser.RSQLParser) Node(cz.jirutka.rsql.parser.ast.Node) Test(org.junit.Test)

Example 7 with RSQLParser

use of cz.jirutka.rsql.parser.RSQLParser in project molgenis by molgenis.

the class MolgenisRSQLTest method beforeMethod.

@BeforeMethod
public void beforeMethod() {
    molgenisRSQL = new MolgenisRSQL(new RSQLParser());
    when(entityType.getId()).thenReturn("Person").getMock();
    Attribute nameAttr = when(mock(Attribute.class).getName()).thenReturn("name").getMock();
    when(nameAttr.getDataType()).thenReturn(STRING);
    Attribute ageAttr = when(mock(Attribute.class).getName()).thenReturn("age").getMock();
    when(ageAttr.getDataType()).thenReturn(INT);
    when(entityType.getAttribute("name")).thenReturn(nameAttr);
    when(entityType.getAttribute("age")).thenReturn(ageAttr);
    when(genderEntityType.getId()).thenReturn("Gender").getMock();
    Attribute genderIdAttribute = when(mock(Attribute.class).getName()).thenReturn("id").getMock();
    when(genderIdAttribute.getDataType()).thenReturn(INT);
    when(genderEntityType.getIdAttribute()).thenReturn(genderIdAttribute);
    Attribute genderAttr = when(mock(Attribute.class).getName()).thenReturn("gender").getMock();
    when(genderAttr.getDataType()).thenReturn(XREF);
    when(genderAttr.getRefEntity()).thenReturn(genderEntityType);
    when(entityType.getAttribute("gender")).thenReturn(genderAttr);
}
Also used : RSQLParser(cz.jirutka.rsql.parser.RSQLParser) Attribute(org.molgenis.data.meta.model.Attribute) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 8 with RSQLParser

use of cz.jirutka.rsql.parser.RSQLParser in project tutorials by eugenp.

the class RsqlIntegrationTest method givenFirstNamePrefix_whenGettingListOfUsers_thenCorrect.

@Test
public void givenFirstNamePrefix_whenGettingListOfUsers_thenCorrect() {
    final Node rootNode = new RSQLParser().parse("firstName==jo*");
    final Specification<User> spec = rootNode.accept(new CustomRsqlVisitor<User>());
    final List<User> results = repository.findAll(spec);
    assertThat(userJohn, isIn(results));
    assertThat(userTom, not(isIn(results)));
}
Also used : User(org.baeldung.persistence.model.User) RSQLParser(cz.jirutka.rsql.parser.RSQLParser) Node(cz.jirutka.rsql.parser.ast.Node) Test(org.junit.Test)

Aggregations

RSQLParser (cz.jirutka.rsql.parser.RSQLParser)8 Node (cz.jirutka.rsql.parser.ast.Node)6 User (org.baeldung.persistence.model.User)6 Test (org.junit.Test)5 ComparisonOperator (cz.jirutka.rsql.parser.ast.ComparisonOperator)1 MyUser (org.baeldung.persistence.model.MyUser)1 Attribute (org.molgenis.data.meta.model.Attribute)1 Bean (org.springframework.context.annotation.Bean)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)1 BeforeMethod (org.testng.annotations.BeforeMethod)1