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