Search in sources :

Example 51 with MockPipelineConfigurer

use of io.cdap.cdap.etl.mock.common.MockPipelineConfigurer in project hydrator-plugins by cdapio.

the class LogParserTransformTest method testConfigurePipelineSchemaValidation.

@Test
public void testConfigurePipelineSchemaValidation() {
    Schema inputSchemaString = Schema.recordOf("event", Schema.Field.of("CLF", Schema.of(Schema.Type.STRING)), Schema.Field.of("body", Schema.of(Schema.Type.STRING)));
    MockPipelineConfigurer mockConfigurer = new MockPipelineConfigurer(inputSchemaString, Collections.emptyMap());
    S3_TRANSFORM.configurePipeline(mockConfigurer);
    Assert.assertEquals(LOG_SCHEMA, mockConfigurer.getOutputSchema());
    Schema inputSchemaBytes = Schema.recordOf("event", Schema.Field.of("CLF", Schema.of(Schema.Type.STRING)), Schema.Field.of("body", Schema.of(Schema.Type.BYTES)));
    mockConfigurer = new MockPipelineConfigurer(inputSchemaBytes, Collections.emptyMap());
    CLF_TRANSFORM.configurePipeline(mockConfigurer);
    Assert.assertEquals(LOG_SCHEMA, mockConfigurer.getOutputSchema());
}
Also used : MockPipelineConfigurer(io.cdap.cdap.etl.mock.common.MockPipelineConfigurer) Schema(io.cdap.cdap.api.data.schema.Schema) Test(org.junit.Test)

Example 52 with MockPipelineConfigurer

use of io.cdap.cdap.etl.mock.common.MockPipelineConfigurer in project hydrator-plugins by cdapio.

the class CSVFormatterTest method testSchemaValidation.

@Test
public void testSchemaValidation() {
    CSVFormatter.Config config = new CSVFormatter.Config("DELIMITED", "VBAR", OUTPUT.toString());
    Transform<StructuredRecord, StructuredRecord> transform = new CSVFormatter(config);
    MockPipelineConfigurer mockPipelineConfigurer = new MockPipelineConfigurer(INPUT1);
    transform.configurePipeline(mockPipelineConfigurer);
    Assert.assertEquals(OUTPUT, mockPipelineConfigurer.getOutputSchema());
}
Also used : MockPipelineConfigurer(io.cdap.cdap.etl.mock.common.MockPipelineConfigurer) StructuredRecord(io.cdap.cdap.api.data.format.StructuredRecord) Test(org.junit.Test)

Example 53 with MockPipelineConfigurer

use of io.cdap.cdap.etl.mock.common.MockPipelineConfigurer in project hydrator-plugins by cdapio.

the class CSVParserTest method testEmptyCustomDelimiter.

@Test
public void testEmptyCustomDelimiter() {
    CSVParser config = new CSVParser(new CSVParser.Config("Custom", null, "body", OUTPUT4.toString()));
    MockPipelineConfigurer configurer = new MockPipelineConfigurer(INPUT2);
    try {
        config.configurePipeline(configurer);
        Assert.fail();
    } catch (ValidationException e) {
        Assert.assertEquals(2, configurer.getStageConfigurer().getFailureCollector().getValidationFailures().size());
    }
}
Also used : ValidationException(io.cdap.cdap.etl.api.validation.ValidationException) MockPipelineConfigurer(io.cdap.cdap.etl.mock.common.MockPipelineConfigurer) Test(org.junit.Test)

Example 54 with MockPipelineConfigurer

use of io.cdap.cdap.etl.mock.common.MockPipelineConfigurer in project hydrator-plugins by cdapio.

the class CSVParserTest method testPassThrough.

@Test
public void testPassThrough() throws Exception {
    MockEmitter<StructuredRecord> emitter = new MockEmitter<>();
    CSVParser.Config config = new CSVParser.Config("DEFAULT", null, "body", OUTPUT3.toString());
    Transform<StructuredRecord, StructuredRecord> transform = new CSVParser(config);
    MockPipelineConfigurer mockPipelineConfigurer = new MockPipelineConfigurer(INPUT2);
    transform.configurePipeline(mockPipelineConfigurer);
    transform.initialize(null);
    transform.transform(StructuredRecord.builder(INPUT2).set("body", "10,stringA,3,4.32,true").set("offset", 10).build(), emitter);
    Assert.assertEquals(10L, emitter.getEmitted().get(0).<Long>get("a").longValue());
    Assert.assertEquals("stringA", emitter.getEmitted().get(0).get("b"));
    Assert.assertEquals(3, emitter.getEmitted().get(0).<Integer>get("c").intValue());
    Assert.assertEquals(4.32d, emitter.getEmitted().get(0).get("d"), 0.0001d);
    Assert.assertEquals(true, emitter.getEmitted().get(0).get("e"));
    // Pass through from input.
    Assert.assertEquals(10, emitter.getEmitted().get(0).<Integer>get("offset").intValue());
}
Also used : MockPipelineConfigurer(io.cdap.cdap.etl.mock.common.MockPipelineConfigurer) MockEmitter(io.cdap.cdap.etl.mock.common.MockEmitter) StructuredRecord(io.cdap.cdap.api.data.format.StructuredRecord) Test(org.junit.Test)

Example 55 with MockPipelineConfigurer

use of io.cdap.cdap.etl.mock.common.MockPipelineConfigurer in project hydrator-plugins by cdapio.

the class CSVParserTest method testPassThroughTypeMisMatch.

@Test
public void testPassThroughTypeMisMatch() {
    CSVParser.Config config = new CSVParser.Config("DEFAULT", null, "body", OUTPUT4.toString());
    Transform<StructuredRecord, StructuredRecord> transform = new CSVParser(config);
    MockPipelineConfigurer configurer = new MockPipelineConfigurer(INPUT2);
    try {
        transform.configurePipeline(configurer);
    } catch (ValidationException e) {
        Assert.assertEquals(1, configurer.getStageConfigurer().getFailureCollector().getValidationFailures().size());
    }
}
Also used : ValidationException(io.cdap.cdap.etl.api.validation.ValidationException) MockPipelineConfigurer(io.cdap.cdap.etl.mock.common.MockPipelineConfigurer) StructuredRecord(io.cdap.cdap.api.data.format.StructuredRecord) Test(org.junit.Test)

Aggregations

MockPipelineConfigurer (io.cdap.cdap.etl.mock.common.MockPipelineConfigurer)89 Test (org.junit.Test)89 Schema (io.cdap.cdap.api.data.schema.Schema)56 FailureCollector (io.cdap.cdap.etl.api.FailureCollector)26 StructuredRecord (io.cdap.cdap.api.data.format.StructuredRecord)22 ValidationException (io.cdap.cdap.etl.api.validation.ValidationException)17 Cause (io.cdap.cdap.etl.api.validation.ValidationFailure.Cause)12 ValidationFailure (io.cdap.cdap.etl.api.validation.ValidationFailure)10 TableSinkConfig (io.cdap.plugin.common.TableSinkConfig)10 HBaseSink (io.cdap.plugin.sink.HBaseSink)7 ETLBatchConfig (io.cdap.cdap.etl.proto.v2.ETLBatchConfig)5 MockEmitter (io.cdap.cdap.etl.mock.common.MockEmitter)4 TransformContext (io.cdap.cdap.etl.api.TransformContext)3 MockTransformContext (io.cdap.cdap.etl.mock.transform.MockTransformContext)3 SolrSearchSink (io.cdap.plugin.batch.SolrSearchSink)3 PipelineConfigurer (io.cdap.cdap.etl.api.PipelineConfigurer)2 LookupConfig (io.cdap.cdap.etl.api.LookupConfig)1 LookupTableConfig (io.cdap.cdap.etl.api.LookupTableConfig)1 MockFailureCollector (io.cdap.cdap.etl.mock.validation.MockFailureCollector)1