Java 类org.easymock.MockControl 实例源码

项目:lams    文件:MissingPatchMigrationRunnerStrategyTest.java   
protected void setUp() throws Exception {
    strategy = new MissingPatchMigrationRunnerStrategy();
    patchInfoStoreControl = MockControl.createControl(PatchInfoStore.class);
    patchInfoStore = (PatchInfoStore) patchInfoStoreControl.getMock();
    allMigrationTasks = new ArrayList<MigrationTask>();
    rollbackableTask2 = new TestRollbackableTask2();
    rollbackableTask4 = new TestRollbackableTask4();
    mockControl = createControl();
    currentPatchInfoStore = mockControl.createMock(PatchInfoStore.class);

    allMigrationTasks.add(new TestRollbackableTask1());
    allMigrationTasks.add(rollbackableTask2);
    allMigrationTasks.add(new TestRollbackableTask3());
    allMigrationTasks.add(rollbackableTask4);
    allMigrationTasks.add(new TestRollbackableTask5());
}
项目:lams    文件:PatchTableTest.java   
/**
 * {@inheritDoc}
 */
protected void setUp() throws Exception
{
    super.setUp();

    conn = getJDBCMockObjectFactory().getMockConnection();

    context = new DataSourceMigrationContext();
    context.setDataSource(new ConnectionWrapperDataSource(conn));
    context.setSystemName("milestone");
    context.setDatabaseType(new DatabaseType("hsqldb"));

    table = new PatchTable(context);
    contextControl = MockControl.createControl(JdbcMigrationContext.class);
    mockContext = (JdbcMigrationContext) contextControl.getMock();
}
项目:spring-osgi    文件:JUnitTestActivatorTest.java   
public void testLoadTest() throws Exception {
    BundleContext ctx = new MockBundleContext();

    MockControl servCtrl = MockControl.createControl(TestRunnerService.class);
    TestRunnerService runner = (TestRunnerService) servCtrl.getMock();

    try {
        activator.executeTest();
        fail("should have thrown exception");
    }
    catch (RuntimeException ex) {
        // expected
    }

    setActivatorField("service", runner);
    runner.runTest(null);
    servCtrl.setMatcher(MockControl.ALWAYS_MATCHER);
    servCtrl.replay();

    setActivatorField("context", ctx);
    OsgiTestInfoHolder.INSTANCE.setTestClassName(TestExample.class.getName());

    activator.executeTest();
    assertSame(ctx, TestExample.context);
    servCtrl.verify();
}
项目:lams    文件:MigrationProcessTest.java   
public void setUp() throws Exception
{
    super.setUp();
    migrationProcess = new MigrationProcess();
    migrationProcess.
            setMigrationRunnerStrategy(MigrationRunnerFactory.getMigrationRunnerStrategy(null));
    migrationContextControl = MockControl.createStrictControl(MigrationContext.class);
    migrationContextMock =
            (MigrationContext) migrationContextControl.getMock();
    migrationTaskSourceControl = MockControl.createStrictControl(MigrationTaskSource.class);
    migrationTaskSourceMock = (MigrationTaskSource) migrationTaskSourceControl.getMock();
    migrationProcess.addPatchResourcePackage("testPackageName");
    patchInfoStoreControl = MockControl.createStrictControl(PatchInfoStore.class);
    patchInfoStoreMock = (PatchInfoStore) patchInfoStoreControl.getMock();
    patchInfoStore = MockBuilder.getPatchInfoStore(3);
}
项目:lams    文件:PatchTableTest.java   
/**
 * Tests when trying to get a connection to the database to create the patch table fails.
 * @throws SQLException shouldn't occur, only declared to make the code below more readable.
 */
public void testCreatePatchesTableWithoutConnection() throws SQLException
{

    // setup mock calls
    mockContext.getDatabaseType();
    contextControl.setReturnValue(new DatabaseType("postgres"), MockControl.ONE_OR_MORE);

    mockContext.getConnection();
    contextControl.setThrowable(new SQLException("An exception during getConnection"));
    contextControl.replay();

    table = new PatchTable(mockContext);
    try 
    {
        table.createPatchStoreIfNeeded();
        fail("Expected a MigrationException");
    } 
    catch (MigrationException e) 
    {
        contextControl.verify();
    }
}
项目:lams    文件:MigrationTest.java   
/**
 * Validates that the migration runner can run the all patches.
 * 
 * @throws MigrationException if an unexpected error occurs
 */
public void testRunAllMigrationTasks() throws MigrationException
{
    List l = runner.getMigrationTasks();
    assertEquals(9, l.size());

    patchInfoStoreControl.expectAndReturn(patchInfoStore.getPatchLevel(), 0, MockControl.ONE_OR_MORE);
    patchInfoStoreControl.replay();

    int level = runner.doMigrations(patchInfoStore, context);
    runner.doPostPatchMigrations(context);
    assertEquals(9, level);
    assertTrue(context.hasExecuted("TestTask1"));
    assertTrue(context.hasExecuted("TestTask2"));
    assertTrue(context.hasExecuted("TestTask3"));
    assertTrue(context.hasExecuted("TestTask4"));
    assertTrue(context.hasExecuted("TestRollbackableTask1"));
    assertTrue(context.hasExecuted("TestRollbackableTask2"));
    assertTrue(context.hasExecuted("TestRollbackableTask3"));
    assertTrue(context.hasExecuted("TestRollbackableTask4"));
    assertTrue(context.hasExecuted("TestRollbackableTask5"));
    assertTrue(context.hasExecuted("TestPostTask1"));
    assertTrue(context.hasExecuted("TestPostTask2"));
    assertEquals(9, getMigrationStartedCount());
    assertEquals(9, getMigrationSuccessCount());
}
项目:lams    文件:MigrationTest.java   
/**
 * Validates that the migration runner will only run the necessary patches
 * to bring the system current 
 * 
 * @throws MigrationException if an unexpected error occurs
 */
public void testRunPartialMigrationTasks() throws MigrationException
{
    List l = runner.getMigrationTasks();
    assertEquals(9, l.size());

    patchInfoStoreControl.expectAndReturn(patchInfoStore.getPatchLevel(), 9, MockControl.ONE_OR_MORE);
    patchInfoStoreControl.replay();

    int level = runner.doMigrations(patchInfoStore, context);
    runner.doPostPatchMigrations(context);
    assertEquals(3, level);
    assertFalse(context.hasExecuted("TestTask1"));
    assertFalse(context.hasExecuted("TestTask2"));
    assertFalse(context.hasExecuted("TestTask3"));
    assertFalse(context.hasExecuted("TestTask4"));
    assertFalse(context.hasExecuted("TestRollbackableTask1"));
    assertFalse(context.hasExecuted("TestRollbackableTask2"));
    assertTrue(context.hasExecuted("TestRollbackableTask3"));
    assertTrue(context.hasExecuted("TestRollbackableTask4"));
    assertTrue(context.hasExecuted("TestRollbackableTask5"));
    assertTrue(context.hasExecuted("TestPostTask1"));
    assertTrue(context.hasExecuted("TestPostTask2"));
    assertEquals(3, getMigrationStartedCount());
    assertEquals(3, getMigrationSuccessCount());
}
项目:lams    文件:DistributedAutoPatchRollbackTest.java   
/**
 * 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);
        }
    }
}
项目:lams    文件:MigrationProcessRollbackTest.java   
/**
 * this is a private helper method to perform initial migrations
 *
 * @throws MigrationException
 */
private void doInitialMigrations() throws MigrationException
{
    List l = runner.getMigrationTasks();
    assertEquals(5, l.size());

    patchInfoStoreControl.expectAndReturn(patchInfoStore.getPatchLevel(), 0, MockControl.ONE_OR_MORE);
    patchInfoStoreControl.replay();
    int level = runner.doMigrations(patchInfoStore, context);
    runner.doPostPatchMigrations(context);
    assertEquals(5, level);
    assertEquals(5, getMigrationSuccessCount());

    assertTrue(context.hasExecuted("TestRollbackableTask1"));
    assertTrue(context.hasExecuted("TestRollbackableTask2"));
    assertTrue(context.hasExecuted("TestRollbackableTask3"));
    assertTrue(context.hasExecuted("TestRollbackableTask4"));
    assertTrue(context.hasExecuted("TestRollbackableTask5"));
}
项目:clichart    文件:AbstractChartBuilderTest.java   
protected void setUp() throws Exception {
    m_control = MockControl.createStrictControl(MockDelegate.class);
    m_delegate = (MockDelegate) m_control.getMock();

    m_chartBuilder = new AbstractChartBuilder(m_options, null) {
        protected void initialiseSeriesColumn(String title) {
            m_delegate.initialiseSeriesColumn(title);
        }

        protected void addYValue(int columnNumber, Object xValue, Object yValue) {
            m_delegate.addYValue(columnNumber, xValue, yValue);
        }

        protected JFreeChart getChartImpl(Options options) {
            return m_delegate.getChartImpl(options);
        }

        protected XYDataset getDataset() {
            return m_delegate.getDataset();
        }

        protected XYToolTipGenerator getToolTipGenerator() {
            return m_delegate.getToolTipGenerator();
        }
    };
}
项目:spring-osgi    文件:MockServiceRegistrationTest.java   
/**
 * Test method for
 * {@link org.springframework.osgi.mock.MockServiceRegistration#setProperties(java.util.Dictionary)}.
 */
public void testSetProperties() {
    Dictionary props = new Hashtable();
    Object value = new Object();
    String key = "foo";
    props.put(key, value);

    assertNull(mock.getReference().getProperty(key));
    mock.setProperties(props);
    assertSame(value, mock.getReference().getProperty(key));
    mock.setReference((ServiceReference) MockControl.createNiceControl(ServiceReference.class).getMock());

    try {
        mock.setProperties(props);
        fail("should have thrown exception");
    }
    catch (RuntimeException ex) {
        // expected
    }
}
项目:spring-osgi    文件:ConfigPropertiesHandlerTest.java   
public void testPropertiesWithDefaultsAndNoOverride() throws Exception {
    persistentId = "noLocalOverride";

    adminControl.reset();
    adminControl.expectAndReturn(admin.getConfiguration(persistentId), cfg, MockControl.ONE_OR_MORE);
    adminControl.replay();

    config.put("foo", "foo");
    config.put("Spring", "Source");
    Object bean = appContext.getBean(persistentId);
    assertTrue(bean instanceof Properties);
    Properties props = (Properties) bean;
    assertFalse(config.equals(bean));
    // the local property has been replaced
    assertEquals("foo", props.getProperty("foo"));
    // but the one not present on the CM are still present
    assertTrue(props.containsKey("kry"));
    assertTrue(props.containsKey("Spring"));
    assertEquals(3, props.entrySet().size());
}
项目:spring-osgi    文件:ConfigPropertiesHandlerTest.java   
public void testPropertiesWithDefaultsAndOverride() throws Exception {
    persistentId = "localOverride";

    adminControl.reset();
    adminControl.expectAndReturn(admin.getConfiguration(persistentId), cfg, MockControl.ONE_OR_MORE);
    adminControl.replay();

    config.put("foo", "foo");
    config.put("Spring", "Source");
    Object bean = appContext.getBean(persistentId);
    assertTrue(bean instanceof Properties);
    Properties props = (Properties) bean;
    assertFalse(config.equals(bean));
    // the local property is still present
    assertEquals("bar", props.getProperty("foo"));
    // the CM props are still there
    assertTrue(props.containsKey("kry"));
    // and so are the local props
    assertTrue(props.containsKey("Spring"));
    assertEquals(3, props.entrySet().size());
}
项目:spring-osgi    文件:ConfigPropertiesHandlerTest.java   
public void tstPropertiesWithPropRef() throws Exception {
    persistentId = "custom-attributes";

    adminControl.reset();
    adminControl.expectAndReturn(admin.getConfiguration(persistentId), cfg, MockControl.ONE_OR_MORE);
    adminControl.replay();

    config.put("foo", "foo");
    config.put("Spring", "Source");
    Object bean = appContext.getBean(persistentId);
    BeanDefinition bd = appContext.getBeanDefinition(persistentId);
    System.out.println(bd.getScope());
    assertTrue(bean instanceof Properties);
    Properties props = (Properties) bean;
    assertFalse(config.equals(bean));
    // the local property is still present
    assertEquals("bar", props.getProperty("foo"));
    // the CM props are still there
    assertTrue(props.containsKey("kry"));
    // and so are the local props
    assertTrue(props.containsKey("Spring"));
    assertEquals(3, props.entrySet().size());
}
项目:spring-osgi    文件:AbstractRefreshableOsgiBundleApplicationContextTest.java   
public void testBundleContext() throws Exception {

        String location = "osgibundle://someLocation";
        Resource bundleResource = new OsgiBundleResource(bundle, location);

        Dictionary dict = new Properties();
        bundleCtrl.expectAndReturn(bundle.getHeaders(), dict);
        bundleCtrl.expectAndReturn(bundle.getSymbolicName(), "symName", MockControl.ONE_OR_MORE);
        bundleCtrl.replay();
        bundleCtxCtrl.replay();

        context.setBundleContext(bundleCtx);
        assertSame(bundle, context.getBundle());
        assertSame(bundleCtx, context.getBundleContext());

        ClassLoader loader = context.getClassLoader();
        assertTrue(loader instanceof BundleDelegatingClassLoader);

        // do some resource loading
        assertEquals(bundleResource, context.getResource(location));

        bundleCtrl.verify();
        bundleCtxCtrl.verify();
    }
项目:spring-osgi    文件:OsgiServiceReferenceUtilsTest.java   
protected void setUp() throws Exception {
    classes = new String[] { Object.class.getName(), Cloneable.class.getName(), Serializable.class.getName() };

    // lowest service reference
    Dictionary dict1 = new Hashtable();
    dict1.put(Constants.SERVICE_RANKING, new Integer(Integer.MIN_VALUE));
    ref1 = new MockServiceReference(null, dict1, null);

    // neutral service reference
    Dictionary dict2 = new Hashtable();
    dict2.put(Constants.SERVICE_ID, new Long(20));

    ref2 = new MockServiceReference(null, dict2, null);

    // neutral service reference
    Dictionary dict3 = new Hashtable();
    dict3.put(Constants.SERVICE_ID, new Long(30));

    ref3 = new MockServiceReference(null, dict3, null);

    ctrl = MockControl.createStrictControl(BundleContext.class);
    context = (BundleContext) ctrl.getMock();

}
项目:spring-osgi    文件:JUnitTestActivatorTest.java   
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();
}
项目:spring-osgi    文件:JUnitTestActivatorTest.java   
public void testStop() throws Exception {
    ServiceReference ref = new MockServiceReference();
    MockControl regCtrl = MockControl.createControl(ServiceRegistration.class);
    ServiceRegistration reg = (ServiceRegistration) regCtrl.getMock();

    MockControl ctxCtrl = MockControl.createControl(BundleContext.class);
    BundleContext ctx = (BundleContext) ctxCtrl.getMock();

    reg.unregister();

    ctxCtrl.replay();
    regCtrl.replay();

    setActivatorField("reference", ref);
    setActivatorField("registration", reg);

    activator.stop(ctx);

    regCtrl.verify();
    ctxCtrl.verify();
}
项目:spring-osgi    文件:OsgiBundleResourceTest.java   
/**
 * 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();
}
项目:spring-osgi    文件:OsgiBundleResourceTest.java   
/**
 * 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();
}
项目:oceano    文件:DefaultWagonManagerTest.java   
public void testGetRemoteJar()
    throws TransferFailedException, ResourceDoesNotExistException, UnsupportedProtocolException, IOException,
    AuthorizationException
{
    Artifact artifact = createTestArtifact( "target/test-data/get-remote-jar", "jar" );

    ArtifactRepository repo = createStringRepo();

    StringWagon wagon = (StringWagon) wagonManager.getWagon( "string" );
    wagon.addExpectedContent( repo.getLayout().pathOf( artifact ), "expected" );

    MockControl control = MockControl.createControl( UpdateCheckManager.class );
    control.replay();

    wagonManager.getArtifact( artifact, repo, null, false );

    assertTrue( artifact.getFile().exists() );
    assertEquals( "expected", FileUtils.fileRead( artifact.getFile(), "UTF-8" ) );

    control.verify();
}
项目:lams    文件:DistributedMigrationProcessTest.java   
public void testValidateControlledSystemsWhenNodePatchLevelsAreInSync() throws Exception
{

    // system has one node
    String systemName = "system1";
    JdbcMigrationLauncher launcher = new JdbcMigrationLauncher();

    MockControl contextControl = MockControl.createControl(JdbcMigrationContext.class);

    JdbcMigrationContext context = (JdbcMigrationContext) contextControl.getMock();
    MockControl patchInfoStoreControl = MockControl.createControl(PatchInfoStore.class);
    PatchInfoStore patchInfoStore = (PatchInfoStore) patchInfoStoreControl.getMock();

    expect(migrationRunnerStrategy.isSynchronized(currentPatchInfoStore, patchInfoStore)).andReturn(true);

    migrationRunnerStrategyControl.replay();

    migrationProcess.setMigrationRunnerStrategy(migrationRunnerStrategy);

    // create the launcher's contexts collection
    LinkedHashMap contexts = new LinkedHashMap();
    contexts.put(context, patchInfoStore);
    launcher.setContexts(contexts);

    HashMap controlledSystems = new HashMap();
    controlledSystems.put(systemName, launcher);

    migrationProcess.setControlledSystems(controlledSystems);

    try
    {
        migrationProcess.validateControlledSystems(currentPatchInfoStore);
    }
    catch(Exception e)
    {
        fail("Unexpected exception when validating controlled systems.");
    }
}
项目:lams    文件:SqlScriptMigrationTaskTest.java   
/**
    * 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();
   }
项目:lams    文件:MigrationTest.java   
/**
 * @see junit.framework.TestCase#setUp()
 */
protected void setUp() throws Exception
{
    super.setUp();
    runner = new MigrationProcess();
    runner.setMigrationRunnerStrategy(MigrationRunnerFactory.getMigrationRunnerStrategy(null));
    runner.addPatchResourceDirectory(getClass().getPackage().getName() + ".tasks.normal");
    runner.addPatchResourceDirectory(getClass().getPackage().getName() + ".tasks.rollback");
    runner.addPostPatchResourceDirectory(getClass().getPackage().getName() + ".tasks.post");
    runner.addListener(this);
    context = new TestMigrationContext();
    patchInfoStoreControl = MockControl.createStrictControl(PatchInfoStore.class);
    patchInfoStore = (PatchInfoStore) patchInfoStoreControl.getMock();
}
项目:lams    文件:MigrationTest.java   
/**
 * Validates that the migration runner will handle busted Migrations ok
 * 
 * @throws MigrationException if an unexpected error occurs
 */
public void testRunBrokenMigrationTasks() throws MigrationException
{
    List l = runner.getMigrationTasks();
    TestMigrationTask3.setFail(true);
    assertEquals(9, l.size());

    int executedTasks = 0;
    try
    {
        patchInfoStoreControl.expectAndReturn(patchInfoStore.getPatchLevel(), 5, MockControl.ONE_OR_MORE);
        patchInfoStoreControl.replay();
        executedTasks = runner.doMigrations(patchInfoStore, context);
        runner.doPostPatchMigrations(context);
        fail("We called a migration that failed, this should have thrown an exception");
    }
    catch (MigrationException me)
    {
        // we expect this
    }
    assertEquals(0, executedTasks);
    assertFalse(context.hasExecuted("TestTask1"));
    assertFalse(context.hasExecuted("TestTask2"));
    assertFalse(context.hasExecuted("TestTask3"));
    assertFalse(context.hasExecuted("TestTask4"));
    assertFalse(context.hasExecuted("TestRollbackableTask1"));
    assertFalse(context.hasExecuted("TestRollbackableTask2"));
    assertFalse(context.hasExecuted("TestRollbackableTask3"));
    assertFalse(context.hasExecuted("TestRollbackableTask4"));
    assertFalse(context.hasExecuted("TestRollbackableTask5"));
    assertFalse(context.hasExecuted("TestPostTask1"));
    assertFalse(context.hasExecuted("TestPostTask2"));
    assertEquals(1, getMigrationStartedCount());
    assertEquals(0, getMigrationSuccessCount());
    assertEquals(1, getMigrationFailedCount());
}
项目:lams    文件:MigrationProcessRollbackTest.java   
/**
 * @see junit.framework.TestCase#setUp()
 */
protected void setUp() throws Exception
{
    super.setUp();
    runner = new MigrationProcess();
    runner.setMigrationRunnerStrategy(MigrationRunnerFactory.getMigrationRunnerStrategy(null));
    runner.addPatchResourceDirectory(getClass().getPackage().getName()
            + ".tasks.rollback");
    runner.addPostPatchResourceDirectory(getClass().getPackage().getName()
            + ".tasks.post");
    runner.addListener(this);
    context = new TestMigrationContext();
    patchInfoStoreControl = MockControl.createStrictControl(PatchInfoStore.class);
    patchInfoStore = (PatchInfoStore) patchInfoStoreControl.getMock();
    currentPatchInfoStore = MockBuilder.getPatchInfoStore(12);

    mockControl = createStrictControl();
    migrationStrategy = mockControl.createMock(MigrationRunnerStrategy.class);
    List<MigrationTask> rollbackCandidates;
    rollbackCandidates = new ArrayList<MigrationTask>();
    rollbackCandidates.add(new TestRollbackableTask5());
    rollbackCandidates.add(new TestRollbackableTask4());
    rollbackCandidates.add(new TestRollbackableTask3());
    rollbackCandidates.add(new TestRollbackableTask2());
    expect(migrationStrategy.getRollbackCandidates(EasyMock.<List<MigrationTask>>anyObject(), eq(ROLLBACK_LEVELS), eq(currentPatchInfoStore))).andReturn(rollbackCandidates);
    expect(migrationStrategy.getRollbackCandidates(EasyMock.<List<MigrationTask>>anyObject(), eq(ROLLBACK_LEVELS), eq(currentPatchInfoStore))).andReturn(Collections.EMPTY_LIST);

}
项目:lams    文件:MigrationProcessRollbackTest.java   
/**
 * This method tests the basic rollback functionality.
 *
 * @throws MigrationException
 */
public void testRollbackAllTasks() throws MigrationException
{
    List migrationTasks = runner.getMigrationTasks();
    assertEquals(5, migrationTasks.size());

    patchInfoStoreControl.expectAndReturn(patchInfoStore.getPatchLevel(), 1, MockControl.ONE_OR_MORE);
    patchInfoStoreControl.replay();

    int level = runner.doMigrations(patchInfoStore, context);
    runner.doPostPatchMigrations(context);
    assertEquals(5, level);
    assertTrue(context.hasExecuted("TestRollbackableTask1"));
    assertTrue(context.hasExecuted("TestRollbackableTask2"));
    assertTrue(context.hasExecuted("TestRollbackableTask3"));
    assertTrue(context.hasExecuted("TestRollbackableTask4"));
    assertTrue(context.hasExecuted("TestRollbackableTask5"));

    // check that the migrations occurred successfully
    assertEquals(5, getMigrationStartedCount());
    assertEquals(5, getMigrationSuccessCount());

    // execute the rollback
    mockControl.replay();
    runner.setMigrationRunnerStrategy(migrationStrategy);
    level = runner.doRollbacks(currentPatchInfoStore, ROLLBACK_LEVELS, context, false);
    assertEquals(4, level);
    assertEquals(4, getRollbackSuccessCount());

}
项目:lams    文件:MigrationProcessRollbackTest.java   
/**
 * This method tests the basic rollback functionality.
 *
 * @throws MigrationException
 */
public void testRollbackPartialTasks() throws MigrationException
{
    List l = runner.getMigrationTasks();
    assertEquals(5, l.size());

    patchInfoStoreControl.expectAndReturn(patchInfoStore.getPatchLevel(), 8, MockControl.ONE_OR_MORE);
    patchInfoStoreControl.replay();

    int level = runner.doMigrations(patchInfoStore, context);
    runner.doPostPatchMigrations(context);
    assertEquals(4, level);
    assertEquals(4, getMigrationSuccessCount());

    assertFalse(context.hasExecuted("TestRollbackableTask1"));
    assertTrue(context.hasExecuted("TestRollbackableTask2"));
    assertTrue(context.hasExecuted("TestRollbackableTask3"));
    assertTrue(context.hasExecuted("TestRollbackableTask4"));
    assertTrue(context.hasExecuted("TestRollbackableTask5"));

    // execute the rollback
    mockControl.replay();
    runner.setMigrationRunnerStrategy(migrationStrategy);
    level = runner.doRollbacks(currentPatchInfoStore, ROLLBACK_LEVELS, context, false);
    assertEquals(4, level);
    assertEquals(4, getRollbackSuccessCount());
}
项目:lams    文件:MigrationProcessRollbackTest.java   
/**
 * this tests the scenario when the user tries to rollback to a level
 * which is greater than the current patch level.
 *
 * @throws MigrationException
 */
public void testInvalidRollbackLevel() throws MigrationException
{
    List l = runner.getMigrationTasks();
    assertEquals(5, l.size());

    patchInfoStoreControl.expectAndReturn(patchInfoStore.getPatchLevel(), 0, MockControl.ONE_OR_MORE);
    patchInfoStoreControl.replay();

    int level = runner.doMigrations(patchInfoStore, context);
    runner.doPostPatchMigrations(context);
    assertEquals(5, level);
    assertEquals(5, getMigrationSuccessCount());

    assertTrue(context.hasExecuted("TestRollbackableTask1"));
    assertTrue(context.hasExecuted("TestRollbackableTask2"));
    assertTrue(context.hasExecuted("TestRollbackableTask3"));
    assertTrue(context.hasExecuted("TestRollbackableTask4"));
    assertTrue(context.hasExecuted("TestRollbackableTask5"));


    try
    {
        PatchInfoStore patchInfoStoreBasedOnLevel = MockBuilder.getPatchInfoStore(level);
        int[] rollbackLevels = new int[]{7};
        level = runner.doRollbacks(patchInfoStoreBasedOnLevel, rollbackLevels, context, false);
    } catch (MigrationException me)
    {
        // expected
    }

}
项目:lams    文件:MigrationProcessRollbackTest.java   
/**
 * this test checks that the system correctly when a rollback is attempted
 * on a non-rollbackable task.
 *
 * @throws MigrationException
 */
public void testMigrationTaskRollback() throws MigrationException
{
    // add additional directory containing MigrationTask
    runner.addPatchResourceDirectory(getClass().getPackage().getName()
            + ".tasks.rollback.migrationtasks");
    List l = runner.getMigrationTasks();

    assertEquals(6, l.size());

    patchInfoStoreControl.expectAndReturn(patchInfoStore.getPatchLevel(), 7, MockControl.ONE_OR_MORE);
    patchInfoStoreControl.replay();

    int level = runner.doMigrations(patchInfoStore, context);
    runner.doPostPatchMigrations(context);
    assertEquals(6, level);
    assertEquals(6, getMigrationSuccessCount());
    assertTrue(context.hasExecuted("TestRollbackableTask1"));
    assertTrue(context.hasExecuted("TestRollbackableTask2"));
    assertTrue(context.hasExecuted("TestRollbackableTask3"));
    assertTrue(context.hasExecuted("TestRollbackableTask4"));
    assertTrue(context.hasExecuted("TestRollbackableTask5"));
    assertTrue(context.hasExecuted("TestMigrationTaskRollback1"));

    try
    {
        PatchInfoStore nestedPatchInfoStore = MockBuilder.getPatchInfoStore(13);
        int[] rollbackLevels = new int[]{12};
        level = runner.doRollbacks(nestedPatchInfoStore, rollbackLevels, context, false);
    } catch (MigrationException me)
    {
        // expected
    }
    assertEquals(0, level);
}
项目:clichart    文件:CliServerTest.java   
protected void setUp() throws IOException {
    m_chartGeneratorControl = MockControl.createStrictControl(ChartGenerator.class);
    m_chartGeneratorMock = (ChartGenerator) m_chartGeneratorControl.getMock();

    m_cliServer = new CliServer();
    m_cliServer.setChartGenerator(m_chartGeneratorMock);
}
项目:clichart    文件:TimeDataParserTest.java   
protected void setUp() throws Exception {
    m_sinkControl = MockControl.createStrictControl(DataSink.class);
    m_sinkControl.setDefaultMatcher(MockControl.ARRAY_MATCHER);
    m_sinkMock = (DataSink) m_sinkControl.getMock();

    m_lineParserControl = MockControl.createStrictControl(LineParser.class);
    m_lineParserMock = (LineParser) m_lineParserControl.getMock();

}
项目:spring-osgi    文件:TomcatWarDeploymentTest.java   
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);
}
项目:spring-osgi    文件:JettyWarDeployerTest.java   
public void testStartDeploymentWithInvalidObject() throws Exception {
    deployer.afterPropertiesSet();
    try {
        deployer.startDeployment((WarDeployment) MockControl.createNiceControl(WarDeployment.class).getMock());
        fail("should have thrown exception when given an non-jetty war deployment");
    }
    catch (RuntimeException ex) {
        // expected
    }
}
项目:spring-osgi    文件:OsgiServiceAnnotationTest.java   
protected void setUp() throws Exception {
    super.setUp();
    processor = new ServiceReferenceInjectionBeanPostProcessor();
    context = new MockBundleContext();
    processor.setBundleContext(context);
    processor.setBeanClassLoader(getClass().getClassLoader());
    MockControl factoryControl = MockControl.createControl(BeanFactory.class);
    BeanFactory factory = (BeanFactory) factoryControl.getMock();
    processor.setBeanFactory(factory);
}
项目:spring-osgi    文件:ContextLoaderListenerTest.java   
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();
}
项目:spring-osgi    文件:ConfigPropertiesHandlerTest.java   
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();
    }
项目:spring-osgi    文件:CmConfigAndCtxPropertiesConfigurationTest.java   
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();
    }
项目:spring-osgi    文件:ManagedServiceFactoryTest.java   
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();
    }
项目:spring-osgi    文件:AbstractBundleXmlApplicationContextTest.java   
protected void setUp() throws Exception {
    bundleCtxCtrl = MockControl.createNiceControl(BundleContext.class);
    context = (BundleContext) bundleCtxCtrl.getMock();
    bundleCtrl = MockControl.createNiceControl(Bundle.class);
    bundle = (Bundle) bundleCtrl.getMock();

    bundleCtxCtrl.expectAndReturn(context.getBundle(), bundle, MockControl.ONE_OR_MORE);

    dictionary = new Hashtable();

    // allow headers to be taken multiple times
    bundleCtrl.expectAndReturn(bundle.getHeaders(), dictionary, MockControl.ONE_OR_MORE);
}