本文整理汇总了Java中org.easymock.MockControl.expectAndReturn方法的典型用法代码示例。如果您正苦于以下问题:Java MockControl.expectAndReturn方法的具体用法?Java MockControl.expectAndReturn怎么用?Java MockControl.expectAndReturn使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.easymock.MockControl
的用法示例。
在下文中一共展示了MockControl.expectAndReturn方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testStart
import org.easymock.MockControl; //导入方法依赖的package包/类
public void testStart() throws Exception {
MockControl ctxCtrl = MockControl.createControl(BundleContext.class);
BundleContext ctx = (BundleContext) ctxCtrl.getMock();
MockControl servCtrl = MockControl.createControl(TestRunnerService.class);
TestRunnerService runner = (TestRunnerService) servCtrl.getMock();
ServiceReference ref = new MockServiceReference();
ctxCtrl.expectAndReturn(ctx.getServiceReference(TestRunnerService.class.getName()), ref);
ctxCtrl.expectAndReturn(ctx.getService(ref), runner);
ctx.registerService((String) null, null, null);
ctxCtrl.setMatcher(MockControl.ALWAYS_MATCHER);
ctxCtrl.setReturnValue(null);
ctxCtrl.replay();
servCtrl.replay();
activator.start(ctx);
ctxCtrl.verify();
}
示例2: testGetResourceFromBundle
import org.easymock.MockControl; //导入方法依赖的package包/类
/**
* Test method for
* {@link org.springframework.osgi.io.OsgiBundleResource#getResourceFromBundleSpace(java.lang.String)}.
*/
public void testGetResourceFromBundle() throws Exception {
MockControl control = MockControl.createControl(Bundle.class);
Bundle mock = (Bundle) control.getMock();
String location = "foo";
URL result = new URL("file:/" + location);
control.expectAndReturn(mock.findEntries("/", "foo", false), new ArrayEnumerator(new URL[] { result }));
control.replay();
resource = new OsgiBundleResource(mock, location);
assertEquals(result, resource.getResourceFromBundleSpace(location).getURL());
control.verify();
}
示例3: testGetResourceFromBundleClasspath
import org.easymock.MockControl; //导入方法依赖的package包/类
/**
* Test method for
* {@link org.springframework.osgi.io.OsgiBundleResource#getResourceFromBundleClasspath(java.lang.String)}.
*/
public void testGetResourceFromBundleClasspath() throws Exception {
MockControl control = MockControl.createControl(Bundle.class);
Bundle mock = (Bundle) control.getMock();
String location = "file://foo";
URL result = new URL(location);
control.expectAndReturn(mock.getResource(location), result);
control.replay();
resource = new OsgiBundleResource(mock, location);
assertSame(result, resource.getResourceFromBundleClasspath(location));
control.verify();
}
示例4: testSybasePatchesCommitsOnEveryStatement
import org.easymock.MockControl; //导入方法依赖的package包/类
/**
* Test that sybase database patches are committed when illegal multi
* statement transaction commands are used.
*
* @throws IOException
* if an unexpected error occurs
* @throws MigrationException
* if an unexpected error occurs
* @throws SQLException
* if an unexpected error occurs
*/
public void testSybasePatchesCommitsOnEveryStatement() throws IOException,
MigrationException, SQLException
{
InputStream is = getClass().getResourceAsStream("test/sybase_tsql.sql");
assertNotNull(is);
task = new SqlScriptMigrationTask("sybase_tsql.sql", 1, is);
MockDatabaseType dbType = new MockDatabaseType("sybase");
dbType.setMultipleStatementsSupported(false);
context.setDatabaseType(dbType);
int numStatements = task.getSqlStatements(context).size();
// setup mocks to verify commits are called
MockControl dataSourceControl = MockControl
.createControl(DataSource.class);
DataSource dataSource = (DataSource) dataSourceControl.getMock();
context.setDataSource(dataSource);
MockControl connectionControl = MockControl
.createControl(Connection.class);
Connection connection = (Connection) connectionControl.getMock();
dataSourceControl.expectAndReturn(dataSource.getConnection(),
connection);
MockControl statementControl = MockControl
.createControl(Statement.class);
Statement statement = (Statement) statementControl.getMock();
statement.execute("");
statementControl.setMatcher(MockControl.ALWAYS_MATCHER);
statementControl.setReturnValue(true, MockControl.ONE_OR_MORE);
statementControl.expectAndReturn(statement.isClosed(), false, MockControl.ONE_OR_MORE);
statement.close();
statementControl.setVoidCallable(MockControl.ONE_OR_MORE);
connectionControl.expectAndReturn(connection.isClosed(), false,
MockControl.ONE_OR_MORE);
connectionControl.expectAndReturn(connection.createStatement(),
statement, numStatements);
connectionControl.expectAndReturn(connection.getAutoCommit(), false,
MockControl.ONE_OR_MORE);
connection.commit();
/*
* Magic Number 4 derived from the assumption that the fixture sql
* contains only one statement that is not allowed in a multi statement
* transaction: commit at beginning of migrate method commit prior to
* running the command not allowed in multi statement transaction to
* clear the transaction state. commit after running the multi statement
* transaction to clear transaction state for upcoming statements.
* commit at end of migrate method once all statements executed.
*
* Therefore, if you add more illegal statements to the fixture, add 2
* more commit call's for each illegal statement.
*/
connectionControl.setVoidCallable(4);
dataSourceControl.replay();
connectionControl.replay();
statementControl.replay();
// run tests
task.migrate(context);
dataSourceControl.verify();
connectionControl.verify();
}
示例5: setUp
import org.easymock.MockControl; //导入方法依赖的package包/类
protected void setUp() throws Exception {
undeployed = false;
String path = "/path";
ServletContext sc = new MockServletContext();
MockControl mc = MockControl.createNiceControl(Context.class);
context = (Context) mc.getMock();
mc.expectAndReturn(context.getPath(), path);
mc.expectAndReturn(context.getServletContext(), sc);
mc.replay();
Bundle bundle = new MockBundle();
deployment = new TomcatWarDeployment(new Undeployer(), bundle, context);
}
示例6: testStart
import org.easymock.MockControl; //导入方法依赖的package包/类
public void testStart() throws Exception {
MockControl bundleContextControl = MockControl.createControl(BundleContext.class);
BundleContext context = (BundleContext) bundleContextControl.getMock();
// platform determination
// extracting bundle id from bundle
bundleContextControl.expectAndReturn(context.getBundle(), new MockBundle());
// look for existing resolved bundles
bundleContextControl.expectAndReturn(context.getBundles(), new Bundle[0], 2);
// register namespace and entity resolving service
// context.registerService((String[]) null, null, null);
// bundleContextControl.setMatcher(MockControl.ALWAYS_MATCHER);
// bundleContextControl.setReturnValue(null);
// register context service
context.registerService((String[]) null, null, null);
bundleContextControl.setMatcher(MockControl.ALWAYS_MATCHER);
bundleContextControl.setReturnValue(null, MockControl.ONE_OR_MORE);
// create task executor
EntryLookupControllingMockBundle aBundle = new EntryLookupControllingMockBundle(null);
aBundle.setEntryReturnOnNextCallToGetEntry(null);
bundleContextControl.expectAndReturn(context.getBundle(), aBundle, MockControl.ONE_OR_MORE);
// listen for bundle events
context.addBundleListener(null);
bundleContextControl.setMatcher(MockControl.ALWAYS_MATCHER);
bundleContextControl.setVoidCallable(2);
bundleContextControl.expectAndReturn(context.registerService(new String[0], null, new Properties()),
new MockServiceRegistration(), MockControl.ONE_OR_MORE);
bundleContextControl.setMatcher(MockControl.ALWAYS_MATCHER);
bundleContextControl.replay();
this.listener.start(context);
bundleContextControl.verify();
}
示例7: setUp
import org.easymock.MockControl; //导入方法依赖的package包/类
protected void setUp() throws Exception {
adminControl = MockControl.createControl(ConfigurationAdmin.class);
admin = (ConfigurationAdmin) adminControl.getMock();
MockControl configMock = MockControl.createControl(Configuration.class);
cfg = (Configuration) configMock.getMock();
config = new Hashtable();
adminControl.expectAndReturn(admin.getConfiguration(persistentId), cfg, MockControl.ONE_OR_MORE);
configMock.expectAndReturn(cfg.getProperties(), config, MockControl.ONE_OR_MORE);
adminControl.replay();
configMock.replay();
bundleContext = new MockBundleContext() {
// add Configuration admin support
public Object getService(ServiceReference reference) {
return admin;
}
};
appContext = new GenericApplicationContext();
appContext.getBeanFactory().addBeanPostProcessor(new BundleContextAwareProcessor(bundleContext));
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(appContext);
// reader.setEventListener(this.listener);
reader.loadBeanDefinitions(new ClassPathResource("configProperties.xml", getClass()));
appContext.refresh();
}
示例8: setUp
import org.easymock.MockControl; //导入方法依赖的package包/类
protected void setUp() throws Exception {
adminControl = MockControl.createControl(ConfigurationAdmin.class);
admin = (ConfigurationAdmin) adminControl.getMock();
MockControl configMock = MockControl.createControl(Configuration.class);
Configuration cfg = (Configuration) configMock.getMock();
config = new Hashtable();
adminControl.expectAndReturn(admin.getConfiguration("com.xyz.myapp"), cfg, MockControl.ONE_OR_MORE);
configMock.expectAndReturn(cfg.getProperties(), config, MockControl.ONE_OR_MORE);
adminControl.replay();
configMock.replay();
bundleContext = new MockBundleContext() {
// add Configuration admin support
public Object getService(ServiceReference reference) {
return admin;
}
};
appContext = new GenericApplicationContext();
appContext.getBeanFactory().addBeanPostProcessor(new BundleContextAwareProcessor(bundleContext));
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(appContext);
// reader.setEventListener(this.listener);
reader.loadBeanDefinitions(new ClassPathResource("osgiPropertyPlaceholder.xml", getClass()));
appContext.refresh();
}
示例9: setUp
import org.easymock.MockControl; //导入方法依赖的package包/类
protected void setUp() throws Exception {
MockControl mc = MockControl.createNiceControl(Configuration.class);
final Configuration cfg = (Configuration) mc.getMock();
mc.expectAndReturn(cfg.getProperties(), new Properties());
mc.replay();
BundleContext bundleContext = new MockBundleContext() {
// always return a ConfigurationAdmin
public Object getService(ServiceReference reference) {
return new MockConfigurationAdmin() {
public Configuration getConfiguration(String pid) throws IOException {
return cfg;
}
};
}
};
appContext = new GenericApplicationContext();
appContext.getBeanFactory().addBeanPostProcessor(new BundleContextAwareProcessor(bundleContext));
appContext.setClassLoader(getClass().getClassLoader());
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(appContext);
reader.loadBeanDefinitions(new ClassPathResource("managedServiceFactory.xml", getClass()));
appContext.refresh();
}
示例10: createMockBF
import org.easymock.MockControl; //导入方法依赖的package包/类
private ConfigurableBeanFactory createMockBF(Object target) {
MockControl ctrl = MockControl.createNiceControl(ConfigurableBeanFactory.class);
ConfigurableBeanFactory cbf = (ConfigurableBeanFactory) ctrl.getMock();
ctrl.expectAndReturn(cbf.getBean(BEAN_NAME), target);
ctrl.expectAndReturn(cbf.getType(BEAN_NAME), target.getClass());
ctrl.replay();
return cbf;
}
示例11: testServiceBeanInjection
import org.easymock.MockControl; //导入方法依赖的package包/类
public void testServiceBeanInjection() throws Exception {
ServiceBean bean = new ServiceBean();
final MyService bean1 = new MyService() {
public Object getId() {
return this;
}
};
final Serializable bean2 = new Serializable() {
public String toString() {
return "bean2";
}
};
BundleContext context = new MockBundleContext() {
public Object getService(org.osgi.framework.ServiceReference reference) {
String clazz = ((String[]) reference.getProperty(Constants.OBJECTCLASS))[0];
if (clazz == null)
return null;
else if (clazz.equals(MyService.class.getName())) {
return bean1;
}
else if (clazz.equals(Serializable.class.getName())) {
return bean2;
}
return null;
}
};
ServiceReferenceInjectionBeanPostProcessor p = new ServiceReferenceInjectionBeanPostProcessor();
p.setBundleContext(context);
p.setBeanClassLoader(getClass().getClassLoader());
MockControl factoryControl = MockControl.createControl(BeanFactory.class);
BeanFactory factory = (BeanFactory) factoryControl.getMock();
factoryControl.expectAndReturn(factory.containsBean("&myBean"), true);
factoryControl.replay();
p.setBeanFactory(factory);
p.postProcessAfterInitialization(bean, "myBean");
assertSame(bean1.getId(), bean.getServiceBean().getId());
assertSame(bean2.toString(), bean.getSerializableBean().toString());
factoryControl.verify();
}
示例12: setUp
import org.easymock.MockControl; //导入方法依赖的package包/类
protected void setUp() throws Exception {
MockControl mc = MockControl.createNiceControl(Configuration.class);
final Configuration cfg = (Configuration) mc.getMock();
mc.expectAndReturn(cfg.getProperties(), new Properties());
mc.replay();
registrationCounter = 0;
unregistrationCounter = 0;
BundleContext bundleContext = new MockBundleContext() {
// always return a ConfigurationAdmin
public Object getService(ServiceReference reference) {
return new MockConfigurationAdmin() {
public Configuration getConfiguration(String pid) throws IOException {
return cfg;
}
};
}
public ServiceRegistration registerService(String[] clazzes, Object service, Dictionary properties) {
if (service instanceof ManagedService) {
registrationCounter++;
return new MockServiceRegistration(clazzes, properties) {
public void unregister() {
super.unregister();
unregistrationCounter++;
}
};
}
return super.registerService(clazzes, service, properties);
}
};
appContext = new GenericApplicationContext();
appContext.getBeanFactory().addBeanPostProcessor(new BundleContextAwareProcessor(bundleContext));
appContext.setClassLoader(getClass().getClassLoader());
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(appContext);
reader.loadBeanDefinitions(new ClassPathResource("managedService.xml", getClass()));
appContext.refresh();
}