use of io.cdap.cdap.etl.mock.common.MockPipelineConfigurer in project hydrator-plugins by cdapio.
the class NormalizeTest method testInvalidOutputSchemaFieldType.
@Test
public void testInvalidOutputSchemaFieldType() throws Exception {
// schema with ID field as long
Schema outputSchema = Schema.recordOf("outputSchema", Schema.Field.of(ID, Schema.of(Schema.Type.LONG)), Schema.Field.of(DATE, Schema.of(Schema.Type.STRING)), Schema.Field.of(ATTRIBUTE_TYPE, Schema.of(Schema.Type.STRING)), Schema.Field.of(ATTRIBUTE_VALUE, Schema.of(Schema.Type.STRING)));
Normalize.NormalizeConfig config = new Normalize.NormalizeConfig(validFieldMapping, validFieldNormalizing, outputSchema.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.OUTPUT_SCHEMA_FIELD, ID);
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 CloneRecordTest method testSchemaValidation.
@Test
public void testSchemaValidation() {
CloneRecord.Config config = new CloneRecord.Config(5);
Transform<StructuredRecord, StructuredRecord> transform = new CloneRecord(config);
MockPipelineConfigurer mockPipelineConfigurer = new MockPipelineConfigurer(INPUT);
transform.configurePipeline(mockPipelineConfigurer);
Assert.assertEquals(INPUT, mockPipelineConfigurer.getOutputSchema());
}
use of io.cdap.cdap.etl.mock.common.MockPipelineConfigurer in project hydrator-plugins by cdapio.
the class CloneRecordTest method testInvalidNumberOfCopies.
@Test
public void testInvalidNumberOfCopies() {
CloneRecord.Config config = new CloneRecord.Config(0);
Transform<StructuredRecord, StructuredRecord> transform = new CloneRecord(config);
MockPipelineConfigurer mockPipelineConfigurer = new MockPipelineConfigurer(INPUT);
transform.configurePipeline(mockPipelineConfigurer);
MockFailureCollector failureCollector = (MockFailureCollector) mockPipelineConfigurer.getStageConfigurer().getFailureCollector();
Assert.assertEquals(1, failureCollector.getValidationFailures().size());
}
use of io.cdap.cdap.etl.mock.common.MockPipelineConfigurer in project hydrator-plugins by cdapio.
the class JSONParserTest method testInvalidJsonPathForNullableSchema.
@Test
public void testInvalidJsonPathForNullableSchema() 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), OUTPUT5.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);
Assert.assertEquals(null, emitter.getEmitted().get(0).get("window"));
final String[] jsonPaths2 = { "expensive:$['expensive']", "bicycle_color:$['store']['bicycle']['color']", "bicycle_price:$['store']['bicycle']['price']", "window:$['store']['window']" };
emitter.clear();
config = new JSONParser.Config("body", Joiner.on(",").join(jsonPaths2), OUTPUT5.toString());
transform = new JSONParser(config);
mockPipelineConfigurer = new MockPipelineConfigurer(INPUT1);
transform.configurePipeline(mockPipelineConfigurer);
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);
Assert.assertEquals(null, emitter.getEmitted().get(0).get("window"));
}
use of io.cdap.cdap.etl.mock.common.MockPipelineConfigurer in project hydrator-plugins by cdapio.
the class JSONParserTest method testSchemaValidation.
@Test
public void testSchemaValidation() throws Exception {
JSONParser.Config config = new JSONParser.Config("body", "", OUTPUT2.toString());
Transform<StructuredRecord, StructuredRecord> transform = new JSONParser(config);
MockPipelineConfigurer mockPipelineConfigurer = new MockPipelineConfigurer(INPUT1);
transform.configurePipeline(mockPipelineConfigurer);
Assert.assertEquals(OUTPUT2, mockPipelineConfigurer.getOutputSchema());
}
Aggregations