Search in sources :

Example 1 with KsqlTestException

use of io.confluent.ksql.test.KsqlTestException in project ksql by confluentinc.

the class SqlTestLoader method loadTest.

/**
 * @param path a single sql test file, containing possibly many tests
 *
 * @return the list of tests to run
 */
public List<SqlTest> loadTest(final Path path) throws IOException {
    final ImmutableList.Builder<SqlTest> builder = ImmutableList.builder();
    List<TestStatement> statements = null;
    String name = null;
    final SqlTestReader reader = SqlTestReader.of(path);
    while (reader.hasNext()) {
        final TestStatement statement = reader.next();
        final Optional<String> nextName = statement.consumeDirective(directive -> directive.getType() == Type.TEST ? directive.getContents() : null);
        if (nextName.isPresent()) {
            // flush the previous test
            if (statements != null) {
                builder.add(new SqlTest(path, name, statements));
            }
            statements = new ArrayList<>();
            name = nextName.get();
        } else if (statements == null) {
            throw new KsqlTestException(statement, path, "Exepcted test to start with --@test.");
        }
        statements.add(statement);
    }
    builder.add(new SqlTest(path, name, statements));
    return builder.build().stream().filter(shouldRun).collect(ImmutableList.toImmutableList());
}
Also used : SqlTest(io.confluent.ksql.test.parser.SqlTestLoader.SqlTest) KsqlTestException(io.confluent.ksql.test.KsqlTestException) ImmutableList(com.google.common.collect.ImmutableList)

Example 2 with KsqlTestException

use of io.confluent.ksql.test.KsqlTestException in project ksql by confluentinc.

the class KsqlTesterTest method test.

@Test
public void test() {
    for (final TestStatement testStatement : statements) {
        try {
            testStatement.consume(this::execute, this::doAssert, this::directive);
        } catch (final Throwable e) {
            handleExpectedException(testStatement, e);
            return;
        }
    }
    if (expectedException != null || expectedMessage != null) {
        final String clazz = expectedException == null ? "<any>" : expectedException.getName();
        final String msg = expectedMessage == null ? "<any>" : expectedMessage;
        throw new KsqlTestException(Iterables.getLast(statements), file, "Did not get expected exception of type " + clazz + " with message " + msg);
    }
}
Also used : KsqlTestException(io.confluent.ksql.test.KsqlTestException) TestStatement(io.confluent.ksql.test.parser.TestStatement) Test(org.junit.Test)

Aggregations

KsqlTestException (io.confluent.ksql.test.KsqlTestException)2 ImmutableList (com.google.common.collect.ImmutableList)1 SqlTest (io.confluent.ksql.test.parser.SqlTestLoader.SqlTest)1 TestStatement (io.confluent.ksql.test.parser.TestStatement)1 Test (org.junit.Test)1