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));
}
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));
}
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));
}
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));
}
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));
}
Aggregations