Class PageContractAssert
#juneau-page contract and <template> ids from a
rendered console page, validates them against PageContractSchema, and offers fluent
assertions so adopters assert on the contract instead of on rendered chrome HTML.
Failures throw AssertionError, so the class works under any test framework.
assertPage(String) also fails immediately if the contract still carries the pre-rename top-level
isValid() is never called.
Example:
String
- Since:
- 10.0.0
-
Method Summary
Modifier and TypeMethodDescriptionstatic PageContractAssertassertPage(String html) Parses the contract and templates out of a rendered page.static voidassertTwins(Map<?, ?> contract, Map<String, String> templates, Map<?, ?> otherContract, Map<String, String> otherTemplates) Asserts two contract and template pairs are twins, asisTwinOf(PageContractAssert)does.contract()Escape hatch for asserts this class does not offer.declaresTopic(String topic) hasActiveNav(String... idPath) hasCardKey(String id, String jsonPointer, Object expected) hasCardOrder(String... ids) hasCardSrc(String id, String src) hasFooterSlot(String name) hasHeaderSlot(String name) hasNavChildren(String idPath, String... childIds) hasNavHref(String id, String href) hasNavPath(String... idPath) AssertsactiveNavis empty (the JS prefix fallback applies).Runs R-10 and R-11 against the standard card-type registry.hasNoWiringErrors(CardTypeRegistry registry) isTwinOf(PageContractAssert other) Asserts this page and another render the same contract and the same template markup.isValid()Asserts the contract passes the schema and rules R-1..R-4.subscribes(String cardId, String topic) subscribes(String cardId, String topic, String role) templateContains(String templateId, String fragment)
-
Method Details
-
assertPage
Parses the contract and templates out of a rendered page.- Parameters:
html- The full rendered page.- Returns:
- A new assertion object.
- Throws:
AssertionError- If the page has no parseable contract island.
-
isValid
Asserts the contract passes the schema and rules R-1..R-4.- Returns:
- This object.
-
hasContractVersion
- Parameters:
v- The expected contract version. @return This object.
-
hasTitle
- Parameters:
v- The expected page title. @return This object.
-
hasTheme
- Parameters:
name- The expected theme name. @return This object.
-
hasHeaderTitle
- Parameters:
v- The expectedheader.title. @return This object.
-
hasHeaderSlot
- Parameters:
name- A header slot name (brand,actions,replace,banner). @return This object.
-
hasCard
- Parameters:
id- The card id.type- The expected card type.- Returns:
- This object.
-
hasCardOrder
- Parameters:
ids- The expected card ids, in contract order. @return This object.
-
subscribes
- Parameters:
cardId- The card id. @param topic A topic the card must subscribe to. @return This object.
-
subscribes
- Parameters:
cardId- The card id.topic- A topic the card must subscribe to.role- The role it must be wired to.- Returns:
- This object.
-
publishes
- Parameters:
cardId- The card id. @param topic A custom topic the card must declare inpublishes. @return This object.
-
declaresTopic
- Parameters:
topic- A top-leveltopicsentry that must exist. @return This object.
-
hasBridge
- Parameters:
id- A top-levelbridgesid that must exist. @return This object.
-
hasNoWiringErrors
Runs R-10 and R-11 against the standard card-type registry. Pair it withBusPolicy.check(contract())(juneau-console-bus) for the server-grant side (E-55). A page with custom card types needs thehasNoWiringErrors(CardTypeRegistry)overload with the registry that knows them.- Returns:
- This object.
-
hasNoWiringErrors
- Parameters:
registry- The registry that knows the page's card types. @return This object.
-
hasCardSrc
- Parameters:
id- The card id.src- The expectedsrcvalue.- Returns:
- This object.
-
hasCardKey
- Parameters:
id- The card id.jsonPointer- A/-separated path into the card's JSON, for example"/table/dataUrl".expected- The expected value at that path.- Returns:
- This object.
-
templateContains
- Parameters:
templateId- Adata-cardordata-slottemplate id.fragment- Markup that must appear in the template.- Returns:
- This object.
-
isTwinOf
Asserts this page and another render the same contract and the same template markup.Use it to prove two ways of producing a page (for example a hand-written template and its builder twin) agree. The contracts are compared as key-sorted JSON; list order is kept, because card, nav and option order is part of the page. Templates are compared by id on their stripped markup, so the whitespace a template author's layout puts around a card body does not count.
The failure message names the first difference, for example
page contracts differ at $.cards[0].bare: this=true other=false.- Parameters:
other- The page this one must equal.- Returns:
- This object.
-
assertTwins
public static void assertTwins(Map<?, ?> contract, Map<String, String> templates, Map<?, ?> otherContract, Map<String, String> otherTemplates) Asserts two contract and template pairs are twins, asisTwinOf(PageContractAssert)does.Exposed so a test that must first adjust either side (for example remove a card known to differ) can still use the shared comparison.
- Parameters:
contract- The first contract.templates- The first page's templates, by id.otherContract- The second contract.otherTemplates- The second page's templates, by id.- Throws:
AssertionError- If the contracts or templates differ.
-
contract
Escape hatch for asserts this class does not offer.- Returns:
- The parsed contract.
-
templates
- Returns:
- Every
<template data-card|data-slot>id mapped to its inner markup, in document order.
-
template
- Parameters:
templateId- Adata-cardordata-slottemplate id.- Returns:
- The template's inner markup.
-
card
- Parameters:
id- The card id.- Returns:
- The card's parsed JSON.
-