use of io.cdap.cdap.etl.mock.common.MockPipelineConfigurer in project hydrator-plugins by cdapio.
the class LogParserTransformTest method testConfigurePipelineSchemaWithMissingInputNameField.
@Test
public void testConfigurePipelineSchemaWithMissingInputNameField() {
Schema inputSchemaString = Schema.recordOf("event", Schema.Field.of("CLF", Schema.of(Schema.Type.STRING)));
MockPipelineConfigurer mockConfigurer = new MockPipelineConfigurer(inputSchemaString, Collections.emptyMap());
S3_TRANSFORM.configurePipeline(mockConfigurer);
FailureCollector collector = mockConfigurer.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, LogParserTransform.LogParserConfig.INPUT_NAME);
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 LogParserTransformTest method testConfigurePipelineInvalidSchema.
@Test
public void testConfigurePipelineInvalidSchema() {
Schema inputSchemaString = Schema.recordOf("event", Schema.Field.of("CLF", Schema.of(Schema.Type.STRING)), // "body" is config.inputName and that should be of only type String or Bytes
Schema.Field.of("body", Schema.of(Schema.Type.INT)));
MockPipelineConfigurer mockConfigurer = new MockPipelineConfigurer(inputSchemaString, Collections.emptyMap());
try {
S3_TRANSFORM.configurePipeline(mockConfigurer);
} catch (ValidationException e) {
Assert.assertEquals(1, e.getFailures().size());
Assert.assertEquals(1, e.getFailures().get(0).getCauses().size());
Cause expectedCause = new Cause();
expectedCause.addAttribute(CauseAttributes.INPUT_SCHEMA_FIELD, "body");
expectedCause.addAttribute(stage, mockStage);
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 ProjectionTransformTest method testConvertFieldsValidations.
@Test
public void testConvertFieldsValidations() {
Schema schema = Schema.recordOf("three", Schema.Field.of("x", Schema.of(Schema.Type.INT)), Schema.Field.of("y", Schema.of(Schema.Type.DOUBLE)), Schema.Field.of("z", Schema.arrayOf(Schema.of(Schema.Type.INT))));
MockPipelineConfigurer mockConfigurer = new MockPipelineConfigurer(schema, Collections.emptyMap());
ProjectionTransform.ProjectionTransformConfig config = new ProjectionTransform.ProjectionTransformConfig(null, null, "n:boolean", "x");
try {
new ProjectionTransform(config).configurePipeline(mockConfigurer);
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(CauseAttributes.STAGE_CONFIG, ProjectionTransform.ProjectionTransformConfig.CONVERT);
expectedCause.addAttribute(CauseAttributes.CONFIG_ELEMENT, "n:boolean");
expectedCause.addAttribute(STAGE, MOCK_STAGE);
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 ProjectionTransformTest method testRenameFieldsValidations.
@Test
public void testRenameFieldsValidations() {
Schema schema = Schema.recordOf("three", Schema.Field.of("x", Schema.of(Schema.Type.INT)), Schema.Field.of("y", Schema.of(Schema.Type.DOUBLE)), Schema.Field.of("z", Schema.arrayOf(Schema.of(Schema.Type.INT))));
MockPipelineConfigurer mockConfigurer = new MockPipelineConfigurer(schema, Collections.emptyMap());
ProjectionTransform.ProjectionTransformConfig config = new ProjectionTransform.ProjectionTransformConfig(null, "n:m", null, "x");
try {
new ProjectionTransform(config).configurePipeline(mockConfigurer);
} catch (ValidationException e) {
Assert.assertEquals(1, e.getFailures().size());
Assert.assertEquals(1, e.getFailures().get(0).getCauses().size());
Cause expectedCause = new Cause();
expectedCause.addAttribute(CauseAttributes.STAGE_CONFIG, ProjectionTransform.ProjectionTransformConfig.RENAME);
expectedCause.addAttribute(CauseAttributes.CONFIG_ELEMENT, "n:m");
expectedCause.addAttribute(STAGE, MOCK_STAGE);
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 ProjectionTransformTest method testConfigurePipelineSchemaValidation.
@Test
public void testConfigurePipelineSchemaValidation() {
Schema schema = Schema.recordOf("three", Schema.Field.of("x", Schema.of(Schema.Type.INT)), Schema.Field.of("y", Schema.of(Schema.Type.DOUBLE)), Schema.Field.of("z", Schema.arrayOf(Schema.of(Schema.Type.INT))));
MockPipelineConfigurer mockConfigurer = new MockPipelineConfigurer(schema, Collections.emptyMap());
// test drop
ProjectionTransform.ProjectionTransformConfig config = new ProjectionTransform.ProjectionTransformConfig("y, z", null, null, null);
new ProjectionTransform(config).configurePipeline(mockConfigurer);
Schema expectedSchema = Schema.recordOf("three.projected", Schema.Field.of("x", Schema.of(Schema.Type.INT)));
Assert.assertEquals(expectedSchema, mockConfigurer.getOutputSchema());
// test keep
config = new ProjectionTransform.ProjectionTransformConfig(null, null, null, "y,z");
new ProjectionTransform(config).configurePipeline(mockConfigurer);
expectedSchema = Schema.recordOf("three.projected", Schema.Field.of("y", Schema.of(Schema.Type.DOUBLE)), Schema.Field.of("z", Schema.arrayOf(Schema.of(Schema.Type.INT))));
Assert.assertEquals(expectedSchema, mockConfigurer.getOutputSchema());
// test rename
config = new ProjectionTransform.ProjectionTransformConfig(null, "x:a, y:b", null, null);
new ProjectionTransform(config).configurePipeline(mockConfigurer);
expectedSchema = Schema.recordOf("three.projected", Schema.Field.of("a", Schema.of(Schema.Type.INT)), Schema.Field.of("b", Schema.of(Schema.Type.DOUBLE)), Schema.Field.of("z", Schema.arrayOf(Schema.of(Schema.Type.INT))));
Assert.assertEquals(expectedSchema, mockConfigurer.getOutputSchema());
// test convert
config = new ProjectionTransform.ProjectionTransformConfig(null, null, "x:string,y:string", null);
new ProjectionTransform(config).configurePipeline(mockConfigurer);
expectedSchema = Schema.recordOf("three.projected", Schema.Field.of("x", Schema.of(Schema.Type.STRING)), Schema.Field.of("y", Schema.of(Schema.Type.STRING)), Schema.Field.of("z", Schema.arrayOf(Schema.of(Schema.Type.INT))));
Assert.assertEquals(expectedSchema, mockConfigurer.getOutputSchema());
// null input schema
mockConfigurer = new MockPipelineConfigurer(null, Collections.emptyMap());
new ProjectionTransform(config).configurePipeline(mockConfigurer);
Assert.assertNull(mockConfigurer.getOutputSchema());
}
Aggregations