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)));
}
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());
}
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());
}
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);
}
}
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);
}
Aggregations