Search in sources :

Example 6 with Query

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

the class QueryMapperTest method testMapAnd.

@Test
void testMapAnd() {
    String value0 = "value0";
    String value1 = "value1";
    Query query = Query.builder().setOperator(Operator.AND).setValue(asList(Query.builder().setOperator(Operator.MATCHES).setValue(value0).build(), Query.builder().setOperator(Operator.MATCHES).setValue(value1).build())).build();
    @SuppressWarnings("unchecked") Repository<Entity> repository = mock(Repository.class);
    assertEquals(new QueryImpl<>(repository).nest().search(value0).and().search(value1).unnest(), queryMapper.map(query, repository));
}
Also used : Entity(org.molgenis.data.Entity) QueryImpl(org.molgenis.data.support.QueryImpl) Query(org.molgenis.api.model.Query) Test(org.junit.jupiter.api.Test) AbstractMockitoTest(org.molgenis.test.AbstractMockitoTest)

Example 7 with Query

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

the class QueryMapperTest method testMapEqualsUnknownAttribute.

@Test
void testMapEqualsUnknownAttribute() {
    String value = "value";
    Query query = Query.builder().setItem("unknownAttribute").setOperator(Operator.EQUALS).setValue(value).build();
    @SuppressWarnings("unchecked") Repository<Entity> repository = mock(Repository.class);
    EntityType entityType = mock(EntityType.class);
    when(repository.getEntityType()).thenReturn(entityType);
    assertThrows(UnknownAttributeException.class, () -> queryMapper.map(query, repository));
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) Entity(org.molgenis.data.Entity) Query(org.molgenis.api.model.Query) Test(org.junit.jupiter.api.Test) AbstractMockitoTest(org.molgenis.test.AbstractMockitoTest)

Example 8 with Query

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

the class QueryMapperTest method testMapGreaterThanOrEqualTo.

@Test
void testMapGreaterThanOrEqualTo() {
    String value = "value";
    Query query = Query.builder().setItem("test").setOperator(Operator.GREATER_THAN_OR_EQUAL_TO).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).ge("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 9 with Query

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

the class QueryMapperTest method testMapContains.

@Test
void testMapContains() {
    String value = "value";
    Query query = Query.builder().setItem("test").setOperator(Operator.CONTAINS).setValue(value).build();
    @SuppressWarnings("unchecked") Repository<Entity> repository = mock(Repository.class);
    assertEquals(new QueryImpl<>(repository).like("test", value), queryMapper.map(query, repository));
}
Also used : Entity(org.molgenis.data.Entity) QueryImpl(org.molgenis.data.support.QueryImpl) Query(org.molgenis.api.model.Query) Test(org.junit.jupiter.api.Test) AbstractMockitoTest(org.molgenis.test.AbstractMockitoTest)

Example 10 with Query

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

the class QueryMapperTest method testMapMatches.

@Test
void testMapMatches() {
    String value = "value";
    Query query = Query.builder().setItem("test").setOperator(Operator.MATCHES).setValue(value).build();
    @SuppressWarnings("unchecked") Repository<Entity> repository = mock(Repository.class);
    assertEquals(new QueryImpl<>(repository).search("test", value), queryMapper.map(query, repository));
}
Also used : Entity(org.molgenis.data.Entity) QueryImpl(org.molgenis.data.support.QueryImpl) Query(org.molgenis.api.model.Query) 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