Search in sources :

Example 1 with DoAllAction

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);
}
Also used : Expectations(org.jmock.Expectations) DoAllAction(org.jmock.lib.action.DoAllAction) Dictionary(java.util.Dictionary) HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletRequest(javax.servlet.ServletRequest) HttpServletResponse(javax.servlet.http.HttpServletResponse) ServletResponse(javax.servlet.ServletResponse) DoAllAction(org.jmock.lib.action.DoAllAction) Action(org.jmock.api.Action) Description(org.hamcrest.Description) ServiceListener(org.osgi.framework.ServiceListener) Invocation(org.jmock.api.Invocation) HashMap(java.util.HashMap) ServiceReference(org.osgi.framework.ServiceReference) StringWriter(java.io.StringWriter) Filter(javax.servlet.Filter) BundleContext(org.osgi.framework.BundleContext) PrintWriter(java.io.PrintWriter)

Aggregations

PrintWriter (java.io.PrintWriter)1 StringWriter (java.io.StringWriter)1 Dictionary (java.util.Dictionary)1 HashMap (java.util.HashMap)1 Filter (javax.servlet.Filter)1 ServletRequest (javax.servlet.ServletRequest)1 ServletResponse (javax.servlet.ServletResponse)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 Description (org.hamcrest.Description)1 Expectations (org.jmock.Expectations)1 Action (org.jmock.api.Action)1 Invocation (org.jmock.api.Invocation)1 DoAllAction (org.jmock.lib.action.DoAllAction)1 BundleContext (org.osgi.framework.BundleContext)1 ServiceListener (org.osgi.framework.ServiceListener)1 ServiceReference (org.osgi.framework.ServiceReference)1