Search in sources :

Example 1 with PathLocation

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

the class TestCasePlanLoader method buildStatementsInTestCase.

private static TestCasePlan buildStatementsInTestCase(final TestCase testCase, final KsqlVersion version, final long timestamp, final Map<String, String> configs, final String simpleTestName, final boolean validateResults) {
    final TestInfoGatherer testInfo = executeTestCaseAndGatherInfo(testCase, validateResults);
    final List<TopicNode> allTopicNodes = getTopicsFromTestCase(testCase, configs);
    final TestCaseNode testCodeNode = new TestCaseNode(simpleTestName, Optional.empty(), ImmutableList.of(), testCase.getInputRecords().stream().map(RecordNode::from).collect(Collectors.toList()), testCase.getOutputRecords().stream().map(RecordNode::from).collect(Collectors.toList()), allTopicNodes, testCase.statements(), testCase.properties(), null, testCase.getPostConditions().asNode(testInfo.getTopics(), testInfo.getSources()), true);
    final TestCaseSpecNode spec = new TestCaseSpecNode(version.getVersion().toString(), timestamp, testCase.getOriginalFileName().toString(), testInfo.getSchemas(), testCodeNode);
    final TestCasePlanNode plan = new TestCasePlanNode(testInfo.getPlans(), configs);
    return new TestCasePlan(// not used
    new PathLocation(Paths.get("").toAbsolutePath()), spec, plan, testInfo.getTopologyDescription());
}
Also used : PathLocation(io.confluent.ksql.test.model.PathLocation) PostTopicNode(io.confluent.ksql.test.model.PostConditionsNode.PostTopicNode) TopicNode(io.confluent.ksql.test.model.TopicNode) TestCaseNode(io.confluent.ksql.test.model.TestCaseNode) RecordNode(io.confluent.ksql.test.model.RecordNode)

Example 2 with PathLocation

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

the class TestCasePlanLoader method parseSpec.

private static TestCasePlan parseSpec(final PlannedTestPath versionDir) {
    final PlannedTestPath planPath = versionDir.resolve(PlannedTestPath.PLAN_FILE);
    final PlannedTestPath specPath = versionDir.resolve(PlannedTestPath.SPEC_FILE);
    final PlannedTestPath topologyPath = versionDir.resolve(PlannedTestPath.TOPOLOGY_FILE);
    return new TestCasePlan(new PathLocation(versionDir.absolutePath()), parseJson(specPath, JsonTestLoader.OBJECT_MAPPER, TestCaseSpecNode.class), parseJson(planPath, PlannedTestUtils.PLAN_MAPPER, TestCasePlanNode.class), slurp(topologyPath));
}
Also used : PathLocation(io.confluent.ksql.test.model.PathLocation)

Example 3 with PathLocation

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

the class KsqlTestingTool method runWithTripleFiles.

static void runWithTripleFiles(final String statementFile, final String inputFile, final String outputFile, final Optional<String> extensionDir) throws Exception {
    final InputRecordsNode inputRecordNodes;
    final OutputRecordsNode outRecordNodes;
    try {
        inputRecordNodes = (inputFile == null) ? null : OBJECT_MAPPER.readValue(new File(inputFile), InputRecordsNode.class);
    } catch (final Exception inputException) {
        throw new Exception("File name: " + inputFile + " Message: " + inputException.getMessage());
    }
    try {
        outRecordNodes = OBJECT_MAPPER.readValue(new File(outputFile), OutputRecordsNode.class);
    } catch (final Exception outputException) {
        throw new Exception("File name: " + outputFile + " Message: " + outputException.getMessage());
    }
    final Path stmtsPath = Paths.get(statementFile);
    final List<String> statements = getSqlStatements(stmtsPath);
    final TestCaseNode testCaseNode = new TestCaseNode("KSQL_Test", Optional.empty(), null, (inputFile == null) ? null : inputRecordNodes.getInputRecords(), outRecordNodes.getOutputRecords(), Collections.emptyList(), statements, null, null, null, true);
    final PathLocation location = new PathLocation(stmtsPath.toAbsolutePath());
    final TestCase testCase = TestCaseBuilder.buildTests(testCaseNode, location.getTestPath(), name -> location).get(0);
    executeTestCase(testCase, TestExecutor.create(true, extensionDir));
}
Also used : Path(java.nio.file.Path) TestCaseNode(io.confluent.ksql.test.model.TestCaseNode) Files(java.nio.file.Files) UTF_8(java.nio.charset.StandardCharsets.UTF_8) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) KsqlParser(io.confluent.ksql.parser.KsqlParser) IOException(java.io.IOException) OutputRecordsNode(io.confluent.ksql.test.model.OutputRecordsNode) Collectors(java.util.stream.Collectors) File(java.io.File) PathLocation(io.confluent.ksql.test.model.PathLocation) TestOptions(io.confluent.ksql.test.tools.command.TestOptions) List(java.util.List) InputRecordsNode(io.confluent.ksql.test.model.InputRecordsNode) Paths(java.nio.file.Paths) DefaultKsqlParser(io.confluent.ksql.parser.DefaultKsqlParser) ParsedStatement(io.confluent.ksql.parser.KsqlParser.ParsedStatement) KsqlException(io.confluent.ksql.util.KsqlException) Optional(java.util.Optional) Path(java.nio.file.Path) Collections(java.util.Collections) PathLocation(io.confluent.ksql.test.model.PathLocation) TestCaseNode(io.confluent.ksql.test.model.TestCaseNode) OutputRecordsNode(io.confluent.ksql.test.model.OutputRecordsNode) InputRecordsNode(io.confluent.ksql.test.model.InputRecordsNode) File(java.io.File) IOException(java.io.IOException) KsqlException(io.confluent.ksql.util.KsqlException)

Aggregations

PathLocation (io.confluent.ksql.test.model.PathLocation)3 TestCaseNode (io.confluent.ksql.test.model.TestCaseNode)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 DefaultKsqlParser (io.confluent.ksql.parser.DefaultKsqlParser)1 KsqlParser (io.confluent.ksql.parser.KsqlParser)1 ParsedStatement (io.confluent.ksql.parser.KsqlParser.ParsedStatement)1 InputRecordsNode (io.confluent.ksql.test.model.InputRecordsNode)1 OutputRecordsNode (io.confluent.ksql.test.model.OutputRecordsNode)1 PostTopicNode (io.confluent.ksql.test.model.PostConditionsNode.PostTopicNode)1 RecordNode (io.confluent.ksql.test.model.RecordNode)1 TopicNode (io.confluent.ksql.test.model.TopicNode)1 TestOptions (io.confluent.ksql.test.tools.command.TestOptions)1 KsqlException (io.confluent.ksql.util.KsqlException)1 File (java.io.File)1 IOException (java.io.IOException)1 UTF_8 (java.nio.charset.StandardCharsets.UTF_8)1 Files (java.nio.file.Files)1 Path (java.nio.file.Path)1 Paths (java.nio.file.Paths)1 Collections (java.util.Collections)1