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