use of org.jmock.lib.action.DoAllAction in project sling by apache.
the class StartupFilterImplTest method setProvider.
private void setProvider(final TestProvider provider) throws Exception {
final BundleContext bundleContext = mockery.mock(BundleContext.class);
final Action storeStatus = new Action() {
@Override
public void describeTo(Description d) {
d.appendText("Store HTTP response values");
}
@Override
public Object invoke(Invocation invocation) throws Throwable {
lastReturnedStatus = (Integer) invocation.getParameter(0);
return null;
}
};
messageWriter = new StringWriter();
final PrintWriter responseWriter = new PrintWriter(messageWriter);
final Map<String, Object> props = new HashMap<String, Object>();
props.put(StartupFilterImpl.ACTIVE_BY_DEFAULT_PROP, Boolean.TRUE);
final ServiceReference[] providerRefs = provider == null ? null : new ServiceReference[] { provider };
mockery.checking(new Expectations() {
{
allowing(bundleContext).createFilter(with(any(String.class)));
allowing(bundleContext).addServiceListener(with(any(ServiceListener.class)));
allowing(bundleContext).addServiceListener(with(any(ServiceListener.class)), with(any(String.class)));
allowing(bundleContext).getServiceReferences(StartupInfoProvider.class.getName(), null);
will(returnValue(providerRefs));
allowing(bundleContext).getService(with(any(ServiceReference.class)));
will(returnValue(provider));
allowing(bundleContext).getProperty(with("felix.webconsole.manager.root"));
will(returnValue(CONSOLE_ROOT));
allowing(bundleContext).registerService(with(equal(Filter.class)), with(any(Filter.class)), with(any(Dictionary.class)));
will(new DoAllAction(new ChangeInteger(activeFilterCount, true), returnValue(serviceRegistration)));
allowing(response).setStatus((with(any(Integer.class))));
will(storeStatus);
allowing(response).setContentType("text/plain");
allowing(response).getWriter();
will(returnValue(responseWriter));
allowing(response).setCharacterEncoding(with(any(String.class)));
allowing(serviceRegistration).unregister();
will(new ChangeInteger(activeFilterCount, false));
allowing(request).getServletPath();
will(returnValue(""));
allowing(request).getPathInfo();
will(returnValue(getPathInfo()));
allowing(chain).doFilter(with(any(ServletRequest.class)), with(any(ServletResponse.class)));
}
});
filter.setup(bundleContext, props);
}
Aggregations