Search in sources :

Example 6 with SearchHit

use of org.springframework.data.elasticsearch.core.SearchHit in project openvsx by eclipse.

the class VSCodeAdapterTest method mockSearch.

// ---------- UTILITY ----------//
private void mockSearch(boolean active) {
    var entry1 = new ExtensionSearch();
    entry1.id = 1;
    var searchHit = new SearchHit<ExtensionSearch>("0", "1", 1.0f, null, null, entry1);
    var searchHits = new SearchHitsImpl<ExtensionSearch>(1, TotalHitsRelation.EQUAL_TO, 1.0f, "1", Arrays.asList(searchHit), new Aggregations(Collections.emptyList()));
    Mockito.when(search.isEnabled()).thenReturn(true);
    var searchOptions = new ISearchService.Options("yaml", null, 50, 0, "desc", "relevance", false);
    Mockito.when(search.search(searchOptions, PageRequest.of(0, 50))).thenReturn(searchHits);
    var extension = mockExtensionDTO();
    List<ExtensionDTO> results = active ? List.of(extension) : Collections.emptyList();
    Mockito.when(repositories.findAllActiveExtensionDTOsById(List.of(entry1.id))).thenReturn(results);
    var publicIds = Set.of(extension.getPublicId());
    Mockito.when(repositories.findAllActiveExtensionDTOsByPublicId(publicIds)).thenReturn(results);
    var ids = List.of(extension.getId());
    Mockito.when(repositories.findAllActiveReviewCountsByExtensionId(ids)).thenReturn(Map.of(extension.getId(), 10));
    var name = extension.getName();
    var namespaceName = extension.getNamespace().getName();
    Mockito.when(repositories.findActiveExtensionDTOByNameAndNamespaceName(name, namespaceName)).thenReturn(extension);
    mockFileResourceDTOs(extension.getLatest());
}
Also used : SearchHit(org.springframework.data.elasticsearch.core.SearchHit) ExtensionSearch(org.eclipse.openvsx.search.ExtensionSearch) Aggregations(org.elasticsearch.search.aggregations.Aggregations) ExtensionDTO(org.eclipse.openvsx.dto.ExtensionDTO) SearchHitsImpl(org.springframework.data.elasticsearch.core.SearchHitsImpl)

Example 7 with SearchHit

use of org.springframework.data.elasticsearch.core.SearchHit in project openvsx by eclipse.

the class RegistryAPITest method mockSearch.

private List<Extension> mockSearch() {
    var extVersion = mockExtension();
    var extension = extVersion.getExtension();
    extension.setId(1l);
    var entry1 = new ExtensionSearch();
    entry1.id = 1;
    var searchHit = new SearchHit<ExtensionSearch>("0", "1", 1.0f, null, null, entry1);
    var searchHits = new SearchHitsImpl<ExtensionSearch>(1, TotalHitsRelation.EQUAL_TO, 1.0f, "1", Arrays.asList(searchHit), new Aggregations(Collections.emptyList()));
    Mockito.when(search.isEnabled()).thenReturn(true);
    var searchOptions = new ISearchService.Options("foo", null, 10, 0, "desc", "relevance", false);
    Mockito.when(search.search(searchOptions, PageRequest.of(0, 10))).thenReturn(searchHits);
    Mockito.when(entityManager.find(Extension.class, 1l)).thenReturn(extension);
    return Arrays.asList(extension);
}
Also used : SearchHit(org.springframework.data.elasticsearch.core.SearchHit) ExtensionSearch(org.eclipse.openvsx.search.ExtensionSearch) Aggregations(org.elasticsearch.search.aggregations.Aggregations) SearchHitsImpl(org.springframework.data.elasticsearch.core.SearchHitsImpl)

Example 8 with SearchHit

use of org.springframework.data.elasticsearch.core.SearchHit in project spring-advanced-training by arnosthavelka.

the class CityServiceTest method search.

@ParameterizedTest
@CsvSource(value = { "Armenia,Colombia,Quindío", "null,Colombia,Quindío", "Armenia,null,Quindío", "Armenia,Colombia,null", "null,null,null" }, nullValues = "null")
void search(String name, String country, String subcountry) {
    Pageable pageable = unpaged();
    var cityHit = new SearchHit<City>(INDEX, UUID.randomUUID().toString(), null, NaN, null, null, null, null, null, null, new City(CITY_ID, name, country, subcountry, 666L));
    List<? extends SearchHit<City>> cities = List.of(cityHit);
    given(esTemplate.search(any(Query.class), eq(City.class), eq(IndexCoordinates.of(INDEX)))).willReturn(new SearchHitsImpl<City>(1, EQUAL_TO, NaN, "scrollId", cities, null, null));
    SearchHits<City> result = service.search(name, country, subcountry, pageable);
    assertThat(result.getTotalHits()).isEqualTo(1);
    verify(esTemplate).search(any(Query.class), eq(City.class), eq(IndexCoordinates.of(INDEX)));
}
Also used : Pageable(org.springframework.data.domain.Pageable) SearchHit(org.springframework.data.elasticsearch.core.SearchHit) Query(org.springframework.data.elasticsearch.core.query.Query) CsvSource(org.junit.jupiter.params.provider.CsvSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

SearchHit (org.springframework.data.elasticsearch.core.SearchHit)8 ArrayList (java.util.ArrayList)3 List (java.util.List)3 Collectors (java.util.stream.Collectors)3 ExtensionSearch (org.eclipse.openvsx.search.ExtensionSearch)3 Aggregations (org.elasticsearch.search.aggregations.Aggregations)3 SearchHitsImpl (org.springframework.data.elasticsearch.core.SearchHitsImpl)3 Extension (org.eclipse.openvsx.entities.Extension)2 RepositoryService (org.eclipse.openvsx.repositories.RepositoryService)2 Autowired (org.springframework.beans.factory.annotation.Autowired)2 Pageable (org.springframework.data.domain.Pageable)2 Sort (org.springframework.data.domain.Sort)2 Strings (com.google.common.base.Strings)1 Iterables (com.google.common.collect.Iterables)1 Lists (com.google.common.collect.Lists)1 InputStream (java.io.InputStream)1 java.util (java.util)1 Collections (java.util.Collections)1 Comparator (java.util.Comparator)1 TimeUnit (java.util.concurrent.TimeUnit)1