Package org.springframework.xd.test.fixtures

Examples of org.springframework.xd.test.fixtures.JdbcSink


   */
  public JdbcSink jdbc() {
    if (environment.getDataSource() == null) {
      return null;
    }
    jdbcSink = new JdbcSink(environment.getDataSource());

    if (!jdbcSink.isReady()) {
      throw new IllegalStateException("Unable to connecto to database.");
    }
    return jdbcSink;
View Full Code Here


*/
public class JdbcModulesTests extends AbstractStreamIntegrationTest {

  @Test
  public void testJdbcSinkWith1InsertionAndDefaultConfiguration() throws Exception {
    JdbcSink jdbcSink = newJdbcSink();

    HttpSource httpSource = newHttpSource();


    String streamName = generateStreamName().replaceAll("-", "_");
    stream().create(streamName, "%s | %s", httpSource, jdbcSink);
    httpSource.ensureReady().postData("Hi there!");

    String query = String.format("SELECT payload FROM %s", streamName);
    assertEquals(
        "Hi there!",
        jdbcSink.getJdbcTemplate().queryForObject(query, String.class));
  }
View Full Code Here

        jdbcSink.getJdbcTemplate().queryForObject(query, String.class));
  }

  @Test
  public void testJdbcSinkWith2InsertionsAndDefaultConfiguration() throws Exception {
    JdbcSink jdbcSink = newJdbcSink();

    HttpSource httpSource = newHttpSource();


    String streamName = generateStreamName().replaceAll("-", "_");
    stream().create(streamName, "%s | %s", httpSource, jdbcSink);
    httpSource.ensureReady().postData("Hi there!");
    httpSource.postData("How are you?");

    String query = String.format("SELECT payload FROM %s", streamName);
    List<String> result = jdbcSink.getJdbcTemplate().queryForList(query, String.class);
    assertThat(result, contains("Hi there!", "How are you?"));
  }
View Full Code Here

  }

  @Test
  public void testJdbcSinkWithCustomTableName() throws Exception {
    String tableName = "foobar";
    JdbcSink jdbcSink = newJdbcSink().tableName(tableName);

    HttpSource httpSource = newHttpSource();

    stream().create(generateStreamName(), "%s | %s", httpSource, jdbcSink);
    httpSource.ensureReady().postData("Hi there!");

    String query = String.format("SELECT payload FROM %s", tableName);
    assertEquals(
        "Hi there!",
        jdbcSink.getJdbcTemplate().queryForObject(query, String.class));
  }
View Full Code Here

        jdbcSink.getJdbcTemplate().queryForObject(query, String.class));
  }

  @Test
  public void testJdbcSinkWithCustomColumnNames() throws Exception {
    JdbcSink jdbcSink = newJdbcSink().columns("foo,bar");

    HttpSource httpSource = newHttpSource();


    String streamName = generateStreamName().replaceAll("-", "_");
    stream().create(streamName, "%s | %s", httpSource, jdbcSink);
    String json = "{\"foo\":5, \"bar\": \"hello\"}";
    httpSource.ensureReady().postData(json);

    String query = String.format("SELECT foo, bar FROM %s", streamName);
    Result result = jdbcSink.getJdbcTemplate().queryForObject(query, new BeanPropertyRowMapper<>(Result.class));
    assertEquals("hello", result.getBar());
    assertEquals(5, result.getFoo());
  }
View Full Code Here

    assertEquals(5, result.getFoo());
  }

  @Test
  public void testJdbcSinkWithCustomColumnNamesWithUnderscores() throws Exception {
    JdbcSink jdbcSink = newJdbcSink().columns("foo_bar,bar_foo,bar_baz");

    HttpSource httpSource = newHttpSource();

    String streamName = generateStreamName().replaceAll("-", "_");
    stream().create(streamName, "%s | %s", httpSource, jdbcSink);
    String json = "{\"fooBar\":5, \"barFoo\": \"hello\", \"bar_baz\": \"good_bye\"}";
    httpSource.ensureReady().postData(json);

    String query = String.format("SELECT foo_bar, bar_foo, bar_baz FROM %s", streamName);
    Map<String, Object> result = jdbcSink.getJdbcTemplate().queryForMap(query);
    assertEquals("hello", result.get("bar_foo"));
    assertEquals("5", result.get("foo_bar"));
    assertEquals("good_bye", result.get("bar_baz"));
  }
View Full Code Here

    disposables.add(tcpSink);
    return tcpSink;
  }

  protected JdbcSink newJdbcSink() {
    return new JdbcSink(createDataSource());
  }
View Full Code Here

TOP

Related Classes of org.springframework.xd.test.fixtures.JdbcSink

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.