Search in sources :

Example 31 with ConfigSource

use of org.embulk.config.ConfigSource in project embulk by embulk.

the class TestRenameFilterPlugin method checkFirstCharacterTypesRuleNeitherReplacePrefix.

@Test
public void checkFirstCharacterTypesRuleNeitherReplacePrefix() {
    HashMap<String, Object> parameters = new HashMap<>();
    parameters.put("rule", "first_character_types");
    ConfigSource config = Exec.newConfigSource().set("rules", ImmutableList.of(ImmutableMap.copyOf(parameters)));
    exception.expect(ConfigException.class);
    // TODO(dmikurube): Except "Caused by": exception.expectCause(instanceOf(JsonMappingException.class));
    // Needs to import org.hamcrest.Matchers... in addition to org.junit...
    renameAndCheckSchema(config, new String[0], new String[0]);
}
Also used : ConfigSource(org.embulk.config.ConfigSource) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 32 with ConfigSource

use of org.embulk.config.ConfigSource in project embulk by embulk.

the class TestRenameFilterPlugin method checkRenaming.

@Test
public void checkRenaming() {
    ConfigSource pluginConfig = Exec.newConfigSource().set("columns", ImmutableMap.of("_c0", "_c0_new"));
    filter.transaction(pluginConfig, SCHEMA, new FilterPlugin.Control() {

        @Override
        public void run(TaskSource task, Schema newSchema) {
            // _c0 -> _c0_new
            Column old0 = SCHEMA.getColumn(0);
            Column new0 = newSchema.getColumn(0);
            assertEquals("_c0_new", new0.getName());
            assertEquals(old0.getType(), new0.getType());
            // _c1 is not changed
            Column old1 = SCHEMA.getColumn(1);
            Column new1 = newSchema.getColumn(1);
            assertEquals("_c1", new1.getName());
            assertEquals(old1.getType(), new1.getType());
        }
    });
}
Also used : ConfigSource(org.embulk.config.ConfigSource) FilterPlugin(org.embulk.spi.FilterPlugin) Column(org.embulk.spi.Column) Schema(org.embulk.spi.Schema) TaskSource(org.embulk.config.TaskSource) Test(org.junit.Test)

Example 33 with ConfigSource

use of org.embulk.config.ConfigSource in project embulk by embulk.

the class TestRenameFilterPlugin method checkFirstCharacterTypesRulePrefixInternal.

private void checkFirstCharacterTypesRulePrefixInternal(final String[] original, final String[] expected, final String prefix, final String[] pass_types, final String pass_characters) {
    HashMap<String, Object> parameters = new HashMap<>();
    parameters.put("rule", "first_character_types");
    if (pass_types.length > 0) {
        parameters.put("pass_types", Arrays.asList(pass_types));
    }
    if (!pass_characters.equals(DEFAULT)) {
        parameters.put("pass_characters", pass_characters);
    }
    if (!prefix.equals(DEFAULT)) {
        parameters.put("prefix", prefix);
    }
    ConfigSource config = Exec.newConfigSource().set("rules", ImmutableList.of(ImmutableMap.copyOf(parameters)));
    renameAndCheckSchema(config, original, expected);
}
Also used : ConfigSource(org.embulk.config.ConfigSource) HashMap(java.util.HashMap)

Example 34 with ConfigSource

use of org.embulk.config.ConfigSource in project embulk by embulk.

the class TestRenameFilterPlugin method checkTruncateRuleNegative.

@Test
public void checkTruncateRuleNegative() {
    final String[] original = { "foo" };
    ConfigSource config = Exec.newConfigSource().set("rules", ImmutableList.of(ImmutableMap.of("rule", "truncate", "max_length", -1)));
    exception.expect(TaskValidationException.class);
    // TODO(dmikurube): Except "Caused by": exception.expectCause(instanceOf(JsonMappingException.class));
    // Needs to import org.hamcrest.Matchers... in addition to org.junit...
    renameAndCheckSchema(config, original, original);
}
Also used : ConfigSource(org.embulk.config.ConfigSource) Test(org.junit.Test)

Example 35 with ConfigSource

use of org.embulk.config.ConfigSource in project embulk by embulk.

the class TestRenameFilterPlugin method checkFirstCharacterTypesRuleBothReplacePrefix.

@Test
public void checkFirstCharacterTypesRuleBothReplacePrefix() {
    HashMap<String, Object> parameters = new HashMap<>();
    parameters.put("rule", "first_character_types");
    parameters.put("replace", "_");
    parameters.put("prefix", "_");
    ConfigSource config = Exec.newConfigSource().set("rules", ImmutableList.of(ImmutableMap.copyOf(parameters)));
    exception.expect(ConfigException.class);
    // TODO(dmikurube): Except "Caused by": exception.expectCause(instanceOf(JsonMappingException.class));
    // Needs to import org.hamcrest.Matchers... in addition to org.junit...
    renameAndCheckSchema(config, new String[0], new String[0]);
}
Also used : ConfigSource(org.embulk.config.ConfigSource) HashMap(java.util.HashMap) Test(org.junit.Test)

Aggregations

ConfigSource (org.embulk.config.ConfigSource)50 Test (org.junit.Test)33 TaskSource (org.embulk.config.TaskSource)12 Schema (org.embulk.spi.Schema)9 HashMap (java.util.HashMap)8 ArrayList (java.util.ArrayList)6 List (java.util.List)6 ConfigDiff (org.embulk.config.ConfigDiff)6 FilterPlugin (org.embulk.spi.FilterPlugin)6 ImmutableList (com.google.common.collect.ImmutableList)5 SchemaConfigException (org.embulk.spi.SchemaConfigException)4 ConfigException (org.embulk.config.ConfigException)3 Column (org.embulk.spi.Column)3 InputPlugin (org.embulk.spi.InputPlugin)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 IOException (java.io.IOException)2 Path (java.nio.file.Path)2 LinkedList (java.util.LinkedList)2 DataSource (org.embulk.config.DataSource)2 TaskReport (org.embulk.config.TaskReport)2