org.easetech.easytest.loader
Class CSVDataLoader

java.lang.Object
  extended by org.easetech.easytest.loader.CSVDataLoader
All Implemented Interfaces:
Loader

public class CSVDataLoader
extends Object
implements Loader

An implementation of Loader for the CSV based files. This Loader is responsible for reading and writing to a list of CSV based files and converting them into a data structure which is understandable by the EasyTest framework. It expects the format of the CSV file to be like this :
testGetItems,LibraryId,itemType,searchText
,4,journal,batman ,2,ebook,spiderman
where testGetItems represents the name of the test method for which the test data is being defined,
LibraryId,itemType,searchText represents the test data fields for the test method, and
,4,journal,batman (and ,2,ebook,spiderman) represents the actual test data to be passed to the test method. Each row in the CSV file represents a single set of test data.
Note the leading "," in the test data row. it is mandatory to use and tells the framework that testGetItems is just a method name and does not have any value.
A CSV cannot have a blank line in between test data whether it is for a single test or for multiple tests. The framework is capable of handling multiple test datas for multiple test methods in a single CSV file. Although a user can choose to define the test data in multiple files as well.
If you want to pass a Collection to the test method, just separate each instance with a ":". For eg. to pass a list of Itemids , pass them as a colon separated list like this -> 12:34:5777:9090
This Loader can also write the data back to the file, either for the given method names or for all the methods in the file. This is handy when we want to write the output data back to the file.

Author:
Anuj Kumar

Field Summary
protected static org.slf4j.Logger LOG
          An instance of logger associated with the test framework.
 
Fields inherited from interface org.easetech.easytest.loader.Loader
ACTUAL_RESULT, AMPERSAND, COMMA, DOUBLE_QUOTE, DURATION, EMPTY_STRING, EXPECTED_RESULT, SINGLE_QUOTE, TEST_FAILED, TEST_PASSED, TEST_STATUS
 
Constructor Summary
CSVDataLoader()
          Construct a new CSVDataLoader
CSVDataLoader(List<InputStream> csvInputStreams)
          Construct a new CSVDataLoader and also load the data.
 
Method Summary
 Map<String,List<Map<String,Object>>> loadData(Resource resource)
          Load the data for the given Resource
 void writeData(Resource resource, Map<String,List<Map<String,Object>>> actualData, String... methodNames)
          Write the data back to the file that is represented by the Resource instance
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOG

protected static final org.slf4j.Logger LOG
An instance of logger associated with the test framework.

Constructor Detail

CSVDataLoader

public CSVDataLoader()
Construct a new CSVDataLoader


CSVDataLoader

public CSVDataLoader(List<InputStream> csvInputStreams)
              throws IOException
Construct a new CSVDataLoader and also load the data.

Parameters:
csvInputStreams - the input stream to load the data from
Throws:
IOException - if an IO Exception occurs
Method Detail

loadData

public Map<String,List<Map<String,Object>>> loadData(Resource resource)
Load the data for the given Resource

Specified by:
loadData in interface Loader
Parameters:
resource -
Returns:

writeData

public void writeData(Resource resource,
                      Map<String,List<Map<String,Object>>> actualData,
                      String... methodNames)
Write the data back to the file that is represented by the Resource instance

Specified by:
writeData in interface Loader
Parameters:
resource - the resource instance to which teh data needs to be written
actualData - the actual data that needs to be written
methodNames - OPTIONAL names of methods for which the data needs to be written. If the method names are not provided, then the data is written for all the test methods ofr which teh data is present in the actualData parameter


Copyright © 2013. All Rights Reserved.