[
https://issues.apache.org/jira/browse/SLING-10937?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Stefan Seifert updated SLING-10937:
-----------------------------------
Summary: Resource in tested Sling Model not equal to Resource it was
adapted from (RESOURCERESOLVER_MOCK) (was: Resource in tested Sling Model not
equal to Resource it was adapted from)
ok, i understand the problem. it should be possible to refactor your test in a
way that it does not rely on the same-check for resources e.g. using
any(Resource.class), but this is probably not the point - it is confusing for
users that it works for JCR_MOCK and the others, but not for
RESOURCERESOLVER_MOCK.
i think a fix like copy ResourceResolverWrapper from the API and somehow trying
to fix the adaptTo method in ResourceREsolverResourceWrapper is not the right
way. the current implementation makes sense - for a resource wrapper. but using
RESOURCERESOLVER_MOCK without explicitly wrapping the code should not return a
resource wrapper.
i think the correct way to go would be:
* implement a ResourceProvider in
sling-org-apache-sling-testing-resourceresolver-mock
* refactor RRMockResourceResolverWrapper to not wrap the existing resource
resolver, but rely only on resource providers that include the new one from
resourceresolver-mock. (we might also start up real sling resourceresolver here
as it is done for JCR_MOCK, but i'm a bit hesitant that this might increase
test run time more than required)
for the time being as a workaround for your test at hand: switch to JCR_MOCK.
> Resource in tested Sling Model not equal to Resource it was adapted from
> (RESOURCERESOLVER_MOCK)
> ------------------------------------------------------------------------------------------------
>
> Key: SLING-10937
> URL: https://issues.apache.org/jira/browse/SLING-10937
> Project: Sling
> Issue Type: Bug
> Components: Testing
> Affects Versions: Testing Sling Mock 3.1.2
> Reporter: Konrad Windszus
> Priority: Major
> Time Spent: 10m
> Remaining Estimate: 0h
>
> The resources returned from
> {{org.apache.sling.testing.mock.sling.RRMockResourceResolverWrapper}} are of
> type {{ResourceResolverResourceWrapper}} (in case the resource providers are
> empty).
> When these resources are adapted to a Sling Model, the injected resource is
> the unwrapped resource which is not equal to the wrapped resource from
> outside.
> This is due to the fact that {{ResourceResolverResourceWrapper.adaptTo(...)}}
> is not overwritten but just delegated to the underlying Resource. That makes
> the Adapter only acting on the unwrapped resource which is not equal to the
> wrapped one.
> This leads to unexpected behaviour when verifying interactions with mocks
> taking the resource as argument, as the wrapped resource is never equal to
> the resource used in the Sling Model given to the mock.
--
This message was sent by Atlassian Jira
(v8.20.1#820001)