Search in sources :

Example 1 with SlingRequestStatusHealthCheck

use of org.apache.sling.hc.support.impl.SlingRequestStatusHealthCheck in project sling by apache.

the class SlingRequestStatusHealthCheckTest method setup.

@Before
public void setup() throws Exception {
    hc = new SlingRequestStatusHealthCheck();
    final ResourceResolverFactory rrf = Mockito.mock(ResourceResolverFactory.class);
    SetField.set(hc, "resolverFactory", rrf);
    final Answer<Void> a = new Answer<Void>() {

        @Override
        public Void answer(InvocationOnMock invocation) {
            final HttpServletRequest request = (HttpServletRequest) invocation.getArguments()[0];
            final HttpServletResponse response = (HttpServletResponse) invocation.getArguments()[1];
            final String path = request.getPathInfo();
            if (path.length() > 0) {
                final String status = path.substring(0, path.indexOf('.'));
                response.setStatus(Integer.valueOf(status));
            }
            return null;
        }
    };
    final SlingRequestProcessor srp = Mockito.mock(SlingRequestProcessor.class);
    SetField.set(hc, "requestProcessor", srp);
    Mockito.doAnswer(a).when(srp).processRequest(Matchers.any(HttpServletRequest.class), Matchers.any(HttpServletResponse.class), Matchers.any(ResourceResolver.class));
    final Map<String, Object> properties = new HashMap<String, Object>();
    properties.put("path", paths);
    hc.activate(properties);
}
Also used : HashMap(java.util.HashMap) SlingRequestProcessor(org.apache.sling.engine.SlingRequestProcessor) HttpServletResponse(javax.servlet.http.HttpServletResponse) HttpServletRequest(javax.servlet.http.HttpServletRequest) Answer(org.mockito.stubbing.Answer) SlingRequestStatusHealthCheck(org.apache.sling.hc.support.impl.SlingRequestStatusHealthCheck) ResourceResolverFactory(org.apache.sling.api.resource.ResourceResolverFactory) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ResourceResolver(org.apache.sling.api.resource.ResourceResolver) Before(org.junit.Before)

Aggregations

HashMap (java.util.HashMap)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 ResourceResolver (org.apache.sling.api.resource.ResourceResolver)1 ResourceResolverFactory (org.apache.sling.api.resource.ResourceResolverFactory)1 SlingRequestProcessor (org.apache.sling.engine.SlingRequestProcessor)1 SlingRequestStatusHealthCheck (org.apache.sling.hc.support.impl.SlingRequestStatusHealthCheck)1 Before (org.junit.Before)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1 Answer (org.mockito.stubbing.Answer)1