Incorrect resourcePage provided in mocked model using a wrapped resource from another page

Description

When constructing a sling model from a wrapped resource (i.e. ModelFactory#getModelFromWrappedRequest) if the resource provided is from a different page then the "resourcePage" injected into the model does not match the page of the resource provided.

In fact, the resourcePage that is injected into the newly constructed model is the same that was injected into the calling module. It seems like that value is set once per request and is not re-calculated.

This differs from the documented behaviour where the "resourcePage" is always expected to be the page containing the current resource.

This works in an actual AEM instance, the injected "resourcePage" is actually the page that contains the resource. The result is that tests fail when they would actually work correctly in AEM.

Activity

Show:
Stefan Seifert
January 3, 2020, 3:18 PM

thanks for reporting - can you provide a PR with a test case that shows the problematic behavior?
please also specify which way you are using to inject the "resourcePage" object in your model (via wcm.io AEM Sling Models extension or via other ways, e.g. injecting from script variables).

Stefan Seifert
January 22, 2020, 11:22 PM

you've provided the PR https://github.com/wcm-io/wcm-io-testing/pull/14 - thanks!

with the problem i was able to reproduce the problem and implemented a fix in AEM Mocks 3.0.0-SNAPSHOT
it also required a small change in sling-mock (SLING-9021)
with this fix you unit tests runs fine.

Fixed

Assignee

Stefan Seifert

Reporter

Kyle Giovannetti

Labels

None

Components

Fix versions

Priority

Major
Configure