Skip to content

Commit

Permalink
[plugin-web-app-to-rest-api] Fix broken unit test with invalid util m…
Browse files Browse the repository at this point in the history
…ethod invocation
  • Loading branch information
valfirst committed May 31, 2024
1 parent 407b2d6 commit 44785fb
Showing 1 changed file with 13 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ class HeadlessCrawlerTableTransformerTests

private static final String CRAWLING_RELATIVE_URL = "/page";

private static final String OUTGOING_ABSOLUT_URL = "http://some.url/path";
private static final String OUTGOING_RELATIVE_URL = "/path";
private static final String OUTGOING_ABSOLUTE_URL = "http://some.url" + OUTGOING_RELATIVE_URL;

private static final String EXCLUDE_EXTENSIONS_REGEX = "js|css";
private static final String EXCLUDE_URLS_REGEX = ".*broken-link*";
Expand Down Expand Up @@ -129,7 +130,7 @@ void testFetchUrlsSuccessfully(String mainAppPageRelativeUrl, Set<String> seedRe
transformer.setExcludeUrlsRegex(EXCLUDE_URLS_REGEX);
transformer.setMainPageUrlProperty(MAIN_APP_PROP);
Set<String> urls = testFetchUrls(mainAppPageRelativeUrl, expectedSeedRelativeUrls);
assertThat(urls, equalTo(Set.of(OUTGOING_ABSOLUT_URL)));
assertThat(urls, equalTo(Set.of(OUTGOING_ABSOLUTE_URL)));
verifyNoInteractions(redirectsProvider);
assertThat(logger.getLoggingEvents(), is(List.of(getMainAppPageWarn())));
}
Expand All @@ -153,7 +154,7 @@ void shouldFilterUrlsWhenLastRedirectUrlAlreadyInTheSet() throws IOException, In
transformer.setFilterRedirects(true);
transformer.setSeedRelativeUrls(toSet(PATH2, PATH3));
transformer.setMainPageUrlProperty(MAIN_APP_PROP);
URI outgoingURI = URI.create(OUTGOING_ABSOLUT_URL);
URI outgoingURI = URI.create(OUTGOING_ABSOLUTE_URL);
when(redirectsProvider.getRedirects(outgoingURI)).thenReturn(List.of(outgoingURI));
Set<String> urls = testFetchUrls(ROOT, asList(PATH2, SLASH_PATH3));
assertThat(urls, equalTo(Set.of()));
Expand All @@ -167,11 +168,11 @@ void shouldTreatInvalidStatusCodeAsNoRedirects() throws IOException, Interrupted
transformer.setFilterRedirects(true);
transformer.setSeedRelativeUrls(toSet(PATH2, PATH3));
transformer.setMainPageUrlProperty(MAIN_APP_PROP);
URI outgoingURI = URI.create(OUTGOING_ABSOLUT_URL);
URI outgoingURI = URI.create(OUTGOING_ABSOLUTE_URL);
var httpResponseException = new HttpResponseException(HttpStatus.SC_NOT_FOUND, "");
when(redirectsProvider.getRedirects(outgoingURI)).thenThrow(httpResponseException);
Set<String> urls = testFetchUrls(ROOT, List.of(PATH2, SLASH_PATH3));
assertThat(urls, equalTo(Set.of(OUTGOING_ABSOLUT_URL)));
assertThat(urls, equalTo(Set.of(OUTGOING_ABSOLUTE_URL)));
assertThat(logger.getLoggingEvents(), is(List.of(getMainAppPageWarn(), warn(httpResponseException,
"Exception during redirects receiving"))));
}
Expand All @@ -182,10 +183,10 @@ void shouldNotFilterUrlsWhenLastRedirectUrlNotInTheSet() throws IOException, Int
transformer.setFilterRedirects(true);
transformer.setSeedRelativeUrls(toSet(PATH2, PATH3));
transformer.setMainPageUrlProperty(MAIN_APP_PROP);
URI outgoingURI = URI.create(OUTGOING_ABSOLUT_URL);
URI outgoingURI = URI.create(OUTGOING_ABSOLUTE_URL);
when(redirectsProvider.getRedirects(outgoingURI)).thenReturn(List.of(URI.create("http://some.url/other")));
Set<String> urls = testFetchUrls(ROOT, asList(PATH2, SLASH_PATH3));
assertThat(urls, equalTo(Set.of(OUTGOING_ABSOLUT_URL)));
assertThat(urls, equalTo(Set.of(OUTGOING_ABSOLUTE_URL)));
assertThat(logger.getLoggingEvents(), is(List.of(getMainAppPageWarn(),
info(REDIRECT_FILTER_LOG, System.lineSeparator(), "http://some.url/path -> http://some.url/other"))));
}
Expand All @@ -195,7 +196,7 @@ void testFetchUrlsTwice() throws IOException, InterruptedException
{
transformer.setSeedRelativeUrls(toSet(SEED));
Set<String> urls = testFetchUrls(DEFAULT_RELATIVE_URL, List.of(SEED));
assertThat(urls, equalTo(Set.of(OUTGOING_ABSOLUT_URL)));
assertThat(urls, equalTo(Set.of(OUTGOING_ABSOLUTE_URL)));
TableProperties tableProperties = buildTableProperties();
Set<String> urls2 = transformer.fetchUrls(tableProperties);
verifyNoMoreInteractions(crawlControllerFactory);
Expand All @@ -214,10 +215,10 @@ void testFetchUrlsTwiceWithSameProperties() throws IOException, InterruptedExcep
transformer.setSeedRelativeUrls(toSet(seedRelativeUrlsProperty));
Set<String> urls = runUrlFetching(mainAppPage, tableProperties,
List.of(seedRelativeUrlsProperty), crawlController, ordered);
assertThat(urls, equalTo(Set.of(OUTGOING_ABSOLUT_URL)));
assertThat(urls, equalTo(Set.of(OUTGOING_ABSOLUTE_URL)));
Set<String> urls2 = transformer.fetchUrls(tableProperties);
verifyNoMoreInteractions(crawlControllerFactory, crawlController);
assertThat(urls2, equalTo(Set.of(OUTGOING_ABSOLUT_URL)));
assertThat(urls2, equalTo(Set.of(OUTGOING_ABSOLUTE_URL)));
assertSame(urls, urls2);
verifyNoInteractions(redirectsProvider);
}
Expand All @@ -228,7 +229,7 @@ void testFetchUrlsWhenSeedRelativeUrlsAreSetViaConfiguration() throws IOExceptio
String seedRelativeUrl = "/fromConfig";
transformer.setSeedRelativeUrls(Set.of(seedRelativeUrl));
Set<String> urls = testFetchUrls(DEFAULT_RELATIVE_URL, List.of(seedRelativeUrl));
assertThat(urls, equalTo(Set.of(OUTGOING_ABSOLUT_URL)));
assertThat(urls, equalTo(Set.of(OUTGOING_ABSOLUTE_URL)));
verifyNoInteractions(redirectsProvider);
}

Expand Down Expand Up @@ -261,7 +262,7 @@ private Set<String> runUrlFetching(String mainAppPage, TableProperties tableProp
{
LinkCrawler linkCrawler = ((LinkCrawlerFactory) factory).newInstance();
HtmlParseData htmlParseData = new HtmlParseData();
String outgoingUrl = UriUtils.buildNewUrl(mainAppPage, OUTGOING_ABSOLUT_URL).toString();
String outgoingUrl = UriUtils.buildNewUrl(mainAppPage, OUTGOING_RELATIVE_URL).toString();
htmlParseData.setOutgoingUrls(Set.of(createWebUrl(outgoingUrl)));
String crawlingPageUrl = UriUtils.buildNewUrl(mainAppPage, CRAWLING_RELATIVE_URL).toString();
WebURL crawlingPageWebUrl = createWebUrl(crawlingPageUrl);
Expand Down

0 comments on commit 44785fb

Please sign in to comment.