Search in sources :

Example 31 with MockPipelineConfigurer

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));
}
Also used : MockPipelineConfigurer(io.cdap.cdap.etl.mock.common.MockPipelineConfigurer) Schema(io.cdap.cdap.api.data.schema.Schema) Cause(io.cdap.cdap.etl.api.validation.ValidationFailure.Cause) FailureCollector(io.cdap.cdap.etl.api.FailureCollector) Test(org.junit.Test)

Example 32 with MockPipelineConfigurer

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));
    }
}
Also used : ValidationException(io.cdap.cdap.etl.api.validation.ValidationException) MockPipelineConfigurer(io.cdap.cdap.etl.mock.common.MockPipelineConfigurer) Schema(io.cdap.cdap.api.data.schema.Schema) Cause(io.cdap.cdap.etl.api.validation.ValidationFailure.Cause) Test(org.junit.Test)

Example 33 with MockPipelineConfigurer

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));
    }
}
Also used : ValidationException(io.cdap.cdap.etl.api.validation.ValidationException) MockPipelineConfigurer(io.cdap.cdap.etl.mock.common.MockPipelineConfigurer) Schema(io.cdap.cdap.api.data.schema.Schema) Cause(io.cdap.cdap.etl.api.validation.ValidationFailure.Cause) Test(org.junit.Test)

Example 34 with MockPipelineConfigurer

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));
    }
}
Also used : ValidationException(io.cdap.cdap.etl.api.validation.ValidationException) MockPipelineConfigurer(io.cdap.cdap.etl.mock.common.MockPipelineConfigurer) Schema(io.cdap.cdap.api.data.schema.Schema) Cause(io.cdap.cdap.etl.api.validation.ValidationFailure.Cause) Test(org.junit.Test)

Example 35 with MockPipelineConfigurer

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());
}
Also used : MockPipelineConfigurer(io.cdap.cdap.etl.mock.common.MockPipelineConfigurer) Schema(io.cdap.cdap.api.data.schema.Schema) Test(org.junit.Test)

Aggregations

MockPipelineConfigurer (io.cdap.cdap.etl.mock.common.MockPipelineConfigurer)89 Test (org.junit.Test)89 Schema (io.cdap.cdap.api.data.schema.Schema)56 FailureCollector (io.cdap.cdap.etl.api.FailureCollector)26 StructuredRecord (io.cdap.cdap.api.data.format.StructuredRecord)22 ValidationException (io.cdap.cdap.etl.api.validation.ValidationException)17 Cause (io.cdap.cdap.etl.api.validation.ValidationFailure.Cause)12 ValidationFailure (io.cdap.cdap.etl.api.validation.ValidationFailure)10 TableSinkConfig (io.cdap.plugin.common.TableSinkConfig)10 HBaseSink (io.cdap.plugin.sink.HBaseSink)7 ETLBatchConfig (io.cdap.cdap.etl.proto.v2.ETLBatchConfig)5 MockEmitter (io.cdap.cdap.etl.mock.common.MockEmitter)4 TransformContext (io.cdap.cdap.etl.api.TransformContext)3 MockTransformContext (io.cdap.cdap.etl.mock.transform.MockTransformContext)3 SolrSearchSink (io.cdap.plugin.batch.SolrSearchSink)3 PipelineConfigurer (io.cdap.cdap.etl.api.PipelineConfigurer)2 LookupConfig (io.cdap.cdap.etl.api.LookupConfig)1 LookupTableConfig (io.cdap.cdap.etl.api.LookupTableConfig)1 MockFailureCollector (io.cdap.cdap.etl.mock.validation.MockFailureCollector)1