Пример #1
0
  @Test
  public void testJavaBuilderWithClassName()
      throws InstantiationException, IllegalAccessException, ClassNotFoundException {
    final List<Object> constructorArgs = new ArrayList<Object>();
    constructorArgs.add(5);
    constructorArgs.add(7);

    final List<Object> methodArgs = new ArrayList<Object>();
    methodArgs.add(4);

    MockBuilder builder =
        new MockBuilder() {
          @Override
          public void configure() {
            java("com.consol.citrus.dsl.util.JavaTest")
                .constructorArgs(constructorArgs)
                .methodArgs(methodArgs)
                .method("add");
          }
        };

    builder.run(null, null);

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

    JavaAction action = ((JavaAction) builder.testCase().getActions().get(0));
    Assert.assertEquals(action.getName(), JavaAction.class.getSimpleName());

    Assert.assertEquals(action.getClassName(), "com.consol.citrus.dsl.util.JavaTest");
    Assert.assertNull(action.getInstance());
    Assert.assertEquals(action.getMethodName(), "add");
    Assert.assertEquals(action.getMethodArgs().size(), 1);
  }
Пример #2
0
  @Test
  public void testJavaBuilderWithObjectInstance()
      throws InstantiationException, IllegalAccessException, ClassNotFoundException {
    final List<Object> methodArgs = new ArrayList<Object>();
    methodArgs.add(new TestContext());

    MockBuilder builder =
        new MockBuilder() {
          @Override
          public void configure() {
            java(new EchoAction()).methodArgs(methodArgs).method("execute");
          }
        };

    builder.run(null, null);

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

    JavaAction action = ((JavaAction) builder.testCase().getActions().get(0));
    Assert.assertEquals(action.getName(), JavaAction.class.getSimpleName());

    Assert.assertNull(action.getClassName());
    Assert.assertNotNull(action.getInstance());
    Assert.assertEquals(action.getMethodName(), "execute");
    Assert.assertEquals(action.getMethodArgs().size(), 1);
  }
  @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 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 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 TestLoadBuilder() {
    MockBuilder builder =
        new MockBuilder(applicationContext) {
          @Override
          public void configure() {
            load("classpath:test.properties");
          }
        };

    builder.run(null, null);

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

    LoadPropertiesAction action = (LoadPropertiesAction) builder.testCase().getActions().get(0);
    Assert.assertEquals(action.getName(), "load");
    Assert.assertEquals(action.getFilePath(), "classpath:test.properties");
  }
  @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 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);
  }