Search in sources :

Example 6 with ConfigSource

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

the class TestFilePreview method assertPreviewedRecords.

private static void assertPreviewedRecords(TestingEmbulk embulk, String loadYamlResourceName, String execYamlResourceName, String sourceCsvResourceName, String resultCsvResourceName) throws IOException {
    Path inputPath = embulk.createTempFile("csv");
    Path outputPath = embulk.createTempFile("csv");
    // in: config
    copyResource(RESOURCE_NAME_PREFIX + sourceCsvResourceName, inputPath);
    ConfigSource load = embulk.loadYamlResource(RESOURCE_NAME_PREFIX + loadYamlResourceName).set("path_prefix", inputPath.toAbsolutePath().toString());
    // exec: config
    final TestingEmbulk.InputBuilder builder = embulk.inputBuilder();
    if (execYamlResourceName != null) {
        final ConfigSource execConfig = embulk.loadYamlResource(RESOURCE_NAME_PREFIX + execYamlResourceName);
        builder.exec(execConfig);
    }
    // execute preview
    final PreviewResult result = builder.in(load).outputPath(outputPath).preview();
    assertThat(readFile(outputPath), is(readResource(RESOURCE_NAME_PREFIX + resultCsvResourceName)));
}
Also used : Path(java.nio.file.Path) ConfigSource(org.embulk.config.ConfigSource) TestingEmbulk(org.embulk.test.TestingEmbulk) PreviewResult(org.embulk.exec.PreviewResult)

Example 7 with ConfigSource

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

the class TestCsvParserPlugin method checkLoadConfig.

@Test
public void checkLoadConfig() {
    ConfigSource config = Exec.newConfigSource().set("charset", "utf-16").set("newline", "LF").set("header_line", true).set("delimiter", "\t").set("quote", "\\").set("allow_optional_columns", true).set("columns", ImmutableList.of(ImmutableMap.of("name", "date_code", "type", "string")));
    CsvParserPlugin.PluginTask task = config.loadConfig(CsvParserPlugin.PluginTask.class);
    assertEquals(Charset.forName("utf-16"), task.getCharset());
    assertEquals(Newline.LF, task.getNewline());
    assertEquals(true, task.getHeaderLine().or(false));
    assertEquals("\t", task.getDelimiter());
    assertEquals(Optional.of(new CsvParserPlugin.QuoteCharacter('\\')), task.getQuoteChar());
    assertEquals(true, task.getAllowOptionalColumns());
}
Also used : ConfigSource(org.embulk.config.ConfigSource) Test(org.junit.Test)

Example 8 with ConfigSource

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

the class TestJsonParserPlugin method checkDefaultValues.

@Test
public void checkDefaultValues() {
    ConfigSource config = Exec.newConfigSource();
    JsonParserPlugin.PluginTask task = config.loadConfig(JsonParserPlugin.PluginTask.class);
    assertEquals(false, task.getStopOnInvalidRecord());
    assertEquals(JsonParserPlugin.InvalidEscapeStringPolicy.PASSTHROUGH, task.getInvalidEscapeStringPolicy());
}
Also used : ConfigSource(org.embulk.config.ConfigSource) Test(org.junit.Test)

Example 9 with ConfigSource

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

the class TestJsonParserPlugin method useStopOnInvalidRecord.

@Test
public void useStopOnInvalidRecord() throws Exception {
    ConfigSource config = this.config.deepCopy().set("stop_on_invalid_record", true);
    try {
        transaction(config, fileInput(// throw DataException
        "[1, 2, 3]"));
        fail();
    } catch (Throwable t) {
        assertTrue(t instanceof DataException);
    }
}
Also used : ConfigSource(org.embulk.config.ConfigSource) DataException(org.embulk.spi.DataException) Test(org.junit.Test)

Example 10 with ConfigSource

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

the class TestRenameFilterPlugin method checkCharacterTypesRuleInternal.

private void checkCharacterTypesRuleInternal(final String[] original, final String[] expected, final String[] pass_types, final String pass_characters, final String replace) {
    HashMap<String, Object> parameters = new HashMap<>();
    parameters.put("rule", "character_types");
    if (pass_types != null) {
        parameters.put("pass_types", ImmutableList.copyOf(pass_types));
    }
    if (!pass_characters.equals(DEFAULT)) {
        parameters.put("pass_characters", pass_characters);
    }
    if (!replace.equals(DEFAULT)) {
        parameters.put("replace", replace);
    }
    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)

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