@Test
  public void testExecutePLSQLBuilderWithSQLResource() throws IOException {
    MockBuilder builder =
        new MockBuilder() {
          @Override
          public void configure() {
            plsql(dataSource).sqlResource(sqlResource);
          }
        };

    reset(sqlResource);
    expect(sqlResource.getInputStream())
        .andReturn(new ByteArrayInputStream("testScript".getBytes()))
        .once();
    replay(sqlResource);

    builder.run(null, null);

    Assert.assertEquals(builder.testCase().getActions().size(), 1);
    Assert.assertEquals(
        builder.testCase().getActions().get(0).getClass(), ExecutePLSQLAction.class);

    ExecutePLSQLAction action = (ExecutePLSQLAction) builder.testCase().getActions().get(0);
    Assert.assertEquals(action.getName(), ExecutePLSQLAction.class.getSimpleName());
    Assert.assertEquals(action.isIgnoreErrors(), false);
    Assert.assertEquals(action.getStatements().size(), 0L);
    Assert.assertEquals(action.getScript(), "testScript");
    Assert.assertEquals(action.getDataSource(), dataSource);
  }
  @Test
  public void testExecutePLSQLBuilderWithStatement() {
    MockBuilder builder =
        new MockBuilder() {
          @Override
          public void configure() {
            plsql(dataSource)
                .statement("Test Statement")
                .statement("Test2 Statement")
                .statement("Test3 Statement");
          }
        };

    builder.run(null, null);

    Assert.assertEquals(builder.testCase().getActions().size(), 1);
    Assert.assertEquals(
        builder.testCase().getActions().get(0).getClass(), ExecutePLSQLAction.class);

    ExecutePLSQLAction action = (ExecutePLSQLAction) builder.testCase().getActions().get(0);
    Assert.assertEquals(action.getName(), ExecutePLSQLAction.class.getSimpleName());
    Assert.assertEquals(action.isIgnoreErrors(), false);
    Assert.assertEquals(
        action.getStatements().toString(), "[Test Statement, Test2 Statement, Test3 Statement]");
    Assert.assertNull(action.getScript());
    Assert.assertNull(action.getSqlResourcePath());
    Assert.assertEquals(action.getDataSource(), dataSource);
  }
  @Test
  public void testPurgeChannelsBuilderWithChannels() {
    MockBuilder builder =
        new MockBuilder(applicationContext) {
          @Override
          public void configure() {
            purgeChannels().channels(channel1, channel2).channel(channel3);
          }
        };

    builder.run(null, null);

    Assert.assertEquals(builder.testCase().getActions().size(), 1);
    Assert.assertEquals(
        builder.testCase().getActions().get(0).getClass(), PurgeMessageChannelAction.class);
    Assert.assertEquals(builder.testCase().getActions().get(0).getName(), "purge-channel");

    PurgeMessageChannelAction action =
        (PurgeMessageChannelAction) builder.testCase().getActions().get(0);
    Assert.assertEquals(action.getChannels().size(), 3);
    Assert.assertEquals(
        action.getChannels().toString(),
        "[" + channel1.toString() + ", " + channel2.toString() + ", " + channel3.toString() + "]");
    Assert.assertNull(action.getMessageSelector());
  }
  @Test
  public void testPurgeChannelBuilderWithNames() {
    MockBuilder builder =
        new MockBuilder(applicationContextMock) {
          @Override
          public void configure() {
            purgeChannels()
                .channelResolver(channelResolver)
                .channelNames("ch1", "ch2", "ch3")
                .channel("ch4")
                .selector(messageSelector);
          }
        };

    reset(applicationContextMock);

    expect(applicationContextMock.getBean(TestListeners.class))
        .andReturn(new TestListeners())
        .once();
    expect(applicationContextMock.getBean(TestActionListeners.class))
        .andReturn(new TestActionListeners())
        .once();
    expect(applicationContextMock.getBeansOfType(SequenceBeforeTest.class))
        .andReturn(new HashMap<String, SequenceBeforeTest>())
        .once();

    replay(applicationContextMock);

    builder.run(null, null);

    Assert.assertEquals(builder.testCase().getActions().size(), 1);
    Assert.assertEquals(
        builder.testCase().getActions().get(0).getClass(), PurgeMessageChannelAction.class);

    PurgeMessageChannelAction action =
        (PurgeMessageChannelAction) builder.testCase().getActions().get(0);
    Assert.assertEquals(action.getChannelNames().size(), 4);
    Assert.assertEquals(action.getChannelNames().toString(), "[ch1, ch2, ch3, ch4]");
    Assert.assertEquals(action.getChannelResolver(), channelResolver);
    Assert.assertEquals(action.getMessageSelector(), messageSelector);

    verify(applicationContextMock);
  }
  @Test
  public void testMissingChannelResolver() {
    MockBuilder builder =
        new MockBuilder(applicationContextMock) {
          @Override
          public void configure() {
            purgeChannels().channel("ch1");
          }
        };

    reset(applicationContextMock);

    expect(applicationContextMock.getBean(TestListeners.class))
        .andReturn(new TestListeners())
        .once();
    expect(applicationContextMock.getBean(TestActionListeners.class))
        .andReturn(new TestActionListeners())
        .once();
    expect(applicationContextMock.getBeansOfType(SequenceBeforeTest.class))
        .andReturn(new HashMap<String, SequenceBeforeTest>())
        .once();

    replay(applicationContextMock);

    builder.run(null, null);

    Assert.assertEquals(builder.testCase().getActions().size(), 1);
    Assert.assertEquals(
        builder.testCase().getActions().get(0).getClass(), PurgeMessageChannelAction.class);

    PurgeMessageChannelAction action =
        (PurgeMessageChannelAction) builder.testCase().getActions().get(0);
    Assert.assertEquals(action.getChannelNames().size(), 1);
    Assert.assertEquals(action.getChannelNames().toString(), "[ch1]");
    Assert.assertNotNull(action.getChannelResolver());
    Assert.assertTrue(action.getChannelResolver() instanceof BeanFactoryChannelResolver);

    verify(applicationContextMock);
  }
  @Test
  public void testExecutePLSQLBuilderWithInlineScript() {
    MockBuilder builder =
        new MockBuilder(applicationContext) {
          @Override
          public void configure() {
            plsql(dataSource).ignoreErrors(true).sqlScript("testScript");
          }
        };

    builder.run(null, null);

    Assert.assertEquals(builder.testCase().getActions().size(), 1);
    Assert.assertEquals(
        builder.testCase().getActions().get(0).getClass(), ExecutePLSQLAction.class);

    ExecutePLSQLAction action = (ExecutePLSQLAction) builder.testCase().getActions().get(0);
    Assert.assertEquals(action.getName(), "plsql");
    Assert.assertEquals(action.isIgnoreErrors(), true);
    Assert.assertEquals(action.getStatements().size(), 0L);
    Assert.assertNull(action.getSqlResourcePath());
    Assert.assertEquals(action.getScript(), "testScript");
    Assert.assertEquals(action.getDataSource(), dataSource);
  }