Search in sources :

Example 1 with MockFailureCollector

use of io.cdap.cdap.etl.mock.validation.MockFailureCollector in project hydrator-plugins by cdapio.

the class UnionSplitterTest method testInvalidSchemas.

@Test
public void testInvalidSchemas() {
    Schema inputSchema = Schema.recordOf("union", Schema.Field.of("a", Schema.unionOf(Schema.of(Schema.Type.NULL), Schema.arrayOf(Schema.of(Schema.Type.STRING)))), Schema.Field.of("b", Schema.unionOf(Schema.of(Schema.Type.NULL), Schema.enumWith("something"))), Schema.Field.of("c", Schema.unionOf(Schema.of(Schema.Type.NULL), Schema.mapOf(Schema.of(Schema.Type.STRING), Schema.of(Schema.Type.STRING)))), Schema.Field.of("d", Schema.nullableOf(Schema.of(Schema.Type.STRING))));
    FailureCollector collector = new MockFailureCollector();
    UnionSplitter.getOutputSchemas(inputSchema, "a", true, collector);
    Assert.assertEquals(1, collector.getValidationFailures().size());
    Assert.assertEquals(2, collector.getValidationFailures().get(0).getCauses().size());
    collector = new MockFailureCollector();
    UnionSplitter.getOutputSchemas(inputSchema, "b", true, collector);
    Assert.assertEquals(1, collector.getValidationFailures().size());
    Assert.assertEquals(2, collector.getValidationFailures().get(0).getCauses().size());
    collector = new MockFailureCollector();
    UnionSplitter.getOutputSchemas(inputSchema, "c", true, collector);
    Assert.assertEquals(1, collector.getValidationFailures().size());
    Assert.assertEquals(2, collector.getValidationFailures().get(0).getCauses().size());
    collector = new MockFailureCollector();
    UnionSplitter.getOutputSchemas(inputSchema, "d", true, collector);
    Assert.assertEquals(0, collector.getValidationFailures().size());
}
Also used : Schema(io.cdap.cdap.api.data.schema.Schema) MockFailureCollector(io.cdap.cdap.etl.mock.validation.MockFailureCollector) FailureCollector(io.cdap.cdap.etl.api.FailureCollector) MockFailureCollector(io.cdap.cdap.etl.mock.validation.MockFailureCollector) Test(org.junit.Test)

Example 2 with MockFailureCollector

use of io.cdap.cdap.etl.mock.validation.MockFailureCollector in project hydrator-plugins by cdapio.

the class CSVParserTest method testSchemaValidation.

@Test
public void testSchemaValidation() {
    CSVParser.Config config = new CSVParser.Config("DEFAULT", null, "body", OUTPUT1.toString());
    CSVParser csvParser = new CSVParser(config);
    MockFailureCollector collector = new MockFailureCollector();
    csvParser.validateInputSchema(INPUT1, collector);
    Assert.assertEquals(0, collector.getValidationFailures().size());
    Schema schema = csvParser.parseAndValidateOutputSchema(INPUT1, collector);
    Assert.assertEquals(0, collector.getValidationFailures().size());
    Assert.assertEquals(OUTPUT1, schema);
}
Also used : Schema(io.cdap.cdap.api.data.schema.Schema) MockFailureCollector(io.cdap.cdap.etl.mock.validation.MockFailureCollector) Test(org.junit.Test)

Example 3 with MockFailureCollector

use of io.cdap.cdap.etl.mock.validation.MockFailureCollector in project hydrator-plugins by cdapio.

the class CSVParserTest method testNullableFieldSchemaValidation.

@Test
public void testNullableFieldSchemaValidation() {
    CSVParser.Config config = new CSVParser.Config("DEFAULT", null, "body", OUTPUT1.toString());
    CSVParser csvParser = new CSVParser(config);
    MockFailureCollector collector = new MockFailureCollector();
    csvParser.validateInputSchema(NULLABLE_INPUT, collector);
    Assert.assertEquals(0, collector.getValidationFailures().size());
    Schema schema = csvParser.parseAndValidateOutputSchema(NULLABLE_INPUT, collector);
    Assert.assertEquals(0, collector.getValidationFailures().size());
    Assert.assertEquals(OUTPUT1, schema);
}
Also used : Schema(io.cdap.cdap.api.data.schema.Schema) MockFailureCollector(io.cdap.cdap.etl.mock.validation.MockFailureCollector) Test(org.junit.Test)

Example 4 with MockFailureCollector

use of io.cdap.cdap.etl.mock.validation.MockFailureCollector 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());
}
Also used : MockPipelineConfigurer(io.cdap.cdap.etl.mock.common.MockPipelineConfigurer) MockFailureCollector(io.cdap.cdap.etl.mock.validation.MockFailureCollector) StructuredRecord(io.cdap.cdap.api.data.format.StructuredRecord) Test(org.junit.Test)

Example 5 with MockFailureCollector

use of io.cdap.cdap.etl.mock.validation.MockFailureCollector in project hydrator-plugins by cdapio.

the class FileBatchSourceTest method testDelimitedFormatsValidSchema.

@Test
public void testDelimitedFormatsValidSchema() throws Exception {
    FileSourceConfig config = new FileSourceConfig();
    FailureCollector collector = new MockFailureCollector();
    FieldSetter.setField(config, AbstractFileSourceConfig.class.getDeclaredField("referenceName"), "ref");
    FieldSetter.setField(config, AbstractFileSourceConfig.class.getDeclaredField("format"), "delimited");
    FieldSetter.setField(config, AbstractFileSourceConfig.class.getDeclaredField("schema"), RECORD_SCHEMA_VALID_DATE.toString());
    FieldSetter.setField(config, FileSourceConfig.class.getDeclaredField("path"), "path");
    config.validate(collector);
    Assert.assertEquals(0, collector.getValidationFailures().size());
}
Also used : AbstractFileSourceConfig(io.cdap.plugin.format.plugin.AbstractFileSourceConfig) MockFailureCollector(io.cdap.cdap.etl.mock.validation.MockFailureCollector) AbstractFileSourceConfig(io.cdap.plugin.format.plugin.AbstractFileSourceConfig) FailureCollector(io.cdap.cdap.etl.api.FailureCollector) MockFailureCollector(io.cdap.cdap.etl.mock.validation.MockFailureCollector) Test(org.junit.Test)

Aggregations

MockFailureCollector (io.cdap.cdap.etl.mock.validation.MockFailureCollector)36 Test (org.junit.Test)36 FailureCollector (io.cdap.cdap.etl.api.FailureCollector)31 Schema (io.cdap.cdap.api.data.schema.Schema)11 AutoJoinerContext (io.cdap.cdap.etl.api.join.AutoJoinerContext)11 HashMap (java.util.HashMap)10 ValidationException (io.cdap.cdap.etl.api.validation.ValidationException)9 Cause (io.cdap.cdap.etl.api.validation.ValidationFailure.Cause)9 JoinDefinition (io.cdap.cdap.etl.api.join.JoinDefinition)6 JoinStage (io.cdap.cdap.etl.api.join.JoinStage)5 ValidationFailure (io.cdap.cdap.etl.api.validation.ValidationFailure)5 JoinField (io.cdap.cdap.etl.api.join.JoinField)2 AbstractFileSourceConfig (io.cdap.plugin.format.plugin.AbstractFileSourceConfig)2 List (java.util.List)2 StructuredRecord (io.cdap.cdap.api.data.format.StructuredRecord)1 JoinCondition (io.cdap.cdap.etl.api.join.JoinCondition)1 MockPipelineConfigurer (io.cdap.cdap.etl.mock.common.MockPipelineConfigurer)1