I would like to retrieve the request used to resolve the resources I retrieve from the ResourceResolver.
I am performing integration testing using Teleporter Rule And can resolve the resource but can't find its corresponding request.
@Rule public final TeleporterRule teleporter = TeleporterRule.forClass(getClass(), "Launchpad");
@Test public void testPage() throws LoginException {
ResourceResolverFactory resourceResolverFactory = teleporter.getService(ResourceResolverFactory.class);
ResourceResolver resourceResolver = resourceResolverFactory.getAdministrativeResourceResolver(null);
Resource resource = resourceResolver.getResource("/content/test/en");
PageModel page = resource.adaptTo(PageModel.class);
}
I would like to be able to retrieve the request like I can with my unit tests using SlingContext.
SlingContextImpl slingContext = new SlingContextImpl();
slingContext.currentResource("/content/test/en");
slingContext.request()
I would like to retrieve the request like I can with my unit tests and properly test my sling models that inject the request.
Solved! Go to Solution.
Views
Replies
Total Likes
I think that SlingModels, which only adapt from a Resource, are much more versatile than SlingModels which can only be adapted from a request. Because the adaption works in nearly every case, and not just in the context of a request. It also makes testing much easier.
You can "simulate" a request from javacode, see [1] for an example. It should also work in the context of your IntegrationTests.
Views
Replies
Total Likes
A resourceResolver is not necessarily tied to a request, but every Request does have a ResourceResolver.
Views
Replies
Total Likes
Hi Jorg,
Ok then, if that is the case. What would be the best way to stimulate a request for a server side integration test and receive a SlingHttpServletRequest from which I can retrieve the resource.
Views
Replies
Total Likes
I think that SlingModels, which only adapt from a Resource, are much more versatile than SlingModels which can only be adapted from a request. Because the adaption works in nearly every case, and not just in the context of a request. It also makes testing much easier.
You can "simulate" a request from javacode, see [1] for an example. It should also work in the context of your IntegrationTests.
Views
Replies
Total Likes
Using the requestResponseFactory in conjunction with the request processor is definitely what I would like to do to. The issue is from that approach is that I seem unable to adapt the request to my model afterwards.
Views
Replies
Total Likes
Views
Likes
Replies