Search in sources :

Example 26 with IMocksControl

use of org.easymock.IMocksControl in project gerrit by GerritCodeReview.

the class AllRequestFilterFilterProxyTest method twoFiltersNoBubbling.

@Test
public void twoFiltersNoBubbling() throws Exception {
    EasyMockSupport ems = new EasyMockSupport();
    FilterConfig config = ems.createMock(FilterConfig.class);
    HttpServletRequest req = new FakeHttpServletRequest();
    HttpServletResponse res = new FakeHttpServletResponse();
    IMocksControl mockControl = ems.createStrictControl();
    FilterChain chain = mockControl.createMock(FilterChain.class);
    AllRequestFilter filterA = mockControl.createMock(AllRequestFilter.class);
    AllRequestFilter filterB = mockControl.createMock(AllRequestFilter.class);
    filterA.init(config);
    filterB.init(config);
    filterA.doFilter(eq(req), eq(res), anyObject(FilterChain.class));
    filterA.destroy();
    filterB.destroy();
    ems.replayAll();
    AllRequestFilter.FilterProxy filterProxy = getFilterProxy();
    addFilter(filterA);
    addFilter(filterB);
    filterProxy.init(config);
    filterProxy.doFilter(req, res, chain);
    filterProxy.destroy();
    ems.verifyAll();
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) FakeHttpServletRequest(com.google.gerrit.util.http.testutil.FakeHttpServletRequest) IMocksControl(org.easymock.IMocksControl) EasyMockSupport(org.easymock.EasyMockSupport) FakeHttpServletRequest(com.google.gerrit.util.http.testutil.FakeHttpServletRequest) FakeHttpServletResponse(com.google.gerrit.util.http.testutil.FakeHttpServletResponse) FilterChain(javax.servlet.FilterChain) FakeHttpServletResponse(com.google.gerrit.util.http.testutil.FakeHttpServletResponse) HttpServletResponse(javax.servlet.http.HttpServletResponse) FilterConfig(javax.servlet.FilterConfig) Test(org.junit.Test)

Example 27 with IMocksControl

use of org.easymock.IMocksControl in project gerrit by GerritCodeReview.

the class AllRequestFilterFilterProxyTest method dynamicUnloading.

@Test
public void dynamicUnloading() throws Exception {
    EasyMockSupport ems = new EasyMockSupport();
    FilterConfig config = ems.createMock(FilterConfig.class);
    HttpServletRequest req1 = new FakeHttpServletRequest();
    HttpServletRequest req2 = new FakeHttpServletRequest();
    HttpServletRequest req3 = new FakeHttpServletRequest();
    HttpServletResponse res1 = new FakeHttpServletResponse();
    HttpServletResponse res2 = new FakeHttpServletResponse();
    HttpServletResponse res3 = new FakeHttpServletResponse();
    Plugin plugin = ems.createMock(Plugin.class);
    IMocksControl mockControl = ems.createStrictControl();
    FilterChain chain = mockControl.createMock("chain", FilterChain.class);
    Capture<FilterChain> capturedChainA1 = new Capture<>();
    Capture<FilterChain> capturedChainB1 = new Capture<>();
    Capture<FilterChain> capturedChainB2 = new Capture<>();
    AllRequestFilter filterA = mockControl.createMock("filterA", AllRequestFilter.class);
    AllRequestFilter filterB = mockControl.createMock("filterB", AllRequestFilter.class);
    filterA.init(config);
    filterB.init(config);
    filterA.doFilter(eq(req1), eq(res1), capture(capturedChainA1));
    filterB.doFilter(eq(req1), eq(res1), capture(capturedChainB1));
    chain.doFilter(req1, res1);
    // Cleaning up of filterA after it got unloaded
    filterA.destroy();
    filterB.doFilter(eq(req2), eq(res2), capture(capturedChainB2));
    chain.doFilter(req2, res2);
    // Cleaning up of filterA after it got unloaded
    filterB.destroy();
    chain.doFilter(req3, res3);
    ems.replayAll();
    AllRequestFilter.FilterProxy filterProxy = getFilterProxy();
    ReloadableRegistrationHandle<AllRequestFilter> handleFilterA = addFilter(filterA);
    ReloadableRegistrationHandle<AllRequestFilter> handleFilterB = addFilter(filterB);
    filterProxy.init(config);
    // Request #1 with filterA and filterB
    filterProxy.doFilter(req1, res1, chain);
    capturedChainA1.getValue().doFilter(req1, res1);
    capturedChainB1.getValue().doFilter(req1, res1);
    // Unloading filterA
    handleFilterA.remove();
    filterProxy.onStopPlugin(plugin);
    // Request #1 only with filterB
    filterProxy.doFilter(req2, res2, chain);
    capturedChainA1.getValue().doFilter(req2, res2);
    // Unloading filterB
    handleFilterB.remove();
    filterProxy.onStopPlugin(plugin);
    // Request #1 with no additional filters
    filterProxy.doFilter(req3, res3, chain);
    filterProxy.destroy();
    ems.verifyAll();
}
Also used : EasyMockSupport(org.easymock.EasyMockSupport) FakeHttpServletRequest(com.google.gerrit.util.http.testutil.FakeHttpServletRequest) FilterChain(javax.servlet.FilterChain) FakeHttpServletResponse(com.google.gerrit.util.http.testutil.FakeHttpServletResponse) HttpServletResponse(javax.servlet.http.HttpServletResponse) Capture(org.easymock.Capture) HttpServletRequest(javax.servlet.http.HttpServletRequest) FakeHttpServletRequest(com.google.gerrit.util.http.testutil.FakeHttpServletRequest) IMocksControl(org.easymock.IMocksControl) FakeHttpServletResponse(com.google.gerrit.util.http.testutil.FakeHttpServletResponse) FilterConfig(javax.servlet.FilterConfig) Plugin(com.google.gerrit.server.plugins.Plugin) Test(org.junit.Test)

Example 28 with IMocksControl

use of org.easymock.IMocksControl in project gerrit by GerritCodeReview.

the class AllRequestFilterFilterProxyTest method singleFilterBubbling.

@Test
public void singleFilterBubbling() throws Exception {
    EasyMockSupport ems = new EasyMockSupport();
    FilterConfig config = ems.createMock(FilterConfig.class);
    HttpServletRequest req = new FakeHttpServletRequest();
    HttpServletResponse res = new FakeHttpServletResponse();
    IMocksControl mockControl = ems.createStrictControl();
    FilterChain chain = mockControl.createMock(FilterChain.class);
    Capture<FilterChain> capturedChain = new Capture<>();
    AllRequestFilter filter = mockControl.createMock(AllRequestFilter.class);
    filter.init(config);
    filter.doFilter(eq(req), eq(res), capture(capturedChain));
    chain.doFilter(req, res);
    filter.destroy();
    ems.replayAll();
    AllRequestFilter.FilterProxy filterProxy = getFilterProxy();
    addFilter(filter);
    filterProxy.init(config);
    filterProxy.doFilter(req, res, chain);
    capturedChain.getValue().doFilter(req, res);
    filterProxy.destroy();
    ems.verifyAll();
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) FakeHttpServletRequest(com.google.gerrit.util.http.testutil.FakeHttpServletRequest) IMocksControl(org.easymock.IMocksControl) EasyMockSupport(org.easymock.EasyMockSupport) FakeHttpServletRequest(com.google.gerrit.util.http.testutil.FakeHttpServletRequest) FakeHttpServletResponse(com.google.gerrit.util.http.testutil.FakeHttpServletResponse) FilterChain(javax.servlet.FilterChain) FakeHttpServletResponse(com.google.gerrit.util.http.testutil.FakeHttpServletResponse) HttpServletResponse(javax.servlet.http.HttpServletResponse) FilterConfig(javax.servlet.FilterConfig) Capture(org.easymock.Capture) Test(org.junit.Test)

Example 29 with IMocksControl

use of org.easymock.IMocksControl in project gerrit by GerritCodeReview.

the class AllRequestFilterFilterProxyTest method twoFiltersBubbling.

@Test
public void twoFiltersBubbling() throws Exception {
    EasyMockSupport ems = new EasyMockSupport();
    FilterConfig config = ems.createMock(FilterConfig.class);
    HttpServletRequest req = new FakeHttpServletRequest();
    HttpServletResponse res = new FakeHttpServletResponse();
    IMocksControl mockControl = ems.createStrictControl();
    FilterChain chain = mockControl.createMock(FilterChain.class);
    Capture<FilterChain> capturedChainA = new Capture<>();
    Capture<FilterChain> capturedChainB = new Capture<>();
    AllRequestFilter filterA = mockControl.createMock(AllRequestFilter.class);
    AllRequestFilter filterB = mockControl.createMock(AllRequestFilter.class);
    filterA.init(config);
    filterB.init(config);
    filterA.doFilter(eq(req), eq(res), capture(capturedChainA));
    filterB.doFilter(eq(req), eq(res), capture(capturedChainB));
    chain.doFilter(req, res);
    filterA.destroy();
    filterB.destroy();
    ems.replayAll();
    AllRequestFilter.FilterProxy filterProxy = getFilterProxy();
    addFilter(filterA);
    addFilter(filterB);
    filterProxy.init(config);
    filterProxy.doFilter(req, res, chain);
    capturedChainA.getValue().doFilter(req, res);
    capturedChainB.getValue().doFilter(req, res);
    filterProxy.destroy();
    ems.verifyAll();
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) FakeHttpServletRequest(com.google.gerrit.util.http.testutil.FakeHttpServletRequest) IMocksControl(org.easymock.IMocksControl) EasyMockSupport(org.easymock.EasyMockSupport) FakeHttpServletRequest(com.google.gerrit.util.http.testutil.FakeHttpServletRequest) FakeHttpServletResponse(com.google.gerrit.util.http.testutil.FakeHttpServletResponse) FilterChain(javax.servlet.FilterChain) FakeHttpServletResponse(com.google.gerrit.util.http.testutil.FakeHttpServletResponse) HttpServletResponse(javax.servlet.http.HttpServletResponse) FilterConfig(javax.servlet.FilterConfig) Capture(org.easymock.Capture) Test(org.junit.Test)

Example 30 with IMocksControl

use of org.easymock.IMocksControl in project roboguice by roboguice.

the class ContextPathTest method runTest.

private void runTest(final String requestURI, final String servletPath, final String contextPath, final boolean filterResult, final boolean fooResult, final boolean barResult) throws Exception {
    IMocksControl testControl = createControl();
    barServlet.clear();
    fooServlet.clear();
    TestFilterChain testFilterChain = new TestFilterChain();
    HttpServletRequest req = testControl.createMock(HttpServletRequest.class);
    HttpServletResponse res = testControl.createMock(HttpServletResponse.class);
    expect(req.getMethod()).andReturn("GET").anyTimes();
    expect(req.getRequestURI()).andReturn(requestURI).anyTimes();
    expect(req.getServletPath()).andReturn(servletPath).anyTimes();
    expect(req.getContextPath()).andReturn(contextPath).anyTimes();
    testControl.replay();
    guiceFilter.doFilter(req, res, testFilterChain);
    assertEquals(filterResult, testFilterChain.isTriggered());
    assertEquals(fooResult, fooServlet.isTriggered());
    assertEquals(barResult, barServlet.isTriggered());
    testControl.verify();
}
Also used : IMocksControl(org.easymock.IMocksControl) HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpServletResponse(javax.servlet.http.HttpServletResponse)

Aggregations

IMocksControl (org.easymock.IMocksControl)57 Test (org.junit.Test)34 HttpServletRequest (javax.servlet.http.HttpServletRequest)11 Message (org.apache.cxf.message.Message)11 HttpServletResponse (javax.servlet.http.HttpServletResponse)9 MessageImpl (org.apache.cxf.message.MessageImpl)9 QName (javax.xml.namespace.QName)7 BindingFactoryManager (org.apache.cxf.binding.BindingFactoryManager)7 Before (org.junit.Before)7 ArrayList (java.util.ArrayList)6 HashSet (java.util.HashSet)6 Set (java.util.Set)6 Exchange (org.apache.cxf.message.Exchange)6 FakeHttpServletRequest (com.google.gerrit.util.http.testutil.FakeHttpServletRequest)5 FakeHttpServletResponse (com.google.gerrit.util.http.testutil.FakeHttpServletResponse)5 IOException (java.io.IOException)5 HashMap (java.util.HashMap)5 Binding (javax.xml.ws.Binding)5 Handler (javax.xml.ws.handler.Handler)5 MessageContext (javax.xml.ws.handler.MessageContext)5