use of io.cdap.cdap.etl.mock.common.MockPipelineConfigurer in project hydrator-plugins by cdapio.
the class ValueMapperTest method testMappingDoesNotExistInInput.
@Test
public void testMappingDoesNotExistInInput() throws Exception {
Schema inputSchema = Schema.recordOf("sourceRecord", Schema.Field.of(ID, Schema.of(Schema.Type.STRING)), Schema.Field.of(NAME, Schema.of(Schema.Type.STRING)), Schema.Field.of(SALARY, Schema.of(Schema.Type.STRING)), Schema.Field.of(DESIGNATIONID, Schema.of(Schema.Type.STRING)));
ValueMapper.Config config = new ValueMapper.Config("does_not_exist:designation_lookup_table:designationName", "does_not_exist:DEFAULTID");
MockPipelineConfigurer configurer = new MockPipelineConfigurer(inputSchema);
ValueMapper mapper = new ValueMapper(config);
try {
mapper.configurePipeline(configurer);
Assert.fail();
} catch (ValidationException e) {
Assert.assertEquals(1, e.getFailures().size());
Assert.assertEquals(1, e.getFailures().get(0).getCauses().size());
Cause expectedCause = new Cause();
expectedCause.addAttribute(STAGE, MOCK_STAGE);
expectedCause.addAttribute(CauseAttributes.STAGE_CONFIG, ValueMapper.Config.MAPPING);
expectedCause.addAttribute(CauseAttributes.CONFIG_ELEMENT, "does_not_exist:designation_lookup_table:designationName");
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 ValueMapperTest method testSchemaHandling.
@Test
public void testSchemaHandling() throws Exception {
Schema inputSchema = Schema.recordOf("sourceRecord", Schema.Field.of(ID, Schema.of(Schema.Type.STRING)), Schema.Field.of(NAME, Schema.of(Schema.Type.STRING)), Schema.Field.of(SALARY, Schema.of(Schema.Type.STRING)), Schema.Field.of(DESIGNATIONID, Schema.nullableOf(Schema.of(Schema.Type.STRING))));
ValueMapper.Config config = new ValueMapper.Config("designationid:designation_lookup_table:designationName", "designationid:DEFAULTID");
MockPipelineConfigurer configurer = new MockPipelineConfigurer(inputSchema);
new ValueMapper(config).configurePipeline(configurer);
Schema outputSchema = configurer.getOutputSchema();
Schema expectedOutputSchema = Schema.recordOf("sourceRecord.formatted", Schema.Field.of(ID, Schema.of(Schema.Type.STRING)), Schema.Field.of(NAME, Schema.of(Schema.Type.STRING)), Schema.Field.of(SALARY, Schema.of(Schema.Type.STRING)), Schema.Field.of(DESIGNATIONNAME, Schema.of(Schema.Type.STRING)));
Assert.assertEquals(expectedOutputSchema, outputSchema);
}
use of io.cdap.cdap.etl.mock.common.MockPipelineConfigurer in project hydrator-plugins by cdapio.
the class XMLParserTest method testInvalidConfig.
@Test
public void testInvalidConfig() throws Exception {
XMLParser.Config config = new XMLParser.Config("body", "UTF-8", "category://book/@category,title://book/title," + "year:/bookstore/book[price>35.00]/year,price:/bookstore/book[price>35.00]/price,subcategory://book/subcategory", "category:,title:string,price:double,year:int,subcategory:string", "Exit on error");
MockPipelineConfigurer configurer = new MockPipelineConfigurer(INPUT);
try {
new XMLParser(config).configurePipeline(configurer);
Assert.fail();
} catch (ValidationException e) {
Assert.assertEquals(1, e.getFailures().size());
Assert.assertEquals(1, e.getFailures().get(0).getCauses().size());
Cause expectedCause = new Cause();
expectedCause.addAttribute("stage", "mockstage");
expectedCause.addAttribute(CauseAttributes.STAGE_CONFIG, XMLParser.Config.FIELD_TYPE_MAPPING);
expectedCause.addAttribute(CauseAttributes.CONFIG_ELEMENT, "category:");
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 XMLToJSONConverterTest method testInvalidInputField.
@Test
public void testInvalidInputField() throws Exception {
XMLToJSON.Config config = new XMLToJSON.Config("does_not_exist", "jsonevent", OUTPUT.toString());
PipelineConfigurer configurer = new MockPipelineConfigurer(INPUT);
FailureCollector collector = configurer.getStageConfigurer().getFailureCollector();
XMLToJSON converter = new XMLToJSON(config);
converter.configurePipeline(configurer);
Assert.assertEquals(1, collector.getValidationFailures().size());
Assert.assertEquals(1, collector.getValidationFailures().get(0).getCauses().size());
Cause expectedCause = new Cause();
expectedCause.addAttribute(CauseAttributes.STAGE_CONFIG, "inputField");
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 NormalizeTest method testInvalidMappingValues.
@Test
public void testInvalidMappingValues() throws Exception {
Normalize.NormalizeConfig config = new Normalize.NormalizeConfig("CustomerId,PurchaseDate:Date", validFieldNormalizing, 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_MAPPING);
expectedCause.addAttribute(CauseAttributes.CONFIG_ELEMENT, "CustomerId");
Assert.assertEquals(expectedCause, collector.getValidationFailures().get(0).getCauses().get(0));
}
Aggregations