本文整理汇总了Java中org.easymock.IMocksControl类的典型用法代码示例。如果您正苦于以下问题:Java IMocksControl类的具体用法?Java IMocksControl怎么用?Java IMocksControl使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
IMocksControl类属于org.easymock包,在下文中一共展示了IMocksControl类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setUp
import org.easymock.IMocksControl; //导入依赖的package包/类
public void setUp() throws Exception
{
super.setUp();
migrationRunnerStrategy = new OrderedMigrationRunnerStrategy();
allMigrationTasks = new ArrayList<MigrationTask>();
IMocksControl mockControl = createControl();
currentPatchInfoStore = mockControl.createMock(PatchInfoStore.class);
allMigrationTasks.add(new TestRollbackableTask1());
allMigrationTasks.add(new TestRollbackableTask2());
allMigrationTasks.add(new TestRollbackableTask3());
allMigrationTasks.add(new TestRollbackableTask4());
allMigrationTasks.add(new TestRollbackableTask5());
expect(currentPatchInfoStore.getPatchLevel()).andReturn(12);
mockControl.replay();
}
示例2: testExportExisting
import org.easymock.IMocksControl; //导入依赖的package包/类
@Test
public void testExportExisting() throws Exception {
IMocksControl c = EasyMock.createControl();
RemoteServiceAdmin rsa = c.createMock(RemoteServiceAdmin.class);
final EndpointListenerNotifier mockEpListenerNotifier = c.createMock(EndpointListenerNotifier.class);
final ServiceReference sref = createUserService(c);
expectServiceExported(c, rsa, mockEpListenerNotifier, sref, createEndpoint());
c.replay();
EndpointRepository endpointRepo = new EndpointRepository();
endpointRepo.setNotifier(mockEpListenerNotifier);
ExportPolicy policy = new DefaultExportPolicy();
TopologyManagerExport exportManager = new TopologyManagerExport(endpointRepo, syncExecutor(), policy);
exportManager.serviceChanged(new ServiceEvent(ServiceEvent.REGISTERED, sref));
exportManager.add(rsa);
c.verify();
}
示例3: testExportExistingMultipleInterfaces
import org.easymock.IMocksControl; //导入依赖的package包/类
@Test
public void testExportExistingMultipleInterfaces() throws Exception {
IMocksControl c = EasyMock.createControl();
RemoteServiceAdmin rsa = c.createMock(RemoteServiceAdmin.class);
final EndpointListenerNotifier mockEpListenerNotifier = c.createMock(EndpointListenerNotifier.class);
List<String> exportedInterfaces = Arrays.asList("a.b.C","foo.Bar");
final ServiceReference sref = createUserService(c, exportedInterfaces);
expectServiceExported(c, rsa, mockEpListenerNotifier, sref, createEndpoint());
c.replay();
EndpointRepository endpointRepo = new EndpointRepository();
endpointRepo.setNotifier(mockEpListenerNotifier);
ExportPolicy policy = new DefaultExportPolicy();
TopologyManagerExport exportManager = new TopologyManagerExport(endpointRepo, syncExecutor(), policy);
exportManager.serviceChanged(new ServiceEvent(ServiceEvent.REGISTERED, sref));
exportManager.add(rsa);
c.verify();
}
示例4: testExportExistingNoExportedInterfaces
import org.easymock.IMocksControl; //导入依赖的package包/类
@Test
public void testExportExistingNoExportedInterfaces() throws Exception {
IMocksControl c = EasyMock.createControl();
RemoteServiceAdmin rsa = c.createMock(RemoteServiceAdmin.class);
final EndpointListenerNotifier mockEpListenerNotifier = c.createMock(EndpointListenerNotifier.class);
String exportedInterfaces = "";
final ServiceReference sref = createUserService(c, exportedInterfaces);
c.replay();
EndpointRepository endpointRepo = new EndpointRepository();
endpointRepo.setNotifier(mockEpListenerNotifier);
ExportPolicy policy = new DefaultExportPolicy();
TopologyManagerExport exportManager = new TopologyManagerExport(endpointRepo, syncExecutor(), policy);
exportManager.serviceChanged(new ServiceEvent(ServiceEvent.REGISTERED, sref));
exportManager.add(rsa);
c.verify();
}
示例5: testAddedRemoved
import org.easymock.IMocksControl; //导入依赖的package包/类
@Test
public void testAddedRemoved() throws InvalidSyntaxException {
IMocksControl c = EasyMock.createControl();
String filter = "(objectClass=My)";
BundleContext bc = createBundleContext();
BundleContext listenerBc = createBundleContext();
ServiceInterestListener serviceInterestListener = c.createMock(ServiceInterestListener.class);
ListenerHookImpl listenerHook = new ListenerHookImpl(bc, serviceInterestListener);
ListenerInfo listener = c.createMock(ListenerInfo.class);
EasyMock.expect(listener.getBundleContext()).andReturn(listenerBc);
EasyMock.expect(listener.getFilter()).andReturn(filter).atLeastOnce();
// Main assertions
serviceInterestListener.addServiceInterest(listenerHook.extendFilter(filter));
EasyMock.expectLastCall();
serviceInterestListener.removeServiceInterest(listenerHook.extendFilter(filter));
EasyMock.expectLastCall();
Collection<ListenerInfo> listeners = Collections.singletonList(listener);
c.replay();
listenerHook.added(listeners);
listenerHook.removed(listeners);
c.verify();
}
示例6: testEndpointRemovalAdding
import org.easymock.IMocksControl; //导入依赖的package包/类
public void testEndpointRemovalAdding() throws KeeperException, InterruptedException {
IMocksControl c = EasyMock.createNiceControl();
BundleContext ctx = c.createMock(BundleContext.class);
ZooKeeper zk = c.createMock(ZooKeeper.class);
String path = ENDPOINT_PATH;
expectCreated(zk, path);
expectDeleted(zk, path);
c.replay();
PublishingEndpointListener eli = new PublishingEndpointListener(zk, ctx);
EndpointDescription endpoint = createEndpoint();
eli.endpointAdded(endpoint, null);
eli.endpointAdded(endpoint, null); // should do nothing
eli.endpointRemoved(endpoint, null);
eli.endpointRemoved(endpoint, null); // should do nothing
c.verify();
}
示例7: testClose
import org.easymock.IMocksControl; //导入依赖的package包/类
public void testClose() throws KeeperException, InterruptedException {
IMocksControl c = EasyMock.createNiceControl();
BundleContext ctx = c.createMock(BundleContext.class);
ZooKeeper zk = c.createMock(ZooKeeper.class);
expectCreated(zk, ENDPOINT_PATH);
expectDeleted(zk, ENDPOINT_PATH);
c.replay();
PublishingEndpointListener eli = new PublishingEndpointListener(zk, ctx);
EndpointDescription endpoint = createEndpoint();
eli.endpointAdded(endpoint, null);
eli.close(); // should result in zk.delete(...)
c.verify();
}
示例8: testScope
import org.easymock.IMocksControl; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public void testScope() {
IMocksControl c = EasyMock.createNiceControl();
BundleContext ctx = c.createMock(BundleContext.class);
ZooKeeper zk = c.createMock(ZooKeeper.class);
@SuppressWarnings("rawtypes")
ServiceRegistration sreg = c.createMock(ServiceRegistration.class);
PublishingEndpointListenerFactory eplf = new PublishingEndpointListenerFactory(zk, ctx);
EasyMock.expect(ctx.registerService(EasyMock.eq(EndpointListener.class.getName()), EasyMock.eq(eplf),
(Dictionary<String, String>)EasyMock.anyObject())).andReturn(sreg).once();
EasyMock.expect(ctx.getProperty(EasyMock.eq("org.osgi.framework.uuid"))).andReturn("myUUID").anyTimes();
c.replay();
eplf.start();
c.verify();
}
示例9: testInterfaceMonitor
import org.easymock.IMocksControl; //导入依赖的package包/类
public void testInterfaceMonitor() throws KeeperException, InterruptedException {
IMocksControl c = EasyMock.createControl();
ZooKeeper zk = c.createMock(ZooKeeper.class);
expect(zk.getState()).andReturn(ZooKeeper.States.CONNECTED).anyTimes();
String scope = "(myProp=test)";
String interf = "es.schaaf.test";
String node = Utils.getZooKeeperPath(interf);
EndpointListener endpointListener = c.createMock(EndpointListener.class);
InterfaceMonitor im = new InterfaceMonitor(zk, interf, endpointListener, scope);
zk.exists(eq(node), eq(im), eq(im), EasyMock.anyObject());
EasyMock.expectLastCall().once();
expect(zk.exists(eq(node), eq(false))).andReturn(new Stat()).anyTimes();
expect(zk.getChildren(eq(node), eq(false))).andReturn(Collections.<String> emptyList()).once();
expect(zk.getChildren(eq(node), eq(im))).andReturn(Collections.<String> emptyList()).once();
c.replay();
im.start();
// simulate a zk callback
WatchedEvent we = new WatchedEvent(EventType.NodeCreated, KeeperState.SyncConnected, node);
im.process(we);
c.verify();
}
示例10: testUpdateConfig
import org.easymock.IMocksControl; //导入依赖的package包/类
public void testUpdateConfig() throws Exception {
final File tempDir = new File("target");
IMocksControl control = EasyMock.createControl();
BundleContext bc = control.createMock(BundleContext.class);
expect(bc.getDataFile("")).andReturn(tempDir);
final MyZooKeeperServerMain mockServer = control.createMock(MyZooKeeperServerMain.class);
control.replay();
ZookeeperStarter starter = new ZookeeperStarter(bc) {
@Override
protected void startFromConfig(QuorumPeerConfig config) {
assertEquals(1234, config.getClientPortAddress().getPort());
assertTrue(config.getDataDir().contains(tempDir + File.separator + "zkdata"));
assertEquals(2000, config.getTickTime());
assertEquals(10, config.getInitLimit());
assertEquals(5, config.getSyncLimit());
this.main = mockServer;
}
};
Dictionary<String, Object> props = new Hashtable<String, Object>();
props.put("clientPort", "1234");
starter.updated(props);
assertNotNull(starter.main);
control.verify();
}
示例11: testDefaults
import org.easymock.IMocksControl; //导入依赖的package包/类
@Test
public void testDefaults() throws ConfigurationException {
IMocksControl c = EasyMock.createControl();
BundleContext bctx = c.createMock(BundleContext.class);
ZooKeeperDiscovery zkd = new ZooKeeperDiscovery(bctx) {
@Override
protected ZooKeeper createZooKeeper(String host, String port, int timeout) {
Assert.assertEquals("localhost", host);
Assert.assertEquals("2181", port);
Assert.assertEquals(3000, timeout);
return null;
}
};
Dictionary<String, Object> configuration = new Hashtable<String, Object>();
zkd.updated(configuration);
}
示例12: testConfig
import org.easymock.IMocksControl; //导入依赖的package包/类
@Test
public void testConfig() throws ConfigurationException {
IMocksControl c = EasyMock.createControl();
BundleContext bctx = c.createMock(BundleContext.class);
ZooKeeperDiscovery zkd = new ZooKeeperDiscovery(bctx) {
@Override
protected ZooKeeper createZooKeeper(String host, String port, int timeout) {
Assert.assertEquals("myhost", host);
Assert.assertEquals("1", port);
Assert.assertEquals(1000, timeout);
return null;
}
};
Dictionary<String, Object> configuration = new Hashtable<String, Object>();
configuration.put("zookeeper.host", "myhost");
configuration.put("zookeeper.port", "1");
configuration.put("zookeeper.timeout", "1000");
zkd.updated(configuration);
}
示例13: testGetService
import org.easymock.IMocksControl; //导入依赖的package包/类
@SuppressWarnings({
"rawtypes"
})
public void testGetService() throws ClassNotFoundException {
final Object myTestProxyObject = new Object();
IMocksControl control = EasyMock.createControl();
EndpointDescription endpoint = createTestEndpointDesc();
ImportRegistrationImpl iri = new ImportRegistrationImpl(endpoint, null);
BundleContext consumerContext = control.createMock(BundleContext.class);
Bundle consumerBundle = control.createMock(Bundle.class);
BundleWiring bundleWiring = control.createMock(BundleWiring.class);
EasyMock.expect(bundleWiring.getClassLoader()).andReturn(this.getClass().getClassLoader());
EasyMock.expect(consumerBundle.adapt(BundleWiring.class)).andReturn(bundleWiring);
EasyMock.expect(consumerBundle.getBundleContext()).andReturn(consumerContext);
ServiceRegistration sreg = control.createMock(ServiceRegistration.class);
DistributionProvider handler = mockDistributionProvider(myTestProxyObject);
control.replay();
ClientServiceFactory csf = new ClientServiceFactory(endpoint, handler, iri);
assertSame(myTestProxyObject, csf.getService(consumerBundle, sreg));
}
示例14: testStartStop
import org.easymock.IMocksControl; //导入依赖的package包/类
@SuppressWarnings({
"rawtypes", "unchecked"
})
@Test
public void testStartStop() throws Exception {
IMocksControl c = EasyMock.createControl();
BundleContext context = c.createMock(BundleContext.class);
ServiceRegistration sreg = c.createMock(ServiceRegistration.class);
expect(context.registerService(EasyMock.eq(DistributionProvider.class), EasyMock.anyObject(DistributionProvider.class), EasyMock.anyObject(Dictionary.class))).andReturn(sreg );
c.replay();
Activator activator = new Activator();
activator.start(context);
activator.stop(context);
c.verify();
}
示例15: doCreateMock
import org.easymock.IMocksControl; //导入依赖的package包/类
private static <T> T doCreateMock(Class<T> type, ConstructorArgs constructorArgs, final IMocksControl control,
Method... methods) {
T mock;
MocksControl mocksControl = ((MocksControl) control);
if (constructorArgs == null) {
if (methods == null) {
mock = mocksControl.createMock(type);
} else {
mock = mocksControl.createMock(type, methods);
}
} else {
if (methods == null) {
mock = mocksControl.createMock(type, constructorArgs);
} else {
mock = mocksControl.createMock(type, constructorArgs, methods);
}
}
return mock;
}