@Test void testFindEntityTypes() { EntityType entityType = mock(EntityType.class); @SuppressWarnings("unchecked") Repository<EntityType> entityTypeRepository = mock(Repository.class); when(entityTypeRepository.getEntityType()).thenReturn(entityType); when(metadataService.getRepository("sys_md_EntityType", EntityType.class)) .thenReturn(Optional.of(entityTypeRepository)); Query query = Query.builder().setItem("id").setOperator(Operator.EQUALS).setValue("id0").build(); when(queryMapper.map(query, entityTypeRepository)).thenReturn(new QueryImpl<>()); @SuppressWarnings("unchecked") ArgumentCaptor<org.molgenis.data.Query<EntityType>> findQueryCaptor = ArgumentCaptor.forClass(org.molgenis.data.Query.class); when(entityTypeRepository.findAll(findQueryCaptor.capture())).thenReturn(Stream.of(entityType)); long total = 100L; @SuppressWarnings("unchecked") ArgumentCaptor<org.molgenis.data.Query<EntityType>> countQueryCaptor = ArgumentCaptor.forClass(org.molgenis.data.Query.class); when(entityTypeRepository.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; EntityTypes expectedEntityTypes = EntityTypes.builder() .setEntityTypes(ImmutableList.of(entityType)) .setTotal((int) total) .build(); EntityTypes entityTypes = metadataApiService.findEntityTypes(query, sort, size, number); org.molgenis.data.Query<EntityType> findQuery = findQueryCaptor.getValue(); org.molgenis.data.Query<EntityType> countQuery = countQueryCaptor.getValue(); assertAll( () -> assertEquals(expectedEntityTypes, entityTypes), () -> assertEquals(size * number, findQuery.getOffset()), () -> assertEquals(size, findQuery.getPageSize()), () -> assertEquals(repositorySort, findQuery.getSort()), () -> assertEquals(0, countQuery.getOffset()), () -> assertEquals(Integer.MAX_VALUE, countQuery.getPageSize())); }
public EntityTypes findEntityTypes( @Nullable @CheckForNull Query query, Sort sort, int size, int number) { Repository<EntityType> repository = getEntityTypeRepository(); org.molgenis.data.Query<EntityType> repositoryQuery = query != null ? queryMapper.map(query, repository) : new QueryImpl<>(repository); org.molgenis.data.Query<EntityType> findQuery = new QueryImpl<>(repositoryQuery); findQuery.offset(number * size); findQuery.pageSize(size); findQuery.sort(sortMapper.map(sort, repository.getEntityType())); List<EntityType> entityTypes = repository.findAll(findQuery).collect(toList()); org.molgenis.data.Query<EntityType> countQuery = new QueryImpl<>(repositoryQuery); countQuery.offset(0); countQuery.pageSize(Integer.MAX_VALUE); int count = Math.toIntExact(repository.count(countQuery)); return EntityTypes.builder().setEntityTypes(entityTypes).setTotal(count).build(); }
MetadataApiServiceImpl implements MetadataApiService { public EntityTypes findEntityTypes( @Nullable @CheckForNull Query query, Sort sort, int size, int number) { Repository<EntityType> repository = getEntityTypeRepository(); org.molgenis.data.Query<EntityType> repositoryQuery = query != null ? queryMapper.map(query, repository) : new QueryImpl<>(repository); org.molgenis.data.Query<EntityType> findQuery = new QueryImpl<>(repositoryQuery); findQuery.offset(number * size); findQuery.pageSize(size); findQuery.sort(sortMapper.map(sort, repository.getEntityType())); List<EntityType> entityTypes = repository.findAll(findQuery).collect(toList()); org.molgenis.data.Query<EntityType> countQuery = new QueryImpl<>(repositoryQuery); countQuery.offset(0); countQuery.pageSize(Integer.MAX_VALUE); int count = Math.toIntExact(repository.count(countQuery)); return EntityTypes.builder().setEntityTypes(entityTypes).setTotal(count).build(); } }
MetadataApiServiceImpl implements MetadataApiService { public EntityTypes findEntityTypes( @Nullable @CheckForNull Query query, Sort sort, int size, int number) { Repository<EntityType> repository = getEntityTypeRepository(); org.molgenis.data.Query<EntityType> repositoryQuery = query != null ? queryMapper.map(query, repository) : new QueryImpl<>(repository); org.molgenis.data.Query<EntityType> findQuery = new QueryImpl<>(repositoryQuery); findQuery.offset(number * size); findQuery.pageSize(size); findQuery.sort(sortMapper.map(sort, repository.getEntityType())); List<EntityType> entityTypes = repository.findAll(findQuery).collect(toList()); org.molgenis.data.Query<EntityType> countQuery = new QueryImpl<>(repositoryQuery); countQuery.offset(0); countQuery.pageSize(Integer.MAX_VALUE); int count = Math.toIntExact(repository.count(countQuery)); return EntityTypes.builder().setEntityTypes(entityTypes).setTotal(count).build(); } MetadataApiServiceImpl(
      MetaDataService metadataService,
      QueryMapper queryMapperV3,
      SortMapper sortMapper,
      MetadataApiJobService metadataApiJobService); }
MetadataApiServiceImpl implements MetadataApiService { public EntityTypes findEntityTypes( @Nullable @CheckForNull Query query, Sort sort, int size, int number) { Repository<EntityType> repository = getEntityTypeRepository(); org.molgenis.data.Query<EntityType> repositoryQuery = query != null ? queryMapper.map(query, repository) : new QueryImpl<>(repository); org.molgenis.data.Query<EntityType> findQuery = new QueryImpl<>(repositoryQuery); findQuery.offset(number * size); findQuery.pageSize(size); findQuery.sort(sortMapper.map(sort, repository.getEntityType())); List<EntityType> entityTypes = repository.findAll(findQuery).collect(toList()); org.molgenis.data.Query<EntityType> countQuery = new QueryImpl<>(repositoryQuery); countQuery.offset(0); countQuery.pageSize(Integer.MAX_VALUE); int count = Math.toIntExact(repository.count(countQuery)); return EntityTypes.builder().setEntityTypes(entityTypes).setTotal(count).build(); } MetadataApiServiceImpl(
      MetaDataService metadataService,
      QueryMapper queryMapperV3,
      SortMapper sortMapper,
      MetadataApiJobService metadataApiJobService); EntityTypes findEntityTypes(
      @Nullable @CheckForNull Query query, Sort sort, int size, int number); @Override EntityType findEntityType(String identifier); @Override Attributes findAttributes(
      String entityTypeId, @Nullable @CheckForNull Query query, Sort sort, int size, int number); @Override Attribute findAttribute(String entityTypeId, String attributeId); @Override MetadataUpsertJobExecution deleteAttributeAsync(String entityTypeId, String attributeId); @Override MetadataUpsertJobExecution deleteAttributesAsync(String entityTypeId, Query query); @Override void createEntityType(EntityType entityType); @Override MetadataUpsertJobExecution updateEntityTypeAsync(EntityType entityType); @Override MetadataDeleteJobExecution deleteEntityTypeAsync(String entityTypeId); @Override MetadataDeleteJobExecution deleteEntityTypesAsync(Query query); }
MetadataApiServiceImpl implements MetadataApiService { public EntityTypes findEntityTypes( @Nullable @CheckForNull Query query, Sort sort, int size, int number) { Repository<EntityType> repository = getEntityTypeRepository(); org.molgenis.data.Query<EntityType> repositoryQuery = query != null ? queryMapper.map(query, repository) : new QueryImpl<>(repository); org.molgenis.data.Query<EntityType> findQuery = new QueryImpl<>(repositoryQuery); findQuery.offset(number * size); findQuery.pageSize(size); findQuery.sort(sortMapper.map(sort, repository.getEntityType())); List<EntityType> entityTypes = repository.findAll(findQuery).collect(toList()); org.molgenis.data.Query<EntityType> countQuery = new QueryImpl<>(repositoryQuery); countQuery.offset(0); countQuery.pageSize(Integer.MAX_VALUE); int count = Math.toIntExact(repository.count(countQuery)); return EntityTypes.builder().setEntityTypes(entityTypes).setTotal(count).build(); } MetadataApiServiceImpl(
      MetaDataService metadataService,
      QueryMapper queryMapperV3,
      SortMapper sortMapper,
      MetadataApiJobService metadataApiJobService); EntityTypes findEntityTypes(
      @Nullable @CheckForNull Query query, Sort sort, int size, int number); @Override EntityType findEntityType(String identifier); @Override Attributes findAttributes(
      String entityTypeId, @Nullable @CheckForNull Query query, Sort sort, int size, int number); @Override Attribute findAttribute(String entityTypeId, String attributeId); @Override MetadataUpsertJobExecution deleteAttributeAsync(String entityTypeId, String attributeId); @Override MetadataUpsertJobExecution deleteAttributesAsync(String entityTypeId, Query query); @Override void createEntityType(EntityType entityType); @Override MetadataUpsertJobExecution updateEntityTypeAsync(EntityType entityType); @Override MetadataDeleteJobExecution deleteEntityTypeAsync(String entityTypeId); @Override MetadataDeleteJobExecution deleteEntityTypesAsync(Query query);  }