use of org.apache.sling.testing.mock.sling.servlet.MockSlingHttpServletResponse in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class SocialMediaHelperImplTest method getSocialMediaHelperUnderTest.
private SocialMediaHelper getSocialMediaHelperUnderTest(String pagePath) {
Resource currentResource = CONTEXT.resourceResolver().getResource(pagePath);
Page currentPage = currentResource.adaptTo(Page.class);
MockSlingHttpServletRequest request = new MockSlingHttpServletRequest(CONTEXT.resourceResolver(), CONTEXT.bundleContext());
MockSlingHttpServletResponse response = new MockSlingHttpServletResponse();
request.setContextPath(CONTEXT_PATH);
request.setResource(currentResource);
MockRequestPathInfo requestPathInfo = (MockRequestPathInfo) request.getRequestPathInfo();
requestPathInfo.setExtension(EXTENSION);
requestPathInfo.setResourcePath(currentResource.getPath());
SlingBindings slingBindings = new SlingBindings();
slingBindings.put(WCMBindings.CURRENT_PAGE, currentPage);
slingBindings.put(SlingBindings.RESOLVER, CONTEXT.resourceResolver());
slingBindings.put(SlingBindings.RESPONSE, response);
request.setAttribute(SlingBindings.class.getName(), slingBindings);
return request.adaptTo(SocialMediaHelper.class);
}
use of org.apache.sling.testing.mock.sling.servlet.MockSlingHttpServletResponse in project sling by apache.
the class MockSling method newSlingScriptHelper.
/**
* Creates a new sling script helper instance using
* {@link #DEFAULT_RESOURCERESOLVER_TYPE} for the resource resolver.
* @param bundleContext Bundle context
* @return Sling script helper instance
*/
public static SlingScriptHelper newSlingScriptHelper(BundleContext bundleContext) {
SlingHttpServletRequest request = new MockSlingHttpServletRequest(newResourceResolver(bundleContext), bundleContext);
SlingHttpServletResponse response = new MockSlingHttpServletResponse();
return newSlingScriptHelper(request, response, bundleContext);
}
use of org.apache.sling.testing.mock.sling.servlet.MockSlingHttpServletResponse in project sling by apache.
the class MockSlingScriptHelperTest method setUp.
@Before
public void setUp() throws Exception {
this.bundleContext = MockOsgi.newBundleContext();
this.resourceResolver = MockSling.newResourceResolver(bundleContext);
this.request = new MockSlingHttpServletRequest(this.resourceResolver, bundleContext);
this.response = new MockSlingHttpServletResponse();
this.scriptHelper = MockSling.newSlingScriptHelper(this.request, this.response, this.bundleContext);
}
use of org.apache.sling.testing.mock.sling.servlet.MockSlingHttpServletResponse in project sling by apache.
the class RatingPostServletTest method successfulSave.
// @Test
public void successfulSave() throws Exception {
Map<String, Object> params = new HashMap<String, Object>();
params.put(RatingsUtil.PROPERTY_RATING, "5");
context.registerService(RatingsService.class, Mockito.mock(RatingsService.class));
RatingPostServlet servlet = context.registerInjectActivateService(new RatingPostServlet());
MockSlingHttpServletRequest request = context.request();
request.setRemoteUser("admin");
request.setParameterMap(params);
request.setResource(context.create().resource(SlingshotConstants.APP_ROOT_PATH + "/content/admin/travel"));
MockSlingHttpServletResponse response = new MockSlingHttpServletResponse();
servlet.doPost(request, response);
assertThat(response.getStatus(), Matchers.equalTo(SC_OK));
String output = response.getOutputAsString();
assertThat(output, equalTo("{ \"rating\" : 0}"));
}
Aggregations