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();
}
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();
}
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();
}
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();
}
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));
}
Aggregations