Commit b907380b authored by root's avatar root

finished the unit test of the filename input plugin

parent 407b5b1b
......@@ -14,17 +14,20 @@ configurations {
}
version = "0.1.0"
sourceCompatibility = 1.7
targetCompatibility = 1.7
dependencies {
compile "org.embulk:embulk-core:0.8.13"
provided "org.embulk:embulk-core:0.8.13"
compile "org.embulk:embulk-standards:0.8.13"
provided "org.embulk:embulk-standards:0.8.13"
compile "org.embulk:embulk-core:0.8.23"
provided "org.embulk:embulk-core:0.8.23"
compile "org.embulk:embulk-standards:0.8.23"
provided "org.embulk:embulk-standards:0.8.23"
// compile "YOUR_JAR_DEPENDENCY_GROUP:YOUR_JAR_DEPENDENCY_MODULE:YOUR_JAR_DEPENDENCY_VERSION"
testCompile "junit:junit:4.+"
testCompile "org.embulk:embulk-core:0.8.23:tests"
testCompile 'org.embulk:embulk-test:0.8.23'
}
test {
dependsOn cleanTest
testLogging.showStandardStreams = true
}
task classpath(type: Copy, dependsOn: ["jar"]) {
......
package org.embulk.input.filename;
import com.google.common.collect.ImmutableList;
import org.embulk.config.ConfigSource;
import org.embulk.config.ConfigDiff;
import org.embulk.test.EmbulkTests;
import org.embulk.test.TestingEmbulk;
import org.embulk.spi.InputPlugin;
import org.embulk.spi.SchemaConfig;
import org.embulk.spi.ColumnConfig;
import org.junit.Rule;
import org.junit.Before;
import org.junit.Test;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.Files;
import java.io.File;
import java.io.IOException;
import java.util.List;
import static org.embulk.test.EmbulkTests.readSortedFile;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
public class TestFilenameFileInputPlugin
{
private static ConfigSource loadYamlResource(TestingEmbulk embulk, String filename) throws Exception{
// This function help load the config yml file.
return embulk.loadYamlResource(filename);
}
@Rule
public TestingEmbulk embulk = TestingEmbulk.builder()
.registerPlugin(InputPlugin.class,"filename",FilenameFileInputPlugin.class)
.build();
@Test
public void test() throws Exception{
File rootFile = new File(TestFilenameFileInputPlugin.class.getResource("/test.yml").toURI()).getParentFile();
String rootPath = rootFile.getAbsolutePath();
System.out.println("This is the root of the resources: "+rootPath);
Path out1 = Paths.get(rootPath+"/output.csv");
//We can load the yml file in the resource or just define the config below
//ConfigSource config = loadYamlResource(embulk,"/test.yml");
//config = config.set("path_prefix",rootPath+"/data/test.csv");
ConfigSource config = embulk.newConfig()
.set("type","filename")
.set("path_prefix",rootPath+"/data/test.csv")
.set("parser",embulk.newConfig()
.set("charset","UTF-8")
.set("newline","CRLF")
.set("type","csv")
.set("delimiter",",")
.set("quote","")
.set("columns",newSchemaConfig("filename:string")));
//System.out.println(config);
TestingEmbulk.RunResult result1 = embulk.runInput(config,out1);
try {
List<String> sourceLines = Files.readAllLines(Paths.get(rootPath+"/data/test.csv"));
List<String> targetLines = Files.readAllLines(Paths.get(rootPath+"/output.csv"));
char zero = (char) 0;
assertEquals(targetLines.get(0),rootPath+"/data/test.csv"+zero);
//assertEquals(targetLines.get(0).trim(),rootPath+"/data/test.csv");
assertEquals(targetLines.size(),sourceLines.size());
for(int i = 1; i<sourceLines.size(); i++){
assertEquals(targetLines.get(i),sourceLines.get(i));
}
} catch (IOException ex){ex.printStackTrace();}
}
public SchemaConfig newSchemaConfig(String...configs){
ImmutableList.Builder<ColumnConfig> schema = ImmutableList.builder();
for (String column: configs){
ColumnConfig columnConfig = newColumnConfig(column);
if (columnConfig != null){
schema.add(columnConfig);
}
}
return new SchemaConfig(schema.build());
}
public ColumnConfig newColumnConfig(String column){
String[] tuple = column.split(":",2);
return new ColumnConfig(embulk.newConfig()
.set("name",tuple[0])
.set("type",tuple[1]));
}
}
type: filename
parser:
charset: UTF-8
newline: CRLF
type: csv
delimiter: '^@'
quote: ''
columns:
- {name: filename, type: string}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment