Search in sources :

Example 41 with Capture

use of org.easymock.Capture 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 42 with Capture

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

the class ReflectionUtilsTest method before.

@BeforeClass
public static void before() throws ClassNotFoundException {
    mockBlueprint = EasyMock.createNiceMock(ExtendedBlueprintContainer.class);
    final Capture<String> nameCapture = new Capture<String>();
    EasyMock.expect(mockBlueprint.loadClass(EasyMock.capture(nameCapture))).andAnswer(new IAnswer<Class<?>>() {

        public Class<?> answer() throws Throwable {
            return Thread.currentThread().getContextClassLoader().loadClass(nameCapture.getValue());
        }
    });
    EasyMock.replay(mockBlueprint);
    ExecutionContext.Holder.setContext(new ExecutionContext() {

        public void addPartialObject(String name, Object object) {
        }

        public boolean containsObject(String name) {
            return false;
        }

        public Object convert(Object value, ReifiedType type) throws Exception {
            if (type.getRawClass().equals(Inconvertible.class))
                throw new Exception();
            else if (type.getRawClass().equals(String.class))
                return String.valueOf(value);
            else if (type.getRawClass().equals(List.class)) {
                if (value == null)
                    return null;
                else if (value instanceof Collection)
                    return new ArrayList((Collection) value);
                else
                    throw new Exception();
            } else if (value == null)
                return null;
            else if (type.getRawClass().isInstance(value))
                return value;
            else
                throw new Exception();
        }

        public boolean canConvert(Object value, ReifiedType type) {
            if (value instanceof Inconvertible)
                return false;
            else if (type.getRawClass().equals(String.class))
                return true;
            else if (type.getRawClass().equals(List.class) && (value == null || value instanceof Collection))
                return true;
            else
                return false;
        }

        public Object getObject(String name) {
            return null;
        }

        public Object getPartialObject(String name) {
            return null;
        }

        public Recipe getRecipe(String name) {
            return null;
        }

        public Class loadClass(String className) throws ClassNotFoundException {
            return null;
        }

        public Recipe pop() {
            return null;
        }

        public void push(Recipe recipe) throws CircularDependencyException {
        }

        public void removePartialObject(String name) {
        }

        public Future<Object> addFullObject(String name, Future<Object> object) {
            return null;
        }
    });
}
Also used : Recipe(org.apache.aries.blueprint.di.Recipe) ReifiedType(org.osgi.service.blueprint.container.ReifiedType) ArrayList(java.util.ArrayList) Capture(org.easymock.Capture) CircularDependencyException(org.apache.aries.blueprint.di.CircularDependencyException) ComponentDefinitionException(org.osgi.service.blueprint.container.ComponentDefinitionException) ExecutionContext(org.apache.aries.blueprint.di.ExecutionContext) Collection(java.util.Collection) Future(java.util.concurrent.Future) BeforeClass(org.junit.BeforeClass) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) ExtendedBlueprintContainer(org.apache.aries.blueprint.services.ExtendedBlueprintContainer) CircularDependencyException(org.apache.aries.blueprint.di.CircularDependencyException) BeforeClass(org.junit.BeforeClass)

Example 43 with Capture

use of org.easymock.Capture in project android_frameworks_base by crdroidandroid.

the class NetworkStatsServiceTest method testStatsRebootPersist.

public void testStatsRebootPersist() throws Exception {
    assertStatsFilesExist(false);
    // pretend that wifi network comes online; service should ask about full
    // network state, and poll any existing interfaces before updating.
    expectCurrentTime();
    expectDefaultSettings();
    expectNetworkState(buildWifiState());
    expectNetworkStatsSummary(buildEmptyStats());
    expectNetworkStatsUidDetail(buildEmptyStats());
    expectNetworkStatsPoll();
    expectBandwidthControlCheck();
    replay();
    mService.forceUpdateIfaces();
    // verify service has empty history for wifi
    assertNetworkTotal(sTemplateWifi, 0L, 0L, 0L, 0L, 0);
    verifyAndReset();
    // modify some number on wifi, and trigger poll event
    incrementCurrentTime(HOUR_IN_MILLIS);
    expectCurrentTime();
    expectDefaultSettings();
    expectNetworkStatsSummary(new NetworkStats(getElapsedRealtime(), 1).addIfaceValues(TEST_IFACE, 1024L, 8L, 2048L, 16L));
    expectNetworkStatsUidDetail(new NetworkStats(getElapsedRealtime(), 2).addValues(TEST_IFACE, UID_RED, SET_DEFAULT, TAG_NONE, 512L, 4L, 256L, 2L, 0L).addValues(TEST_IFACE, UID_RED, SET_DEFAULT, 0xFAAD, 256L, 2L, 128L, 1L, 0L).addValues(TEST_IFACE, UID_RED, SET_FOREGROUND, TAG_NONE, 512L, 4L, 256L, 2L, 0L).addValues(TEST_IFACE, UID_RED, SET_FOREGROUND, 0xFAAD, 256L, 2L, 128L, 1L, 0L).addValues(TEST_IFACE, UID_BLUE, SET_DEFAULT, TAG_NONE, 128L, 1L, 128L, 1L, 0L));
    expectNetworkStatsPoll();
    mService.setUidForeground(UID_RED, false);
    mService.incrementOperationCount(UID_RED, 0xFAAD, 4);
    mService.setUidForeground(UID_RED, true);
    mService.incrementOperationCount(UID_RED, 0xFAAD, 6);
    replay();
    forcePollAndWaitForIdle();
    // verify service recorded history
    assertNetworkTotal(sTemplateWifi, 1024L, 8L, 2048L, 16L, 0);
    assertUidTotal(sTemplateWifi, UID_RED, 1024L, 8L, 512L, 4L, 10);
    assertUidTotal(sTemplateWifi, UID_RED, SET_DEFAULT, ROAMING_NO, 512L, 4L, 256L, 2L, 4);
    assertUidTotal(sTemplateWifi, UID_RED, SET_FOREGROUND, ROAMING_NO, 512L, 4L, 256L, 2L, 6);
    assertUidTotal(sTemplateWifi, UID_BLUE, 128L, 1L, 128L, 1L, 0);
    verifyAndReset();
    // graceful shutdown system, which should trigger persist of stats, and
    // clear any values in memory.
    expectCurrentTime();
    expectDefaultSettings();
    replay();
    mServiceContext.sendBroadcast(new Intent(Intent.ACTION_SHUTDOWN));
    verifyAndReset();
    assertStatsFilesExist(true);
    // boot through serviceReady() again
    expectCurrentTime();
    expectDefaultSettings();
    expectNetworkStatsUidDetail(buildEmptyStats());
    expectSystemReady();
    // catch INetworkManagementEventObserver during systemReady()
    final Capture<INetworkManagementEventObserver> networkObserver = new Capture<INetworkManagementEventObserver>();
    mNetManager.registerObserver(capture(networkObserver));
    expectLastCall().atLeastOnce();
    replay();
    mService.systemReady();
    mNetworkObserver = networkObserver.getValue();
    // after systemReady(), we should have historical stats loaded again
    assertNetworkTotal(sTemplateWifi, 1024L, 8L, 2048L, 16L, 0);
    assertUidTotal(sTemplateWifi, UID_RED, 1024L, 8L, 512L, 4L, 10);
    assertUidTotal(sTemplateWifi, UID_RED, SET_DEFAULT, ROAMING_NO, 512L, 4L, 256L, 2L, 4);
    assertUidTotal(sTemplateWifi, UID_RED, SET_FOREGROUND, ROAMING_NO, 512L, 4L, 256L, 2L, 6);
    assertUidTotal(sTemplateWifi, UID_BLUE, 128L, 1L, 128L, 1L, 0);
    verifyAndReset();
}
Also used : NetworkStats(android.net.NetworkStats) INetworkManagementEventObserver(android.net.INetworkManagementEventObserver) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) Capture(org.easymock.Capture)

Aggregations

Capture (org.easymock.Capture)43 Test (org.junit.Test)19 INetworkManagementEventObserver (android.net.INetworkManagementEventObserver)12 Intent (android.content.Intent)8 IConnectivityManager (android.net.IConnectivityManager)8 INetworkManagementService (android.os.INetworkManagementService)8 TrustedTime (android.util.TrustedTime)8 CacheRefreshedEvent (com.netflix.discovery.CacheRefreshedEvent)6 EurekaEventListener (com.netflix.discovery.EurekaEventListener)6 ByteString (com.linkedin.data.ByteString)5 CountDownLatch (java.util.concurrent.CountDownLatch)5 Callback (com.linkedin.common.callback.Callback)4 EurekaClient (com.netflix.discovery.EurekaClient)4 ServerListUpdater (com.netflix.loadbalancer.ServerListUpdater)4 AlarmManager (android.app.AlarmManager)3 IActivityManager (android.app.IActivityManager)3 IAlarmManager (android.app.IAlarmManager)3 INotificationManager (android.app.INotificationManager)3 IProcessObserver (android.app.IProcessObserver)3 PendingIntent (android.app.PendingIntent)3