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