Search in sources :

Example 1 with SqlTest

use of io.confluent.ksql.test.parser.SqlTestLoader.SqlTest 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 SqlTest

use of io.confluent.ksql.test.parser.SqlTestLoader.SqlTest in project ksql by confluentinc.

the class SqlTestLoader method load.

@Override
public Stream<SqlTest> load() throws IOException {
    final List<Path> files = Files.find(path, Integer.MAX_VALUE, (filePath, fileAttr) -> fileAttr.isRegularFile()).collect(Collectors.toList());
    final ImmutableList.Builder<SqlTest> builder = ImmutableList.builder();
    final List<String> whiteList = TestLoader.getWhiteList();
    for (final Path file : files) {
        if (whiteList.isEmpty() || whiteList.stream().anyMatch(file::endsWith)) {
            builder.addAll(loadTest(file));
        }
    }
    return builder.build().stream();
}
Also used : Path(java.nio.file.Path) Files(java.nio.file.Files) Predicate(java.util.function.Predicate) TestLocation(io.confluent.ksql.test.model.TestLocation) Type(io.confluent.ksql.test.parser.TestDirective.Type) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) TestLoader(io.confluent.ksql.test.loader.TestLoader) ArrayList(java.util.ArrayList) Test(io.confluent.ksql.test.tools.Test) Objects(java.util.Objects) SqlTest(io.confluent.ksql.test.parser.SqlTestLoader.SqlTest) List(java.util.List) Stream(java.util.stream.Stream) ImmutableList(com.google.common.collect.ImmutableList) KsqlTestException(io.confluent.ksql.test.KsqlTestException) Optional(java.util.Optional) Path(java.nio.file.Path) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings) SqlTest(io.confluent.ksql.test.parser.SqlTestLoader.SqlTest) ImmutableList(com.google.common.collect.ImmutableList)

Aggregations

ImmutableList (com.google.common.collect.ImmutableList)2 KsqlTestException (io.confluent.ksql.test.KsqlTestException)2 SqlTest (io.confluent.ksql.test.parser.SqlTestLoader.SqlTest)2 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)1 TestLoader (io.confluent.ksql.test.loader.TestLoader)1 TestLocation (io.confluent.ksql.test.model.TestLocation)1 Type (io.confluent.ksql.test.parser.TestDirective.Type)1 Test (io.confluent.ksql.test.tools.Test)1 IOException (java.io.IOException)1 Files (java.nio.file.Files)1 Path (java.nio.file.Path)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 Predicate (java.util.function.Predicate)1 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1