Search in sources :

Example 1 with TestLocation

use of io.confluent.ksql.test.model.TestLocation in project ksql by confluentinc.

the class RestTestCaseBuilder method buildTests.

static Stream<RestTestCase> buildTests(final RestTestCaseNode test, final TestFileContext ctx) {
    if (!test.isEnabled()) {
        return Stream.of();
    }
    try {
        final Stream<Optional<String>> formats = test.formats().isEmpty() ? Stream.of(Optional.empty()) : test.formats().stream().map(Optional::of);
        final TestLocation location = ctx.getTestLocation(test.name());
        return formats.map(format -> createTest(test, format, location));
    } catch (final Exception e) {
        throw new AssertionError("Invalid test '" + test.name() + "': " + e.getMessage(), e);
    }
}
Also used : Optional(java.util.Optional) TestLocation(io.confluent.ksql.test.model.TestLocation)

Example 2 with TestLocation

use of io.confluent.ksql.test.model.TestLocation in project ksql by confluentinc.

the class TestCaseBuilder method createTest.

private static TestCase createTest(final TestCaseNode test, final Path originalFileName, final TestLocation location, final Optional<String> explicitFormat) {
    final String testName = TestCaseBuilderUtil.buildTestName(originalFileName, test.name(), explicitFormat);
    try {
        final VersionBounds versionBounds = test.versionBounds().build();
        final List<String> statements = TestCaseBuilderUtil.buildStatements(test.statements(), explicitFormat);
        final Optional<Matcher<Throwable>> ee = test.expectedException().map(ExpectedExceptionNode::build);
        final Map<String, Topic> topics = TestCaseBuilderUtil.getAllTopics(statements, test.topics().stream().map(TopicNode::build).collect(Collectors.toList()), test.outputs().stream().map(RecordNode::build).collect(Collectors.toList()), test.inputs().stream().map(RecordNode::build).collect(Collectors.toList()), new InternalFunctionRegistry(), new KsqlConfig(test.properties())).stream().collect(Collectors.toMap(t -> t.getName().toLowerCase(), t -> t));
        final List<Record> inputRecords = test.inputs().stream().map(r -> {
            final String topicName = r.topicName().toLowerCase();
            // parse columns which value type cannot be detected without a schema
            if (topics.containsKey(topicName)) {
                return r.build(topics.get(topicName).getKeySchema(), topics.get(topicName).getValueSchema(), topics.get(topicName).getKeyFeatures(), topics.get(topicName).getValueFeatures());
            }
            return r.build();
        }).collect(Collectors.toList());
        final List<Record> outputRecords = test.outputs().stream().map(RecordNode::build).collect(Collectors.toList());
        final PostConditions post = test.postConditions().map(PostConditionsNode::build).orElse(PostConditions.NONE);
        return new TestCase(location, originalFileName, testName, versionBounds, test.properties(), topics.values(), inputRecords, outputRecords, statements, ee, post);
    } catch (final Exception e) {
        throw new AssertionError(testName + ": Invalid test. " + e.getMessage(), e);
    }
}
Also used : TestCaseNode(io.confluent.ksql.test.model.TestCaseNode) InternalFunctionRegistry(io.confluent.ksql.function.InternalFunctionRegistry) TestLocation(io.confluent.ksql.test.model.TestLocation) KsqlConfig(io.confluent.ksql.util.KsqlConfig) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) List(java.util.List) Stream(java.util.stream.Stream) ImmutableList(com.google.common.collect.ImmutableList) ExpectedExceptionNode(io.confluent.ksql.test.model.ExpectedExceptionNode) TopicNode(io.confluent.ksql.test.model.TopicNode) PostConditionsNode(io.confluent.ksql.test.model.PostConditionsNode) PostConditions(io.confluent.ksql.test.tools.conditions.PostConditions) Map(java.util.Map) Matcher(org.hamcrest.Matcher) Optional(java.util.Optional) RecordNode(io.confluent.ksql.test.model.RecordNode) Path(java.nio.file.Path) TopicNode(io.confluent.ksql.test.model.TopicNode) Matcher(org.hamcrest.Matcher) KsqlConfig(io.confluent.ksql.util.KsqlConfig) ExpectedExceptionNode(io.confluent.ksql.test.model.ExpectedExceptionNode) RecordNode(io.confluent.ksql.test.model.RecordNode) PostConditions(io.confluent.ksql.test.tools.conditions.PostConditions) InternalFunctionRegistry(io.confluent.ksql.function.InternalFunctionRegistry)

Example 3 with TestLocation

use of io.confluent.ksql.test.model.TestLocation in project ksql by confluentinc.

the class TestCaseBuilder method buildTests.

public static List<TestCase> buildTests(final TestCaseNode test, final Path originalFileName, final Function<String, TestLocation> testLocator) {
    if (!test.isEnabled()) {
        return ImmutableList.of();
    }
    try {
        final Stream<Optional<String>> formats = test.formats().isEmpty() ? Stream.of(Optional.empty()) : test.formats().stream().map(Optional::of);
        final TestLocation location = testLocator.apply(test.name());
        return formats.map(format -> createTest(test, originalFileName, location, format)).collect(Collectors.toList());
    } catch (final Exception e) {
        throw new AssertionError("Invalid test '" + test.name() + "': " + e.getMessage(), e);
    }
}
Also used : TestCaseNode(io.confluent.ksql.test.model.TestCaseNode) InternalFunctionRegistry(io.confluent.ksql.function.InternalFunctionRegistry) TestLocation(io.confluent.ksql.test.model.TestLocation) KsqlConfig(io.confluent.ksql.util.KsqlConfig) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) List(java.util.List) Stream(java.util.stream.Stream) ImmutableList(com.google.common.collect.ImmutableList) ExpectedExceptionNode(io.confluent.ksql.test.model.ExpectedExceptionNode) TopicNode(io.confluent.ksql.test.model.TopicNode) PostConditionsNode(io.confluent.ksql.test.model.PostConditionsNode) PostConditions(io.confluent.ksql.test.tools.conditions.PostConditions) Map(java.util.Map) Matcher(org.hamcrest.Matcher) Optional(java.util.Optional) RecordNode(io.confluent.ksql.test.model.RecordNode) Path(java.nio.file.Path) Optional(java.util.Optional) TestLocation(io.confluent.ksql.test.model.TestLocation)

Aggregations

TestLocation (io.confluent.ksql.test.model.TestLocation)3 Optional (java.util.Optional)3 ImmutableList (com.google.common.collect.ImmutableList)2 InternalFunctionRegistry (io.confluent.ksql.function.InternalFunctionRegistry)2 ExpectedExceptionNode (io.confluent.ksql.test.model.ExpectedExceptionNode)2 PostConditionsNode (io.confluent.ksql.test.model.PostConditionsNode)2 RecordNode (io.confluent.ksql.test.model.RecordNode)2 TestCaseNode (io.confluent.ksql.test.model.TestCaseNode)2 TopicNode (io.confluent.ksql.test.model.TopicNode)2 PostConditions (io.confluent.ksql.test.tools.conditions.PostConditions)2 KsqlConfig (io.confluent.ksql.util.KsqlConfig)2 Path (java.nio.file.Path)2 List (java.util.List)2 Map (java.util.Map)2 Function (java.util.function.Function)2 Collectors (java.util.stream.Collectors)2 Stream (java.util.stream.Stream)2 Matcher (org.hamcrest.Matcher)2