Skip to content

Add higher-fidelity page-serialization tests (#456 follow-up) #460

@tkuhn

Description

@tkuhn

Follow-up to #456 (merged in PR #457).

PR #457 added two cheap guard tests: a render-strategy assertion in WicketApplicationTest, and reflection-based field-architecture tests in SpacePageTest / MaintainedResourcePageTest. Three higher-fidelity tests were discussed but not added because they involve more setup. Filing here so we don't lose them.

1. LDM serialization round-trip

Build a LoadableDetachableModel<Space> exactly like the one in SpacePage, mock SpaceRepository.findById to return distinct objects across two calls, and assert:

  • getObject() returns the first instance.
  • After detach(), getObject() returns the second instance — i.e. it actually re-loads.
  • After Java serialization round-trip, the previously-loaded instance is not reachable from the deserialized model.

Pins the contract that the LDM doesn't smuggle a snapshot into the page store.

2. WicketTester page-store round-trip (closest thing to F5 in a test)

WicketTester tester = new WicketTester(new WicketApplication());
// mock SpaceRepository.findById(...) to return a Space stub
tester.startPage(SpacePage.class, new PageParameters().set("id", "https://w3id.org/spaces/test"));
tester.assertRenderedPage(SpacePage.class);

Page p = tester.getLastRenderedPage();
byte[] bytes = SerializationUtils.serialize(p);
SpacePage restored = (SpacePage) SerializationUtils.deserialize(bytes);
// mutate the mocked Space's label, then detach + re-render and assert HTML reflects the *new* label

Higher cost (needs SpaceRepository / MaintainedResourceRepository stubbing — MockedStatic from Mockito works, see DownloadRdfPageTest.RetrieveResponseWithWaitTest for a pattern). But this is the test that would have caught the original regression behind #401.

3. SerializationCheckerObjectOutputStream smoke

Wicket ships a debug serialization checker that fails fast on non-serializable references in a page tree. Wire it up once in a test that constructs each touched page; catches accidental non-serializable captures (e.g. anonymous inner class holding a non-Serializable) at test time instead of runtime.

Priority

Medium. #1 and #3 are cheap and high-leverage. #2 has the highest fidelity but requires more scaffolding.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels
    No fields configured for Feature.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions