当前位置: 首页>>代码示例>>Java>>正文


Java MockControl.setReturnValue方法代码示例

本文整理汇总了Java中org.easymock.MockControl.setReturnValue方法的典型用法代码示例。如果您正苦于以下问题:Java MockControl.setReturnValue方法的具体用法?Java MockControl.setReturnValue怎么用?Java MockControl.setReturnValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.easymock.MockControl的用法示例。


在下文中一共展示了MockControl.setReturnValue方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: setReportedPatchLevel

import org.easymock.MockControl; //导入方法依赖的package包/类
/**
 * For the given launchers, set all it's context's patch info stores as mocks
 * that report the given patch level.  This method is a helper to get this
 * test to pass the DisitributedMigrationProcess::validateControlledSystems() test.
 * @param launchers Collection of JDBCMigrationLaunchers
 * @param levelToReport the patch level the mock should report
 * @throws MigrationException 
 */
protected void setReportedPatchLevel(Collection launchers, int levelToReport) throws MigrationException
{
    for(Iterator launchersIterator = launchers.iterator(); launchersIterator.hasNext(); )
    {
        JdbcMigrationLauncher launcher = (JdbcMigrationLauncher) launchersIterator.next();
        for(Iterator it = launcher.getContexts().keySet().iterator(); it.hasNext(); )
        {
            MigrationContext ctx = (MigrationContext) it.next();
            MockControl patchInfoStoreControl = MockControl.createControl(PatchInfoStore.class);
            PatchInfoStore patchInfoStore = (PatchInfoStore) patchInfoStoreControl.getMock();
            patchInfoStore.getPatchLevel();
            patchInfoStoreControl.setReturnValue(levelToReport);
            patchInfoStoreControl.replay();
            launcher.getContexts().put(ctx, patchInfoStore);
        }
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:26,代码来源:DistributedAutoPatchRollbackTest.java

示例2: 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();
}
 
开发者ID:BeamFoundry,项目名称:spring-osgi,代码行数:24,代码来源:JUnitTestActivatorTest.java

示例3: 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();
   }
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:77,代码来源:SqlScriptMigrationTaskTest.java

示例4: 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();
}
 
开发者ID:BeamFoundry,项目名称:spring-osgi,代码行数:41,代码来源:ContextLoaderListenerTest.java

示例5: testGetServiceProperties

import org.easymock.MockControl; //导入方法依赖的package包/类
public void testGetServiceProperties() {
	MockControl bundleContextControl = MockControl.createControl(BundleContext.class);
	BundleContext mockContext = (BundleContext) bundleContextControl.getMock();
	MockControl bundleControl = MockControl.createControl(Bundle.class);
	Bundle mockBundle = (Bundle) bundleControl.getMock();
	
	mockContext.getBundle();
	bundleContextControl.setReturnValue(mockBundle);
	mockBundle.getSymbolicName();
	bundleControl.setReturnValue("symbolic-name");
	mockContext.getBundle();
	bundleContextControl.setReturnValue(mockBundle);
	mockBundle.getHeaders();
	Properties props = new Properties();
	props.put(Constants.BUNDLE_VERSION,"1.0.0");
	bundleControl.setReturnValue(props);
	
	bundleContextControl.replay();
	bundleControl.replay();
	
	BeanNameServicePropertiesResolver resolver = new BeanNameServicePropertiesResolver();
	resolver.setBundleContext(mockContext);
	Map ret = resolver.getServiceProperties("myBean");
	
	bundleControl.verify();
	bundleContextControl.verify();
	
	assertEquals("3 properties",3,ret.size());
	assertEquals("symbolic-name",ret.get("Bundle-SymbolicName"));
	assertEquals("1.0.0",ret.get("Bundle-Version"));
	assertEquals("myBean",ret.get("org.springframework.osgi.bean.name"));
}
 
开发者ID:BeamFoundry,项目名称:spring-osgi,代码行数:33,代码来源:BeanNameServicePropertiesResolverTest.java

示例6: testValidateControlledSystemsWhenNodePatchLevelsAreOutOfSync

import org.easymock.MockControl; //导入方法依赖的package包/类
public void testValidateControlledSystemsWhenNodePatchLevelsAreOutOfSync() throws Exception
{
    // system has one node
    String systemName = "system1";
    JdbcMigrationLauncher launcher = new JdbcMigrationLauncher();
    
    // first node is at the 'current' patch level
    MockControl node1ContextControl = MockControl.createControl(JdbcMigrationContext.class);
    JdbcMigrationContext node1Context = (JdbcMigrationContext) node1ContextControl.getMock();
    MockControl node1PatchInfoStoreControl = MockControl.createControl(PatchInfoStore.class);
    PatchInfoStore node1PatchInfoStore = (PatchInfoStore) node1PatchInfoStoreControl.getMock();
    // setup mock patch info store to return the patch level we want
    node1Context.getDatabaseName();
    node1ContextControl.setReturnValue("node1", MockControl.ONE_OR_MORE);
    node1ContextControl.replay();

    // second node simulates a newly added database instance, it has not been patched
    MockControl node2ContextControl = MockControl.createControl(JdbcMigrationContext.class);
    JdbcMigrationContext node2Context = (JdbcMigrationContext) node2ContextControl.getMock();
    MockControl node2PatchInfoStoreControl = MockControl.createControl(PatchInfoStore.class);
    PatchInfoStore node2PatchInfoStore = (PatchInfoStore) node2PatchInfoStoreControl.getMock();
    // setup mock patch info store to return the patch level we want
    node2Context.getDatabaseName();
    node2ContextControl.setReturnValue("node2", MockControl.ONE_OR_MORE);
    node2ContextControl.replay();

    // create the launcher's contexts collection
    LinkedHashMap contexts = new LinkedHashMap();
    contexts.put(node1Context, node1PatchInfoStore);
    contexts.put(node2Context, node2PatchInfoStore);
    launcher.setContexts(contexts);
    
    HashMap controlledSystems = new HashMap();
    controlledSystems.put(systemName, launcher);
    
    migrationProcess.setControlledSystems(controlledSystems);
    expect(migrationRunnerStrategy.isSynchronized(currentPatchInfoStore, node1PatchInfoStore)).andReturn(true);
    expect(migrationRunnerStrategy.isSynchronized(currentPatchInfoStore, node2PatchInfoStore)).andReturn(false);

    migrationRunnerStrategyControl.replay();

    migrationProcess.setMigrationRunnerStrategy(migrationRunnerStrategy);
    try
    {
        migrationProcess.validateControlledSystems(currentPatchInfoStore);
        fail("Unexpected exception when validating controlled systems.");
    }
    catch(MigrationException me)
    {
    }
    catch(Exception e)
    {
        fail("Unexpected exception when validating controlled systems.");
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:56,代码来源:DistributedMigrationProcessTest.java

示例7: testDoMigrationsWithLockRace

import org.easymock.MockControl; //导入方法依赖的package包/类
/**
 * Test doing migrations with a lock race from a quick cluster
 *
 * @throws Exception if there is a problem
 */
public void testDoMigrationsWithLockRace() throws Exception {
    // Setup enough for the first
    PreparedStatementResultSetHandler h = conn.getPreparedStatementResultSetHandler();
    MockResultSet rs = h.createResultSet();
    rs.addRow(new Integer[]{new Integer(0)});
    h.prepareGlobalResultSet(rs);


    MockControl mockControl = MockControl.createStrictControl(PatchInfoStore.class);
    PatchInfoStore patchStore = (PatchInfoStore) mockControl.getMock();

    // First they see if it is locked, and it is, so they spin
    patchStore.isPatchStoreLocked();
    mockControl.setReturnValue(true);

    // Second they see if it is locked again, and it isn't, so they try and fail and spin
    patchStore.isPatchStoreLocked();
    mockControl.setReturnValue(false);
    patchStore.getPatchLevel();
    mockControl.setReturnValue(0);
    patchStore.lockPatchStore();
    mockControl.setThrowable(new IllegalStateException("The table is already locked"));

    // Finally they see if it is locked again, and it isn't, and it works
    patchStore.isPatchStoreLocked();
    mockControl.setReturnValue(false);


    patchStore.getPatchLevel();
    mockControl.setReturnValue(2, MockControl.ONE_OR_MORE);
    patchStore.lockPatchStore();

    IMocksControl migrationRunnerStrategyControl = createStrictControl();
    MigrationRunnerStrategy migrationStrategyMock = migrationRunnerStrategyControl.createMock(MigrationRunnerStrategy.class);
    expect(migrationStrategyMock.shouldMigrationRun(anyInt(), eq(patchStore))).andReturn(true).anyTimes();

    patchStore.updatePatchLevel(4);
    patchStore.updatePatchLevel(5);
    patchStore.updatePatchLevel(6);
    patchStore.updatePatchLevel(7);
    patchStore.unlockPatchStore();

    mockControl.replay();
    migrationRunnerStrategyControl.replay();

    TestJdbcMigrationLauncher testLauncher = new TestJdbcMigrationLauncher(context);
    testLauncher.getMigrationProcess().setMigrationRunnerStrategy(migrationStrategyMock);
    testLauncher.setLockPollMillis(0);
    testLauncher.setLockPollRetries(4);
    testLauncher.setIgnoreMigrationSuccessfulEvents(false);
    testLauncher.setPatchStore(patchStore);
    testLauncher.setPatchPath("com.tacitknowledge.util.migration.tasks.normal");
    testLauncher.doMigrations();
    mockControl.verify();
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:61,代码来源:JdbcMigrationLauncherTest.java

示例8: testLockOverride

import org.easymock.MockControl; //导入方法依赖的package包/类
/**
 * Test doing migrations with a lock override
 *
 * @throws Exception if there is a problem
 */
public void testLockOverride() throws Exception {
    // Setup enough for the first
    PreparedStatementResultSetHandler h = conn.getPreparedStatementResultSetHandler();
    MockResultSet rs = h.createResultSet();
    rs.addRow(new Integer[]{new Integer(0)});
    h.prepareGlobalResultSet(rs);


    MockControl mockControl = MockControl.createStrictControl(PatchInfoStore.class);
    PatchInfoStore patchStore = (PatchInfoStore) mockControl.getMock();

    // First they see if it is locked three times, and it is, so they spin
    patchStore.isPatchStoreLocked();
    mockControl.setReturnValue(true);
    patchStore.isPatchStoreLocked();
    mockControl.setReturnValue(true);
    patchStore.isPatchStoreLocked();
    mockControl.setReturnValue(true);
    patchStore.isPatchStoreLocked();
    mockControl.setReturnValue(true);

    // after the third time, they unlock it
    patchStore.unlockPatchStore();

    // now the lock succeeds
    patchStore.isPatchStoreLocked();
    mockControl.setReturnValue(false);
    patchStore.getPatchLevel();
    mockControl.setReturnValue(2);
    patchStore.lockPatchStore();

    IMocksControl migrationRunnerStrategyControl = createStrictControl();
    MigrationRunnerStrategy migrationStrategyMock = migrationRunnerStrategyControl.createMock(MigrationRunnerStrategy.class);
    expect(migrationStrategyMock.shouldMigrationRun(anyInt(), eq(patchStore))).andReturn(true).anyTimes();

    patchStore.updatePatchLevel(4);
    patchStore.updatePatchLevel(5);
    patchStore.updatePatchLevel(6);
    patchStore.updatePatchLevel(7);
    patchStore.unlockPatchStore();

    TestJdbcMigrationLauncher testLauncher = new TestJdbcMigrationLauncher(context);
    testLauncher.getMigrationProcess().setMigrationRunnerStrategy(migrationStrategyMock);
    testLauncher.setLockPollMillis(0);
    testLauncher.setLockPollRetries(3);
    testLauncher.setIgnoreMigrationSuccessfulEvents(false);
    testLauncher.setPatchStore(patchStore);
    testLauncher.setPatchPath("com.tacitknowledge.util.migration.tasks.normal");

    mockControl.replay();
    migrationRunnerStrategyControl.replay();
    testLauncher.doMigrations();
    mockControl.verify();
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:60,代码来源:JdbcMigrationLauncherTest.java


注:本文中的org.easymock.MockControl.setReturnValue方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。