Search in sources :

Example 11 with MockFailureCollector

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

the class XMLReaderConfigTest method testActionAfterProcessAndReprocessingConflict.

@Test
public void testActionAfterProcessAndReprocessingConflict() {
    XMLReaderBatchSource.XMLReaderConfig config = new XMLReaderBatchSource.XMLReaderConfig("conflictReference", "/opt/hdfs/catalog.xml", null, "/catalog/book/", "Delete", null, "Yes", "XMLTrackingTable", 30, "/tmp");
    FailureCollector collector = new MockFailureCollector();
    config.validate(collector);
    Assert.assertEquals(1, collector.getValidationFailures().size());
    Assert.assertEquals(2, collector.getValidationFailures().get(0).getCauses().size());
}
Also used : 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 12 with MockFailureCollector

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

the class JoinerConfigTest method testJoinerConfigWithoutFieldsToRename.

@Test
public void testJoinerConfigWithoutFieldsToRename() {
    String selectedFields = "film.film_id, film.film_name, " + "filmActor.actor_name as renamed_actor, filmCategory.category_name as renamed_category";
    JoinerConfig config = new JoinerConfig("film.film_id=filmActor.film_id=filmCategory.film_id&" + "film.film_name=filmActor.film_name=filmCategory.film_name", selectedFields, "film,filmActor,filmCategory");
    FailureCollector failureCollector = new MockFailureCollector();
    List<JoinField> actual = config.getSelectedFields(failureCollector);
    List<JoinField> expected = Arrays.asList(new JoinField("film", "film_id", "film_id"), new JoinField("film", "film_name", "film_name"), new JoinField("filmActor", "actor_name", "renamed_actor"), new JoinField("filmCategory", "category_name", "renamed_category"));
    Assert.assertEquals(expected, actual);
}
Also used : MockFailureCollector(io.cdap.cdap.etl.mock.validation.MockFailureCollector) JoinField(io.cdap.cdap.etl.api.join.JoinField) FailureCollector(io.cdap.cdap.etl.api.FailureCollector) MockFailureCollector(io.cdap.cdap.etl.mock.validation.MockFailureCollector) Test(org.junit.Test)

Example 13 with MockFailureCollector

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

the class JoinerConfigTest method testJoinerConfigWithoutJoinKeys.

@Test
public void testJoinerConfigWithoutJoinKeys() {
    JoinerConfig config = new JoinerConfig("", SELECTED_FIELDS, "film,filmActor,filmCategory");
    MockFailureCollector failureCollector = new MockFailureCollector();
    try {
        config.getJoinKeys(failureCollector);
    } catch (ValidationException e) {
        Assert.assertEquals(1, e.getFailures().size());
        ValidationFailure failure = e.getFailures().get(0);
        Assert.assertEquals(1, failure.getCauses().size());
    }
}
Also used : ValidationException(io.cdap.cdap.etl.api.validation.ValidationException) MockFailureCollector(io.cdap.cdap.etl.mock.validation.MockFailureCollector) ValidationFailure(io.cdap.cdap.etl.api.validation.ValidationFailure) Test(org.junit.Test)

Example 14 with MockFailureCollector

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

the class JoinerConfigTest method testAdvancedWithTooManyInputs.

@Test
public void testAdvancedWithTooManyInputs() {
    JoinerConfig conf = new JoinerConfig("users.id, emails.email", "users.id = emails.userid", new HashSet<>(Arrays.asList("users", "emails")));
    Joiner joiner = new Joiner(conf);
    FailureCollector collector = new MockFailureCollector();
    Schema userSchema = Schema.recordOf("user", Schema.Field.of("id", Schema.of(Schema.Type.INT)));
    Schema emailSchema = Schema.recordOf("email", Schema.Field.of("email", Schema.of(Schema.Type.STRING)), Schema.Field.of("userid", Schema.of(Schema.Type.INT)));
    Map<String, JoinStage> inputStages = new HashMap<>();
    inputStages.put("users", JoinStage.builder("users", userSchema).build());
    inputStages.put("emails", JoinStage.builder("emails", emailSchema).build());
    inputStages.put("users2", JoinStage.builder("users2", userSchema).build());
    AutoJoinerContext autoJoinerContext = new MockAutoJoinerContext(inputStages, collector);
    try {
        joiner.define(autoJoinerContext);
        Assert.fail("Advanced join did not fail with 3 inputs as expected.");
    } catch (ValidationException e) {
        List<ValidationFailure> failures = e.getFailures();
        Assert.assertEquals(1, failures.size());
        List<ValidationFailure.Cause> causes = failures.get(0).getCauses();
        Assert.assertEquals(1, causes.size());
        Assert.assertEquals(JoinerConfig.CONDITION_TYPE, causes.get(0).getAttribute(CauseAttributes.STAGE_CONFIG));
    }
}
Also used : JoinStage(io.cdap.cdap.etl.api.join.JoinStage) ValidationException(io.cdap.cdap.etl.api.validation.ValidationException) HashMap(java.util.HashMap) Schema(io.cdap.cdap.api.data.schema.Schema) ValidationFailure(io.cdap.cdap.etl.api.validation.ValidationFailure) AutoJoinerContext(io.cdap.cdap.etl.api.join.AutoJoinerContext) MockFailureCollector(io.cdap.cdap.etl.mock.validation.MockFailureCollector) List(java.util.List) FailureCollector(io.cdap.cdap.etl.api.FailureCollector) MockFailureCollector(io.cdap.cdap.etl.mock.validation.MockFailureCollector) Test(org.junit.Test)

Example 15 with MockFailureCollector

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

the class JoinerConfigTest method testJoinerConfigWithDuplicateOutputFields.

@Test
public void testJoinerConfigWithDuplicateOutputFields() {
    String selectedFields = "film.film_id, film.film_name, " + "filmActor.actor_name as name, filmCategory.category_name as name";
    JoinerConfig config = new JoinerConfig("film.film_id=filmActor.film_id=filmCategory.film_id&" + "film.film_name=filmActor.film_name=filmCategory.film_name", selectedFields, "film,filmActor,filmCategory");
    Joiner joiner = new Joiner(config);
    FailureCollector collector = new MockFailureCollector();
    AutoJoinerContext autoJoinerContext = new MockAutoJoinerContext(INPUT_STAGES, collector);
    try {
        joiner.define(autoJoinerContext);
        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, JoinerConfig.SELECTED_FIELDS);
        expectedCause.addAttribute(STAGE, MOCK_STAGE);
        expectedCause.addAttribute(CauseAttributes.CONFIG_ELEMENT, "filmCategory.category_name as name");
        Assert.assertEquals(expectedCause, e.getFailures().get(0).getCauses().get(0));
    }
}
Also used : AutoJoinerContext(io.cdap.cdap.etl.api.join.AutoJoinerContext) ValidationException(io.cdap.cdap.etl.api.validation.ValidationException) Cause(io.cdap.cdap.etl.api.validation.ValidationFailure.Cause) 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)

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