Search in sources :

Example 6 with MockPipelineConfigurer

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

the class XMLParserTest method testInputFieldNotInSchema.

@Test
public void testInputFieldNotInSchema() throws Exception {
    Schema schema = Schema.recordOf("record", Schema.Field.of("title", Schema.nullableOf(Schema.of(Schema.Type.STRING))), Schema.Field.of("author", Schema.nullableOf(Schema.of(Schema.Type.STRING))), Schema.Field.of("year", Schema.nullableOf(Schema.of(Schema.Type.STRING))));
    XMLParser.Config config = new XMLParser.Config("x", "UTF-8", "title:/book/title,author:/book/author,year:/book/year", "title:string,author:string,year:string", "Write to error dataset");
    MockPipelineConfigurer configurer = new MockPipelineConfigurer(INPUT);
    new XMLParser(config).configurePipeline(configurer);
    FailureCollector collector = configurer.getStageConfigurer().getFailureCollector();
    Assert.assertEquals(1, collector.getValidationFailures().size());
    Assert.assertEquals(1, collector.getValidationFailures().get(0).getCauses().size());
    Cause expectedCause = new Cause();
    expectedCause.addAttribute(CauseAttributes.STAGE_CONFIG, XMLParser.Config.INPUT);
    Assert.assertEquals(expectedCause, collector.getValidationFailures().get(0).getCauses().get(0));
}
Also used : MockPipelineConfigurer(io.cdap.cdap.etl.mock.common.MockPipelineConfigurer) Schema(io.cdap.cdap.api.data.schema.Schema) Cause(io.cdap.cdap.etl.api.validation.ValidationFailure.Cause) FailureCollector(io.cdap.cdap.etl.api.FailureCollector) Test(org.junit.Test)

Example 7 with MockPipelineConfigurer

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

the class XMLToJSONConverterTest method testInvalidInputFieldType.

@Test
public void testInvalidInputFieldType() throws Exception {
    Schema schema = Schema.recordOf("input1", Schema.Field.of("body", Schema.of(Schema.Type.INT)));
    XMLToJSON.Config config = new XMLToJSON.Config("body", "jsonevent", OUTPUT.toString());
    PipelineConfigurer configurer = new MockPipelineConfigurer(schema);
    FailureCollector collector = configurer.getStageConfigurer().getFailureCollector();
    XMLToJSON converter = new XMLToJSON(config);
    converter.configurePipeline(configurer);
    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) PipelineConfigurer(io.cdap.cdap.etl.api.PipelineConfigurer) MockPipelineConfigurer(io.cdap.cdap.etl.mock.common.MockPipelineConfigurer) FailureCollector(io.cdap.cdap.etl.api.FailureCollector) Test(org.junit.Test)

Example 8 with MockPipelineConfigurer

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

the class NormalizeTest method testEmptyFieldMapping.

@Test
public void testEmptyFieldMapping() throws Exception {
    Normalize.NormalizeConfig config = new Normalize.NormalizeConfig(null, validFieldNormalizing, OUTPUT_SCHEMA.toString());
    MockPipelineConfigurer configurer = new MockPipelineConfigurer(INPUT_SCHEMA);
    try {
        new Normalize(config).configurePipeline(configurer);
        Assert.fail();
    } catch (ValidationException e) {
        Assert.assertEquals(1, e.getFailures().size());
        Assert.assertEquals(1, e.getFailures().get(0).getCauses().size());
        ValidationFailure.Cause expectedCause = new ValidationFailure.Cause();
        expectedCause.addAttribute(STAGE, MOCK_STAGE);
        expectedCause.addAttribute(CauseAttributes.STAGE_CONFIG, Normalize.NormalizeConfig.FIELD_MAPPING);
        Assert.assertEquals(expectedCause, e.getFailures().get(0).getCauses().get(0));
    }
}
Also used : ValidationException(io.cdap.cdap.etl.api.validation.ValidationException) MockPipelineConfigurer(io.cdap.cdap.etl.mock.common.MockPipelineConfigurer) ValidationFailure(io.cdap.cdap.etl.api.validation.ValidationFailure) Test(org.junit.Test)

Example 9 with MockPipelineConfigurer

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

the class NormalizeTest method testEmptyFieldNormalizing.

@Test
public void testEmptyFieldNormalizing() throws Exception {
    Normalize.NormalizeConfig config = new Normalize.NormalizeConfig(validFieldMapping, null, OUTPUT_SCHEMA.toString());
    MockPipelineConfigurer configurer = new MockPipelineConfigurer(INPUT_SCHEMA);
    try {
        new Normalize(config).configurePipeline(configurer);
        Assert.fail();
    } catch (ValidationException e) {
        Assert.assertEquals(1, e.getFailures().size());
        Assert.assertEquals(1, e.getFailures().get(0).getCauses().size());
        ValidationFailure.Cause expectedCause = new ValidationFailure.Cause();
        expectedCause.addAttribute(STAGE, MOCK_STAGE);
        expectedCause.addAttribute(CauseAttributes.STAGE_CONFIG, Normalize.NormalizeConfig.FIELD_NORMALIZING);
        Assert.assertEquals(expectedCause, e.getFailures().get(0).getCauses().get(0));
    }
}
Also used : ValidationException(io.cdap.cdap.etl.api.validation.ValidationException) MockPipelineConfigurer(io.cdap.cdap.etl.mock.common.MockPipelineConfigurer) ValidationFailure(io.cdap.cdap.etl.api.validation.ValidationFailure) Test(org.junit.Test)

Example 10 with MockPipelineConfigurer

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

the class NormalizeTest method testInvalidNormalizingValues.

@Test
public void testInvalidNormalizingValues() throws Exception {
    Normalize.NormalizeConfig config = new Normalize.NormalizeConfig(validFieldMapping, "ItemId:AttributeType," + "ItemCost:AttributeType:AttributeValue", OUTPUT_SCHEMA.toString());
    MockPipelineConfigurer configurer = new MockPipelineConfigurer(INPUT_SCHEMA);
    new Normalize(config).configurePipeline(configurer);
    FailureCollector collector = configurer.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, Normalize.NormalizeConfig.FIELD_NORMALIZING);
    expectedCause.addAttribute(CauseAttributes.CONFIG_ELEMENT, "ItemId:AttributeType");
    Assert.assertEquals(expectedCause, collector.getValidationFailures().get(0).getCauses().get(0));
}
Also used : MockPipelineConfigurer(io.cdap.cdap.etl.mock.common.MockPipelineConfigurer) FailureCollector(io.cdap.cdap.etl.api.FailureCollector) ValidationFailure(io.cdap.cdap.etl.api.validation.ValidationFailure) 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