|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.mockrunner.jdbc.FileResultSetFactory
public class FileResultSetFactory
Can be used to create a ResultSet
based on
a table specified in a CSV file. You can specify the delimiter
of the columns (default is ;
). Furthermore you can specify if the first line
contains the column names (default is false
) and if
the column entries should be trimmed (default is true
).
With setUseTemplates(boolean)
you can enable template replacement in the
files (default is false
, i.e. templates are disabled).
The file can be specified directly or by its name. The class
tries to find the file in the absolut or relative path and
(if not found) by calling getResource
. Note that the
file must exist in the local file system and cannot be loaded from
inside a jar archive.
Constructor Summary | |
---|---|
FileResultSetFactory(java.io.File file)
|
|
FileResultSetFactory(java.lang.String fileName)
|
Method Summary | |
---|---|
MockResultSet |
create(java.lang.String id)
|
java.io.File |
getFile()
Get the File being used to read in the
ResultSet . |
void |
setDefaultTemplateConfiguration()
This method sets the default template configuration. |
void |
setDelimiter(java.lang.String delimiter)
Set the delimiter. |
void |
setFirstLineContainsColumnNames(boolean firstLineContainsColumnNames)
Set if the first line contains the column names. |
void |
setTemplateConfiguration(java.lang.String marker,
java.util.Map templates)
This method sets a custom template configuration. |
void |
setTrim(boolean trim)
Set if the column entries should be trimmed. |
void |
setUseTemplates(boolean useTemplates)
Set this to true to allow the use of templates
in data files. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public FileResultSetFactory(java.lang.String fileName)
public FileResultSetFactory(java.io.File file)
Method Detail |
---|
public java.io.File getFile()
File
being used to read in the
ResultSet
. Throws a RuntimeException
if the file does not exist.
public void setDelimiter(java.lang.String delimiter)
delimiter
- the delimiterpublic void setFirstLineContainsColumnNames(boolean firstLineContainsColumnNames)
false
.
public void setTrim(boolean trim)
true
.
public void setUseTemplates(boolean useTemplates)
true
to allow the use of templates
in data files. A template is identified by a marker followed
by a label. The template is replaced by a predefined string in
the corresponding data file. E.g. with the default configuration,
$defaultString
is replaced by an empty string
in the file.
The default configuration which is automatically set uses
$
as a marker. See setDefaultTemplateConfiguration()
for details. You can also set a custom template configuration using
setTemplateConfiguration(String, Map)
.
Default is false
, i.e. templates are disabled.
useTemplates
- set true
to enable templates.public void setTemplateConfiguration(java.lang.String marker, java.util.Map templates)
setUseTemplates(boolean)
for an explanation how templates work.
marker + map key
is replaced by the corresponding map
value
in the data files.
Please use setDefaultTemplateConfiguration()
to set a
default configuration.
marker
- the custom marker replacing the default $
templates
- the custom template mappublic void setDefaultTemplateConfiguration()
setUseTemplates(boolean)
for an explanation how templates work.
The default marker is $
and the default templates are:$defaultString
is replaced by an empty string$defaultDate
is replaced by 1970-01-01
$defaultInteger
is replaced by 0
setTemplateConfiguration(String, Map)
to set a
custom marker and custom templates.
public MockResultSet create(java.lang.String id)
create
in interface ResultSetFactory
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |