Search in sources :

Example 1 with SqlCreateConnectorStatement

use of io.confluent.ksql.tools.migrations.util.CommandParser.SqlCreateConnectorStatement in project ksql by confluentinc.

the class CommandParserTest method shouldParseCreateConnectorStatementWithVariables.

@Test
public void shouldParseCreateConnectorStatementWithVariables() {
    // Given:
    final String createConnector = "CREATE SOURCE CONNECTOR ${name} WITH(\n" + "    \"connector.class\"='io.confluent.connect.jdbc.JdbcSourceConnector',\n" + "    \"connection.url\"=${url},\n" + "    \"mode\"='bulk',\n" + "    \"topic.prefix\"='jdbc-',\n" + "    \"table.whitelist\"='users',\n" + "    \"key\"='username');";
    // When:
    List<SqlCommand> commands = parse(createConnector, ImmutableMap.of("url", "'jdbc:postgresql://localhost:5432/my.db'", "name", "`jdbc_connector`"));
    // Then:
    assertThat(commands.size(), is(1));
    assertThat(commands.get(0), instanceOf(SqlCreateConnectorStatement.class));
    assertThat(commands.get(0).getCommand(), is(createConnector));
    assertThat(((SqlCreateConnectorStatement) commands.get(0)).getName(), is("`jdbc_connector`"));
    assertThat(((SqlCreateConnectorStatement) commands.get(0)).isSource(), is(true));
    assertThat(((SqlCreateConnectorStatement) commands.get(0)).getProperties().size(), is(6));
    assertThat(((SqlCreateConnectorStatement) commands.get(0)).getProperties().get("connector.class"), is("io.confluent.connect.jdbc.JdbcSourceConnector"));
    assertThat(((SqlCreateConnectorStatement) commands.get(0)).getProperties().get("connection.url"), is("jdbc:postgresql://localhost:5432/my.db"));
    assertThat(((SqlCreateConnectorStatement) commands.get(0)).getProperties().get("mode"), is("bulk"));
    assertThat(((SqlCreateConnectorStatement) commands.get(0)).getProperties().get("topic.prefix"), is("jdbc-"));
    assertThat(((SqlCreateConnectorStatement) commands.get(0)).getProperties().get("table.whitelist"), is("users"));
    assertThat(((SqlCreateConnectorStatement) commands.get(0)).getProperties().get("key"), is("username"));
}
Also used : Matchers.containsString(org.hamcrest.Matchers.containsString) SqlCreateConnectorStatement(io.confluent.ksql.tools.migrations.util.CommandParser.SqlCreateConnectorStatement) SqlCommand(io.confluent.ksql.tools.migrations.util.CommandParser.SqlCommand) Test(org.junit.Test)

Example 2 with SqlCreateConnectorStatement

use of io.confluent.ksql.tools.migrations.util.CommandParser.SqlCreateConnectorStatement in project ksql by confluentinc.

the class CommandParserTest method shouldParseCreateConnectorStatement.

@Test
public void shouldParseCreateConnectorStatement() {
    // Given:
    final String createConnector = "CREATE SOURCE CONNECTOR `jdbc-connector` WITH(\n" + "    \"connector.class\"='io.confluent.connect.jdbc.JdbcSourceConnector',\n" + "    \"connection.url\"='jdbc:postgresql://localhost:5432/my.db',\n" + "    \"mode\"='bulk',\n" + "    \"topic.prefix\"='jdbc-',\n" + "    \"table.whitelist\"='users',\n" + "    \"key\"='username');";
    // When:
    List<SqlCommand> commands = parse(createConnector);
    // Then:
    assertThat(commands.size(), is(1));
    assertThat(commands.get(0), instanceOf(SqlCreateConnectorStatement.class));
    assertThat(commands.get(0).getCommand(), is(createConnector));
    assertThat(((SqlCreateConnectorStatement) commands.get(0)).getName(), is("`jdbc-connector`"));
    assertThat(((SqlCreateConnectorStatement) commands.get(0)).isSource(), is(true));
    assertThat(((SqlCreateConnectorStatement) commands.get(0)).getProperties().size(), is(6));
    assertThat(((SqlCreateConnectorStatement) commands.get(0)).getProperties().get("connector.class"), is("io.confluent.connect.jdbc.JdbcSourceConnector"));
    assertThat(((SqlCreateConnectorStatement) commands.get(0)).getProperties().get("connection.url"), is("jdbc:postgresql://localhost:5432/my.db"));
    assertThat(((SqlCreateConnectorStatement) commands.get(0)).getProperties().get("mode"), is("bulk"));
    assertThat(((SqlCreateConnectorStatement) commands.get(0)).getProperties().get("topic.prefix"), is("jdbc-"));
    assertThat(((SqlCreateConnectorStatement) commands.get(0)).getProperties().get("table.whitelist"), is("users"));
    assertThat(((SqlCreateConnectorStatement) commands.get(0)).getProperties().get("key"), is("username"));
}
Also used : Matchers.containsString(org.hamcrest.Matchers.containsString) SqlCreateConnectorStatement(io.confluent.ksql.tools.migrations.util.CommandParser.SqlCreateConnectorStatement) SqlCommand(io.confluent.ksql.tools.migrations.util.CommandParser.SqlCommand) Test(org.junit.Test)

Aggregations

SqlCommand (io.confluent.ksql.tools.migrations.util.CommandParser.SqlCommand)2 SqlCreateConnectorStatement (io.confluent.ksql.tools.migrations.util.CommandParser.SqlCreateConnectorStatement)2 Matchers.containsString (org.hamcrest.Matchers.containsString)2 Test (org.junit.Test)2