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));
}
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());
}
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));
}
}
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));
}
}
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));
}
Aggregations