Skip to content

Commit

Permalink
refactor SearXNGWebSearchEngineIT
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin7-1 committed Dec 4, 2024
1 parent a40ff82 commit d677d07
Showing 1 changed file with 32 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
import java.util.HashMap;
import java.util.Map;

import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.assertj.core.api.Assertions.assertThat;

@Testcontainers
class SearXNGWebSearchEngineIT extends WebSearchEngineIT {
Expand All @@ -28,12 +27,15 @@ class SearXNGWebSearchEngineIT extends WebSearchEngineIT {
@Container
static GenericContainer<?> searxng = new GenericContainer<>(DockerImageName.parse("searxng/searxng:latest"))
.withExposedPorts(8080)
.withCopyFileToContainer(MountableFile.forClasspathResource("settings.yml"), "/usr/local/searxng/searx/settings.yml")
.withCopyFileToContainer(
MountableFile.forClasspathResource("settings.yml"), "/usr/local/searxng/searx/settings.yml")
.waitingFor(Wait.forLogMessage(".*spawned uWSGI worker.*\\n", 1));

@Override
protected WebSearchEngine searchEngine() {
return SearXNGWebSearchEngine.builder().baseUrl("http://" + searxng.getHost() + ":" + searxng.getMappedPort(8080)).build();
return SearXNGWebSearchEngine.builder()
.baseUrl("http://" + searxng.getHost() + ":" + searxng.getMappedPort(8080))
.build();
}

@BeforeAll
Expand Down Expand Up @@ -63,32 +65,33 @@ private static String engine(WebSearchOrganicResult webSearchOrganicResult) {
void should_search_with_start_page() {
// given
final String searchTerms = "What is Artificial Intelligence?";
WebSearchRequest request1 = WebSearchRequest.builder()
.searchTerms(searchTerms)
.build();
WebSearchRequest request1 =
WebSearchRequest.builder().searchTerms(searchTerms).build();

WebSearchRequest request2 = WebSearchRequest.builder()
.searchTerms(searchTerms)
.startPage(2)
.build();
WebSearchRequest request2 =
WebSearchRequest.builder().searchTerms(searchTerms).startPage(2).build();

WebSearchRequest request3 = WebSearchRequest.builder()
.searchTerms(searchTerms)
.startPage(3)
.build();
WebSearchRequest request3 =
WebSearchRequest.builder().searchTerms(searchTerms).startPage(3).build();
// when
WebSearchResults webSearchResults1 = searchEngine().search(request1);
WebSearchResults webSearchResults2 = searchEngine().search(request2);
WebSearchResults webSearchResults3 = searchEngine().search(request3);

// then
assertNotEquals(contentForComparison(webSearchResults1.results().get(0)), contentForComparison(webSearchResults2.results().get(0)));
assertNotEquals(contentForComparison(webSearchResults1.results().get(0)), contentForComparison(webSearchResults3.results().get(0)));
assertNotEquals(contentForComparison(webSearchResults2.results().get(0)), contentForComparison(webSearchResults3.results().get(0)));

assertNotEquals(contentForComparison(webSearchResults1.results().get(1)), contentForComparison(webSearchResults2.results().get(1)));
assertNotEquals(contentForComparison(webSearchResults1.results().get(1)), contentForComparison(webSearchResults3.results().get(1)));
assertNotEquals(contentForComparison(webSearchResults2.results().get(1)), contentForComparison(webSearchResults3.results().get(1)));
assertThat(contentForComparison(webSearchResults1.results().get(0)))
.isNotEqualTo(contentForComparison(webSearchResults2.results().get(0)));
assertThat(contentForComparison(webSearchResults1.results().get(0)))
.isNotEqualTo(contentForComparison(webSearchResults3.results().get(0)));
assertThat(contentForComparison(webSearchResults2.results().get(0)))
.isNotEqualTo(contentForComparison(webSearchResults3.results().get(0)));

assertThat(contentForComparison(webSearchResults1.results().get(1)))
.isNotEqualTo(contentForComparison(webSearchResults2.results().get(1)));
assertThat(contentForComparison(webSearchResults1.results().get(1)))
.isNotEqualTo(contentForComparison(webSearchResults3.results().get(1)));
assertThat(contentForComparison(webSearchResults2.results().get(1)))
.isNotEqualTo(contentForComparison(webSearchResults3.results().get(1)));
}

@Test
Expand All @@ -111,8 +114,10 @@ void should_search_with_language() {
WebSearchResults webSearchResults2 = searchEngine().search(request2);

// then
assertNotEquals(contentForComparison(webSearchResults1.results().get(0)), contentForComparison(webSearchResults2.results().get(0)));
assertNotEquals(contentForComparison(webSearchResults1.results().get(1)), contentForComparison(webSearchResults2.results().get(1)));
assertThat(contentForComparison(webSearchResults1.results().get(0)))
.isNotEqualTo(contentForComparison(webSearchResults2.results().get(0)));
assertThat(contentForComparison(webSearchResults1.results().get(1)))
.isNotEqualTo(contentForComparison(webSearchResults2.results().get(1)));
}

@Test
Expand Down Expand Up @@ -147,16 +152,13 @@ void should_search_with_additional_params() {

// then
for (final WebSearchOrganicResult result : webSearchResults1.results()) {
assertEquals("google", engine(result));

assertThat(engine(result)).isEqualTo("google");
}
for (final WebSearchOrganicResult result : webSearchResults2.results()) {
assertEquals("bing", engine(result));

assertThat(engine(result)).isEqualTo("bing");
}
for (final WebSearchOrganicResult result : webSearchResults3.results()) {
assertEquals("yahoo", engine(result));

assertThat(engine(result)).isEqualTo("yahoo");
}
}
}

0 comments on commit d677d07

Please sign in to comment.