Search in sources :

Example 76 with Capture

use of org.easymock.Capture in project shiro by apache.

the class SimpleFilterChainTest method testDoFilter.

@Test
public void testDoFilter() throws Exception {
    IMocksControl ctrl = createStrictControl();
    FilterChain originalChain = ctrl.createMock(FilterChain.class);
    Filter filter1 = ctrl.createMock("filter1", Filter.class);
    Filter filter2 = ctrl.createMock("filter2", Filter.class);
    ServletRequest request = ctrl.createMock(ServletRequest.class);
    ServletResponse response = ctrl.createMock(ServletResponse.class);
    Capture<FilterChain> fc1 = new Capture<FilterChain>();
    Capture<FilterChain> fc2 = new Capture<FilterChain>();
    filter1.doFilter(same(request), same(response), and(anyObject(FilterChain.class), capture(fc1)));
    filter2.doFilter(same(request), same(response), and(anyObject(FilterChain.class), capture(fc2)));
    originalChain.doFilter(request, response);
    ctrl.replay();
    SimpleFilterChain underTest = new SimpleFilterChain(originalChain, Arrays.asList(filter1, filter2).iterator());
    // all we actually care about is that, if we keep calling the filter chain, everything is called in the right
    // order - we don't care what fc actually contains
    underTest.doFilter(request, response);
    fc1.getValue().doFilter(request, response);
    fc2.getValue().doFilter(request, response);
    ctrl.verify();
}
Also used : IMocksControl(org.easymock.IMocksControl) ServletRequest(javax.servlet.ServletRequest) ServletResponse(javax.servlet.ServletResponse) Filter(javax.servlet.Filter) FilterChain(javax.servlet.FilterChain) Capture(org.easymock.Capture) Test(org.junit.Test)

Example 77 with Capture

use of org.easymock.Capture in project google-gin by gwtplus.

the class BindingResolverTest method testDepHiddenInChildBlocksResolvingInRoot.

public void testDepHiddenInChildBlocksResolvingInRoot() throws Exception {
    GinjectorBindings root = createInjectorNode("root");
    GinjectorBindings child = createInjectorNode("child_module");
    setChildren(root, child);
    bind(baz(), root);
    bind(bar(), child);
    expect(root.isBoundLocallyInChild(bar())).andReturn(true).anyTimes();
    expect(root.getChildWhichBindsLocally(bar())).andReturn(child);
    expectCreateBinding(foo(), required(foo(), bar()), required(foo(), baz()));
    expectCreateBinding(bar());
    Capture<String> errorMessage = new Capture<String>();
    errorManager.logError(isA(String.class), isA(Object.class), capture(errorMessage), // failure to create bar b/c already bound
    isA(Object.class));
    replayAndResolve(root, required(Dependency.GINJECTOR, foo()));
    assertTrue(errorMessage.getValue().contains("child_module"));
}
Also used : GinjectorBindings(com.google.gwt.inject.rebind.GinjectorBindings) Capture(org.easymock.Capture)

Example 78 with Capture

use of org.easymock.Capture in project ribbon by Netflix.

the class EurekaDynamicServerListLoadBalancerTest method testLoadBalancerHappyCase.

@Test
public void testLoadBalancerHappyCase() throws Exception {
    Assert.assertNotEquals("the two test server list counts should be different", secondServerListSize, initialServerListSize);
    DynamicServerListLoadBalancer<DiscoveryEnabledServer> lb = null;
    try {
        Capture<EurekaEventListener> eventListenerCapture = new Capture<EurekaEventListener>();
        eurekaClientMock.registerEventListener(EasyMock.capture(eventListenerCapture));
        PowerMock.replay(DiscoveryClient.class);
        PowerMock.replay(eurekaClientMock);
        // actual testing
        // initial creation and loading of the first serverlist
        lb = new DynamicServerListLoadBalancer<DiscoveryEnabledServer>(config, new AvailabilityFilteringRule(), new DummyPing(), new DiscoveryEnabledNIWSServerList(vipAddress, eurekaClientProvider), new ZoneAffinityServerListFilter<DiscoveryEnabledServer>(), new EurekaNotificationServerListUpdater(eurekaClientProvider));
        Assert.assertEquals(initialServerListSize, lb.getServerCount(false));
        // trigger an eureka CacheRefreshEvent
        eventListenerCapture.getValue().onEvent(new CacheRefreshedEvent());
        Assert.assertTrue(verifyFinalServerListCount(secondServerListSize, lb));
    } finally {
        if (lb != null) {
            lb.shutdown();
            PowerMock.verify(eurekaClientMock);
            PowerMock.verify(DiscoveryClient.class);
        }
    }
}
Also used : DiscoveryEnabledNIWSServerList(com.netflix.niws.loadbalancer.DiscoveryEnabledNIWSServerList) DiscoveryEnabledServer(com.netflix.niws.loadbalancer.DiscoveryEnabledServer) EurekaEventListener(com.netflix.discovery.EurekaEventListener) EurekaNotificationServerListUpdater(com.netflix.niws.loadbalancer.EurekaNotificationServerListUpdater) Capture(org.easymock.Capture) CacheRefreshedEvent(com.netflix.discovery.CacheRefreshedEvent) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 79 with Capture

use of org.easymock.Capture in project ribbon by Netflix.

the class EurekaNotificationServerListUpdaterTest method testTaskAlreadyQueued.

@Test
public void testTaskAlreadyQueued() throws Exception {
    EurekaNotificationServerListUpdater serverListUpdater = new EurekaNotificationServerListUpdater(new Provider<EurekaClient>() {

        @Override
        public EurekaClient get() {
            return eurekaClientMock;
        }
    }, testExecutor);
    try {
        Capture<EurekaEventListener> eventListenerCapture = new Capture<EurekaEventListener>();
        eurekaClientMock.registerEventListener(EasyMock.capture(eventListenerCapture));
        EasyMock.replay(eurekaClientMock);
        final CountDownLatch countDownLatch = new CountDownLatch(1);
        serverListUpdater.start(new ServerListUpdater.UpdateAction() {

            @Override
            public void doUpdate() {
                if (countDownLatch.getCount() == 0) {
                    Assert.fail("should only countdown once");
                }
                countDownLatch.countDown();
            }
        });
        eventListenerCapture.getValue().onEvent(new CacheRefreshedEvent());
        eventListenerCapture.getValue().onEvent(new CacheRefreshedEvent());
        Assert.assertTrue(countDownLatch.await(2, TimeUnit.SECONDS));
        // sleep a bit more
        Thread.sleep(100);
        Assert.assertFalse(serverListUpdater.updateQueued.get());
    } finally {
        serverListUpdater.stop();
        EasyMock.verify(eurekaClientMock);
    }
}
Also used : EurekaClient(com.netflix.discovery.EurekaClient) EurekaEventListener(com.netflix.discovery.EurekaEventListener) CountDownLatch(java.util.concurrent.CountDownLatch) Capture(org.easymock.Capture) ServerListUpdater(com.netflix.loadbalancer.ServerListUpdater) CacheRefreshedEvent(com.netflix.discovery.CacheRefreshedEvent) Test(org.junit.Test)

Aggregations

Capture (org.easymock.Capture)79 Test (org.junit.Test)42 INetworkManagementEventObserver (android.net.INetworkManagementEventObserver)12 File (java.io.File)10 Intent (android.content.Intent)8 IConnectivityManager (android.net.IConnectivityManager)8 INetworkManagementService (android.os.INetworkManagementService)8 TrustedTime (android.util.TrustedTime)8 IAnswer (org.easymock.IAnswer)7 CacheRefreshedEvent (com.netflix.discovery.CacheRefreshedEvent)6 EurekaEventListener (com.netflix.discovery.EurekaEventListener)6 Map (java.util.Map)6 UrlRewriteEnvironment (org.apache.knox.gateway.filter.rewrite.api.UrlRewriteEnvironment)6 UrlRewriteContext (org.apache.knox.gateway.filter.rewrite.spi.UrlRewriteContext)6 OutputStream (java.io.OutputStream)5 HashMap (java.util.HashMap)5 Template (org.apache.knox.gateway.util.urltemplate.Template)5 EurekaClient (com.netflix.discovery.EurekaClient)4 ServerListUpdater (com.netflix.loadbalancer.ServerListUpdater)4 URI (java.net.URI)4