Search in sources :

Example 16 with MockPipelineConfigurer

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

the class JSONParserTest method testSchemaInvalidSchema.

@Test
public void testSchemaInvalidSchema() throws Exception {
    JSONParser.Config config = new JSONParser.Config("body2", "", OUTPUT2.toString());
    Transform<StructuredRecord, StructuredRecord> transform = new JSONParser(config);
    MockPipelineConfigurer mockPipelineConfigurer = new MockPipelineConfigurer(INPUT1);
    transform.configurePipeline(mockPipelineConfigurer);
    FailureCollector collector = mockPipelineConfigurer.getStageConfigurer().getFailureCollector();
    Assert.assertEquals(1, collector.getValidationFailures().size());
    Assert.assertEquals(1, collector.getValidationFailures().get(0).getCauses().size());
    ValidationFailure.Cause expectedCause = new ValidationFailure.Cause();
    expectedCause.addAttribute(CauseAttributes.STAGE_CONFIG, JSONParser.Config.FIELD);
    Assert.assertEquals(expectedCause, collector.getValidationFailures().get(0).getCauses().get(0));
}
Also used : MockPipelineConfigurer(io.cdap.cdap.etl.mock.common.MockPipelineConfigurer) StructuredRecord(io.cdap.cdap.api.data.format.StructuredRecord) FailureCollector(io.cdap.cdap.etl.api.FailureCollector) ValidationFailure(io.cdap.cdap.etl.api.validation.ValidationFailure) Test(org.junit.Test)

Example 17 with MockPipelineConfigurer

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

the class JSONParserTest method testComplexJSONParsing.

@Test
public void testComplexJSONParsing() throws Exception {
    final String[] jsonPaths = { "expensive:$.expensive", "bicycle_color:$.store.bicycle.color", "bicycle_price:$.store.bicycle.price", "window:$.store.window" };
    MockEmitter<StructuredRecord> emitter = new MockEmitter<>();
    JSONParser.Config config = new JSONParser.Config("body", Joiner.on(",").join(jsonPaths), OUTPUT3.toString());
    Transform<StructuredRecord, StructuredRecord> transform = new JSONParser(config);
    MockPipelineConfigurer mockPipelineConfigurer = new MockPipelineConfigurer(INPUT1);
    transform.configurePipeline(mockPipelineConfigurer);
    TransformContext context = new MockTransformContext();
    transform.initialize(context);
    transform.transform(StructuredRecord.builder(INPUT1).set("body", json).build(), emitter);
    Assert.assertEquals(10, emitter.getEmitted().get(0).<Integer>get("expensive").intValue());
    Assert.assertEquals("red", emitter.getEmitted().get(0).get("bicycle_color"));
    Assert.assertEquals(19.95d, emitter.getEmitted().get(0).get("bicycle_price"), 0.0001d);
}
Also used : MockTransformContext(io.cdap.cdap.etl.mock.transform.MockTransformContext) MockEmitter(io.cdap.cdap.etl.mock.common.MockEmitter) StructuredRecord(io.cdap.cdap.api.data.format.StructuredRecord) MockPipelineConfigurer(io.cdap.cdap.etl.mock.common.MockPipelineConfigurer) TransformContext(io.cdap.cdap.etl.api.TransformContext) MockTransformContext(io.cdap.cdap.etl.mock.transform.MockTransformContext) Test(org.junit.Test)

Example 18 with MockPipelineConfigurer

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

the class DecoderTest method testSchemaValidationWithInvalidInputSchema.

@Test
public void testSchemaValidationWithInvalidInputSchema() {
    Transform<StructuredRecord, StructuredRecord> decoder = new Decoder(new Decoder.Config("a:BASE64", OUTPUT.toString()));
    final Schema invalidInput = Schema.recordOf("input", Schema.Field.of("a", Schema.of(Schema.Type.INT)), Schema.Field.of("b", Schema.of(Schema.Type.STRING)), Schema.Field.of("c", Schema.of(Schema.Type.STRING)));
    MockPipelineConfigurer mockPipelineConfigurer = new MockPipelineConfigurer(invalidInput);
    decoder.configurePipeline(mockPipelineConfigurer);
    FailureCollector failureCollector = mockPipelineConfigurer.getStageConfigurer().getFailureCollector();
    Assert.assertEquals(1, failureCollector.getValidationFailures().size());
}
Also used : MockPipelineConfigurer(io.cdap.cdap.etl.mock.common.MockPipelineConfigurer) Schema(io.cdap.cdap.api.data.schema.Schema) StructuredRecord(io.cdap.cdap.api.data.format.StructuredRecord) FailureCollector(io.cdap.cdap.etl.api.FailureCollector) Test(org.junit.Test)

Example 19 with MockPipelineConfigurer

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

the class DecompressorTest method testSchemaValidationWithInvalidInputSchema.

@Test
public void testSchemaValidationWithInvalidInputSchema() {
    Transform<StructuredRecord, StructuredRecord> transform = new Decompressor(new Decompressor.Config("a:ZIP", OUTPUT.toString()));
    Schema invalidInput = Schema.recordOf("input", Schema.Field.of("a", Schema.of(Schema.Type.STRING)), Schema.Field.of("b", Schema.of(Schema.Type.STRING)));
    MockPipelineConfigurer mockPipelineConfigurer = new MockPipelineConfigurer(invalidInput);
    transform.configurePipeline(mockPipelineConfigurer);
    FailureCollector collector = mockPipelineConfigurer.getStageConfigurer().getFailureCollector();
    Assert.assertEquals(1, collector.getValidationFailures().size());
    Assert.assertEquals(OUTPUT, mockPipelineConfigurer.getOutputSchema());
}
Also used : MockPipelineConfigurer(io.cdap.cdap.etl.mock.common.MockPipelineConfigurer) Schema(io.cdap.cdap.api.data.schema.Schema) StructuredRecord(io.cdap.cdap.api.data.format.StructuredRecord) FailureCollector(io.cdap.cdap.etl.api.FailureCollector) Test(org.junit.Test)

Example 20 with MockPipelineConfigurer

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

the class EncoderTest method testSchemaValidationWithInvalidInputSchema.

@Test
public void testSchemaValidationWithInvalidInputSchema() throws Exception {
    Transform<StructuredRecord, StructuredRecord> transform = new Encoder(new Encoder.Config("a:BASE32", OUTPUTSTR.toString()));
    final Schema invalidInput = Schema.recordOf("input", Schema.Field.of("a", Schema.of(Schema.Type.INT)), Schema.Field.of("b", Schema.of(Schema.Type.STRING)), Schema.Field.of("c", Schema.of(Schema.Type.STRING)));
    MockPipelineConfigurer mockPipelineConfigurer = new MockPipelineConfigurer(invalidInput);
    transform.configurePipeline(mockPipelineConfigurer);
    FailureCollector collector = mockPipelineConfigurer.getStageConfigurer().getFailureCollector();
    Assert.assertEquals(1, collector.getValidationFailures().size());
    Assert.assertEquals(2, collector.getValidationFailures().get(0).getCauses().size());
}
Also used : MockPipelineConfigurer(io.cdap.cdap.etl.mock.common.MockPipelineConfigurer) Schema(io.cdap.cdap.api.data.schema.Schema) StructuredRecord(io.cdap.cdap.api.data.format.StructuredRecord) FailureCollector(io.cdap.cdap.etl.api.FailureCollector) 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