This is the codeAbility Sharing Platform! Learn more about the codeAbility Sharing Platform.

Skip to content
Snippets Groups Projects
Commit 09b50e9d authored by Michael Breu's avatar Michael Breu
Browse files

Minor code smells in tests

parent e91f5d3a
Branches
2 merge requests!222Bringing the december release into production,!215Resolve "Relevance Ranking in Metadata"
......@@ -311,7 +311,7 @@ public class MetaDataRepository {
}
});
reloadedCachedCompletions.values().forEach(c -> simplify(c));
reloadedCachedCompletions.values().forEach(this::simplify);
cachedCompletions = reloadedCachedCompletions;
} catch (co.elastic.clients.elasticsearch._types.ElasticsearchException | ElasticsearchException | ConnectException ex) {
// this may happen mainly during testing, when
......@@ -336,7 +336,7 @@ public class MetaDataRepository {
entries.forEach((lowerCaseValue, upperCaseValues) -> {
final Optional<Entry<String, Integer>> max = upperCaseValues.entrySet().stream().max((e1, e2) -> e1.getValue() - e2.getValue());
max.ifPresent(maxEntry -> {
int sum = upperCaseValues.entrySet().stream().mapToInt(o -> o.getValue()).sum();
int sum = upperCaseValues.entrySet().stream().mapToInt(Entry::getValue).sum();
entries.put(lowerCaseValue, Collections.singletonMap(maxEntry.getKey(), sum));
});
});
......
......@@ -19,6 +19,7 @@ import static org.mockito.Mockito.when;
import at.ac.uibk.gitsearch.IntegrationTest;
import at.ac.uibk.gitsearch.repository.gitlab.GitLabRepository;
import at.ac.uibk.gitsearch.repository.jpa.StatisticsRepository;
import at.ac.uibk.gitsearch.repository.search.ElasticSearchRepository;
import at.ac.uibk.gitsearch.repository.search.MetaDataRepository;
import at.ac.uibk.gitsearch.repository.search.testESService.ElasticSearchTestConfiguration;
import at.ac.uibk.gitsearch.security.jwt.TokenProvider;
......@@ -83,6 +84,9 @@ public class SearchServiceIT {
@Autowired
StatisticsService statisticsService;
@Autowired
ElasticSearchRepository elasticSearchRepository;
@MockBean
RepositoryApi mockedRepositoryApi;
......@@ -96,7 +100,8 @@ public class SearchServiceIT {
static ElasticSearchTestConfiguration staticElasticSearchTestConfiguration;
@BeforeEach // must be started as BeforeEach, in order to autowire the ElasticSearchTestConfiguration
@BeforeEach // must be started as BeforeEach, in order to autowire the
// ElasticSearchTestConfiguration
@Timeout(value = 3, unit = TimeUnit.MINUTES)
public void setUpESServer() throws IOException, NodeValidationException {
if (staticElasticSearchTestConfiguration == null) {
......@@ -194,13 +199,10 @@ public class SearchServiceIT {
statisticsRepository.flush();
SearchResultsDTO searchResultPage2;
int maxRetries = 10;
do {
TimeUnit.MILLISECONDS.sleep(500);
searchResultPage2 = searchService.searchResultPage(searchQuery);
// it occurs that upon requesting elastic search right after updating the indices, the old order is retrieved
} while (searchResultPage2.getSearchResult().iterator().next().getSearchStatistics() == null && maxRetries-- > 0);
elasticSearchRepository.waitForIndexingFinished();
SearchResultsDTO searchResultPage2 = searchService.searchResultPage(searchQuery);
// it occurs that upon requesting elastic search right after updating the
// indices, the old order is retrieved
Comparator<SearchResultDTO> orderComparator = Comparator.comparing(sr -> {
if (sr.getSearchStatistics() == null) {
......@@ -228,7 +230,7 @@ public class SearchServiceIT {
assertThat(sr.getSearchStatistics().getViews()).isGreaterThanOrEqualTo(95);
}
if (previousSearchResult != null) {
assertThat(orderComparator.compare(previousSearchResult, sr)).isGreaterThan(0);
assertThat(orderComparator.compare(previousSearchResult, sr)).isPositive();
}
previousSearchResult = sr;
}
......@@ -328,19 +330,24 @@ public class SearchServiceIT {
}
// does not work with metadata version 0.4
// @Test
// void testTypesSearch() throws IOException {
// final SearchInputMetadataDTO searchMetadata = new SearchInputMetadataDTO(null, "latex", null, null, null,null);
// searchMetadata.setTypes(Collections.singletonList(ExerciseType.COLLECTION));
// SearchInputDTO searchQuery = new SearchInputDTO(null, searchMetadata, null, null, null, 0);
// SearchResultsDTO searchResultPage = searchService.searchResultPage(searchQuery);
// @Test
// void testTypesSearch() throws IOException {
// final SearchInputMetadataDTO searchMetadata = new
// SearchInputMetadataDTO(null, "latex", null, null, null,null);
// searchMetadata.setTypes(Collections.singletonList(ExerciseType.COLLECTION));
// SearchInputDTO searchQuery = new SearchInputDTO(null, searchMetadata, null,
// null, null, 0);
// SearchResultsDTO searchResultPage =
// searchService.searchResultPage(searchQuery);
//
// org.junit.Assert.assertNotNull(searchResultPage.getSearchResult());
// org.junit.Assert.assertTrue("At least one test hit", searchResultPage.getHitCount() >= 1);
// assertThat(searchResultPage.getSearchResult(),
// everyItem(hasProperty("metadata", hasProperty("keyword", hasItemInArray(containsString("latex"))))));
// org.junit.Assert.assertNotNull(searchResultPage.getSearchResult());
// org.junit.Assert.assertTrue("At least one test hit",
// searchResultPage.getHitCount() >= 1);
// assertThat(searchResultPage.getSearchResult(),
// everyItem(hasProperty("metadata", hasProperty("keyword",
// hasItemInArray(containsString("latex"))))));
//
// }
// }
@Test
@Timeout(value = 1, unit = TimeUnit.MINUTES)
......@@ -389,20 +396,24 @@ public class SearchServiceIT {
}
// does not work with metadata version 0.4
// @Test
// void testTypesSearchNegative() throws IOException {
// final SearchInputMetadataDTO searchMetadata = new SearchInputMetadataDTO(null, "latex", null, null, null,null);
// searchMetadata.setTypes(Collections.singletonList(ExerciseType.OTHER));
// SearchInputDTO searchQuery = new SearchInputDTO(null, searchMetadata, null, null, null, 0);
// SearchResultsDTO searchResultPage = searchService.searchResultPage(searchQuery);
// @Test
// void testTypesSearchNegative() throws IOException {
// final SearchInputMetadataDTO searchMetadata = new
// SearchInputMetadataDTO(null, "latex", null, null, null,null);
// searchMetadata.setTypes(Collections.singletonList(ExerciseType.OTHER));
// SearchInputDTO searchQuery = new SearchInputDTO(null, searchMetadata, null,
// null, null, 0);
// SearchResultsDTO searchResultPage =
// searchService.searchResultPage(searchQuery);
//
// org.junit.Assert.assertNotNull(searchResultPage.getSearchResult());
// org.junit.Assert.assertTrue("We expect no hit for \"latex\" and ExerciseType.OTHER", searchResultPage.getHitCount() == 0);
// org.junit.Assert.assertNotNull(searchResultPage.getSearchResult());
// org.junit.Assert.assertTrue("We expect no hit for \"latex\" and
// ExerciseType.OTHER", searchResultPage.getHitCount() == 0);
//
// }
// }
// @Test()
// @Ignore() // Test funktioniert momentan nicht?
// @Test()
// @Ignore() // Test funktioniert momentan nicht?
void testLicenseSearch() throws IOException {
final SearchInputMetadataDTO searchMetadata = new SearchInputMetadataDTO(null, null, null, "MIT", null, null);
SearchInputDTO searchQuery = new SearchInputDTO(null, searchMetadata, null, null, null, 0);
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment