Search in sources :

Example 51 with Query

use of org.molgenis.api.model.Query in project molgenis by molgenis.

the class QueryMapperTest method testMapEqualsSubAttribute.

@Test
void testMapEqualsSubAttribute() {
    String value = "value";
    Query query = Query.builder().setItem("test.subtest").setOperator(Operator.EQUALS).setValue(value).build();
    Attribute subAttribute = mock(Attribute.class);
    EntityType refEntityType = mock(EntityType.class);
    when(refEntityType.getAttribute("subtest")).thenReturn(subAttribute);
    Attribute attribute = mock(Attribute.class);
    when(attribute.getRefEntity()).thenReturn(refEntityType);
    Repository<Entity> repository = createMockRepository(attribute);
    Object parsedValue = mock(Object.class);
    when(rsqlValueParser.parse(value, subAttribute)).thenReturn(parsedValue);
    assertEquals(new QueryImpl<>(repository).eq("test.subtest", parsedValue), queryMapper.map(query, repository));
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) Entity(org.molgenis.data.Entity) QueryImpl(org.molgenis.data.support.QueryImpl) Query(org.molgenis.api.model.Query) Attribute(org.molgenis.data.meta.model.Attribute) Test(org.junit.jupiter.api.Test) AbstractMockitoTest(org.molgenis.test.AbstractMockitoTest)

Example 52 with Query

use of org.molgenis.api.model.Query in project molgenis by molgenis.

the class QueryMapperTest method testMapIn.

@Test
void testMapIn() {
    String value0 = "value0";
    String value1 = "value1";
    Query query = Query.builder().setItem("test").setOperator(Operator.IN).setValue(asList(value0, value1)).build();
    Attribute attribute = mock(Attribute.class);
    Repository<Entity> repository = createMockRepository(attribute);
    Object parsedValue0 = mock(Object.class);
    doReturn(parsedValue0).when(rsqlValueParser).parse(value0, attribute);
    Object parsedValue1 = mock(Object.class);
    doReturn(parsedValue1).when(rsqlValueParser).parse(value1, attribute);
    assertEquals(new QueryImpl<>(repository).in("test", asList(parsedValue0, parsedValue1)), queryMapper.map(query, repository));
}
Also used : Entity(org.molgenis.data.Entity) QueryImpl(org.molgenis.data.support.QueryImpl) Query(org.molgenis.api.model.Query) Attribute(org.molgenis.data.meta.model.Attribute) Test(org.junit.jupiter.api.Test) AbstractMockitoTest(org.molgenis.test.AbstractMockitoTest)

Example 53 with Query

use of org.molgenis.api.model.Query in project molgenis by molgenis.

the class QueryMapperTest method testMapLessThan.

@Test
void testMapLessThan() {
    String value = "value";
    Query query = Query.builder().setItem("test").setOperator(Operator.LESS_THAN).setValue(value).build();
    Attribute attribute = mock(Attribute.class);
    Repository<Entity> repository = createMockRepository(attribute, AttributeType.INT);
    Object parsedValue = "parsedValue";
    when(rsqlValueParser.parse(value, attribute)).thenReturn(parsedValue);
    assertEquals(new QueryImpl<>(repository).lt("test", parsedValue), queryMapper.map(query, repository));
}
Also used : Entity(org.molgenis.data.Entity) QueryImpl(org.molgenis.data.support.QueryImpl) Query(org.molgenis.api.model.Query) Attribute(org.molgenis.data.meta.model.Attribute) Test(org.junit.jupiter.api.Test) AbstractMockitoTest(org.molgenis.test.AbstractMockitoTest)

Example 54 with Query

use of org.molgenis.api.model.Query in project molgenis by molgenis.

the class QueryMapperTest method testMapCompoundAttribute.

@Test
void testMapCompoundAttribute() {
    String value = "value";
    Query query = Query.builder().setItem("test").setOperator(Operator.EQUALS).setValue(value).build();
    Attribute attribute = mock(Attribute.class);
    Repository<Entity> repository = createMockRepository(attribute, AttributeType.COMPOUND);
    assertThrows(UnexpectedEnumException.class, () -> queryMapper.map(query, repository));
}
Also used : Entity(org.molgenis.data.Entity) Query(org.molgenis.api.model.Query) Attribute(org.molgenis.data.meta.model.Attribute) Test(org.junit.jupiter.api.Test) AbstractMockitoTest(org.molgenis.test.AbstractMockitoTest)

Example 55 with Query

use of org.molgenis.api.model.Query in project molgenis by molgenis.

the class QueryMapperTest method testMapGreaterThan.

@Test
void testMapGreaterThan() {
    String value = "value";
    Query query = Query.builder().setItem("test").setOperator(Operator.GREATER_THAN).setValue(value).build();
    Attribute attribute = mock(Attribute.class);
    Repository<Entity> repository = createMockRepository(attribute, AttributeType.INT);
    Object parsedValue = "parsedValue";
    when(rsqlValueParser.parse(value, attribute)).thenReturn(parsedValue);
    assertEquals(new QueryImpl<>(repository).gt("test", parsedValue), queryMapper.map(query, repository));
}
Also used : Entity(org.molgenis.data.Entity) QueryImpl(org.molgenis.data.support.QueryImpl) Query(org.molgenis.api.model.Query) Attribute(org.molgenis.data.meta.model.Attribute) Test(org.junit.jupiter.api.Test) AbstractMockitoTest(org.molgenis.test.AbstractMockitoTest)

Aggregations

Query (org.molgenis.api.model.Query)58 Test (org.junit.jupiter.api.Test)52 AbstractMockitoTest (org.molgenis.test.AbstractMockitoTest)52 Entity (org.molgenis.data.Entity)27 Attribute (org.molgenis.data.meta.model.Attribute)22 QueryImpl (org.molgenis.data.support.QueryImpl)22 ComparisonNode (cz.jirutka.rsql.parser.ast.ComparisonNode)17 ComparisonOperator (cz.jirutka.rsql.parser.ast.ComparisonOperator)17 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)16 EntityType (org.molgenis.data.meta.model.EntityType)15 Sort (org.molgenis.api.model.Sort)14 Selection (org.molgenis.api.model.Selection)9 Fetch (org.molgenis.data.Fetch)7 AttributeMetadata (org.molgenis.data.meta.model.AttributeMetadata)5 MethodSource (org.junit.jupiter.params.provider.MethodSource)4 EntitiesResponse (org.molgenis.api.data.v3.model.EntitiesResponse)2 QueryRule (org.molgenis.data.QueryRule)2 AndNode (cz.jirutka.rsql.parser.ast.AndNode)1 OrNode (cz.jirutka.rsql.parser.ast.OrNode)1 Stream (java.util.stream.Stream)1