Class AssetResolutionAssert

java.lang.Object
org.apache.juneau.console.test.AssetResolutionAssert

public final class AssetResolutionAssert extends Object
Test helper that checks every asset a rendered console page links (stylesheets, scripts, images, icons) actually resolves.

The console chrome links its assets at context-root URLs such as /juneau-console/chrome.css, so they only load if the host mounts something at those paths. Page tests that assert the hrefs cannot see a missing mount; this helper fetches each URL through whatever client the caller supplies and reports every one that does not answer 200.

The fetcher is a plain Function from URL to HTTP status, so the class has no dependency on a test framework or on a particular client. Failures throw AssertionError. Only same-origin URLs are checked: absolute http(s):, protocol-relative, data: and fragment-only URLs are skipped.

Example:

MockRestClient client = MockRestClient.buildLax(MyHost.class); String html = client.get("/page").run().getContent().asString(); AssetResolutionAssert.assertAssetsResolve(html, url -> client.get(url).run().getStatusCode());

Since:
10.0.0
  • Method Details

    • assetUrls

      public static List<String> assetUrls(String html)
      Returns the same-origin asset URLs a page links, in document order and without duplicates.

      Covers <script src>, <img src> and <link href> whose rel is a stylesheet, icon, preload or manifest. &amp; is decoded and any fragment is dropped.

      Parameters:
      html - The rendered page.
      Returns:
      The asset URLs. Never null.
    • unresolved

      public static List<String> unresolved(String html, Function<String,Integer> statusOf)
      Returns a description of every linked asset that does not answer 200.
      Parameters:
      html - The rendered page.
      statusOf - Fetches a URL and returns its HTTP status code.
      Returns:
      One "<status> <url>" entry per failing asset, sorted; empty when every asset resolves.
    • assertAssetsResolve

      public static void assertAssetsResolve(String html, Function<String,Integer> statusOf)
      Asserts that every asset the page links answers 200.
      Parameters:
      html - The rendered page.
      statusOf - Fetches a URL and returns its HTTP status code.
      Throws:
      AssertionError - If any linked asset does not resolve; the message lists each one.
    • assertAssetsResolve

      public static void assertAssetsResolve(String page, String html, Function<String,Integer> statusOf)
      Asserts that every asset the page links answers 200, naming the page in the failure message.
      Parameters:
      page - A label for the page (typically its path); can be null.
      html - The rendered page.
      statusOf - Fetches a URL and returns its HTTP status code.
      Throws:
      AssertionError - If any linked asset does not resolve; the message lists each one.