Search in sources :

Example 31 with MockFailureCollector

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

the class JoinerConfigTest method testJoinerOutputSchema.

@Test
public void testJoinerOutputSchema() {
    String joinKeys = "film.film_id=filmActor.film_id=filmCategory.film_id";
    String selectedFields = "film.film_id, film.film_name, filmActor.actor_name as renamed_actor, " + "filmCategory.category_name as renamed_category";
    String requiredInputs = "film,filmActor,filmCategory";
    JoinerConfig joinerConfig = new JoinerConfig(joinKeys, selectedFields, requiredInputs);
    Joiner joiner = new Joiner(joinerConfig);
    FailureCollector collector = new MockFailureCollector();
    AutoJoinerContext autoJoinerContext = new MockAutoJoinerContext(INPUT_STAGES, collector);
    JoinDefinition joinDefinition = joiner.define(autoJoinerContext);
    Assert.assertEquals(OUTPUT_SCHEMA, joinDefinition.getOutputSchema());
    Assert.assertEquals(0, collector.getValidationFailures().size());
}
Also used : AutoJoinerContext(io.cdap.cdap.etl.api.join.AutoJoinerContext) JoinDefinition(io.cdap.cdap.etl.api.join.JoinDefinition) 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 32 with MockFailureCollector

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

the class JoinerConfigTest method testJoinerConfigWithoutRequiredInputs.

@Test
public void testJoinerConfigWithoutRequiredInputs() {
    Schema outputSchema = Schema.recordOf("join.output", Schema.Field.of("film_id", Schema.of(Schema.Type.STRING)), Schema.Field.of("film_name", Schema.of(Schema.Type.STRING)), Schema.Field.of("renamed_actor", Schema.nullableOf(Schema.of(Schema.Type.STRING))), Schema.Field.of("renamed_category", Schema.nullableOf(Schema.of(Schema.Type.STRING))));
    JoinerConfig config = new JoinerConfig("film.film_id=filmActor.film_id=filmCategory.film_id&" + "film.film_name=filmActor.film_name=filmCategory.film_name", SELECTED_FIELDS, "film");
    Joiner joiner = new Joiner(config);
    FailureCollector collector = new MockFailureCollector();
    AutoJoinerContext autoJoinerContext = new MockAutoJoinerContext(INPUT_STAGES, collector);
    JoinDefinition joinDefinition = joiner.define(autoJoinerContext);
    Assert.assertEquals(outputSchema, joinDefinition.getOutputSchema());
    Assert.assertEquals(0, collector.getValidationFailures().size());
}
Also used : AutoJoinerContext(io.cdap.cdap.etl.api.join.AutoJoinerContext) JoinDefinition(io.cdap.cdap.etl.api.join.JoinDefinition) 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 33 with MockFailureCollector

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

the class JoinerConfigTest method testJoinerWithNullableSchema.

@Test
public void testJoinerWithNullableSchema() {
    Schema filmCategorySchema = Schema.recordOf("filmCategory", Schema.Field.of("film_id", Schema.of(Schema.Type.STRING)), Schema.Field.of("film_name", Schema.of(Schema.Type.STRING)), Schema.Field.of("category_name", Schema.nullableOf(Schema.of(Schema.Type.STRING))));
    String joinKeys = "film.film_id=filmActor.film_id=filmCategory.film_id";
    String selectedFields = "film.film_id, film.film_name, filmActor.actor_name as renamed_actor, " + "filmCategory.category_name as renamed_category";
    String requiredInputs = "film,filmActor";
    JoinerConfig conf = new JoinerConfig(joinKeys, selectedFields, requiredInputs);
    Schema outputSchema = Schema.recordOf("join.output", Schema.Field.of("film_id", Schema.of(Schema.Type.STRING)), Schema.Field.of("film_name", Schema.of(Schema.Type.STRING)), Schema.Field.of("renamed_actor", Schema.of(Schema.Type.STRING)), Schema.Field.of("renamed_category", filmCategorySchema.getField("category_name").getSchema()));
    Joiner joiner = new Joiner(conf);
    FailureCollector collector = new MockFailureCollector();
    AutoJoinerContext autoJoinerContext = new MockAutoJoinerContext(INPUT_STAGES, collector);
    JoinDefinition joinDefinition = joiner.define(autoJoinerContext);
    Assert.assertEquals(outputSchema, joinDefinition.getOutputSchema());
    Assert.assertEquals(0, collector.getValidationFailures().size());
}
Also used : AutoJoinerContext(io.cdap.cdap.etl.api.join.AutoJoinerContext) JoinDefinition(io.cdap.cdap.etl.api.join.JoinDefinition) 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 34 with MockFailureCollector

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

the class XMLReaderConfigTest method testEmptyNodePath.

@Test
public void testEmptyNodePath() {
    XMLReaderBatchSource.XMLReaderConfig config = new XMLReaderBatchSource.XMLReaderConfig("emptyNodePathReference", "/opt/hdfs/catalog.xml", null, "", null, null, "Yes", "XMLTrackingTable", 30, "/tmp");
    FailureCollector collector = new MockFailureCollector();
    config.validate(collector);
    Assert.assertEquals(1, collector.getValidationFailures().size());
    Assert.assertEquals(1, collector.getValidationFailures().get(0).getCauses().size());
    Cause expectedCause = new Cause();
    expectedCause.addAttribute(CauseAttributes.STAGE_CONFIG, XMLReaderBatchSource.XMLReaderConfig.NODE_PATH);
    Assert.assertEquals(expectedCause, collector.getValidationFailures().get(0).getCauses().get(0));
}
Also used : Cause(io.cdap.cdap.etl.api.validation.ValidationFailure.Cause) MockFailureCollector(io.cdap.cdap.etl.mock.validation.MockFailureCollector) MockFailureCollector(io.cdap.cdap.etl.mock.validation.MockFailureCollector) FailureCollector(io.cdap.cdap.etl.api.FailureCollector) Test(org.junit.Test)

Example 35 with MockFailureCollector

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

the class XMLReaderConfigTest method testEmptyTemporaryFolder.

@Test
public void testEmptyTemporaryFolder() {
    XMLReaderBatchSource.XMLReaderConfig config = new XMLReaderBatchSource.XMLReaderConfig("emptyNodePathReference", "/opt/hdfs/catalog.xml", null, "/catalog/book/", "Delete", null, "No", "XMLTrackingTable", 30, null);
    FailureCollector collector = new MockFailureCollector();
    config.validate(collector);
    Assert.assertEquals(1, collector.getValidationFailures().size());
    Assert.assertEquals(1, collector.getValidationFailures().get(0).getCauses().size());
    Cause expectedCause = new Cause();
    expectedCause.addAttribute(CauseAttributes.STAGE_CONFIG, XMLReaderBatchSource.XMLReaderConfig.TEMPORARY_FOLDER);
    Assert.assertEquals(expectedCause, collector.getValidationFailures().get(0).getCauses().get(0));
}
Also used : Cause(io.cdap.cdap.etl.api.validation.ValidationFailure.Cause) MockFailureCollector(io.cdap.cdap.etl.mock.validation.MockFailureCollector) MockFailureCollector(io.cdap.cdap.etl.mock.validation.MockFailureCollector) FailureCollector(io.cdap.cdap.etl.api.FailureCollector) 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