Search in sources :

Example 31 with IMocksControl

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

the class ContextPathTest method testSimple.

public void testSimple() throws Exception {
    IMocksControl testControl = createControl();
    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("/bar/foo").anyTimes();
    expect(req.getServletPath()).andReturn("/bar/foo").anyTimes();
    expect(req.getContextPath()).andReturn("").anyTimes();
    testControl.replay();
    guiceFilter.doFilter(req, res, testFilterChain);
    assertFalse(testFilterChain.isTriggered());
    assertFalse(fooServlet.isTriggered());
    assertTrue(barServlet.isTriggered());
    testControl.verify();
}
Also used : IMocksControl(org.easymock.IMocksControl) HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpServletResponse(javax.servlet.http.HttpServletResponse)

Example 32 with IMocksControl

use of org.easymock.IMocksControl in project karaf by apache.

the class DeployerTest method testInstallSimpleFeature.

@Test
public void testInstallSimpleFeature() throws Exception {
    IMocksControl c = EasyMock.createControl();
    String dataDir = "data1";
    TestDownloadManager manager = new TestDownloadManager(getClass(), dataDir);
    RepositoryImpl repo = new RepositoryImpl(getClass().getResource(dataDir + "/features.xml").toURI());
    repo.load(true);
    Feature f100 = repo.getFeatures()[0];
    Feature f101 = repo.getFeatures()[1];
    Deployer.DeployCallback callback = c.createMock(Deployer.DeployCallback.class);
    BundleInstallSupport installSupport = c.createMock(BundleInstallSupportImpl.class);
    Deployer deployer = new Deployer(manager, resolver, installSupport, callback);
    callback.print(EasyMock.anyString(), EasyMock.anyBoolean());
    EasyMock.expectLastCall().anyTimes();
    callback.callListeners(DeploymentEvent.DEPLOYMENT_STARTED);
    EasyMock.expectLastCall();
    installSupport.replaceDigraph(EasyMock.anyObject(), EasyMock.anyObject());
    EasyMock.expectLastCall();
    callback.saveState(EasyMock.anyObject());
    EasyMock.expectLastCall();
    installSupport.installConfigs(f100);
    EasyMock.expectLastCall();
    installSupport.installLibraries(f100);
    EasyMock.expectLastCall();
    callback.callListeners(DeploymentEvent.BUNDLES_INSTALLED);
    EasyMock.expectLastCall();
    installSupport.resolveBundles(EasyMock.anyObject(), EasyMock.anyObject(), EasyMock.anyObject());
    EasyMock.expectLastCall();
    callback.callListeners(DeploymentEvent.BUNDLES_RESOLVED);
    EasyMock.expectLastCall();
    callback.callListeners(EasyMock.<FeatureEvent>anyObject());
    EasyMock.expectLastCall();
    callback.callListeners(DeploymentEvent.DEPLOYMENT_FINISHED);
    EasyMock.expectLastCall();
    Bundle bundleA = createTestBundle(1, Bundle.ACTIVE, dataDir, "a100");
    EasyMock.expect(installSupport.installBundle(EasyMock.eq(ROOT_REGION), EasyMock.eq("a100"), EasyMock.anyObject())).andReturn(bundleA);
    c.replay();
    Deployer.DeploymentState dstate = new Deployer.DeploymentState();
    dstate.state = new State();
    dstate.bundles = new HashMap<>();
    dstate.bundlesPerRegion = new HashMap<>();
    dstate.features = new HashMap<>();
    dstate.features.put(f100.getId(), f100);
    dstate.features.put(f101.getId(), f101);
    dstate.filtersPerRegion = new HashMap<>();
    dstate.filtersPerRegion.put(ROOT_REGION, new HashMap<>());
    Deployer.DeploymentRequest request = new Deployer.DeploymentRequest();
    request.bundleUpdateRange = DEFAULT_BUNDLE_UPDATE_RANGE;
    request.featureResolutionRange = DEFAULT_FEATURE_RESOLUTION_RANGE;
    request.globalRepository = null;
    request.options = EnumSet.noneOf(Option.class);
    request.overrides = Collections.emptySet();
    request.stateChanges = Collections.emptyMap();
    request.updateSnaphots = UPDATE_SNAPSHOTS_NONE;
    request.requirements = new HashMap<>();
    addToMapSet(request.requirements, ROOT_REGION, f100.getName() + "/" + new VersionRange(f100.getVersion(), true));
    deployer.deploy(dstate, request);
    c.verify();
}
Also used : Bundle(org.osgi.framework.Bundle) TestBundle(org.apache.karaf.features.internal.support.TestBundle) VersionRange(org.apache.felix.utils.version.VersionRange) Feature(org.apache.karaf.features.Feature) IMocksControl(org.easymock.IMocksControl) TestDownloadManager(org.apache.karaf.features.internal.support.TestDownloadManager) Test(org.junit.Test)

Example 33 with IMocksControl

use of org.easymock.IMocksControl in project karaf by apache.

the class EventDisplayCommandTest method testExecute.

@Test
public void testExecute() throws Exception {
    IMocksControl c = createControl();
    EventDisplayCommand display = new EventDisplayCommand();
    display.session = c.createMock(Session.class);
    expect(display.session.getConsole()).andReturn(System.out);
    display.collector = new EventCollector();
    display.collector.handleEvent(new Event("myTopic", new HashMap<>()));
    c.replay();
    display.execute();
    c.verify();
}
Also used : IMocksControl(org.easymock.IMocksControl) EventDisplayCommand(org.apache.karaf.event.command.EventDisplayCommand) HashMap(java.util.HashMap) EventCollector(org.apache.karaf.event.service.EventCollector) Event(org.osgi.service.event.Event) Session(org.apache.karaf.shell.api.console.Session) Test(org.junit.Test)

Example 34 with IMocksControl

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

the class InterceptorTest method postCallWithTransaction.

private void postCallWithTransaction(Throwable th, boolean expectRollback, boolean failCoordination) throws Throwable {
    IMocksControl c = EasyMock.createControl();
    TransactionManager tm = c.createMock(TransactionManager.class);
    Coordinator coordinator = c.createMock(Coordinator.class);
    ComponentTxData txData = new ComponentTxData(AnnotatedPojo.class);
    TxInterceptorImpl sut = new TxInterceptorImpl(tm, coordinator, txData);
    Transaction tran = c.createMock(Transaction.class);
    if (expectRollback) {
        tran.setRollbackOnly();
        EasyMock.expectLastCall();
    }
    Coordination coordination = c.createMock(Coordination.class);
    coordination.end();
    if (failCoordination) {
        EasyMock.expectLastCall().andThrow(coordinationException(th));
    } else {
        EasyMock.expectLastCall();
    }
    c.replay();
    TransactionToken tt = new TransactionToken(tran, null, TransactionAttribute.REQUIRED);
    tt.setCoordination(coordination);
    sut.postCallWithException(null, this.getClass().getMethods()[0], th, tt);
    c.verify();
}
Also used : IMocksControl(org.easymock.IMocksControl) Transaction(javax.transaction.Transaction) Coordination(org.osgi.service.coordinator.Coordination) TransactionManager(javax.transaction.TransactionManager) Coordinator(org.osgi.service.coordinator.Coordinator)

Example 35 with IMocksControl

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

the class BPQuiesceTest method canQuiesceNoBPBundle.

@Test
public void canQuiesceNoBPBundle() throws Exception {
    IMocksControl c = EasyMock.createControl();
    BundleContext ctx = c.createMock(BundleContext.class);
    Bundle bpBundle = c.createMock(Bundle.class);
    Bundle testBundle = c.createMock(Bundle.class);
    EasyMock.expect(ctx.getBundle()).andReturn(bpBundle);
    BlueprintQuiesceParticipant bqp = new BlueprintQuiesceParticipant(ctx, new BlueprintExtender() {

        @Override
        protected BlueprintContainerImpl getBlueprintContainerImpl(Bundle bundle) {
            return null;
        }
    });
    final Semaphore result = new Semaphore(0);
    QuiesceCallback qc = new QuiesceCallback() {

        public void bundleQuiesced(Bundle... bundlesQuiesced) {
            result.release();
        }
    };
    c.replay();
    bqp.quiesce(qc, Arrays.asList(testBundle));
    c.verify();
    assertTrue(result.tryAcquire(2, TimeUnit.SECONDS));
}
Also used : IMocksControl(org.easymock.IMocksControl) Bundle(org.osgi.framework.Bundle) Semaphore(java.util.concurrent.Semaphore) QuiesceCallback(org.apache.aries.quiesce.manager.QuiesceCallback) BundleContext(org.osgi.framework.BundleContext) Test(org.junit.Test)

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