use of io.confluent.ksql.api.client.KsqlObject in project ksql by confluentinc.
the class ApplyMigrationCommandTest method shouldResetVariablesBetweenMigrations.
@SuppressWarnings("unchecked")
@Test
public void shouldResetVariablesBetweenMigrations() throws Exception {
// Given:
final Map<String, Object> variables = ImmutableMap.of("cat", "pat");
command = PARSER.parse("-a");
createMigrationFile(1, NAME, migrationsDir, "DEFINE cat='pat';");
createMigrationFile(2, NAME, migrationsDir, "INSERT INTO FOO VALUES ('${cat}');");
when(versionQueryResult.get()).thenReturn(ImmutableList.of());
when(ksqlClient.getVariables()).thenReturn(ImmutableMap.of(), ImmutableMap.of(), variables, ImmutableMap.of());
givenAppliedMigration(1, NAME, MigrationState.MIGRATED);
// When:
final int result = command.command(config, (cfg, headers) -> ksqlClient, migrationsDir, Clock.fixed(Instant.ofEpochMilli(1000), ZoneId.systemDefault()));
// Then:
assertThat(result, is(0));
final InOrder inOrder = inOrder(ksqlClient);
inOrder.verify(ksqlClient, times(2)).getVariables();
inOrder.verify(ksqlClient).define("cat", "pat");
inOrder.verify(ksqlClient).getVariables();
inOrder.verify(ksqlClient).undefine("cat");
inOrder.verify(ksqlClient).getVariables();
inOrder.verify(ksqlClient).insertInto("`FOO`", new KsqlObject(ImmutableMap.of("`A`", "${cat}")));
inOrder.verify(ksqlClient).close();
inOrder.verifyNoMoreInteractions();
}
Aggregations