use of org.molgenis.api.model.Query in project molgenis by molgenis.
the class MetadataApiServiceImplTest method testFindAttributes.
@SuppressWarnings("unchecked")
@Test
void testFindAttributes() {
Repository<Attribute> attributeRepository = mock(Repository.class);
EntityType entityType = mock(EntityType.class);
when(attributeRepository.getEntityType()).thenReturn(entityType);
when(metadataService.getRepository("sys_md_Attribute", Attribute.class)).thenReturn(Optional.of(attributeRepository));
Query query = mock(Query.class);
when(queryMapper.map(query, attributeRepository)).thenReturn(new QueryImpl<>());
Attribute attribute = mock(Attribute.class);
ArgumentCaptor<org.molgenis.data.Query<Attribute>> findQueryCaptor = ArgumentCaptor.forClass(org.molgenis.data.Query.class);
when(attributeRepository.findAll(findQueryCaptor.capture())).thenReturn(Stream.of(attribute));
long total = 100L;
ArgumentCaptor<org.molgenis.data.Query<Attribute>> countQueryCaptor = ArgumentCaptor.forClass(org.molgenis.data.Query.class);
when(attributeRepository.count(countQueryCaptor.capture())).thenReturn(total);
Sort sort = Sort.EMPTY_SORT;
org.molgenis.data.Sort repositorySort = mock(org.molgenis.data.Sort.class);
when(sortMapper.map(sort, entityType)).thenReturn(repositorySort);
int size = 5;
int number = 2;
Attributes expectedAttributes = Attributes.builder().setAttributes(ImmutableList.of(attribute)).setTotal((int) total).build();
String entityTypeId = "MyEntityTypeId";
when(metadataService.hasEntityType(entityTypeId)).thenReturn(true);
Attributes attributes = metadataApiService.findAttributes(entityTypeId, query, sort, size, number);
org.molgenis.data.Query<Attribute> findQuery = findQueryCaptor.getValue();
org.molgenis.data.Query<Attribute> countQuery = countQueryCaptor.getValue();
assertAll(() -> assertEquals(expectedAttributes, attributes), () -> assertEquals(singletonList(new QueryRule("entity", QueryRule.Operator.EQUALS, entityTypeId)), findQuery.getRules()), () -> assertEquals(size * number, findQuery.getOffset()), () -> assertEquals(size, findQuery.getPageSize()), () -> assertEquals(repositorySort, findQuery.getSort()), () -> assertEquals(singletonList(new QueryRule("entity", QueryRule.Operator.EQUALS, entityTypeId)), countQuery.getRules()), () -> assertEquals(0, countQuery.getOffset()), () -> assertEquals(Integer.MAX_VALUE, countQuery.getPageSize()));
}
use of org.molgenis.api.model.Query in project molgenis by molgenis.
the class QueryRsqlVisitorTest method testVisitComparisonNodeContains.
@Test
void testVisitComparisonNodeContains() {
String selector = "name";
String argument = "piet";
ComparisonOperator operator = new ComparisonOperator("=like=");
ComparisonNode node = new ComparisonNode(operator, selector, singletonList(argument));
Query query = Query.builder().setItem(selector).setOperator(CONTAINS).setValue(argument).build();
assertEquals(query, queryRsqlVisitor.visit(node));
}
use of org.molgenis.api.model.Query in project molgenis by molgenis.
the class QueryRsqlVisitorTest method testVisitComparisonNodeNotEquals.
@Test
void testVisitComparisonNodeNotEquals() {
String selector = "name";
String argument = "piet";
ComparisonOperator operator = new ComparisonOperator("!=");
ComparisonNode node = new ComparisonNode(operator, selector, singletonList(argument));
Query query = Query.builder().setItem(selector).setOperator(NOT_EQUALS).setValue(argument).build();
assertEquals(query, queryRsqlVisitor.visit(node));
}
use of org.molgenis.api.model.Query in project molgenis by molgenis.
the class QueryRsqlVisitorTest method testVisitComparisonNodeNotIn.
@Test
void testVisitComparisonNodeNotIn() {
String selector = "name";
List<String> arguments = asList("jan", "piet");
ComparisonOperator operator = new ComparisonOperator("=out=", true);
ComparisonNode node = new ComparisonNode(operator, selector, arguments);
Query query = Query.builder().setItem(selector).setOperator(NOT_IN).setValue(arguments).build();
assertEquals(query, queryRsqlVisitor.visit(node));
}
use of org.molgenis.api.model.Query in project molgenis by molgenis.
the class QueryRsqlVisitorTest method testVisitComparisonNodeMatches.
@Test
void testVisitComparisonNodeMatches() {
String selector = "name";
String argument = "piet";
ComparisonOperator operator = new ComparisonOperator("=q=");
ComparisonNode node = new ComparisonNode(operator, selector, singletonList(argument));
Query query = Query.builder().setItem(selector).setOperator(MATCHES).setValue(argument).build();
assertEquals(query, queryRsqlVisitor.visit(node));
}
Aggregations