Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
E
embulk-input-filename
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Klaus Wölfel
embulk-input-filename
Commits
b907380b
Commit
b907380b
authored
Jun 30, 2017
by
root
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
finished the unit test of the filename input plugin
parent
407b5b1b
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
108 additions
and
8 deletions
+108
-8
build.gradle
build.gradle
+11
-8
src/test/java/org/embulk/input/filename/TestFilenameFileInputPlugin.java
...rg/embulk/input/filename/TestFilenameFileInputPlugin.java
+86
-0
src/test/resources/data/test.csv
src/test/resources/data/test.csv
+2
-0
src/test/resources/test.yml
src/test/resources/test.yml
+9
-0
No files found.
build.gradle
View file @
b907380b
...
...
@@ -14,17 +14,20 @@ configurations {
}
version
=
"0.1.0"
sourceCompatibility
=
1.7
targetCompatibility
=
1.7
dependencies
{
compile
"org.embulk:embulk-core:0.8.
1
3"
provided
"org.embulk:embulk-core:0.8.
1
3"
compile
"org.embulk:embulk-standards:0.8.
1
3"
provided
"org.embulk:embulk-standards:0.8.
1
3"
compile
"org.embulk:embulk-core:0.8.
2
3"
provided
"org.embulk:embulk-core:0.8.
2
3"
compile
"org.embulk:embulk-standards:0.8.
2
3"
provided
"org.embulk:embulk-standards:0.8.
2
3"
// 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"
])
{
...
...
src/test/java/org/embulk/input/filename/TestFilenameFileInputPlugin.java
View file @
b907380b
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
]));
}
}
src/test/resources/data/test.csv
0 → 100644
View file @
b907380b
ABCDEFG
HIJKL
src/test/resources/test.yml
0 → 100644
View file @
b907380b
type
:
filename
parser
:
charset
:
UTF-8
newline
:
CRLF
type
:
csv
delimiter
:
'
^@'
quote
:
'
'
columns
:
-
{
name
:
filename
,
type
:
string
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment