use of org.apache.sling.servlethelpers.MockRequestDispatcherFactory in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class AmpModeForwardFilterTest method testFilteringWithoutAmpSelector.
@Test
void testFilteringWithoutAmpSelector() throws IOException, ServletException {
context.request().setRequestDispatcherFactory(new MockRequestDispatcherFactory() {
@Override
public RequestDispatcher getRequestDispatcher(String path, RequestDispatcherOptions options) {
return null;
}
@Override
public RequestDispatcher getRequestDispatcher(Resource resource, RequestDispatcherOptions options) {
return new MockRequestDispatcher(options);
}
});
context.currentPage(AMP_SELECTOR);
context.requestPathInfo().setSelectorString("campaign.content");
context.requestPathInfo().setExtension("html");
spyAmpModeForwardFilter.doFilter(context.request(), context.response(), filterChain);
}
use of org.apache.sling.servlethelpers.MockRequestDispatcherFactory in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class AmpModeForwardFilterTest method setUp.
@BeforeEach
void setUp() {
// use spy to verify the filter
spyAmpModeForwardFilter = Mockito.spy(new AmpModeForwardFilter());
filterChain = mock(FilterChain.class);
MockRequestDispatcherFactory mockRequestDispatcherFactory = new MockRequestDispatcherFactory() {
@Override
public RequestDispatcher getRequestDispatcher(String s, RequestDispatcherOptions requestDispatcherOptions) {
return mock(RequestDispatcher.class);
}
@Override
public RequestDispatcher getRequestDispatcher(Resource resource, RequestDispatcherOptions requestDispatcherOptions) {
return mock(RequestDispatcher.class);
}
};
context.request().setRequestDispatcherFactory(mockRequestDispatcherFactory);
context.load().json(TEST_BASE + AmpTestContext.TEST_CONTENT_JSON, TEST_ROOT_PAGE);
}
use of org.apache.sling.servlethelpers.MockRequestDispatcherFactory in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class OptionsImplTest method getOptionsUnderTest.
private Options getOptionsUnderTest(String resourcePath) {
Resource resource = context.resourceResolver().getResource(resourcePath);
if (resource == null) {
throw new IllegalStateException("Did you forget to define test resource " + resourcePath + "?");
}
MockSlingHttpServletRequest request = new MockSlingHttpServletRequest(context.resourceResolver(), context.bundleContext());
MockSlingHttpServletResponse response = new MockSlingHttpServletResponse();
request.setResource(resource);
SlingBindings bindings = new SlingBindings();
bindings.put(SlingBindings.RESOURCE, resource);
bindings.put(SlingBindings.REQUEST, request);
bindings.put(SlingBindings.RESOLVER, context.resourceResolver());
bindings.put(SlingBindings.RESPONSE, response);
bindings.put(WCMBindings.PROPERTIES, resource.getValueMap());
request.setAttribute(SlingBindings.class.getName(), bindings);
request.setRequestDispatcherFactory(new MockRequestDispatcherFactory() {
@Override
public RequestDispatcher getRequestDispatcher(String s, RequestDispatcherOptions requestDispatcherOptions) {
return null;
}
@Override
public RequestDispatcher getRequestDispatcher(Resource resource, RequestDispatcherOptions requestDispatcherOptions) {
return new MockRequestDispatcher(requestDispatcherOptions);
}
});
return request.adaptTo(Options.class);
}
Aggregations